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

[SPIR-V] The result pointer storage class and base pointer storage class in OpAccessChain do not match #3035

Closed
Jasper-Bekkers opened this issue Jul 13, 2020 · 5 comments · Fixed by #3039
Assignees
Labels
spirv Work related to SPIR-V

Comments

@Jasper-Bekkers
Copy link

Simple repro:

struct MeshPart {
	uint indexOffset;
	uint positionOffset;
	uint normalOffset;
	uint texCoord0Offset;
};

StructuredBuffer<MeshPart> g_meshParts[] : register(t2, space1);
RWStructuredBuffer<uint> g_output : register(u1, space2);

[numthreads(64, 1, 1)]
void main()
{
	MeshPart meshPart = g_meshParts[0][0];
	g_output[0] = meshPart.indexOffset;
}

Compiling with these arguments generates incorrect build output: dxc -fspv-target-env=vulkan1.2 -spirv -Tcs_6_6 <filename>

fatal error: generated SPIR-V is invalid: The result pointer storage class and base pointer storage class in OpAccessChain do not match.
  %22 = OpAccessChain %_ptr_StorageBuffer_MeshPart %g_meshParts %int_0 %int_0 %uint_0

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

However, compiling with these arguments generates valid spirv: dxc -fspv-target-env=vulkan1.1 -spirv -Tcs_6_6:

; SPIR-V
; Version: 1.3
; Generator: Google spiregg; 0
; Bound: 25
; Schema: 0
               OpCapability Shader
               OpCapability RuntimeDescriptorArray
               OpExtension "SPV_EXT_descriptor_indexing"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %main "main"
               OpExecutionMode %main LocalSize 64 1 1
               OpSource HLSL 660
               OpName %type_StructuredBuffer_MeshPart "type.StructuredBuffer.MeshPart"
               OpName %MeshPart "MeshPart"
               OpMemberName %MeshPart 0 "indexOffset"
               OpMemberName %MeshPart 1 "positionOffset"
               OpMemberName %MeshPart 2 "normalOffset"
               OpMemberName %MeshPart 3 "texCoord0Offset"
               OpName %g_meshParts "g_meshParts"
               OpName %type_RWStructuredBuffer_uint "type.RWStructuredBuffer.uint"
               OpName %g_output "g_output"
               OpName %main "main"
               OpDecorate %g_meshParts DescriptorSet 1
               OpDecorate %g_meshParts Binding 2
               OpDecorate %g_output DescriptorSet 2
               OpDecorate %g_output Binding 1
               OpMemberDecorate %MeshPart 0 Offset 0
               OpMemberDecorate %MeshPart 1 Offset 4
               OpMemberDecorate %MeshPart 2 Offset 8
               OpMemberDecorate %MeshPart 3 Offset 12
               OpDecorate %_runtimearr_MeshPart ArrayStride 16
               OpMemberDecorate %type_StructuredBuffer_MeshPart 0 Offset 0
               OpMemberDecorate %type_StructuredBuffer_MeshPart 0 NonWritable
               OpDecorate %type_StructuredBuffer_MeshPart BufferBlock
               OpDecorate %_runtimearr_uint ArrayStride 4
               OpMemberDecorate %type_RWStructuredBuffer_uint 0 Offset 0
               OpDecorate %type_RWStructuredBuffer_uint BufferBlock
        %int = OpTypeInt 32 1
      %int_0 = OpConstant %int 0
       %uint = OpTypeInt 32 0
     %uint_0 = OpConstant %uint 0
   %MeshPart = OpTypeStruct %uint %uint %uint %uint
%_runtimearr_MeshPart = OpTypeRuntimeArray %MeshPart
%type_StructuredBuffer_MeshPart = OpTypeStruct %_runtimearr_MeshPart
%_runtimearr_type_StructuredBuffer_MeshPart = OpTypeRuntimeArray %type_StructuredBuffer_MeshPart
%_ptr_Uniform__runtimearr_type_StructuredBuffer_MeshPart = OpTypePointer Uniform %_runtimearr_type_StructuredBuffer_MeshPart
%_runtimearr_uint = OpTypeRuntimeArray %uint
%type_RWStructuredBuffer_uint = OpTypeStruct %_runtimearr_uint
%_ptr_Uniform_type_RWStructuredBuffer_uint = OpTypePointer Uniform %type_RWStructuredBuffer_uint
       %void = OpTypeVoid
         %17 = OpTypeFunction %void
%_ptr_Uniform_MeshPart = OpTypePointer Uniform %MeshPart
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%g_meshParts = OpVariable %_ptr_Uniform__runtimearr_type_StructuredBuffer_MeshPart Uniform
   %g_output = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_uint Uniform
       %main = OpFunction %void None %17
         %20 = OpLabel
         %21 = OpAccessChain %_ptr_Uniform_MeshPart %g_meshParts %int_0 %int_0 %uint_0
         %22 = OpAccessChain %_ptr_Uniform_uint %21 %uint_0
         %23 = OpLoad %uint %22
         %24 = OpAccessChain %_ptr_Uniform_uint %g_output %int_0 %uint_0
               OpStore %24 %23
               OpReturn
               OpFunctionEnd

Tested with the AppVeyor build from f78b10c

@Jasper-Bekkers
Copy link
Author

Compiling with dxc -Vd -fspv-target-env=vulkan1.2 -spirv -Tcs_6_6 (validation disabled) clearly shows what's going wrong:

; SPIR-V
; Version: 1.5
; Generator: Google spiregg; 0
; Bound: 26
; Schema: 0
               OpCapability Shader
               OpCapability RuntimeDescriptorArray
               OpExtension "SPV_EXT_descriptor_indexing"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %main "main" %g_meshParts %g_output
               OpExecutionMode %main LocalSize 64 1 1
               OpSource HLSL 660
               OpName %type_StructuredBuffer_MeshPart "type.StructuredBuffer.MeshPart"
               OpName %MeshPart "MeshPart"
               OpMemberName %MeshPart 0 "indexOffset"
               OpMemberName %MeshPart 1 "positionOffset"
               OpMemberName %MeshPart 2 "normalOffset"
               OpMemberName %MeshPart 3 "texCoord0Offset"
               OpName %g_meshParts "g_meshParts"
               OpName %type_RWStructuredBuffer_uint "type.RWStructuredBuffer.uint"
               OpName %g_output "g_output"
               OpName %main "main"
               OpDecorate %g_meshParts DescriptorSet 1
               OpDecorate %g_meshParts Binding 2
               OpDecorate %g_output DescriptorSet 2
               OpDecorate %g_output Binding 1
               OpMemberDecorate %MeshPart 0 Offset 0
               OpMemberDecorate %MeshPart 1 Offset 4
               OpMemberDecorate %MeshPart 2 Offset 8
               OpMemberDecorate %MeshPart 3 Offset 12
               OpDecorate %_runtimearr_MeshPart ArrayStride 16
               OpMemberDecorate %type_StructuredBuffer_MeshPart 0 Offset 0
               OpMemberDecorate %type_StructuredBuffer_MeshPart 0 NonWritable
               OpDecorate %type_StructuredBuffer_MeshPart Block
               OpDecorate %_runtimearr_uint ArrayStride 4
               OpMemberDecorate %type_RWStructuredBuffer_uint 0 Offset 0
               OpDecorate %type_RWStructuredBuffer_uint Block
        %int = OpTypeInt 32 1
      %int_0 = OpConstant %int 0
       %uint = OpTypeInt 32 0
     %uint_0 = OpConstant %uint 0
   %MeshPart = OpTypeStruct %uint %uint %uint %uint
%_runtimearr_MeshPart = OpTypeRuntimeArray %MeshPart
%type_StructuredBuffer_MeshPart = OpTypeStruct %_runtimearr_MeshPart
%_runtimearr_type_StructuredBuffer_MeshPart = OpTypeRuntimeArray %type_StructuredBuffer_MeshPart
%_ptr_Uniform__runtimearr_type_StructuredBuffer_MeshPart = OpTypePointer Uniform %_runtimearr_type_StructuredBuffer_MeshPart
%_runtimearr_uint = OpTypeRuntimeArray %uint
%type_RWStructuredBuffer_uint = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer_type_RWStructuredBuffer_uint = OpTypePointer StorageBuffer %type_RWStructuredBuffer_uint
       %void = OpTypeVoid
         %17 = OpTypeFunction %void
%_ptr_StorageBuffer_MeshPart = OpTypePointer StorageBuffer %MeshPart
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%g_meshParts = OpVariable %_ptr_Uniform__runtimearr_type_StructuredBuffer_MeshPart Uniform
   %g_output = OpVariable %_ptr_StorageBuffer_type_RWStructuredBuffer_uint StorageBuffer
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
       %main = OpFunction %void None %17
         %21 = OpLabel
         %22 = OpAccessChain %_ptr_StorageBuffer_MeshPart %g_meshParts %int_0 %int_0 %uint_0
         %23 = OpAccessChain %_ptr_Uniform_uint %22 %uint_0
         %24 = OpLoad %uint %23
         %25 = OpAccessChain %_ptr_StorageBuffer_uint %g_output %int_0 %uint_0
               OpStore %25 %24
               OpReturn
               OpFunctionEnd

For %22 the OpAccessChain has a mismatching Storage Class - the OpTypePointer has a Storage Class of StorageBuffer and the OpVariable has a Storage Class of Uniform whereas before, both were Uniform in this case.

@Jasper-Bekkers
Copy link
Author

@ehsannas These errors usually seems to be in your street, right? :-)

@ehsannas ehsannas added the spirv Work related to SPIR-V label Jul 13, 2020
@ehsannas ehsannas changed the title generated SPIR-V is invalid: The result pointer storage class and base pointer storage class in OpAccessChain do not match [SPIR-V] The result pointer storage class and base pointer storage class in OpAccessChain do not match Jul 13, 2020
@ehsannas
Copy link
Contributor

Hi @Jasper-Bekkers , Yup, Thanks for reporting! We'll take a look.

@ehsannas
Copy link
Contributor

@jaebaek will investigate.

@Jasper-Bekkers
Copy link
Author

Thanks @ehsannas and @jaebaek #3039 fixes the issue for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spirv Work related to SPIR-V
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants