GLSL/HLSL: Fix nonuniform qualifier for SSBO atomics.
This commit is contained in:
parent
a3d3c80dd7
commit
05004a57ea
@ -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();
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
@ -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
|
@ -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)
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user