Merge pull request #1296 from KhronosGroup/fix-1292

Fix nonuniform qualifier with atomics
This commit is contained in:
Hans-Kristian Arntzen 2020-03-19 13:29:19 +01:00 committed by GitHub
commit c3d216c011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 305 additions and 7 deletions

View File

@ -0,0 +1,21 @@
RWByteAddressBuffer ssbos[] : register(u0, space0);
static uint3 gl_GlobalInvocationID;
struct SPIRV_Cross_Input
{
uint3 gl_GlobalInvocationID : SV_DispatchThreadID;
};
void comp_main()
{
uint _24 = gl_GlobalInvocationID.z;
uint _25;
ssbos[NonUniformResourceIndex(_24)].InterlockedAdd(0, 1u, _25);
}
[numthreads(1, 1, 1)]
void main(SPIRV_Cross_Input stage_input)
{
gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID;
comp_main();
}

View File

@ -0,0 +1,21 @@
RWTexture2D<uint> uImage[] : register(u0, space0);
static uint3 gl_GlobalInvocationID;
struct SPIRV_Cross_Input
{
uint3 gl_GlobalInvocationID : SV_DispatchThreadID;
};
void comp_main()
{
uint _26 = gl_GlobalInvocationID.z;
uint _31;
InterlockedAdd(uImage[NonUniformResourceIndex(_26)][int2(gl_GlobalInvocationID.xy)], 1u, _31);
}
[numthreads(1, 1, 1)]
void main(SPIRV_Cross_Input stage_input)
{
gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID;
comp_main();
}

View File

@ -1,9 +1,9 @@
struct UBO_1_1
struct UBO_1_1_1
{
float4 v[64];
};
ConstantBuffer<UBO_1_1> ubos[] : register(b0, space2);
ConstantBuffer<UBO_1_1_1> ubos[] : register(b0, space2);
ByteAddressBuffer ssbos[] : register(t0, space3);
Texture2D<float4> uSamplers[] : register(t0, space0);
SamplerState uSamps[] : register(s0, space1);

View File

@ -0,0 +1,15 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0, std430) buffer SSBO
{
uint v;
} ssbos[];
void main()
{
uint _24 = gl_GlobalInvocationID.z;
uint _25 = atomicAdd(ssbos[nonuniformEXT(_24)].v, 1u);
}

View File

@ -0,0 +1,12 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0, r32ui) uniform uimage2D uImage[];
void main()
{
uint _26 = gl_GlobalInvocationID.z;
uint _31 = imageAtomicAdd(uImage[nonuniformEXT(_26)], ivec2(gl_GlobalInvocationID.xy), 1u);
}

View File

@ -0,0 +1,53 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 8
; Bound: 26
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability StorageBufferArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%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_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %SSBO "SSBO"
OpMemberName %SSBO 0 "v"
OpName %ssbos "ssbos"
OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %SSBO BufferBlock
OpDecorate %ssbos DescriptorSet 0
OpDecorate %ssbos Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %22 NonUniform
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%SSBO = OpTypeStruct %uint
%_runtimearr_SSBO = OpTypeRuntimeArray %SSBO
%_ptr_Uniform__runtimearr_SSBO = OpTypePointer Uniform %_runtimearr_SSBO
%ssbos = OpVariable %_ptr_Uniform__runtimearr_SSBO Uniform
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_2 = OpConstant %uint 2
%_ptr_Input_uint = OpTypePointer Input %uint
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%uint_1 = OpConstant %uint 1
%uint_0 = OpConstant %uint 0
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
%17 = OpLoad %uint %16
%18 = OpCopyObject %uint %17
%22 = OpAccessChain %_ptr_Uniform_uint %ssbos %18 %int_0
%25 = OpAtomicIAdd %uint %22 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,55 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 8
; Bound: 32
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability StorageImageArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%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_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %uImage "uImage"
OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
OpDecorate %uImage DescriptorSet 0
OpDecorate %uImage Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %30 NonUniform
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%7 = OpTypeImage %uint 2D 0 0 0 2 R32ui
%_runtimearr_7 = OpTypeRuntimeArray %7
%_ptr_UniformConstant__runtimearr_7 = OpTypePointer UniformConstant %_runtimearr_7
%uImage = OpVariable %_ptr_UniformConstant__runtimearr_7 UniformConstant
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_2 = OpConstant %uint 2
%_ptr_Input_uint = OpTypePointer Input %uint
%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
%v2uint = OpTypeVector %uint 2
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%uint_1 = OpConstant %uint 1
%uint_0 = OpConstant %uint 0
%_ptr_Image_uint = OpTypePointer Image %uint
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
%17 = OpLoad %uint %16
%18 = OpCopyObject %uint %17
%20 = OpAccessChain %_ptr_UniformConstant_7 %uImage %18
%22 = OpLoad %v3uint %gl_GlobalInvocationID
%23 = OpVectorShuffle %v2uint %22 %22 0 1
%26 = OpBitcast %v2int %23
%30 = OpImageTexelPointer %_ptr_Image_uint %20 %26 %uint_0
%31 = OpAtomicIAdd %uint %30 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,53 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 8
; Bound: 26
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability StorageBufferArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%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_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %SSBO "SSBO"
OpMemberName %SSBO 0 "v"
OpName %ssbos "ssbos"
OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %SSBO BufferBlock
OpDecorate %ssbos DescriptorSet 0
OpDecorate %ssbos Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %22 NonUniform
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%SSBO = OpTypeStruct %uint
%_runtimearr_SSBO = OpTypeRuntimeArray %SSBO
%_ptr_Uniform__runtimearr_SSBO = OpTypePointer Uniform %_runtimearr_SSBO
%ssbos = OpVariable %_ptr_Uniform__runtimearr_SSBO Uniform
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_2 = OpConstant %uint 2
%_ptr_Input_uint = OpTypePointer Input %uint
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%uint_1 = OpConstant %uint 1
%uint_0 = OpConstant %uint 0
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
%17 = OpLoad %uint %16
%18 = OpCopyObject %uint %17
%22 = OpAccessChain %_ptr_Uniform_uint %ssbos %18 %int_0
%25 = OpAtomicIAdd %uint %22 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,55 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 8
; Bound: 32
; Schema: 0
OpCapability Shader
OpCapability ShaderNonUniform
OpCapability RuntimeDescriptorArray
OpCapability StorageImageArrayNonUniformIndexing
OpExtension "SPV_EXT_descriptor_indexing"
%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_EXT_nonuniform_qualifier"
OpName %main "main"
OpName %uImage "uImage"
OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
OpDecorate %uImage DescriptorSet 0
OpDecorate %uImage Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %30 NonUniform
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%7 = OpTypeImage %uint 2D 0 0 0 2 R32ui
%_runtimearr_7 = OpTypeRuntimeArray %7
%_ptr_UniformConstant__runtimearr_7 = OpTypePointer UniformConstant %_runtimearr_7
%uImage = OpVariable %_ptr_UniformConstant__runtimearr_7 UniformConstant
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_2 = OpConstant %uint 2
%_ptr_Input_uint = OpTypePointer Input %uint
%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
%v2uint = OpTypeVector %uint 2
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%uint_1 = OpConstant %uint 1
%uint_0 = OpConstant %uint 0
%_ptr_Image_uint = OpTypePointer Image %uint
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
%17 = OpLoad %uint %16
%18 = OpCopyObject %uint %17
%20 = OpAccessChain %_ptr_UniformConstant_7 %uImage %18
%22 = OpLoad %v3uint %gl_GlobalInvocationID
%23 = OpVectorShuffle %v2uint %22 %22 0 1
%26 = OpBitcast %v2int %23
%30 = OpImageTexelPointer %_ptr_Image_uint %20 %26 %uint_0
%31 = OpAtomicIAdd %uint %30 %uint_1 %uint_0 %uint_1
OpReturn
OpFunctionEnd

View File

@ -8474,6 +8474,9 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
if (expr.expression_dependencies.empty())
forwarded_temporaries.erase(ops[1]);
if (has_decoration(ops[1], DecorationNonUniformEXT) || has_decoration(ops[2], DecorationNonUniformEXT))
propagate_nonuniform_qualifier(ops[1]);
break;
}
@ -8481,9 +8484,6 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto *var = maybe_get<SPIRVariable>(ops[0]);
if (has_decoration(ops[0], DecorationNonUniformEXT))
propagate_nonuniform_qualifier(ops[0]);
if (var && var->statically_assigned)
var->static_expression = ops[1];
else if (var && var->loop_variable && !var->loop_variable_enable)
@ -10088,7 +10088,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
target_coord_type.basetype = SPIRType::Int;
coord_expr = bitcast_expression(target_coord_type, expression_type(ops[3]).basetype, coord_expr);
auto &e = set<SPIRExpression>(id, join(to_expression(ops[2]), ", ", coord_expr), result_type, true);
auto expr = join(to_expression(ops[2]), ", ", coord_expr);
if (has_decoration(id, DecorationNonUniformEXT) || has_decoration(ops[2], DecorationNonUniformEXT))
convert_non_uniform_expression(expression_type(ops[2]), expr);
auto &e = set<SPIRExpression>(id, expr, result_type, true);
// When using the pointer, we need to know which variable it is actually loaded from.
auto *var = maybe_get_backing_variable(ops[2]);

View File

@ -4010,6 +4010,9 @@ void CompilerHLSL::emit_access_chain(const Instruction &instruction)
inherit_expression_dependencies(ops[1], ops[i]);
add_implied_read_expression(e, ops[i]);
}
if (has_decoration(ops[1], DecorationNonUniformEXT) || has_decoration(ops[2], DecorationNonUniformEXT))
propagate_nonuniform_qualifier(ops[1]);
}
else
{
@ -4848,8 +4851,14 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto expr = to_expression(ops[2]);
if (has_decoration(id, DecorationNonUniformEXT) || has_decoration(ops[2], DecorationNonUniformEXT))
convert_non_uniform_expression(expression_type(ops[2]), expr);
expr += join("[", to_expression(ops[3]), "]");
auto &e =
set<SPIRExpression>(id, join(to_expression(ops[2]), "[", to_expression(ops[3]), "]"), result_type, true);
set<SPIRExpression>(id, expr, result_type, true);
// When using the pointer, we need to know which variable it is actually loaded from.
auto *var = maybe_get_backing_variable(ops[2]);