GLSL/HLSL: Implement nonuniform qualifier for image atomics.
This commit is contained in:
parent
65aa0c35d6
commit
a3d3c80dd7
@ -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();
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
@ -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
|
@ -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]);
|
||||
|
@ -4848,8 +4848,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]);
|
||||
|
Loading…
Reference in New Issue
Block a user