Skip to content

Commit bb373fb

Browse files
authored
[spirv] Avoid adding spec and push constants to global ubo (microsoft#6832)
The code the decides which global variables to include in the implicit global cbuffer does not check for spec constant or push constant. They end up being incorrectly include in it, causing problems. The solution is to add those to the type of variable that should be skipped. Fixes microsoft#4542
1 parent ef043e9 commit bb373fb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ bool shouldSkipInStructLayout(const Decl *decl) {
320320
// $Globals' "struct" is the TranslationUnit, so we should ignore resources
321321
// in the TranslationUnit "struct" and its child namespaces.
322322
if (declContext->isTranslationUnit() || declContext->isNamespace()) {
323+
324+
if (decl->hasAttr<VKConstantIdAttr>()) {
325+
return true;
326+
}
327+
328+
if (decl->hasAttr<VKPushConstantAttr>()) {
329+
return true;
330+
}
331+
323332
// External visibility
324333
if (const auto *declDecl = dyn_cast<DeclaratorDecl>(decl))
325334
if (!declDecl->hasExternalFormalLinkage())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %dxc -T ps_6_0 -E main %s -spirv | FileCheck %s
2+
3+
// This test checks that the specialization constant and push constants are not
4+
// included in the implicit global ubo.
5+
6+
// CHECK: OpDecorate %mySpecializationConstant SpecId 1
7+
// CHECK: %mySpecializationConstant = OpSpecConstant %int 0
8+
[[ vk::constant_id ( 1 )]] const int mySpecializationConstant = 0;
9+
10+
// CHECK: %push_const = OpVariable %_ptr_PushConstant_type_PushConstant_ PushConstant
11+
[[ vk::push_constant]] struct { int value; } push_const;
12+
13+
14+
15+
float myGlobal;
16+
17+
float4 main(float4 col : COLOR) : SV_Target0
18+
{
19+
if(mySpecializationConstant && push_const.value)
20+
return 0.xxxx;
21+
22+
return myGlobal.xxxx;
23+
}

0 commit comments

Comments
 (0)