Skip to content

Commit f687155

Browse files
authored
[SPIR-V] fix variable with inline SC added to CB (#7967)
Before this commit, non-static global variables with a inline SPIR-V ext_storage_class attribute were added to the default constant buffer global struct. This is an issue as the point of a custom storage class is to create globals such as acceleration structures. Fixes #7742
1 parent 4d616c7 commit f687155

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ bool shouldSkipInStructLayout(const Decl *decl) {
330330
return true;
331331
}
332332

333+
if (decl->hasAttr<VKStorageClassExtAttr>()) {
334+
return true;
335+
}
336+
333337
// External visibility
334338
if (const auto *declDecl = dyn_cast<DeclaratorDecl>(decl))
335339
if (!declDecl->hasExternalFormalLinkage())
@@ -1183,14 +1187,15 @@ SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var) {
11831187
SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var,
11841188
QualType type) {
11851189
const bool isGroupShared = var->hasAttr<HLSLGroupSharedAttr>();
1190+
const bool hasInlineSpirvSC = var->hasAttr<VKStorageClassExtAttr>();
11861191
const bool isACSBuffer =
11871192
isAppendStructuredBuffer(type) || isConsumeStructuredBuffer(type);
11881193
const bool isRWSBuffer = isRWStructuredBuffer(type);
11891194
const auto storageClass = getStorageClassForExternVar(type, isGroupShared);
11901195
const auto rule = getLayoutRuleForExternVar(type, spirvOptions);
11911196
const auto loc = var->getLocation();
11921197

1193-
if (!isGroupShared && !isResourceType(type) &&
1198+
if (!isGroupShared && !isResourceType(type) && !hasInlineSpirvSC &&
11941199
!isResourceOnlyStructure(type)) {
11951200

11961201
// We currently cannot support global structures that contain both resources
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// RUN: %dxc -T ps_6_0 -E main -spirv -Vd -fcgl %s -spirv | FileCheck %s
22

3-
//CHECK: [[payloadTy:%[a-zA-Z0-9_]+]] = OpTypeStruct %v4float
4-
//CHECK-NEXT: [[payloadTyPtr:%[a-zA-Z0-9_]+]] = OpTypePointer RayPayloadKHR [[payloadTy]]
5-
//CHECK: [[crossTy:%[a-zA-Z0-9_]+]] = OpTypePointer CrossWorkgroup %int
6-
//CHECK: {{%[a-zA-Z0-9_]+}} = OpVariable [[payloadTyPtr]] RayPayloadKHR
7-
//CHECK: {{%[a-zA-Z0-9_]+}} = OpVariable [[crossTy]] CrossWorkgroup
8-
3+
[[vk::ext_extension("SPV_KHR_ray_tracing")]]
4+
[[vk::ext_capability(/* RayTracingKHR */ 4479)]]
95
[[vk::ext_storage_class(/*RayPayloadKHR*/5338)]]
106
float4 payload;
7+
// CHECK-DAG: [[ptr_payload_v4:%[a-zA-Z0-9_]+]] = OpTypePointer RayPayloadKHR %v4float
8+
// CHECK-DAG: %payload = OpVariable [[ptr_payload_v4]] RayPayloadKHR
119

1210
int main() : SV_Target0 {
13-
[[vk::ext_storage_class(/* CrossWorkgroup */ 5)]] int foo = 3;
11+
12+
[[vk::ext_storage_class(/* CrossWorkgroup */ 5)]]
13+
int foo = 3;
14+
// CHECK-DAG: [[ptr_cw_int:%[a-zA-Z0-9_]+]] = OpTypePointer CrossWorkgroup %int
15+
// CHECK-DAG: %foo = OpVariable [[ptr_cw_int]] CrossWorkgroup
16+
1417
return foo;
1518
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %dxc %s -T cs_6_8 -spirv -fspv-target-env=vulkan1.3 -E main -O0 | FileCheck %s
2+
3+
// CHECK-DAG: OpCapability RuntimeDescriptorArray
4+
// CHECK-DAG: OpCapability RayQueryKHR
5+
6+
using A = vk::SpirvOpaqueType</* OpTypeAccelerationStructureKHR */ 5341>;
7+
// CHECK: %[[name:[^ ]+]] = OpTypeAccelerationStructureKHR
8+
9+
using RA [[vk::ext_capability(/* RuntimeDescriptorArray */ 5302)]] = vk::SpirvOpaqueType</* OpTypeRuntimeArray */ 29, A>;
10+
// CHECK: %[[rarr:[^ ]+]] = OpTypeRuntimeArray %[[name]]
11+
12+
// CHECK: %[[ptr:[^ ]+]] = OpTypePointer UniformConstant %[[rarr]]
13+
// CHECK: %MyScene = OpVariable %[[ptr]] UniformConstant
14+
[[vk::ext_storage_class(0)]]
15+
RA MyScene;
16+
17+
[numthreads(1, 1, 1)]
18+
void main() {}

0 commit comments

Comments
 (0)