Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions tools/clang/lib/AST/HlslTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,17 +753,7 @@ clang::RecordDecl *GetRecordDeclFromNodeObjectType(clang::QualType ObjectTy) {
}

bool IsHLSLRayQueryType(clang::QualType type) {
type = type.getCanonicalType();
if (const RecordType *RT = dyn_cast<RecordType>(type)) {
if (const ClassTemplateSpecializationDecl *templateDecl =
dyn_cast<ClassTemplateSpecializationDecl>(
RT->getAsCXXRecordDecl())) {
StringRef name = templateDecl->getName();
if (name == "RayQuery")
return true;
}
}
return false;
return nullptr != getAttr<HLSLRayQueryObjectAttr>(type);
}

#ifdef ENABLE_SPIRV_CODEGEN
Expand Down
7 changes: 4 additions & 3 deletions tools/clang/lib/SPIRV/AstTypeProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,13 @@ bool isOpaqueType(QualType type) {
if (name == "RaytracingAccelerationStructure")
return true;

if (name == "RayQuery")
return true;

if (name == "SubpassInput")
return true;
}

if (hlsl::IsHLSLRayQueryType(type))
Comment thread
brendan-duncan marked this conversation as resolved.
return true;

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ LowerTypeVisitor::lowerResourceType(QualType type, SpirvLayoutRule rule,
return spvContext.getAccelerationStructureTypeNV();
}

if (name == "RayQuery")
if (hlsl::IsHLSLRayQueryType(type))
Comment thread
brendan-duncan marked this conversation as resolved.
return spvContext.getRayQueryTypeKHR();

if (name == "StructuredBuffer" || name == "RWStructuredBuffer" ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %dxc -T cs_6_6 -E MainRayGenShader -fcgl -spirv %s | FileCheck %s --implicit-check-not=OpTypeRayQueryKHR

// A user-defined struct named "RayQuery" that shadows the reserved intrinsic
// name must be lowered as an ordinary struct, not as the opaque ray query
// type. Previously this crashed the SPIR-V backend.
// See https://github.com/microsoft/DirectXShaderCompiler/issues/8601

namespace UnifiedRT {
struct RayQuery {
float4 foo;
};
} // namespace UnifiedRT

// The shadowing struct is lowered to an ordinary struct with a float4 field,
// and the local variable uses that struct type in the Function storage class.
// CHECK: %RayQuery = OpTypeStruct %v4float
// CHECK: %_ptr_Function_RayQuery = OpTypePointer Function %RayQuery
// CHECK: %rayQuery = OpVariable %_ptr_Function_RayQuery Function

// It must not be lowered to the opaque ray query type. The absence of
// OpTypeRayQueryKHR anywhere in the module is checked by the
// --implicit-check-not on the FileCheck invocation above.

StructuredBuffer<uint> _UnifiedRT_DispatchDims;

[numthreads(128, 1, 1)]
void MainRayGenShader(in uint3 gidx : SV_DispatchThreadID,
in uint lidx : SV_GroupIndex) {
if (gidx.x >= _UnifiedRT_DispatchDims[0] ||
gidx.y >= _UnifiedRT_DispatchDims[1] ||
gidx.z >= _UnifiedRT_DispatchDims[2])
return;

UnifiedRT::RayQuery rayQuery;
rayQuery.foo = float4(1.0, 1.0, 1.0, 1.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %dxc -T cs_6_6 -E MainRayGenShader -HV 2021 -fcgl -spirv %s | FileCheck %s --implicit-check-not=OpTypeRayQueryKHR

// A user-defined class template named "RayQuery" that shadows the reserved
// intrinsic name must be lowered as an ordinary struct, not as the opaque ray
// query type. The intrinsic is itself a class template, so detecting it by
// name and specialization kind alone also misclassifies this case.
// See https://github.com/microsoft/DirectXShaderCompiler/issues/8601

namespace UnifiedRT {
template <typename T> struct RayQuery {
T foo;
};
} // namespace UnifiedRT

// The shadowing template instance is lowered to an ordinary struct with a
// float4 field, and the local variable uses that struct type in the Function
// storage class.
// CHECK: %RayQuery = OpTypeStruct %v4float
// CHECK: %_ptr_Function_RayQuery = OpTypePointer Function %RayQuery
// CHECK: %rayQuery = OpVariable %_ptr_Function_RayQuery Function

StructuredBuffer<uint> _UnifiedRT_DispatchDims;

[numthreads(128, 1, 1)]
void MainRayGenShader(in uint3 gidx : SV_DispatchThreadID,
in uint lidx : SV_GroupIndex) {
if (gidx.x >= _UnifiedRT_DispatchDims[0] ||
gidx.y >= _UnifiedRT_DispatchDims[1] ||
gidx.z >= _UnifiedRT_DispatchDims[2])
return;

UnifiedRT::RayQuery<float4> rayQuery;
rayQuery.foo = float4(1.0, 1.0, 1.0, 1.0);
}
Loading