summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-11-06 16:42:46 -0800
committerGitHub <noreply@github.com>2024-11-06 16:42:46 -0800
commit65de5452b71a311d66169ea16334e84d7e6465c1 (patch)
tree761919385f68123e00657794400fc463e371c0d1 /source
parent989847f6a9408b68e90ac242f4a19d3266054c3e (diff)
Fix the WGSL error about semantic when a nested struct is inlined (#5506)
After a struct with a semantic is inlined to a newly synthasized struct, the previous semantic must be removed in order to avoid duplicated semantic on the same location. The following function is copied from slang-ir-metal-legalize.cpp, - removeSemanticLayoutsFromLegalizedStructs() This must be refactored to reduce the code duplication later. Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-wgsl-legalize.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/source/slang/slang-ir-wgsl-legalize.cpp b/source/slang/slang-ir-wgsl-legalize.cpp
index 6e554a8f8..b990ad12f 100644
--- a/source/slang/slang-ir-wgsl-legalize.cpp
+++ b/source/slang/slang-ir-wgsl-legalize.cpp
@@ -30,6 +30,32 @@ struct LegalizeWGSLEntryPointContext
{
}
+ void removeSemanticLayoutsFromLegalizedStructs()
+ {
+ // WGSL does not allow duplicate attributes to appear in the same shader.
+ // If we emit our own struct with `[[color(0)]`, all existing uses of `[[color(0)]]`
+ // must be removed.
+ for (auto field : semanticInfoToRemove)
+ {
+ auto key = field->getKey();
+ // Some decorations appear twice, destroy all found
+ for (;;)
+ {
+ if (auto semanticDecor = key->findDecoration<IRSemanticDecoration>())
+ {
+ semanticDecor->removeAndDeallocate();
+ continue;
+ }
+ else if (auto layoutDecor = key->findDecoration<IRLayoutDecoration>())
+ {
+ layoutDecor->removeAndDeallocate();
+ continue;
+ }
+ break;
+ }
+ }
+ }
+
// Flattens all struct parameters of an entryPoint to ensure parameters are a flat struct
void flattenInputParameters(EntryPointInfo entryPoint)
{
@@ -1419,9 +1445,8 @@ void legalizeIRForWGSL(IRModule* module, DiagnosticSink* sink)
LegalizeWGSLEntryPointContext context(sink, module);
for (auto entryPoint : entryPoints)
- {
context.legalizeEntryPointForWGSL(entryPoint);
- }
+ context.removeSemanticLayoutsFromLegalizedStructs();
// Go through every instruction in the module and legalize them as needed.
context.processInst(module->getModuleInst());