shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
3.2k stars 214 forks source link

PushConstant gets mistakenly recognized as binding #5693

Open fknfilewalker opened 6 days ago

fknfilewalker commented 6 days ago

The following code, produces the following error


[[vk::binding(0, 0)]] RWTexture2D<float4> output;
[[vk::push_constant]] RaytracingAccelerationStructure tlas;

[shader("raygeneration")]
void rayGenMain()
{}
VUID-VkRayTracingPipelineCreateInfoKHR-layout-07988(ERROR / SPEC): msgNum: -859700687 - Validation Error: [ VUID-VkRayTracingPipelineCreateInfoKHR-layout-07988 ] Object 0: handle = 0x4fac1c0000000032, type = VK_OBJECT_TYPE_SHADER_MODULE; Object 1: handle = 0xa808d50000000033, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0xccc20231 | vkCreateRayTracingPipelinesKHR(): pCreateInfos[0].pStages[0] SPIR-V (VK_SHADER_STAGE_RAYGEN_BIT_KHR) uses descriptor [Set 0, Binding 1, variable "tlas"] (type VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) but was not declared in the pipeline layout.
The Vulkan spec states: If a resource variables is declared in a shader, a descriptor slot in layout must match the shader stage (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkRayTracingPipelineCreateInfoKHR-layout-07988)
    Objects: 2
        [0] 0x4fac1c0000000032, type: 15, name: NULL
        [1] 0xa808d50000000033, type: 17, name: NULL

For some reason the pushconstant is a descriptor binding (set 0, binding 1)

csyonghe commented 1 day ago

RaytracingAccelerationStructure is an opaque handle and it is not possible to place it as a push constant in SPIRV. Therefore the [vk::push_constant] attribute has no meaning and is ignored by the compiler.

fknfilewalker commented 1 day ago

Oh ok but cast from uint64 should work? At least in glsl this worked.

csyonghe commented 1 day ago

Casting from uint64 to AccelerationStructure is not valid in HLSL and it is not supported in Slang either. D3D does not specify that AccelerationStructure can be constructed from uint64. If we add such support in Slang, it won't be a cross-platform operation either.

fknfilewalker commented 1 day ago

I guess I could hack something together with inline spirv?

csyonghe commented 1 day ago

That may be possible and certainly worth a try.