Skip to content

Commit d02e7b3

Browse files
committed
Fix #8151.
1 parent 04a3401 commit d02e7b3

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

naga/src/front/spv/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,10 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
38693869
crate::Barrier::TEXTURE,
38703870
semantics & spirv::MemorySemantics::IMAGE_MEMORY.bits() != 0,
38713871
);
3872+
3873+
block.extend(emitter.finish(ctx.expressions));
38723874
block.push(crate::Statement::ControlBarrier(flags), span);
3875+
emitter.start(ctx.expressions);
38733876
} else {
38743877
log::warn!("Unsupported barrier execution scope: {exec_scope}");
38753878
}
@@ -3911,7 +3914,10 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
39113914
crate::Barrier::TEXTURE,
39123915
semantics & spirv::MemorySemantics::IMAGE_MEMORY.bits() != 0,
39133916
);
3917+
3918+
block.extend(emitter.finish(ctx.expressions));
39143919
block.push(crate::Statement::MemoryBarrier(flags), span);
3920+
emitter.start(ctx.expressions);
39153921
}
39163922
Op::CopyObject => {
39173923
inst.expect(4)?;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
; SPIR-V
2+
; Version: 1.3
3+
; Generator: Google rspirv; 0
4+
; Bound: 45
5+
; Schema: 0
6+
OpCapability Shader
7+
OpCapability VulkanMemoryModel
8+
OpExtension "SPV_KHR_vulkan_memory_model"
9+
OpMemoryModel Logical Vulkan
10+
OpEntryPoint GLCompute %1 "barrier_reorder_bug" %gl_LocalInvocationID
11+
OpExecutionMode %1 LocalSize 2 1 1
12+
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
13+
OpDecorate %_runtimearr_uint ArrayStride 4
14+
OpDecorate %_struct_8 Block
15+
OpMemberDecorate %_struct_8 0 Offset 0
16+
OpDecorate %5 Binding 0
17+
OpDecorate %5 DescriptorSet 0
18+
%uint = OpTypeInt 32 0
19+
%v3uint = OpTypeVector %uint 3
20+
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
21+
%void = OpTypeVoid
22+
%13 = OpTypeFunction %void
23+
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input
24+
%_runtimearr_uint = OpTypeRuntimeArray %uint
25+
%_struct_8 = OpTypeStruct %_runtimearr_uint
26+
%_ptr_StorageBuffer__struct_8 = OpTypePointer StorageBuffer %_struct_8
27+
%5 = OpVariable %_ptr_StorageBuffer__struct_8 StorageBuffer
28+
%uint_0 = OpConstant %uint 0
29+
%bool = OpTypeBool
30+
%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
31+
%6 = OpVariable %_ptr_Workgroup_uint Workgroup
32+
%uint_1 = OpConstant %uint 1
33+
%uint_2 = OpConstant %uint 2
34+
%uint_264 = OpConstant %uint 264
35+
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
36+
%1 = OpFunction %void None %13
37+
%23 = OpLabel
38+
%24 = OpLoad %v3uint %gl_LocalInvocationID
39+
%27 = OpCompositeExtract %uint %24 0
40+
%28 = OpIEqual %bool %27 %uint_0
41+
OpSelectionMerge %29 None
42+
OpBranchConditional %28 %30 %31
43+
%30 = OpLabel
44+
OpStore %6 %uint_1
45+
OpBranch %29
46+
%31 = OpLabel
47+
OpBranch %29
48+
%29 = OpLabel
49+
OpControlBarrier %uint_2 %uint_2 %uint_264
50+
%32 = OpLoad %uint %6
51+
OpControlBarrier %uint_2 %uint_2 %uint_264
52+
%39 = OpInBoundsAccessChain %_ptr_StorageBuffer_uint %5 %uint_0 %27
53+
OpStore %39 %32
54+
OpSelectionMerge %42 None
55+
OpBranchConditional %28 %43 %44
56+
%43 = OpLabel
57+
OpStore %6 %uint_2
58+
OpBranch %42
59+
%44 = OpLabel
60+
OpBranch %42
61+
%42 = OpLabel
62+
OpReturn
63+
OpFunctionEnd
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
struct type_3 {
2+
member: array<u32>,
3+
}
4+
5+
var<private> global: vec3<u32>;
6+
@group(0) @binding(0)
7+
var<storage, read_write> global_1: type_3;
8+
var<workgroup> global_2: u32;
9+
10+
fn function() {
11+
let _e6 = global;
12+
let _e8 = (_e6.x == 0u);
13+
if _e8 {
14+
global_2 = 1u;
15+
}
16+
workgroupBarrier();
17+
let _e9 = global_2;
18+
workgroupBarrier();
19+
global_1.member[_e6.x] = _e9;
20+
if _e8 {
21+
global_2 = 2u;
22+
}
23+
return;
24+
}
25+
26+
@compute @workgroup_size(2, 1, 1)
27+
fn barrier_reorder_bug(@builtin(local_invocation_id) param: vec3<u32>) {
28+
global = param;
29+
function();
30+
}

0 commit comments

Comments
 (0)