The group shared data is always declared as a straight float array, regardless of the actual underlying type, and this causes garbage in output in some cases, as the name of the structured variable is uninitialized.
Example HLSL:
8<8<8<8<8<8<
Texture2D Input;
RWTexture2D Result;
The group shared data is always declared as a straight float array, regardless of the actual underlying type, and this causes garbage in output in some cases, as the name of the structured variable is uninitialized.
Example HLSL: 8<8<8<8<8<8< Texture2D Input; RWTexture2D Result;
define blocksize 8
define groupthreads (blocksize*blocksize)
groupshared float4 accum[groupthreads];
[numthreads(blocksize,blocksize,1)] void main( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex ) { accum[GI] = Input[DTid.xy];
} 8<8<8<8<8<
Bytecode:
8<8<8<8<8<8< // // Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 // // // Resource Bindings: // // Name Type Format Dim Slot Elements // ------------------------------ ---------- ------- ----------- ---- -------- // Input texture float4 2d 0 1 // Result UAV float4 2d 0 1 // // // // Input signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // no Input // // Output signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // no Output cs_5_0 dcl_globalFlags refactoringAllowed dcl_resource_texture2d (float,float,float,float) t0 dcl_uav_typed_texture2d (float,float,float,float) u0 dcl_input vThreadIDInGroupFlattened dcl_input vThreadGroupID.xy dcl_input vThreadID.xy dcl_temps 3 dcl_tgsm_structured g0, 16, 64 dcl_thread_group 8, 8, 1 mov r0.xy, vThreadID.xyxx mov r0.zw, l(0,0,0,0) ld_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyzw, t0.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw sync_g_t ult r1.xyzw, vThreadIDInGroupFlattened.xxxx, l(32, 16, 8, 4) if_nz r1.x iadd r1.x, vThreadIDInGroupFlattened.x, l(32) ld_structured r2.xyzw, r1.x, l(0), g0.xyzw add r0.xyzw, r0.xyzw, r2.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw endif sync_g_t if_nz r1.y iadd r0.x, vThreadIDInGroupFlattened.x, l(16) ld_structured r0.xyzw, r0.x, l(0), g0.xyzw ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw add r0.xyzw, r0.xyzw, r2.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw endif sync_g_t if_nz r1.z iadd r0.x, vThreadIDInGroupFlattened.x, l(8) ld_structured r0.xyzw, r0.x, l(0), g0.xyzw ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw add r0.xyzw, r0.xyzw, r2.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw endif sync_g_t if_nz r1.w iadd r0.x, vThreadIDInGroupFlattened.x, l(4) ld_structured r0.xyzw, r0.x, l(0), g0.xyzw ld_structured r1.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw add r0.xyzw, r0.xyzw, r1.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw endif sync_g_t ult r0.xy, vThreadIDInGroupFlattened.xxxx, l(2, 1, 0, 0) if_nz r0.x iadd r0.x, vThreadIDInGroupFlattened.x, l(2) ld_structured r1.xyzw, r0.x, l(0), g0.xyzw ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw add r1.xyzw, r1.xyzw, r2.xyzw store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r1.xyzw endif sync_g_t if_nz r0.y ld_structured r0.xyzw, l(1), l(0), g0.xyzw ld_structured r1.xyzw, l(0), l(0), g0.xyzw add r0.xyzw, r0.xyzw, r1.xyzw store_structured g0.xyzw, l(0), l(0), r0.xyzw endif if_z vThreadIDInGroupFlattened.x ld_structured r0.xyzw, l(0), l(0), g0.xyzw mul r0.xyzw, r0.xyzw, l(0.015625, 0.015625, 0.015625, 0.015625) store_uav_typed u0.xyzw, vThreadGroupID.xyyy, r0.xyzw endif ret // Approximately 58 instruction slots used 8<8<8<8<8<8<8<
Resulting GLSL:
8<8<8<8<8<8<8<8<
version 310 es
struct vec1 { float x; }; struct uvec1 { uint x; }; struct ivec1 { int x; }; precision lowp sampler3D; precision lowp samplerCubeShadow; precision lowp sampler2DShadow; precision lowp sampler2DArray; precision lowp sampler2DArrayShadow; precision lowp isampler2D; precision lowp isampler3D; precision lowp isamplerCube; precision lowp isampler2DArray; precision lowp usampler2D; precision lowp usampler3D; precision lowp usamplerCube; precision lowp usampler2DArray; precision lowp isampler2DMS; precision lowp usampler2D; precision lowp usampler3D; precision lowp usamplerCube; precision lowp usampler2DArray; precision lowp usampler2DMS; precision lowp image2D; precision lowp image3D; precision lowp imageCube; precision lowp image2DArray; precision lowp iimage2D; precision lowp iimage3D; precision lowp iimageCube; precision lowp uimage2DArray; precision highp atomic_uint; uniform sampler2D Input; writeonly uniform image2D UAV0; vec4 Temp[3]; ivec4 Temp_int[3]; uvec4 Temp_uint[3]; shared float TGSM0[256]; layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; void main() { //--- Start Early Main --- //--- End Early Main --- //Instruction 0 //MOV Temp_uint[0].xy = uvec4(gl_GlobalInvocationID.xyxx).xy; //Instruction 1 //MOV Temp[0].zw = vec4(vec4(0.000000, 0.000000, 0.000000, 0.000000)).zw; //Instruction 2 //LD Temp[0] = texelFetch(Input, ivec2((ivec4(Temp_uint[0])).xy), 0); //Instruction 3 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; //Instruction 4 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 5 //ULT Temp_uint[1] = uvec4(lessThan(uvec4(gl_LocalInvocationIndex.xxxx).xyzw, uvec4(uvec4(32u, 16u, 8u, 4u)).xyzw)) * 0xFFFFFFFFu; //Instruction 6 //IF if((Temp_uint[1].x)!=0u){ //Instruction 7 //IADD Temp_uint[1].x = gl_LocalInvocationIndex.x + 32u; //Instruction 8 //LD_STRUCTURED Temp[2].x = TGSM0[Temp_uint[1].x].ô³üN´!; Temp[2].y = TGSM0[Temp_uint[1].x].ô³üN´!; Temp[2].z = TGSM0[Temp_uint[1].x].ô³üN´!; Temp[2].w = TGSM0[Temp_uint[1].x].ô³üN´!; //Instruction 9 //ADD Temp[0] = vec4(Temp[0] + Temp[2]); //Instruction 10 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; //Instruction 11 //ENDIF } //Instruction 12 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 13 //IF if((Temp_uint[1].y)!=0u){ //Instruction 14 //IADD Temp_uint[0].x = gl_LocalInvocationIndex.x + 16u; //Instruction 15 //LD_STRUCTURED Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!; //Instruction 16 //LD_STRUCTURED Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; //Instruction 17 //ADD Temp[0] = vec4(Temp[0] + Temp[2]); //Instruction 18 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; //Instruction 19 //ENDIF } //Instruction 20 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 21 //IF if((Temp_uint[1].z)!=0u){ //Instruction 22 //IADD Temp_uint[0].x = gl_LocalInvocationIndex.x + 8u; //Instruction 23 //LD_STRUCTURED Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!; //Instruction 24 //LD_STRUCTURED Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; //Instruction 25 //ADD Temp[0] = vec4(Temp[0] + Temp[2]); //Instruction 26 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; //Instruction 27 //ENDIF } //Instruction 28 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 29 //IF if((Temp_uint[1].w)!=0u){ //Instruction 30 //IADD Temp_uint[0].x = gl_LocalInvocationIndex.x + 4u; //Instruction 31 //LD_STRUCTURED Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!; //Instruction 32 //LD_STRUCTURED Temp[1].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[1].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[1].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[1].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; //Instruction 33 //ADD Temp[0] = vec4(Temp[0] + Temp[1]); //Instruction 34 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0]; //Instruction 35 //ENDIF } //Instruction 36 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 37 //ULT Temp_uint[0].xy = uvec2(lessThan(uvec4(gl_LocalInvocationIndex.xxxx).xy, uvec4(uvec4(2u, 1u, 0u, 0u)).xy)) * 0xFFFFFFFFu; //Instruction 38 //IF if((Temp_uint[0].x)!=0u){ //Instruction 39 //IADD Temp_uint[0].x = gl_LocalInvocationIndex.x + 2u; //Instruction 40 //LD_STRUCTURED Temp[1].x = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[1].y = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[1].z = TGSM0[Temp_uint[0].x].ô³üN´!; Temp[1].w = TGSM0[Temp_uint[0].x].ô³üN´!; //Instruction 41 //LD_STRUCTURED Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!; //Instruction 42 //ADD Temp[1] = vec4(Temp[1] + Temp[2]); //Instruction 43 //STORE_STRUCTURED TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1]; TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1]; //Instruction 44 //ENDIF } //Instruction 45 //SYNC groupMemoryBarrier(); memoryBarrierShared(); //Instruction 46 //IF if((Temp_uint[0].y)!=0u){ //Instruction 47 //LD_STRUCTURED Temp[0].x = TGSM0[1u].ô³üN´!; Temp[0].y = TGSM0[1u].ô³üN´!; Temp[0].z = TGSM0[1u].ô³üN´!; Temp[0].w = TGSM0[1u].ô³üN´!; //Instruction 48 //LD_STRUCTURED Temp[1].x = TGSM0[0u].ô³üN´!; Temp[1].y = TGSM0[0u].ô³üN´!; Temp[1].z = TGSM0[0u].ô³üN´!; Temp[1].w = TGSM0[0u].ô³üN´!; //Instruction 49 //ADD Temp[0] = vec4(Temp[0] + Temp[1]); //Instruction 50 //STORE_STRUCTURED TGSM0[0u].ô³üN´! = Temp[0]; TGSM0[0u].ô³üN´! = Temp[0]; TGSM0[0u].ô³üN´! = Temp[0]; TGSM0[0u].ô³üN´! = Temp[0]; //Instruction 51 //ENDIF } //Instruction 52 //IF if((gl_LocalInvocationIndex.x)==0u){ //Instruction 53 //LD_STRUCTURED Temp[0].x = TGSM0[0u].ô³üN´!; Temp[0].y = TGSM0[0u].ô³üN´!; Temp[0].z = TGSM0[0u].ô³üN´!; Temp[0].w = TGSM0[0u].ô³üN´!; //Instruction 54 //MUL Temp[0] = vec4(Temp[0] * vec4(0.015625, 0.015625, 0.015625, 0.015625)); //Instruction 55 //STORE_UAV_TYPED imageStore(UAV0, ivec2(gl_LocalInvocationID.xy), Temp[0]); //Instruction 56 //ENDIF } //Instruction 57 //RET return; }