From 79056cd7e0ba261a007e21a98a6f49cb0b032e25 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:31:47 -0800 Subject: Legalize the Entry-point for WGSL (#5498) * Legalize the Entry-point for WGSL The return type of the entry-point needs to be legalized when targeting WGSL. This commit flattens the nested-structs of the return type and the input parameters of the entry-point. Most of code is copied from the legalization code for Metal. The following functions are exactly same to the implementation for Metal or almost same. - flattenInputParameters() : 136 lines - reportUnsupportedSystemAttribute() : 7 lines - ensureResultStructHasUserSemantic() : 46 lines - struct MapStructToFlatStruct : 176 lines - flattenNestedStructs() : 95 lines - maybeFlattenNestedStructs() : 42 lines - _replaceAllReturnInst() : 19 lines - _returnNonOverlappingAttributeIndex() : 16 lines - _replaceAttributeOfLayout() : 23 lines - tryConvertValue() : 41 lines - legalizeSystemValueParameters() : 11 lines They need to be refactored to reduce the duplication later. The test case, `tests/compute/assoctype-lookup.slang`, had a bug that the compute shader was trying to use the varying input/output with the user defined semantics. This commit removes the user defined semantics, because the compute shaders cannot use the user defined semantics. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-emit-c-like.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 5d04a50db..020c31fdc 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3293,6 +3293,11 @@ void CLikeSourceEmitter::emitSemanticsUsingVarLayout(IRVarLayout* varLayout) } } +void CLikeSourceEmitter::emitSemanticsPrefix(IRInst* inst) +{ + emitSemanticsPrefixImpl(inst); +} + void CLikeSourceEmitter::emitSemantics(IRInst* inst, bool allowOffsetLayout) { emitSemanticsImpl(inst, allowOffsetLayout); @@ -3869,6 +3874,7 @@ void CLikeSourceEmitter::emitStructDeclarationsBlock( emitPackOffsetModifier(fieldKey, fieldType, packOffsetDecoration); } } + emitSemanticsPrefix(fieldKey); emitStructFieldAttributes(structType, ff); emitMemoryQualifiers(fieldKey); emitType(fieldType, getName(fieldKey)); -- cgit v1.2.3