Skip to content

uniform params to raygeneration shaders are treated as ShaderRecordBufferKHRs not PushConstants #10435

@expenses

Description

@expenses

Issue Description

For SPIR-V outputs, I expect all uniform entry point struct params to be treated as PushConstants. At the very least, this is what https://shader-slang.org/slang/user-guide/spirv-target-specific#push-constants states. However, compiling the following with slangc shaders/test.slang -o out.spv shows that this is not consistent between compute and raygeneration shaders:

struct Const {
    uint* val;
}

[shader("compute")]
void compute(uniform Const const) {
    const.val++;
}

[shader("raygeneration")]
void raygeneration(uniform Const const) {
    const.val++;
}
; SPIR-V
; Version: 1.5
; Generator: Khronos Slang Compiler; 0
; Bound: 64
; Schema: 0
               OpCapability PhysicalStorageBufferAddresses
               OpCapability RayTracingKHR
               OpCapability Shader
               OpExtension "SPV_KHR_physical_storage_buffer"
               OpExtension "SPV_KHR_ray_tracing"
               OpMemoryModel PhysicalStorageBuffer64 GLSL450
               OpEntryPoint GLCompute %compute "compute" %entryPointParams
               OpEntryPoint RayGenerationKHR %raygeneration "raygeneration" %entryPointParams_0
               OpExecutionMode %compute LocalSize 1 1 1
               OpSource Slang 1
               OpName %Const_std430_logical "Const_std430_logical"
               OpMemberName %Const_std430_logical 0 "val"
               OpName %Const_std430 "Const_std430"
               OpMemberName %Const_std430 0 "val"
               OpName %EntryPointParams_std430 "EntryPointParams_std430"
               OpMemberName %EntryPointParams_std430 0 "const"
               OpName %entryPointParams "entryPointParams"
               OpName %compute "compute"
               OpName %EntryPointParams_std430_0 "EntryPointParams_std430"
               OpMemberName %EntryPointParams_std430_0 0 "const"
               OpName %entryPointParams_0 "entryPointParams"
               OpName %raygeneration "raygeneration"
               OpDecorate %_ptr_PhysicalStorageBuffer_uint ArrayStride 4
               OpMemberDecorate %Const_std430 0 Offset 0
               OpDecorate %EntryPointParams_std430 Block
               OpMemberDecorate %EntryPointParams_std430 0 Offset 0
               OpDecorate %EntryPointParams_std430_0 Block
               OpMemberDecorate %EntryPointParams_std430_0 0 Offset 0
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
       %uint = OpTypeInt 32 0
%_ptr_PhysicalStorageBuffer_uint = OpTypePointer PhysicalStorageBuffer %uint
%Const_std430_logical = OpTypeStruct %_ptr_PhysicalStorageBuffer_uint
%Const_std430 = OpTypeStruct %_ptr_PhysicalStorageBuffer_uint
%EntryPointParams_std430 = OpTypeStruct %Const_std430
%_ptr_PushConstant_EntryPointParams_std430 = OpTypePointer PushConstant %EntryPointParams_std430
        %int = OpTypeInt 32 1
      %int_0 = OpConstant %int 0
%_ptr_PushConstant_Const_std430 = OpTypePointer PushConstant %Const_std430
      %int_1 = OpConstant %int 1
%EntryPointParams_std430_0 = OpTypeStruct %Const_std430
%_ptr_ShaderRecordBufferKHR_EntryPointParams_std430_0 = OpTypePointer ShaderRecordBufferKHR %EntryPointParams_std430_0
%_ptr_ShaderRecordBufferKHR_Const_std430 = OpTypePointer ShaderRecordBufferKHR %Const_std430
%entryPointParams = OpVariable %_ptr_PushConstant_EntryPointParams_std430 PushConstant
%entryPointParams_0 = OpVariable %_ptr_ShaderRecordBufferKHR_EntryPointParams_std430_0 ShaderRecordBufferKHR
    %compute = OpFunction %void None %3
          %4 = OpLabel
         %20 = OpAccessChain %_ptr_PushConstant_Const_std430 %entryPointParams %int_0
         %21 = OpLoad %Const_std430 %20
         %22 = OpCopyLogical %Const_std430_logical %21
         %59 = OpCompositeExtract %_ptr_PhysicalStorageBuffer_uint %22 0
         %31 = OpPtrAccessChain %_ptr_PhysicalStorageBuffer_uint %59 %int_1
               OpReturn
               OpFunctionEnd
%raygeneration = OpFunction %void None %3
         %36 = OpLabel
         %43 = OpAccessChain %_ptr_ShaderRecordBufferKHR_Const_std430 %entryPointParams_0 %int_0
         %44 = OpLoad %Const_std430 %43
         %45 = OpCopyLogical %Const_std430_logical %44
         %63 = OpCompositeExtract %_ptr_PhysicalStorageBuffer_uint %45 0
         %53 = OpPtrAccessChain %_ptr_PhysicalStorageBuffer_uint %63 %int_1
               OpReturn
               OpFunctionEnd

One becomes OpVariable %_ptr_PushConstant_EntryPointParams_std430 PushConstant while the other becomes OpTypePointer ShaderRecordBufferKHR %EntryPointParams_std430_0. This is a total footgun.

Environment

  • Slang Version: v2026.3.1-nixpkgs
  • OS: Linux

Additional context

Add any other context about the problem here.

Metadata

Metadata

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions