Merge pull request #1518 from KhronosGroup/fix-nonuniform-bracket-handling

GLSL: Fix nonuniformEXT injection.
This commit is contained in:
Hans-Kristian Arntzen 2020-10-30 15:48:37 +01:00 committed by GitHub
commit 303f813166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 631 additions and 1 deletions

View File

@ -0,0 +1,37 @@
ByteAddressBuffer _8 : register(t0, space0);
Texture2D<float4> uSamplers[] : register(t0, space0);
SamplerState _uSamplers_sampler[] : register(s0, space0);
Texture2D<float4> uSampler : register(t0, space1);
SamplerState _uSampler_sampler : register(s0, space1);
static float4 gl_FragCoord;
static float4 FragColor;
static float2 vUV;
struct SPIRV_Cross_Input
{
float2 vUV : TEXCOORD0;
float4 gl_FragCoord : SV_Position;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = uSamplers[NonUniformResourceIndex(_8.Load(40))].SampleLevel(_uSamplers_sampler[NonUniformResourceIndex(_8.Load(40))], vUV, 0.0f);
FragColor += uSampler.SampleLevel(_uSampler_sampler, vUV, float(_8.Load(int(gl_FragCoord.y) * 4 + 0)));
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_FragCoord = stage_input.gl_FragCoord;
gl_FragCoord.w = 1.0 / gl_FragCoord.w;
vUV = stage_input.vUV;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,55 @@
#version 450
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_KHR_shader_subgroup_ballot : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0, std430) restrict readonly buffer SSBO_Offsets
{
uvec2 _m0[];
} _7;
layout(push_constant, std430) uniform RootConstants
{
uint _m0;
uint _m1;
uint _m2;
uint _m3;
uint _m4;
uint _m5;
uint _m6;
uint _m7;
} registers;
layout(set = 1, binding = 0) uniform samplerBuffer _8[];
layout(set = 4, binding = 0, r32f) uniform imageBuffer _9[];
layout(set = 4, binding = 0, r32ui) uniform uimageBuffer _10[];
void main()
{
uint _60 = registers._m4 + 2u;
uint _63 = subgroupBroadcastFirst(_60);
uint _70 = subgroupBroadcastFirst(registers._m4);
uint _75 = registers._m1 + 1u;
uint _78 = subgroupBroadcastFirst(_75);
uint _87 = gl_GlobalInvocationID.x + 4u;
uint _98 = gl_GlobalInvocationID.x + 1024u;
imageStore(_9[registers._m4], int((_98 < _7._m0[_70].y) ? (_98 + _7._m0[_70].x) : 4294967295u), vec4(imageLoad(_9[registers._m4], int((_87 < _7._m0[_70].y) ? (_87 + _7._m0[_70].x) : 4294967295u))));
uint _105 = gl_GlobalInvocationID.x + 2u;
uint _116 = gl_GlobalInvocationID.x + 2048u;
imageStore(_9[registers._m4], int((_116 < _7._m0[_70].y) ? (_116 + _7._m0[_70].x) : 4294967295u), vec4(texelFetch(_8[_75], int((_105 < _7._m0[_78].y) ? (_105 + _7._m0[_78].x) : 4294967295u))));
uint _129 = imageAtomicAdd(_10[_60], int((gl_GlobalInvocationID.x < _7._m0[_63].y) ? (gl_GlobalInvocationID.x + _7._m0[_63].x) : 4294967295u), 40u);
uint _136 = imageAtomicCompSwap(_10[_60], int((gl_GlobalInvocationID.y < _7._m0[_63].y) ? (gl_GlobalInvocationID.y + _7._m0[_63].x) : 4294967295u), 40u, 50u);
imageStore(_9[registers._m4], int((0u < _7._m0[_70].y) ? (0u + _7._m0[_70].x) : 4294967295u), vec4(float(_7._m0[_70].y)));
imageStore(_9[registers._m4], int((1u < _7._m0[_70].y) ? (1u + _7._m0[_70].x) : 4294967295u), vec4(float(_7._m0[_78].y)));
uint _11 = registers._m4 + (gl_GlobalInvocationID.z + 0u);
imageStore(_9[nonuniformEXT(_11)], int((_98 < _7._m0[_11].y) ? (_98 + _7._m0[_11].x) : 4294967295u), vec4(imageLoad(_9[nonuniformEXT(_11)], int((_87 < _7._m0[_11].y) ? (_87 + _7._m0[_11].x) : 4294967295u))));
uint _13 = registers._m1 + (gl_GlobalInvocationID.z + 0u);
imageStore(_9[nonuniformEXT(_11)], int((_116 < _7._m0[_11].y) ? (_116 + _7._m0[_11].x) : 4294967295u), vec4(texelFetch(_8[nonuniformEXT(_13)], int((_87 < _7._m0[_13].y) ? (_87 + _7._m0[_13].x) : 4294967295u))));
uint _15 = registers._m4 + (gl_GlobalInvocationID.z + 0u);
uint _208 = imageAtomicAdd(_10[nonuniformEXT(_15)], int((gl_GlobalInvocationID.y < _7._m0[_15].y) ? (gl_GlobalInvocationID.y + _7._m0[_15].x) : 4294967295u), 40u);
uint _215 = imageAtomicCompSwap(_10[nonuniformEXT(_15)], int((gl_GlobalInvocationID.y < _7._m0[_15].y) ? (gl_GlobalInvocationID.y + _7._m0[_15].x) : 4294967295u), 40u, 70u);
imageStore(_9[registers._m4], int((2u < _7._m0[_70].y) ? (2u + _7._m0[_70].x) : 4294967295u), vec4(float(_7._m0[_11].y)));
imageStore(_9[registers._m4], int((3u < _7._m0[_70].y) ? (3u + _7._m0[_70].x) : 4294967295u), vec4(float(_7._m0[_13].y)));
}

View File

@ -0,0 +1,20 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
layout(set = 0, binding = 0, std430) readonly buffer SSBO
{
uint indices[];
} _8;
layout(set = 0, binding = 0) uniform sampler2D uSamplers[];
layout(set = 1, binding = 0) uniform sampler2D uSampler;
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec2 vUV;
void main()
{
FragColor = textureLod(uSamplers[nonuniformEXT(_8.indices[10])], vUV, 0.0);
FragColor += textureLod(uSampler, vUV, float(_8.indices[int(gl_FragCoord.y)]));
}

View File

@ -0,0 +1,96 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 53
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability SampledImageArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %vUV %gl_FragCoord
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpSourceExtension "GL_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %FragColor "FragColor"
OpName %uSamplers "uSamplers"
OpName %SSBO "SSBO"
OpMemberName %SSBO 0 "indices"
OpName %_ ""
OpName %vUV "vUV"
OpName %uSampler "uSampler"
OpName %gl_FragCoord "gl_FragCoord"
OpDecorate %FragColor Location 0
OpDecorate %uSamplers DescriptorSet 0
OpDecorate %uSamplers Binding 0
OpDecorate %_runtimearr_uint ArrayStride 4
OpMemberDecorate %SSBO 0 NonWritable
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %SSBO BufferBlock
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
OpDecorate %26 NonUniform
OpDecorate %28 NonUniform
OpDecorate %29 NonUniform
OpDecorate %vUV Location 0
OpDecorate %uSampler DescriptorSet 1
OpDecorate %uSampler Binding 0
OpDecorate %38 NonUniform
OpDecorate %gl_FragCoord BuiltIn FragCoord
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%10 = OpTypeImage %float 2D 0 0 0 1 Unknown
%11 = OpTypeSampledImage %10
%_runtimearr_11 = OpTypeRuntimeArray %11
%_ptr_UniformConstant__runtimearr_11 = OpTypePointer UniformConstant %_runtimearr_11
%uSamplers = OpVariable %_ptr_UniformConstant__runtimearr_11 UniformConstant
%uint = OpTypeInt 32 0
%_runtimearr_uint = OpTypeRuntimeArray %uint
%SSBO = OpTypeStruct %_runtimearr_uint
%_ptr_Uniform_SSBO = OpTypePointer Uniform %SSBO
%_ = OpVariable %_ptr_Uniform_SSBO Uniform
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_10 = OpConstant %int 10
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%vUV = OpVariable %_ptr_Input_v2float Input
%float_0 = OpConstant %float 0
%uSampler = OpVariable %_ptr_UniformConstant_11 UniformConstant
%_ptr_Input_v4float = OpTypePointer Input %v4float
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
%uint_1 = OpConstant %uint 1
%_ptr_Input_float = OpTypePointer Input %float
%main = OpFunction %void None %3
%5 = OpLabel
%24 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %int_10
%26 = OpLoad %uint %24
%28 = OpAccessChain %_ptr_UniformConstant_11 %uSamplers %26
%29 = OpLoad %11 %28
%33 = OpLoad %v2float %vUV
%35 = OpImageSampleExplicitLod %v4float %29 %33 Lod %float_0
OpStore %FragColor %35
%37 = OpLoad %11 %uSampler
%38 = OpCopyObject %11 %37
%39 = OpLoad %v2float %vUV
%44 = OpAccessChain %_ptr_Input_float %gl_FragCoord %uint_1
%45 = OpLoad %float %44
%46 = OpConvertFToS %int %45
%47 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %46
%48 = OpLoad %uint %47
%49 = OpConvertUToF %float %48
%50 = OpImageSampleExplicitLod %v4float %38 %39 Lod %49
%51 = OpLoad %v4float %FragColor
%52 = OpFAdd %v4float %51 %50
OpStore %FragColor %52
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,298 @@
; SPIR-V
; Version: 1.3
; Generator: Unknown(30017); 21022
; Bound: 233
; Schema: 0
OpCapability Shader
OpCapability SampledBuffer
OpCapability ImageBuffer
OpCapability ImageQuery
OpCapability StorageImageWriteWithoutFormat
OpCapability GroupNonUniformBallot
OpCapability RuntimeDescriptorArray
OpCapability UniformTexelBufferArrayDynamicIndexing
OpCapability StorageTexelBufferArrayDynamicIndexing
OpCapability UniformTexelBufferArrayNonUniformIndexing
OpCapability StorageTexelBufferArrayNonUniformIndexing
OpCapability PhysicalStorageBufferAddresses
OpExtension "SPV_EXT_descriptor_indexing"
OpExtension "SPV_KHR_physical_storage_buffer"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpExecutionMode %main LocalSize 1 1 1
OpName %main "main"
OpName %RootConstants "RootConstants"
OpName %registers "registers"
OpName %SSBO_Offsets "SSBO_Offsets"
OpDecorate %RootConstants Block
OpMemberDecorate %RootConstants 0 Offset 0
OpMemberDecorate %RootConstants 1 Offset 4
OpMemberDecorate %RootConstants 2 Offset 8
OpMemberDecorate %RootConstants 3 Offset 12
OpMemberDecorate %RootConstants 4 Offset 16
OpMemberDecorate %RootConstants 5 Offset 20
OpMemberDecorate %RootConstants 6 Offset 24
OpMemberDecorate %RootConstants 7 Offset 28
OpDecorate %_runtimearr_v2uint ArrayStride 8
OpMemberDecorate %SSBO_Offsets 0 Offset 0
OpDecorate %SSBO_Offsets Block
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 0
OpDecorate %13 NonWritable
OpDecorate %13 Restrict
OpDecorate %18 DescriptorSet 1
OpDecorate %18 Binding 0
OpDecorate %22 DescriptorSet 4
OpDecorate %22 Binding 0
OpDecorate %26 DescriptorSet 4
OpDecorate %26 Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %148 NonUniform
OpDecorate %149 NonUniform
OpDecorate %172 NonUniform
OpDecorate %173 NonUniform
OpDecorate %196 NonUniform
OpDecorate %197 NonUniform
OpDecorate %205 NonUniform
%void = OpTypeVoid
%2 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%RootConstants = OpTypeStruct %uint %uint %uint %uint %uint %uint %uint %uint
%_ptr_PushConstant_RootConstants = OpTypePointer PushConstant %RootConstants
%registers = OpVariable %_ptr_PushConstant_RootConstants PushConstant
%v2uint = OpTypeVector %uint 2
%_runtimearr_v2uint = OpTypeRuntimeArray %v2uint
%SSBO_Offsets = OpTypeStruct %_runtimearr_v2uint
%_ptr_StorageBuffer_SSBO_Offsets = OpTypePointer StorageBuffer %SSBO_Offsets
%13 = OpVariable %_ptr_StorageBuffer_SSBO_Offsets StorageBuffer
%float = OpTypeFloat 32
%15 = OpTypeImage %float Buffer 0 0 0 1 Unknown
%_runtimearr_15 = OpTypeRuntimeArray %15
%_ptr_UniformConstant__runtimearr_15 = OpTypePointer UniformConstant %_runtimearr_15
%18 = OpVariable %_ptr_UniformConstant__runtimearr_15 UniformConstant
%19 = OpTypeImage %float Buffer 0 0 0 2 R32f
%_runtimearr_19 = OpTypeRuntimeArray %19
%_ptr_UniformConstant__runtimearr_19 = OpTypePointer UniformConstant %_runtimearr_19
%22 = OpVariable %_ptr_UniformConstant__runtimearr_19 UniformConstant
%23 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
%_runtimearr_23 = OpTypeRuntimeArray %23
%_ptr_UniformConstant__runtimearr_23 = OpTypePointer UniformConstant %_runtimearr_23
%26 = OpVariable %_ptr_UniformConstant__runtimearr_23 UniformConstant
%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23
%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
%uint_4 = OpConstant %uint 4
%uint_2 = OpConstant %uint 2
%uint_3 = OpConstant %uint 3
%_ptr_StorageBuffer_v2uint = OpTypePointer StorageBuffer %v2uint
%uint_0 = OpConstant %uint 0
%_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
%uint_1 = OpConstant %uint 1
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%_ptr_Input_uint = OpTypePointer Input %uint
%bool = OpTypeBool
%uint_4294967295 = OpConstant %uint 4294967295
%v4float = OpTypeVector %float 4
%uint_1024 = OpConstant %uint 1024
%uint_2048 = OpConstant %uint 2048
%_ptr_Image_uint = OpTypePointer Image %uint
%uint_40 = OpConstant %uint 40
%uint_50 = OpConstant %uint 50
%uint_70 = OpConstant %uint 70
%main = OpFunction %void None %2
%4 = OpLabel
OpBranch %231
%231 = OpLabel
%30 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_4
%32 = OpLoad %uint %30
%33 = OpIAdd %uint %32 %uint_2
%28 = OpAccessChain %_ptr_UniformConstant_23 %26 %33
%35 = OpLoad %23 %28
%36 = OpGroupNonUniformBroadcastFirst %uint %uint_3 %33
%39 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %36
%41 = OpLoad %v2uint %39
%44 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_4
%45 = OpLoad %uint %44
%43 = OpAccessChain %_ptr_UniformConstant_19 %22 %45
%46 = OpLoad %19 %43
%47 = OpGroupNonUniformBroadcastFirst %uint %uint_3 %45
%48 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %47
%49 = OpLoad %v2uint %48
%52 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_1
%54 = OpLoad %uint %52
%55 = OpIAdd %uint %54 %uint_1
%51 = OpAccessChain %_ptr_UniformConstant_15 %18 %55
%56 = OpLoad %15 %51
%57 = OpGroupNonUniformBroadcastFirst %uint %uint_3 %55
%58 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %57
%59 = OpLoad %v2uint %58
%64 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
%65 = OpLoad %uint %64
%66 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_1
%67 = OpLoad %uint %66
%68 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
%69 = OpLoad %uint %68
%70 = OpIAdd %uint %65 %uint_4
%71 = OpCompositeExtract %uint %49 0
%72 = OpCompositeExtract %uint %49 1
%73 = OpIAdd %uint %70 %71
%75 = OpULessThan %bool %70 %72
%76 = OpSelect %uint %75 %73 %uint_4294967295
%79 = OpImageRead %v4float %46 %76
%80 = OpCompositeExtract %float %79 0
%81 = OpCompositeExtract %float %79 1
%82 = OpCompositeExtract %float %79 2
%83 = OpCompositeExtract %float %79 3
%84 = OpIAdd %uint %65 %uint_1024
%86 = OpCompositeExtract %uint %49 0
%87 = OpCompositeExtract %uint %49 1
%88 = OpIAdd %uint %84 %86
%89 = OpULessThan %bool %84 %87
%90 = OpSelect %uint %89 %88 %uint_4294967295
%91 = OpCompositeConstruct %v4float %80 %81 %82 %83
OpImageWrite %46 %90 %91
%92 = OpIAdd %uint %65 %uint_2
%93 = OpCompositeExtract %uint %59 0
%94 = OpCompositeExtract %uint %59 1
%95 = OpIAdd %uint %92 %93
%96 = OpULessThan %bool %92 %94
%97 = OpSelect %uint %96 %95 %uint_4294967295
%98 = OpImageFetch %v4float %56 %97
%99 = OpCompositeExtract %float %98 0
%100 = OpCompositeExtract %float %98 1
%101 = OpCompositeExtract %float %98 2
%102 = OpCompositeExtract %float %98 3
%103 = OpIAdd %uint %65 %uint_2048
%105 = OpCompositeExtract %uint %49 0
%106 = OpCompositeExtract %uint %49 1
%107 = OpIAdd %uint %103 %105
%108 = OpULessThan %bool %103 %106
%109 = OpSelect %uint %108 %107 %uint_4294967295
%110 = OpCompositeConstruct %v4float %99 %100 %101 %102
OpImageWrite %46 %109 %110
%111 = OpCompositeExtract %uint %41 0
%112 = OpCompositeExtract %uint %41 1
%113 = OpIAdd %uint %65 %111
%114 = OpULessThan %bool %65 %112
%115 = OpSelect %uint %114 %113 %uint_4294967295
%117 = OpImageTexelPointer %_ptr_Image_uint %28 %115 %uint_0
%118 = OpAtomicIAdd %uint %117 %uint_1 %uint_0 %uint_40
%120 = OpCompositeExtract %uint %41 0
%121 = OpCompositeExtract %uint %41 1
%122 = OpIAdd %uint %67 %120
%123 = OpULessThan %bool %67 %121
%124 = OpSelect %uint %123 %122 %uint_4294967295
%125 = OpImageTexelPointer %_ptr_Image_uint %28 %124 %uint_0
%126 = OpAtomicCompareExchange %uint %125 %uint_1 %uint_0 %uint_0 %uint_50 %uint_40
%128 = OpCompositeExtract %uint %49 1
%129 = OpConvertUToF %float %128
%130 = OpCompositeExtract %uint %49 0
%131 = OpCompositeExtract %uint %49 1
%132 = OpIAdd %uint %uint_0 %130
%133 = OpULessThan %bool %uint_0 %131
%134 = OpSelect %uint %133 %132 %uint_4294967295
%135 = OpCompositeConstruct %v4float %129 %129 %129 %129
OpImageWrite %46 %134 %135
%136 = OpCompositeExtract %uint %59 1
%137 = OpConvertUToF %float %136
%138 = OpCompositeExtract %uint %49 0
%139 = OpCompositeExtract %uint %49 1
%140 = OpIAdd %uint %uint_1 %138
%141 = OpULessThan %bool %uint_1 %139
%142 = OpSelect %uint %141 %140 %uint_4294967295
%143 = OpCompositeConstruct %v4float %137 %137 %137 %137
OpImageWrite %46 %142 %143
%144 = OpIAdd %uint %69 %uint_0
%146 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_4
%147 = OpLoad %uint %146
%148 = OpIAdd %uint %147 %144
%145 = OpAccessChain %_ptr_UniformConstant_19 %22 %148
%149 = OpLoad %19 %145
%150 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %148
%151 = OpLoad %v2uint %150
%152 = OpCompositeExtract %uint %151 0
%153 = OpCompositeExtract %uint %151 1
%154 = OpIAdd %uint %70 %152
%155 = OpULessThan %bool %70 %153
%156 = OpSelect %uint %155 %154 %uint_4294967295
%157 = OpImageRead %v4float %149 %156
%158 = OpCompositeExtract %float %157 0
%159 = OpCompositeExtract %float %157 1
%160 = OpCompositeExtract %float %157 2
%161 = OpCompositeExtract %float %157 3
%162 = OpCompositeExtract %uint %151 0
%163 = OpCompositeExtract %uint %151 1
%164 = OpIAdd %uint %84 %162
%165 = OpULessThan %bool %84 %163
%166 = OpSelect %uint %165 %164 %uint_4294967295
%167 = OpCompositeConstruct %v4float %158 %159 %160 %161
OpImageWrite %149 %166 %167
%168 = OpIAdd %uint %69 %uint_0
%170 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_1
%171 = OpLoad %uint %170
%172 = OpIAdd %uint %171 %168
%169 = OpAccessChain %_ptr_UniformConstant_15 %18 %172
%173 = OpLoad %15 %169
%174 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %172
%175 = OpLoad %v2uint %174
%176 = OpCompositeExtract %uint %175 0
%177 = OpCompositeExtract %uint %175 1
%178 = OpIAdd %uint %70 %176
%179 = OpULessThan %bool %70 %177
%180 = OpSelect %uint %179 %178 %uint_4294967295
%181 = OpImageFetch %v4float %173 %180
%182 = OpCompositeExtract %float %181 0
%183 = OpCompositeExtract %float %181 1
%184 = OpCompositeExtract %float %181 2
%185 = OpCompositeExtract %float %181 3
%186 = OpCompositeExtract %uint %151 0
%187 = OpCompositeExtract %uint %151 1
%188 = OpIAdd %uint %103 %186
%189 = OpULessThan %bool %103 %187
%190 = OpSelect %uint %189 %188 %uint_4294967295
%191 = OpCompositeConstruct %v4float %182 %183 %184 %185
OpImageWrite %149 %190 %191
%192 = OpIAdd %uint %69 %uint_0
%194 = OpAccessChain %_ptr_PushConstant_uint %registers %uint_4
%195 = OpLoad %uint %194
%196 = OpIAdd %uint %195 %192
%193 = OpAccessChain %_ptr_UniformConstant_23 %26 %196
%197 = OpLoad %23 %193
%198 = OpAccessChain %_ptr_StorageBuffer_v2uint %13 %uint_0 %196
%199 = OpLoad %v2uint %198
%200 = OpCompositeExtract %uint %199 0
%201 = OpCompositeExtract %uint %199 1
%202 = OpIAdd %uint %67 %200
%203 = OpULessThan %bool %67 %201
%204 = OpSelect %uint %203 %202 %uint_4294967295
%205 = OpImageTexelPointer %_ptr_Image_uint %193 %204 %uint_0
%206 = OpAtomicIAdd %uint %205 %uint_1 %uint_0 %uint_40
%207 = OpCompositeExtract %uint %199 0
%208 = OpCompositeExtract %uint %199 1
%209 = OpIAdd %uint %67 %207
%210 = OpULessThan %bool %67 %208
%211 = OpSelect %uint %210 %209 %uint_4294967295
%212 = OpImageTexelPointer %_ptr_Image_uint %193 %211 %uint_0
%213 = OpAtomicCompareExchange %uint %212 %uint_1 %uint_0 %uint_0 %uint_70 %uint_40
%215 = OpCompositeExtract %uint %151 1
%216 = OpConvertUToF %float %215
%217 = OpCompositeExtract %uint %49 0
%218 = OpCompositeExtract %uint %49 1
%219 = OpIAdd %uint %uint_2 %217
%220 = OpULessThan %bool %uint_2 %218
%221 = OpSelect %uint %220 %219 %uint_4294967295
%222 = OpCompositeConstruct %v4float %216 %216 %216 %216
OpImageWrite %46 %221 %222
%223 = OpCompositeExtract %uint %175 1
%224 = OpConvertUToF %float %223
%225 = OpCompositeExtract %uint %49 0
%226 = OpCompositeExtract %uint %49 1
%227 = OpIAdd %uint %uint_3 %225
%228 = OpULessThan %bool %uint_3 %226
%229 = OpSelect %uint %228 %227 %uint_4294967295
%230 = OpCompositeConstruct %v4float %224 %224 %224 %224
OpImageWrite %46 %229 %230
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,96 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 53
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability SampledImageArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %vUV %gl_FragCoord
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpSourceExtension "GL_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %FragColor "FragColor"
OpName %uSamplers "uSamplers"
OpName %SSBO "SSBO"
OpMemberName %SSBO 0 "indices"
OpName %_ ""
OpName %vUV "vUV"
OpName %uSampler "uSampler"
OpName %gl_FragCoord "gl_FragCoord"
OpDecorate %FragColor Location 0
OpDecorate %uSamplers DescriptorSet 0
OpDecorate %uSamplers Binding 0
OpDecorate %_runtimearr_uint ArrayStride 4
OpMemberDecorate %SSBO 0 NonWritable
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %SSBO BufferBlock
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
OpDecorate %26 NonUniform
OpDecorate %28 NonUniform
OpDecorate %29 NonUniform
OpDecorate %vUV Location 0
OpDecorate %uSampler DescriptorSet 1
OpDecorate %uSampler Binding 0
OpDecorate %38 NonUniform
OpDecorate %gl_FragCoord BuiltIn FragCoord
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%10 = OpTypeImage %float 2D 0 0 0 1 Unknown
%11 = OpTypeSampledImage %10
%_runtimearr_11 = OpTypeRuntimeArray %11
%_ptr_UniformConstant__runtimearr_11 = OpTypePointer UniformConstant %_runtimearr_11
%uSamplers = OpVariable %_ptr_UniformConstant__runtimearr_11 UniformConstant
%uint = OpTypeInt 32 0
%_runtimearr_uint = OpTypeRuntimeArray %uint
%SSBO = OpTypeStruct %_runtimearr_uint
%_ptr_Uniform_SSBO = OpTypePointer Uniform %SSBO
%_ = OpVariable %_ptr_Uniform_SSBO Uniform
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_10 = OpConstant %int 10
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%vUV = OpVariable %_ptr_Input_v2float Input
%float_0 = OpConstant %float 0
%uSampler = OpVariable %_ptr_UniformConstant_11 UniformConstant
%_ptr_Input_v4float = OpTypePointer Input %v4float
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
%uint_1 = OpConstant %uint 1
%_ptr_Input_float = OpTypePointer Input %float
%main = OpFunction %void None %3
%5 = OpLabel
%24 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %int_10
%26 = OpLoad %uint %24
%28 = OpAccessChain %_ptr_UniformConstant_11 %uSamplers %26
%29 = OpLoad %11 %28
%33 = OpLoad %v2float %vUV
%35 = OpImageSampleExplicitLod %v4float %29 %33 Lod %float_0
OpStore %FragColor %35
%37 = OpLoad %11 %uSampler
%38 = OpCopyObject %11 %37
%39 = OpLoad %v2float %vUV
%44 = OpAccessChain %_ptr_Input_float %gl_FragCoord %uint_1
%45 = OpLoad %float %44
%46 = OpConvertFToS %int %45
%47 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %46
%48 = OpLoad %uint %47
%49 = OpConvertUToF %float %48
%50 = OpImageSampleExplicitLod %v4float %38 %39 Lod %49
%51 = OpLoad %v4float %FragColor
%52 = OpFAdd %v4float %51 %50
OpStore %FragColor %52
OpReturn
OpFunctionEnd

View File

@ -14600,7 +14600,35 @@ void CompilerGLSL::convert_non_uniform_expression(const SPIRType &type, std::str
// so we might have to fixup the OpLoad-ed expression late.
auto start_array_index = expr.find_first_of('[');
auto end_array_index = expr.find_last_of(']');
if (start_array_index == string::npos)
return;
// Check for the edge case that a non-arrayed resource was marked to be nonuniform,
// and the bracket we found is actually part of non-resource related data.
if (expr.find_first_of(',') < start_array_index)
return;
// We've opened a bracket, track expressions until we can close the bracket.
// This must be our image index.
size_t end_array_index = string::npos;
unsigned bracket_count = 1;
for (size_t index = start_array_index + 1; index < expr.size(); index++)
{
if (expr[index] == ']')
{
if (--bracket_count == 0)
{
end_array_index = index;
break;
}
}
else if (expr[index] == '[')
bracket_count++;
}
assert(bracket_count == 0);
// Doesn't really make sense to declare a non-arrayed image with nonuniformEXT, but there's
// nothing we can do here to express that.
if (start_array_index == string::npos || end_array_index == string::npos || end_array_index < start_array_index)