From fec9c42d4c61d1bdd54d020d55a3155e0d54fce7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 22 Jan 2024 15:19:26 -0800 Subject: Bug fixes for the direct spirv backend. (#3474) * Fix GLSL legalization bug that leads to crash. * Update diagnostic id to avoid conflict. * Fix std140 layout logic. --------- Co-authored-by: Yong He --- source/slang/slang-diagnostic-defs.h | 2 +- source/slang/slang-ir-glsl-legalize.cpp | 10 ++++++++-- source/slang/slang-ir-layout.cpp | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index b7189ab0d..9bad4b716 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -451,7 +451,7 @@ DIAGNOSTIC(30510, Error, loopInDiffFuncRequireUnrollOrMaxIters, "loops inside a DIAGNOSTIC(39999, Fatal, cyclicReference, "cyclic reference '$0'.") DIAGNOSTIC(39999, Error, localVariableUsedBeforeDeclared, "local variable '$0' is being used before its declaration.") DIAGNOSTIC(39999, Error, variableUsedInItsOwnDefinition, "the initial-value expression for variable '$0' depends on the value of the variable itself") -DIAGNOSTIC(39001, Fatal , cannotProcessInclude, "internal compiler error: cannot process '__include' in the current semantic checking context.") +DIAGNOSTIC(39901, Fatal , cannotProcessInclude, "internal compiler error: cannot process '__include' in the current semantic checking context.") // 304xx: generics DIAGNOSTIC(30400, Error, genericTypeNeedsArgs, "generic type '$0' used without argument") diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index 4d2b12bc4..65efde214 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -1599,7 +1599,10 @@ void assign( auto arrayIndexInst = builder->getIntValue(builder->getIntType(), arrayIndex); // Store to the index - auto address = builder->emitElementAddress(right.irValue->getFullType(), left.irValue, arrayIndexInst); + auto address = builder->emitElementAddress( + builder->getPtrType(right.irValue->getFullType()), + left.irValue, + arrayIndexInst); builder->emitStore(address, rhs); break; @@ -1613,7 +1616,10 @@ void assign( auto address = left.irValue; if(index) { - address = builder->emitElementAddress(right.irValue->getFullType(), left.irValue, index); + address = builder->emitElementAddress( + builder->getPtrType(right.irValue->getFullType()), + left.irValue, + index); } builder->emitStore(address, right.irValue); break; diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp index 79012e7ba..a6684c7b1 100644 --- a/source/slang/slang-ir-layout.cpp +++ b/source/slang/slang-ir-layout.cpp @@ -461,9 +461,10 @@ struct Std140LayoutRules : IRTypeLayoutRules } virtual IRSizeAndAlignment getVectorSizeAndAlignment(IRSizeAndAlignment element, IRIntegerValue count) { + IRIntegerValue alignmentCount = count; if (count == 3) - count = 4; - return IRSizeAndAlignment((int)(element.size * count), (int)(element.size * count)); + alignmentCount = 4; + return IRSizeAndAlignment((int)(element.size * count), (int)(element.size * alignmentCount)); } }; -- cgit v1.2.3