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

Cannot use OpTypeArray directly as function parameter type. #5413

Open
csyonghe opened this issue Sep 22, 2023 · 1 comment
Open

Cannot use OpTypeArray directly as function parameter type. #5413

csyonghe opened this issue Sep 22, 2023 · 1 comment

Comments

@csyonghe
Copy link

csyonghe commented Sep 22, 2023

The following SPIRV triggers a validation error:

; SPIR-V
; Version: 1.5
; Generator: Khronos; 0
; Bound: 103
; Schema: 0
               OpCapability Shader
               OpExtension "SPV_KHR_storage_buffer_storage_class"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %computeMain "main" %23 %29
               OpExecutionMode %computeMain LocalSize 1 1 1

               ; Debug Information
               OpName %Val "Val"  ; id %5
               OpName %_Array_std430_float33 "_Array_std430_float33"  ; id %16
               OpName %Val_std430 "Val_std430"  ; id %15
               OpName %RWStructuredBuffer "RWStructuredBuffer"  ; id %20
               OpName %_Array_std140_float33 "_Array_std140_float33"  ; id %27
               OpName %SLANG_ParameterGroup_Uniforms_std140 "SLANG_ParameterGroup_Uniforms_std140"  ; id %26
               OpName %unpackStorage "unpackStorage"  ; id %34
               OpName %unpackStorage_0 "unpackStorage"  ; id %49
               OpName %unpackStorage_1 "unpackStorage"  ; id %55
               OpName %unpackStorage_2 "unpackStorage"  ; id %41
               OpName %Val_set "Val.set"  ; id %68
               OpName %packStorage "packStorage"  ; id %84
               OpName %packStorage_0 "packStorage"  ; id %92
               OpName %packStorage_1 "packStorage"  ; id %77
               OpName %computeMain "computeMain"  ; id %2

               ; Annotations
               OpDecorate %_arr_v3float_int_3 ArrayStride 12
               OpMemberDecorate %Val 0 Offset 0
               OpMemberDecorate %Val 1 Offset 4
               OpDecorate %_arr_v3float_int_3_0 ArrayStride 16
               OpMemberDecorate %_Array_std430_float33 0 Offset 0
               OpMemberDecorate %Val_std430 0 Offset 0
               OpMemberDecorate %Val_std430 1 Offset 16
               OpDecorate %_runtimearr_Val_std430 ArrayStride 64
               OpDecorate %RWStructuredBuffer Block
               OpMemberDecorate %RWStructuredBuffer 0 Offset 0
               OpDecorate %23 Binding 1
               OpDecorate %23 DescriptorSet 0
               OpMemberDecorate %_Array_std140_float33 0 Offset 0
               OpDecorate %SLANG_ParameterGroup_Uniforms_std140 Block
               OpMemberDecorate %SLANG_ParameterGroup_Uniforms_std140 0 Offset 0
               OpMemberDecorate %SLANG_ParameterGroup_Uniforms_std140 1 Offset 16
               OpDecorate %29 Binding 0
               OpDecorate %29 DescriptorSet 0

               ; Types, variables and constants
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
       %bool = OpTypeBool
      %float = OpTypeFloat 32
    %v3float = OpTypeVector %float 3
        %int = OpTypeInt 32 1
      %int_3 = OpConstant %int 3
%_arr_v3float_int_3 = OpTypeArray %v3float %int_3
        %Val = OpTypeStruct %bool %_arr_v3float_int_3
%_ptr_Function_Val = OpTypePointer Function %Val
      %int_0 = OpConstant %int 0
%_arr_v3float_int_3_0 = OpTypeArray %v3float %int_3
%_Array_std430_float33 = OpTypeStruct %_arr_v3float_int_3_0
 %Val_std430 = OpTypeStruct %int %_Array_std430_float33
%_ptr_StorageBuffer_Val_std430 = OpTypePointer StorageBuffer %Val_std430
%_runtimearr_Val_std430 = OpTypeRuntimeArray %Val_std430
%RWStructuredBuffer = OpTypeStruct %_runtimearr_Val_std430
%_ptr_StorageBuffer_RWStructuredBuffer = OpTypePointer StorageBuffer %RWStructuredBuffer
       %uint = OpTypeInt 32 0
     %uint_0 = OpConstant %uint 0
%_Array_std140_float33 = OpTypeStruct %_arr_v3float_int_3_0
%SLANG_ParameterGroup_Uniforms_std140 = OpTypeStruct %int %_Array_std140_float33
%_ptr_Uniform_SLANG_ParameterGroup_Uniforms_std140 = OpTypePointer Uniform %SLANG_ParameterGroup_Uniforms_std140
%_ptr_Uniform_int = OpTypePointer Uniform %int
         %35 = OpTypeFunction %bool %int
         %42 = OpTypeFunction %Val %Val_std430
%_ptr_Function__arr_v3float_int_3 = OpTypePointer Function %_arr_v3float_int_3
         %56 = OpTypeFunction %void %_Array_std430_float33 %_ptr_Function__arr_v3float_int_3
         %69 = OpTypeFunction %void %_ptr_Function_Val %bool
%_ptr_Function_bool = OpTypePointer Function %bool
         %78 = OpTypeFunction %Val_std430 %Val
         %85 = OpTypeFunction %int %bool
      %int_1 = OpConstant %int 1
         %23 = OpVariable %_ptr_StorageBuffer_RWStructuredBuffer StorageBuffer
         %29 = OpVariable %_ptr_Uniform_SLANG_ParameterGroup_Uniforms_std140 Uniform

               ; Function computeMain
%computeMain = OpFunction %void None %3
          %4 = OpLabel
         %13 = OpVariable %_ptr_Function_Val Function
         %19 = OpAccessChain %_ptr_StorageBuffer_Val_std430 %23 %int_0 %uint_0
         %31 = OpAccessChain %_ptr_Uniform_int %29 %int_0
         %32 = OpLoad %int %31
         %33 = OpFunctionCall %bool %unpackStorage %32
         %39 = OpLoad %Val_std430 %19
         %40 = OpFunctionCall %Val %unpackStorage_2 %39
               OpStore %13 %40
         %67 = OpFunctionCall %void %Val_set %13 %33
         %75 = OpLoad %Val %13
         %76 = OpFunctionCall %Val_std430 %packStorage_1 %75
               OpStore %19 %76
               OpReturn
               OpFunctionEnd

               ; Function unpackStorage
%unpackStorage = OpFunction %bool None %35
         %36 = OpFunctionParameter %int
         %37 = OpLabel
         %38 = OpINotEqual %bool %36 %int_0
               OpReturnValue %38
               OpFunctionEnd

               ; Function unpackStorage_2
%unpackStorage_2 = OpFunction %Val None %42
         %43 = OpFunctionParameter %Val_std430
         %44 = OpLabel
         %46 = OpVariable %_ptr_Function__arr_v3float_int_3 Function
         %47 = OpCompositeExtract %int %43 0
         %48 = OpFunctionCall %bool %unpackStorage_0 %47
         %53 = OpCompositeExtract %_Array_std430_float33 %43 1
         %54 = OpFunctionCall %void %unpackStorage_1 %53 %46
         %65 = OpLoad %_arr_v3float_int_3 %46
         %66 = OpCompositeConstruct %Val %48 %65
               OpReturnValue %66
               OpFunctionEnd

               ; Function unpackStorage_0
%unpackStorage_0 = OpFunction %bool None %35
         %50 = OpFunctionParameter %int
         %51 = OpLabel
         %52 = OpINotEqual %bool %50 %int_0
               OpReturnValue %52
               OpFunctionEnd

               ; Function unpackStorage_1
%unpackStorage_1 = OpFunction %void None %56
         %57 = OpFunctionParameter %_Array_std430_float33
         %58 = OpFunctionParameter %_ptr_Function__arr_v3float_int_3
         %59 = OpLabel
         %60 = OpCompositeExtract %_arr_v3float_int_3_0 %57 0
         %61 = OpCompositeExtract %v3float %60 0
         %62 = OpCompositeExtract %v3float %60 1
         %63 = OpCompositeExtract %v3float %60 2
         %64 = OpCompositeConstruct %_arr_v3float_int_3 %61 %62 %63
               OpStore %58 %64
               OpReturn
               OpFunctionEnd

               ; Function Val_set
    %Val_set = OpFunction %void None %69
         %70 = OpFunctionParameter %_ptr_Function_Val
         %71 = OpFunctionParameter %bool
         %72 = OpLabel
         %74 = OpAccessChain %_ptr_Function_bool %70 %int_0
               OpStore %74 %71
               OpReturn
               OpFunctionEnd

               ; Function packStorage_1
%packStorage_1 = OpFunction %Val_std430 None %78
         %79 = OpFunctionParameter %Val
         %80 = OpLabel
         %81 = OpVariable %_ptr_Function__arr_v3float_int_3 Function
         %82 = OpCompositeExtract %bool %79 0
         %83 = OpFunctionCall %int %packStorage %82
         %90 = OpCompositeExtract %_arr_v3float_int_3 %79 1
         %91 = OpFunctionCall %void %packStorage_0 %90 %81
        %101 = OpLoad %_arr_v3float_int_3 %81
        %102 = OpCompositeConstruct %Val_std430 %83 %101
               OpReturnValue %102
               OpFunctionEnd

               ; Function packStorage
%packStorage = OpFunction %int None %85
         %86 = OpFunctionParameter %bool
         %87 = OpLabel
         %88 = OpSelect %int %86 %int_1 %int_0
               OpReturnValue %88
               OpFunctionEnd

               ; Function packStorage_0
%packStorage_0 = OpFunction %void None %56
         %93 = OpFunctionParameter %_arr_v3float_int_3
         %94 = OpFunctionParameter %_ptr_Function__arr_v3float_int_3
         %95 = OpLabel
         %96 = OpCompositeExtract %v3float %93 0
         %97 = OpCompositeExtract %v3float %93 1
         %98 = OpCompositeExtract %v3float %93 2
         %99 = OpCompositeConstruct %_arr_v3float_int_3_0 %96 %97 %98
        %100 = OpCompositeConstruct %_Array_std430_float33 %99
               OpStore %94 %100
               OpReturn
               OpFunctionEnd

spirv-val outputs this:

error: line 141: OpFunctionCall Argument <id> '90[%90]'s type does not match Function <id> '16[%_Array_std430_float33]'s parameter type.
  %91 = OpFunctionCall %void %packStorage_0 %90 %81

Which is confusing and incorrect. The SPIRV code here is using the correct type as argument. %90's type is %_arr_v3float_int_3, and the first parameter of %packStorage_0 also has %_arr_v3float_int_3 type. The function being called is %packStorage_0 but the validation error message says it is '16[%_Array_std430_float33]', which is not a function.

@csyonghe
Copy link
Author

Further digging into the code reveals that the error is in function packStorage_0, where the OpStore %94 %100 inst doesn't type check. Fixing that also removes the validation error, so the issue is just the diagnostic being confusing.

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

No branches or pull requests

3 participants