Skip to content

Commit

Permalink
Fix CUDA reflection for acceleration structure handle size. (#6055)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Jan 10, 2025
1 parent 4104aa7 commit a985e24
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/slang/slang-reflection-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ static void emitReflectionResourceTypeBaseInfoJSON(
CASE(TEXTURE_BUFFER, textureBuffer);
CASE(STRUCTURED_BUFFER, structuredBuffer);
CASE(BYTE_ADDRESS_BUFFER, byteAddressBuffer);
CASE(ACCELERATION_STRUCTURE, accelerationStructure);
#undef CASE
}
writer << "\"";
Expand Down
20 changes: 20 additions & 0 deletions source/slang/slang-type-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,15 @@ static LayoutResourceKind _getHLSLLayoutResourceKind(ShaderParameterKind kind)
case ShaderParameterKind::RawBuffer:
case ShaderParameterKind::Buffer:
case ShaderParameterKind::Texture:
case ShaderParameterKind::AccelerationStructure:
return LayoutResourceKind::ShaderResource;

case ShaderParameterKind::MutableStructuredBuffer:
case ShaderParameterKind::MutableRawBuffer:
case ShaderParameterKind::MutableBuffer:
case ShaderParameterKind::MutableTexture:
case ShaderParameterKind::AppendConsumeStructuredBuffer:
case ShaderParameterKind::ShaderStorageBuffer:
return LayoutResourceKind::UnorderedAccess;

case ShaderParameterKind::SamplerState:
Expand Down Expand Up @@ -900,8 +902,10 @@ struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
case ShaderParameterKind::RawBuffer:
case ShaderParameterKind::Buffer:
case ShaderParameterKind::Texture:
case ShaderParameterKind::AccelerationStructure:
return SimpleLayoutInfo(LayoutResourceKind::ShaderResource, 1);

case ShaderParameterKind::ShaderStorageBuffer:
case ShaderParameterKind::MutableStructuredBuffer:
case ShaderParameterKind::MutableRawBuffer:
case ShaderParameterKind::MutableBuffer:
Expand Down Expand Up @@ -1218,6 +1222,8 @@ struct CPUObjectLayoutRulesImpl : ObjectLayoutRulesImpl
sizeof(void*) * 2,
SLANG_ALIGN_OF(void*));

case ShaderParameterKind::ShaderStorageBuffer:
case ShaderParameterKind::AccelerationStructure:
case ShaderParameterKind::SamplerState:
// It's a pointer
return SimpleLayoutInfo(
Expand Down Expand Up @@ -1308,6 +1314,15 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl
_roundToAlignment(sizeof(CUDAPtr) + sizeof(CUDACount), sizeof(CUDAPtr));
return SimpleLayoutInfo(LayoutResourceKind::Uniform, size, sizeof(CUDAPtr));
}
case ShaderParameterKind::ShaderStorageBuffer:
case ShaderParameterKind::AccelerationStructure:
{
// It's a pointer.
return SimpleLayoutInfo(
LayoutResourceKind::Uniform,
sizeof(CUDAPtr),
sizeof(CUDAPtr));
}
case ShaderParameterKind::SamplerState:
{
// In CUDA it seems that sampler states are combined into texture objects.
Expand Down Expand Up @@ -1868,6 +1883,8 @@ struct MetalObjectLayoutRulesImpl : ObjectLayoutRulesImpl
case ShaderParameterKind::Buffer:
case ShaderParameterKind::MutableRawBuffer:
case ShaderParameterKind::MutableBuffer:
case ShaderParameterKind::ShaderStorageBuffer:
case ShaderParameterKind::AccelerationStructure:
return SimpleLayoutInfo(LayoutResourceKind::MetalBuffer, 1);
case ShaderParameterKind::AppendConsumeStructuredBuffer:
return SimpleLayoutInfo(LayoutResourceKind::MetalBuffer, 2);
Expand Down Expand Up @@ -1934,6 +1951,8 @@ struct MetalArgumentBufferElementLayoutRulesImpl : ObjectLayoutRulesImpl, Defaul
case ShaderParameterKind::TextureUniformBuffer:
case ShaderParameterKind::Texture:
case ShaderParameterKind::SamplerState:
case ShaderParameterKind::ShaderStorageBuffer:
case ShaderParameterKind::AccelerationStructure:
{
return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1);
}
Expand Down Expand Up @@ -4657,6 +4676,7 @@ static TypeLayoutResult _createTypeLayout(TypeLayoutContext& context, Type* type
CASE(GLSLInputAttachmentType, InputRenderTarget);

// This case is mostly to allow users to add new resource types...
CASE(RaytracingAccelerationStructureType, AccelerationStructure);
CASE(UntypedBufferResourceType, RawBuffer);

CASE(GLSLShaderStorageBufferType, MutableRawBuffer);
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-type-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ enum class ShaderParameterKind
AtomicUint,

SubpassInput,

AccelerationStructure,
ParameterBlock,
};

Expand Down
8 changes: 8 additions & 0 deletions tests/reflection/acceleration-structure.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//TEST(64-bit):REFLECTION(filecheck=CHECK): -target cuda

// CHECK: "binding": {"kind": "uniform", "offset": 0, "size": 8},
uniform RaytracingAccelerationStructure accel;

[numthreads(1,1,1)]
void main()
{}

0 comments on commit a985e24

Please sign in to comment.