Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection of shader with pointer to POD (not a struct) crashes #287

Closed
danginsburg opened this issue Dec 3, 2024 · 1 comment · Fixed by #289
Closed

Reflection of shader with pointer to POD (not a struct) crashes #287

danginsburg opened this issue Dec 3, 2024 · 1 comment · Fixed by #289

Comments

@danginsburg
Copy link
Contributor

The following shader compiled in slang will crash spirv-reflect (https://shader-slang.com/slang-playground/?target=SPIRV&code=eJx9j0FLw0AQhe_zKwZyaaW15hwUtFYUFEpSvJRS1s2sGUx2y85uVUr_u9vaiAeRub158-Z7WU2GLeG0vK7u19X8oXxel7O7x9l0gTlAxiYZ_toCTCa4aFjwndsWtVfSoGzYb8eeTEs6jJADKpHYkeC8-RTWqq2C8-qVbqIx5E-3L4QSfNRBIFo2zncY2YYzrFVQRYKgVgi-LXibtB0gYnLgRwH7XyDOvwke6pz_BB3sfVBGtmYDsLSxC40nVcsgH6UZrmDruEbtuk0M9KTYDoaw-699AjimLi9WeIl5cYLs5fFV6OXjz_0Xh3px2w)

#define CRASH_SPIRV_REFLECT 1

#ifdef CRASH_SPIRV_REFLECT

// This will crash spirv-reflect, it assumes PhysicalStorageBuffers will be structs
uniform uint* data;

#else
struct Data{
   int x;
}

// This works fine.
uniform Data* data;
#endif

[numthreads(1,1,1)]
void computeMain()
{
#ifdef CRASH_SPIRV_REFLECT
    data[0] = 1;
#else
    data->t = 1;
#endif
}

The crashing spir-v is below:

; SPIR-V
; Version: 1.5
; Generator: Khronos; 40
; Bound: 19
; Schema: 0
               OpCapability PhysicalStorageBufferAddresses
               OpCapability Shader
               OpExtension "SPV_KHR_physical_storage_buffer"
               OpMemoryModel PhysicalStorageBuffer64 GLSL450
               OpEntryPoint GLCompute %computeMain "main" %globalParams
               OpExecutionMode %computeMain LocalSize 1 1 1
               OpSource Slang 1
               OpName %GlobalParams_std140 "GlobalParams_std140"
               OpMemberName %GlobalParams_std140 0 "data"
               OpName %globalParams "globalParams"
               OpName %computeMain "computeMain"
               OpDecorate %_ptr_PhysicalStorageBuffer_uint ArrayStride 4
               OpDecorate %GlobalParams_std140 Block
               OpMemberDecorate %GlobalParams_std140 0 Offset 0
               OpDecorate %globalParams Binding 0
               OpDecorate %globalParams DescriptorSet 0
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
       %uint = OpTypeInt 32 0
%_ptr_PhysicalStorageBuffer_uint = OpTypePointer PhysicalStorageBuffer %uint
%GlobalParams_std140 = OpTypeStruct %_ptr_PhysicalStorageBuffer_uint
%_ptr_Uniform_GlobalParams_std140 = OpTypePointer Uniform %GlobalParams_std140
        %int = OpTypeInt 32 1
      %int_0 = OpConstant %int 0
%_ptr_Uniform__ptr_PhysicalStorageBuffer_uint = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_uint
     %uint_1 = OpConstant %uint 1
%globalParams = OpVariable %_ptr_Uniform_GlobalParams_std140 Uniform
%computeMain = OpFunction %void None %3
          %4 = OpLabel
         %13 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_uint %globalParams %int_0
         %14 = OpLoad %_ptr_PhysicalStorageBuffer_uint %13
         %15 = OpPtrAccessChain %_ptr_PhysicalStorageBuffer_uint %14 %int_0
               OpStore %15 %uint_1 Aligned 4
               OpReturn
               OpFunctionEnd
danginsburg pushed a commit to danginsburg/SPIRV-Reflect that referenced this issue Dec 3, 2024
…ysicalStorageBuffers will always point to structs. They can point to plain data types.
@spencer-lunarg
Copy link
Contributor

spencer-lunarg commented Dec 4, 2024

Can reproduce as see the issue of the OpPtrAccessChain not being handled

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants