Skip to content

Commit 38e0ea8

Browse files
authored
[SPIR-V] Fix layout rule on ConstantBuffer alias (#7960)
When a CB or derivative was passed as parameter, the layout rules were not passed, meaning the loaded type would get extracted, but to the wrong type. Fixes #7954
1 parent aa9b462 commit 38e0ea8

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,9 @@ DeclResultIdMapper::createFnParam(const ParmVarDecl *param,
10641064
(void)getTypeAndCreateCounterForPotentialAliasVar(param, &isAlias);
10651065
fnParamInstr->setContainsAliasComponent(isAlias);
10661066

1067+
if (isConstantTextureBuffer(type))
1068+
fnParamInstr->setLayoutRule(spirvOptions.cBufferLayoutRule);
1069+
10671070
assert(astDecls[param].instr == nullptr);
10681071
registerVariableForDecl(param, fnParamInstr);
10691072

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK-DAG: OpMemberDecorate %Inner 0 Offset 0
4+
5+
// CHECK-DAG: %Inner = OpTypeStruct %float
6+
// CHECK-DAG: %type_ConstantBuffer_CBS = OpTypeStruct %Inner
7+
// CHECK-DAG: %Inner_0 = OpTypeStruct %float
8+
// CHECK-DAG: %CBS = OpTypeStruct %Inner_0
9+
struct Inner
10+
{
11+
float field;
12+
};
13+
14+
struct CBS
15+
{
16+
Inner entry;
17+
};
18+
19+
float foo(ConstantBuffer<CBS> param)
20+
{
21+
CBS alias = param;
22+
// CHECK: [[copy:%[0-9]+]] = OpLoad %type_ConstantBuffer_CBS %param
23+
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %Inner [[copy]]
24+
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]]
25+
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %Inner_0 [[e2]]
26+
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %CBS [[c2]]
27+
// CHECK: OpStore %alias [[c1]]
28+
return alias.entry.field;
29+
}
30+
31+
ConstantBuffer<CBS> input;
32+
33+
float main() : A
34+
{
35+
return foo(input);
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK-DAG: OpMemberDecorate %Inner 0 Offset 0
4+
5+
// CHECK-DAG: %Inner = OpTypeStruct %float
6+
// CHECK-DAG: %type_TextureBuffer_CBS = OpTypeStruct %Inner
7+
// CHECK-DAG: %Inner_0 = OpTypeStruct %float
8+
// CHECK-DAG: %CBS = OpTypeStruct %Inner_0
9+
struct Inner
10+
{
11+
float field;
12+
};
13+
14+
struct CBS
15+
{
16+
Inner entry;
17+
};
18+
19+
float foo(TextureBuffer<CBS> param)
20+
{
21+
CBS alias = param;
22+
// CHECK: [[copy:%[0-9]+]] = OpLoad %type_TextureBuffer_CBS %param
23+
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %Inner [[copy]]
24+
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]]
25+
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %Inner_0 [[e2]]
26+
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %CBS [[c2]]
27+
// CHECK: OpStore %alias [[c1]]
28+
return alias.entry.field;
29+
}
30+
31+
TextureBuffer<CBS> input;
32+
33+
float main() : A
34+
{
35+
return foo(input);
36+
}
37+

0 commit comments

Comments
 (0)