forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SPIRV struct reconstruction with bitfields (microsoft#5390)
HLSL/SPIR-V structs have some layout differences due to bitfields being squashed. The reconstruction logic was using the AST layout, and not the new SPIR-V layout, meaning we could generate invalid indices during extraction/construction. This PR fixes a potential bug with bitfields, while making the code reusable. --------- Signed-off-by: Nathan Gauër <[email protected]>
- Loading branch information
Showing
3 changed files
with
152 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tools/clang/test/CodeGenSPIRV/op.structured-buffer.reconstruct.bitfield.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %dxc -T cs_6_0 -E main -HV 2021 | ||
|
||
struct Base { | ||
uint base; | ||
}; | ||
|
||
struct Derived : Base { | ||
uint a; | ||
uint b : 3; | ||
uint c : 3; | ||
uint d; | ||
}; | ||
|
||
RWStructuredBuffer<Derived> g_probes : register(u0); | ||
|
||
[numthreads(64u, 1u, 1u)] | ||
void main(uint3 dispatchThreadId : SV_DispatchThreadID) { | ||
|
||
// CHECK: [[p:%\w+]] = OpVariable %_ptr_Function_Derived_0 Function | ||
Derived p; | ||
|
||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_Base_0 [[p]] %uint_0 | ||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_uint [[tmp]] %int_0 | ||
// CHECK: OpStore [[tmp]] %uint_5 | ||
p.base = 5; | ||
|
||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_uint [[p]] %int_1 | ||
// CHECK: OpStore [[tmp]] %uint_1 | ||
p.a = 1; | ||
|
||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_uint [[p]] %int_2 | ||
// CHECK: [[value:%\d+]] = OpLoad %uint [[tmp]] | ||
// CHECK: [[value:%\d+]] = OpBitFieldInsert %uint [[value]] %uint_2 %uint_0 %uint_3 | ||
// CHECK: OpStore [[tmp]] [[value]] | ||
p.b = 2; | ||
|
||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_uint [[p]] %int_2 | ||
// CHECK: [[value:%\d+]] = OpLoad %uint [[tmp]] | ||
// CHECK: [[value:%\d+]] = OpBitFieldInsert %uint [[value]] %uint_3 %uint_3 %uint_3 | ||
// CHECK: OpStore [[tmp]] [[value]] | ||
p.c = 3; | ||
|
||
// CHECK: [[tmp:%\d+]] = OpAccessChain %_ptr_Function_uint [[p]] %int_3 | ||
// CHECK: OpStore [[tmp]] %uint_4 | ||
p.d = 4; | ||
|
||
|
||
// CHECK: [[p:%\d+]] = OpLoad %Derived_0 [[p]] | ||
// CHECK: [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_Derived %g_probes %int_0 %uint_0 | ||
// CHECK: [[tmp:%\d+]] = OpCompositeExtract %Base_0 [[p]] 0 | ||
// CHECK: [[tmp:%\d+]] = OpCompositeExtract %uint [[tmp]] 0 | ||
// CHECK: [[base:%\d+]] = OpCompositeConstruct %Base [[tmp]] | ||
// CHECK: [[mem1:%\d+]] = OpCompositeExtract %uint [[p]] 1 | ||
// CHECK: [[mem2:%\d+]] = OpCompositeExtract %uint [[p]] 2 | ||
// CHECK: [[mem3:%\d+]] = OpCompositeExtract %uint [[p]] 3 | ||
// CHECK: [[tmp:%\d+]] = OpCompositeConstruct %Derived [[base]] [[mem1]] [[mem2]] [[mem3]] | ||
// CHECK: OpStore [[ptr]] [[tmp]] | ||
g_probes[0] = p; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters