summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-wgsl.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-11-05 16:31:47 -0800
committerGitHub <noreply@github.com>2024-11-05 16:31:47 -0800
commit79056cd7e0ba261a007e21a98a6f49cb0b032e25 (patch)
treef08c26c9f16ddbfb4a890ce7d201f27d037ccd03 /source/slang/slang-emit-wgsl.cpp
parent4fa76f374c0c35c9c7d186e8addf6861e98baaec (diff)
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>
Diffstat (limited to 'source/slang/slang-emit-wgsl.cpp')
-rw-r--r--source/slang/slang-emit-wgsl.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp
index dea95c6ec..256697bc7 100644
--- a/source/slang/slang-emit-wgsl.cpp
+++ b/source/slang/slang-emit-wgsl.cpp
@@ -236,6 +236,32 @@ static bool isPowerOf2(const uint32_t n)
return (n != 0U) && ((n - 1U) & n) == 0U;
}
+bool WGSLSourceEmitter::maybeEmitSystemSemantic(IRInst* inst)
+{
+ if (auto sysSemanticDecor = inst->findDecoration<IRTargetSystemValueDecoration>())
+ {
+ m_writer->emit("@builtin(");
+ m_writer->emit(sysSemanticDecor->getSemantic());
+ m_writer->emit(")");
+ return true;
+ }
+ return false;
+}
+
+void WGSLSourceEmitter::emitSemanticsPrefixImpl(IRInst* inst)
+{
+ if (!maybeEmitSystemSemantic(inst))
+ {
+ if (auto semanticDecoration = inst->findDecoration<IRSemanticDecoration>())
+ {
+ m_writer->emit("@location(");
+ m_writer->emit(semanticDecoration->getSemanticIndex());
+ m_writer->emit(")");
+ return;
+ }
+ }
+}
+
void WGSLSourceEmitter::emitStructFieldAttributes(IRStructType* structType, IRStructField* field)
{
// Tint emits errors unless we explicitly spell out the layout in some cases, so emit