Skip to content

Commit

Permalink
Bug fixes for the direct spirv backend. (#3474)
Browse files Browse the repository at this point in the history
* Fix GLSL legalization bug that leads to crash.

* Update diagnostic id to avoid conflict.

* Fix std140 layout logic.

---------

Co-authored-by: Yong He <yhe@nvidia.com>
  • Loading branch information
csyonghe and Yong He authored Jan 22, 2024
1 parent c4e42ab commit fec9c42
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 8 additions & 2 deletions source/slang/slang-ir-glsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions source/slang/slang-ir-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down
17 changes: 17 additions & 0 deletions tests/spirv/std140-layout.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

//TEST:SIMPLE(filecheck=SPIRV): -stage fragment -entry main -target spirv -emit-spirv-directly

// SPIRV: OpMemberDecorate %{{.*}} 0 Offset 0
// SPIRV: OpMemberDecorate %{{.*}} 1 Offset 16
// SPIRV: OpMemberDecorate %{{.*}} 2 Offset 28

uniform float3 v0;
uniform float3 v1;
uniform float v2;



float4 main() : SV_Target
{
return float4(v2);
}

0 comments on commit fec9c42

Please sign in to comment.