Skip to content

Commit 3125e84

Browse files
committed
Fix cbuffer PushConstants.
1 parent 9c3cb73 commit 3125e84

File tree

2 files changed

+9
-56
lines changed

2 files changed

+9
-56
lines changed

Tests/DiligentCoreTest/assets/shaders/SPIRV/MixedResources.psh

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,16 @@ RWTexture2D<float4> StorageTex : register(u1);
2727
// Sampler
2828
SamplerState Sampler : register(s0);
2929

30-
// Test for push constants
30+
// Test struct for push constants
3131
struct PushConstants_t
3232
{
3333
float2 Offset;
3434
float Time;
3535
uint FrameCount;
3636
};
3737

38-
#if DXC
39-
40-
#define g_PushConstants PushConstants
41-
42-
[[vk::push_constant]]
43-
PushConstants_t g_PushConstants;
44-
45-
#else
46-
47-
[[vk::push_constant]]
48-
cbuffer PushConstants
49-
{
50-
PushConstants_t g_PushConstants;
51-
};
52-
53-
#endif
38+
//note that cbuffer PushConstants is not allowed in DXC, but ConstantBuffer<PushConstants_t> is allowed
39+
[[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants;
5440

5541
float4 main() : SV_Target
5642
{
@@ -70,8 +56,8 @@ float4 main() : SV_Target
7056
StorageTex[uint2(0, 0)] = color;
7157

7258
// Use push constant data
73-
color.xy += g_PushConstants.Offset;
74-
color.rgb *= sin(g_PushConstants.Time) * 0.5 + 0.5;
59+
color.xy += PushConstants.Offset;
60+
color.rgb *= sin(PushConstants.Time) * 0.5 + 0.5;
7561

7662
return color;
7763
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/PushConstants.psh

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,16 @@ struct PushConstants_t
88
uint g_Padding;
99
};
1010

11-
/*
12-
Note that glslang allows following declaration:
13-
14-
[[vk::push_constant]]
15-
cbuffer PushConstants
16-
{
17-
PushConstants_t g_PushConstants;
18-
};
19-
20-
to generate a push constant resource: "Push Constants 'PushConstants'".
21-
22-
but DXC does not allow it.
23-
24-
Glslang converts "[[vk::push_constant]] PushConstants_t g_PushConstants;" into an unnamed resource:
25-
"Uniform Buffer '$Global'" instead of what we expected: "Push Constants 'PushConstants'",
26-
27-
Thus we have to use "[[vk::push_constant]] cbuffer PushConstants" under glslang while "[[vk::push_constant]] PushConstants_t g_PushConstants;" under DXC.
28-
*/
29-
30-
#if DXC
31-
32-
#define g_PushConstants PushConstants
33-
34-
[[vk::push_constant]]
35-
PushConstants_t g_PushConstants;
36-
37-
#else
38-
39-
[[vk::push_constant]]
40-
cbuffer PushConstants
41-
{
42-
PushConstants_t g_PushConstants;
43-
};
44-
45-
#endif
11+
//note that cbuffer PushConstants is not allowed in DXC, but ConstantBuffer<PushConstants_t> is allowed
12+
[[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants;
4613

4714
float4 main() : SV_Target
4815
{
4916
// Use push constant data through the structure instance
50-
float4 result = g_PushConstants.g_Color * g_PushConstants.g_Scale;
17+
float4 result = PushConstants.g_Color * PushConstants.g_Scale;
5118

5219
// Apply offset to result (simplified example)
53-
result.xy += g_PushConstants.g_Offset;
20+
result.xy += PushConstants.g_Offset;
5421

5522
return result;
5623
}

0 commit comments

Comments
 (0)