forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPIR-V] Fix static const in push constants (microsoft#6403)
Struct lowering is slightly different for push constants, and we didn't checked if the field was static or not. In SPIR-V, when a field is const static, we either replace all loads by a the immediate (when usage is `Struct::field`), or create a global variable we initialize to the correct value and reference instead. The field is then ignored from the struct definition, and this variable is used. This hasn't changed with this commit, I just made push-buffers use the same logic. Fixed microsoft#6006 --------- Signed-off-by: Nathan Gauër <[email protected]>
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 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
34 changes: 34 additions & 0 deletions
34
tools/clang/test/CodeGenSPIRV/vk.push-constant.static.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,34 @@ | ||
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
struct S | ||
{ | ||
const static uint a = 1; | ||
uint b; | ||
}; | ||
|
||
// CHECK: OpMemberName %type_PushConstant_S 0 "b" | ||
// CHECK: %type_PushConstant_S = OpTypeStruct %uint | ||
// CHECK: %_ptr_PushConstant_type_PushConstant_S = OpTypePointer PushConstant %type_PushConstant_S | ||
|
||
[[vk::push_constant]] S s; | ||
// CHECK: %a = OpVariable %_ptr_Private_uint Private | ||
// CHECK: %s = OpVariable %_ptr_PushConstant_type_PushConstant_S PushConstant | ||
|
||
// CHECK: OpStore %a %uint_1 | ||
|
||
[numthreads(1,1,1)] | ||
void main() | ||
{ | ||
uint32_t v = s.b; | ||
// CHECK: %v = OpVariable %_ptr_Function_uint Function | ||
// CHECK: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_PushConstant_uint %s %int_0 | ||
// CHECK: [[load:%[0-9]+]] = OpLoad %uint [[ptr]] | ||
// CHECK: OpStore %v [[load]] | ||
|
||
uint32_t w = S::a; | ||
// CHECK: OpStore %w %uint_1 | ||
|
||
uint32_t x = s.a; | ||
// CHECK: [[load:%[0-9]+]] = OpLoad %uint %a | ||
// CHECK: OpStore %x [[load]] | ||
} |