I have a simple compute shader:
#version 450 core
#extension GL_ARB_gpu_shader_int64: require
#define STATE_SIZE_UINT64 25 /** 200 bytes */
layout(binding = 0) buffer writeonly State {
uint64_t st[];
};
const uint64_t RC[4] = {
0x0000000000000001UL, 0x0000000000008082UL,
0x800000000000808aUL, 0xf123456789abcdefUL
};
void main()
{
uint index = gl_GlobalInvocationID.x;
uint sti = index * STATE_SIZE_UINT64;
uint i = 3;
st[sti] = RC[i];
return;
}
After executing the shader I expect first 8 bytes of buffer to be:
0xefcdab89674523f1
but instead I am getting:
0x00d0ab89674523f1
If I rewrite shader code to access constant directly:
...
st[sti] = RC[3];
...
then it works fine.
System: Arch Linux
Kernel: 4.15.10
Nvidia driver: 390.42
GPU: NVIDIA Corporation GK208 [GeForce GT 730] (rev a1)
Shader compiler: Glslang Version: 6.5.2629
Tried it on GeForce 1080Ti - same problem persist
Tried on AMD GPU (RX570) - works as expected
SPIR-V disassembly listing:
OpCapability Shader
OpCapability Int64
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 450
OpSourceExtension "GL_ARB_gpu_shader_int64"
OpName %main "main"
OpName %index "index"
OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
OpName %sti "sti"
OpName %i "i"
OpName %State "State"
OpMemberName %State 0 "st"
OpName %_ ""
OpName %indexable "indexable"
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %_runtimearr_ulong ArrayStride 8
OpMemberDecorate %State 0 NonReadable
OpMemberDecorate %State 0 Offset 0
OpDecorate %State BufferBlock
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%_ptr_Function_uint = OpTypePointer Function %uint
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_0 = OpConstant %uint 0
%_ptr_Input_uint = OpTypePointer Input %uint
%uint_25 = OpConstant %uint 25
%uint_3 = OpConstant %uint 3
%ulong = OpTypeInt 64 0
%_runtimearr_ulong = OpTypeRuntimeArray %ulong
%State = OpTypeStruct %_runtimearr_ulong
%_ptr_Uniform_State = OpTypePointer Uniform %State
%_ = OpVariable %_ptr_Uniform_State Uniform
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%uint_4 = OpConstant %uint 4
%_arr_ulong_uint_4 = OpTypeArray %ulong %uint_4
%ulong_1 = OpConstant %ulong 1
%ulong_32898 = OpConstant %ulong 32898
%ulong_9223372036854808714 = OpConstant %ulong 9223372036854808714
%ulong_17375808098319191535 = OpConstant %ulong 17375808098319191535
%36 = OpConstantComposite %_arr_ulong_uint_4 %ulong_1 %ulong_32898 %ulong_9223372036854808714 %ulong_17375808098319191535
%_ptr_Function__arr_ulong_uint_4 = OpTypePointer Function %_arr_ulong_uint_4
%_ptr_Function_ulong = OpTypePointer Function %ulong
%_ptr_Uniform_ulong = OpTypePointer Uniform %ulong
%main = OpFunction %void None %3
%5 = OpLabel
%index = OpVariable %_ptr_Function_uint Function
%sti = OpVariable %_ptr_Function_uint Function
%i = OpVariable %_ptr_Function_uint Function
%indexable = OpVariable %_ptr_Function__arr_ulong_uint_4 Function
%14 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
%15 = OpLoad %uint %14
OpStore %index %15
%17 = OpLoad %uint %index
%19 = OpIMul %uint %17 %uint_25
OpStore %sti %19
OpStore %i %uint_3
%29 = OpLoad %uint %sti
%37 = OpLoad %uint %i
OpStore %indexable %36
%41 = OpAccessChain %_ptr_Function_ulong %indexable %37
%42 = OpLoad %ulong %41
%44 = OpAccessChain %_ptr_Uniform_ulong %_ %int_0 %29
OpStore %44 %42
OpReturn
OpFunctionEnd