File tree Expand file tree Collapse file tree 4 files changed +12
-34
lines changed
examples/shaders/reduce/src
tests/difftests/tests/arch
atomic_ops/atomic_ops-rust/src
memory_barriers/memory_barriers-rust/src
workgroup_memory/workgroup_memory-rust/src Expand file tree Collapse file tree 4 files changed +12
-34
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ pub fn main(
54
54
if subgroup_local_invocation_id == 0 {
55
55
shared[ subgroup_id as usize ] = sum;
56
56
}
57
- unsafe { spirv_std:: arch:: workgroup_memory_barrier_with_group_sync ( ) } ;
57
+ spirv_std:: arch:: workgroup_memory_barrier_with_group_sync ( ) ;
58
58
let mut sum = 0 ;
59
59
if subgroup_id == 0 {
60
60
if subgroup_local_invocation_id < num_subgroups {
Original file line number Diff line number Diff line change @@ -31,9 +31,7 @@ pub fn main_cs(
31
31
// Thread 0 stores the final values after all operations complete
32
32
if tid == 0 {
33
33
// Use atomic loads to ensure we read the final values
34
- unsafe {
35
- spirv_std:: arch:: workgroup_memory_barrier_with_group_sync ( ) ;
36
- }
34
+ spirv_std:: arch:: workgroup_memory_barrier_with_group_sync ( ) ;
37
35
output[ 0 ] = counters[ 0 ] ; // Should be initial + 32
38
36
output[ 1 ] = counters[ 1 ] ; // Should be initial - 32
39
37
output[ 2 ] = counters[ 2 ] ; // Should be min(initial, 0)
Original file line number Diff line number Diff line change @@ -19,9 +19,7 @@ pub fn main_cs(
19
19
shared[ lid] = input[ tid] ;
20
20
21
21
// Workgroup barrier to ensure all threads have loaded their data
22
- unsafe {
23
- workgroup_memory_barrier_with_group_sync ( ) ;
24
- }
22
+ workgroup_memory_barrier_with_group_sync ( ) ;
25
23
26
24
// Perform operations on shared memory
27
25
let mut result = shared[ lid] ;
@@ -53,17 +51,13 @@ pub fn main_cs(
53
51
}
54
52
55
53
// Another barrier before writing back
56
- unsafe {
57
- workgroup_memory_barrier_with_group_sync ( ) ;
58
- }
54
+ workgroup_memory_barrier_with_group_sync ( ) ;
59
55
60
56
// Write result back to shared memory
61
57
shared[ lid] = result;
62
58
63
59
// Memory barrier to ensure writes are visible
64
- unsafe {
65
- workgroup_memory_barrier_with_group_sync ( ) ;
66
- }
60
+ workgroup_memory_barrier_with_group_sync ( ) ;
67
61
68
62
// Final read and output
69
63
output[ tid] = shared[ lid] ;
Original file line number Diff line number Diff line change @@ -14,59 +14,45 @@ pub fn main_cs(
14
14
shared[ lid] = input[ lid] ;
15
15
16
16
// Synchronize to ensure all threads have loaded
17
- unsafe {
18
- workgroup_memory_barrier_with_group_sync ( ) ;
19
- }
17
+ workgroup_memory_barrier_with_group_sync ( ) ;
20
18
21
19
// Each thread sums its value with its neighbor (reduction step)
22
20
if lid < 32 {
23
21
shared[ lid] += shared[ lid + 32 ] ;
24
22
}
25
23
26
24
// Synchronize again
27
- unsafe {
28
- workgroup_memory_barrier_with_group_sync ( ) ;
29
- }
25
+ workgroup_memory_barrier_with_group_sync ( ) ;
30
26
31
27
if lid < 16 {
32
28
shared[ lid] += shared[ lid + 16 ] ;
33
29
}
34
30
35
- unsafe {
36
- workgroup_memory_barrier_with_group_sync ( ) ;
37
- }
31
+ workgroup_memory_barrier_with_group_sync ( ) ;
38
32
39
33
if lid < 8 {
40
34
shared[ lid] += shared[ lid + 8 ] ;
41
35
}
42
36
43
- unsafe {
44
- workgroup_memory_barrier_with_group_sync ( ) ;
45
- }
37
+ workgroup_memory_barrier_with_group_sync ( ) ;
46
38
47
39
if lid < 4 {
48
40
shared[ lid] += shared[ lid + 4 ] ;
49
41
}
50
42
51
- unsafe {
52
- workgroup_memory_barrier_with_group_sync ( ) ;
53
- }
43
+ workgroup_memory_barrier_with_group_sync ( ) ;
54
44
55
45
if lid < 2 {
56
46
shared[ lid] += shared[ lid + 2 ] ;
57
47
}
58
48
59
- unsafe {
60
- workgroup_memory_barrier_with_group_sync ( ) ;
61
- }
49
+ workgroup_memory_barrier_with_group_sync ( ) ;
62
50
63
51
if lid < 1 {
64
52
shared[ lid] += shared[ lid + 1 ] ;
65
53
}
66
54
67
- unsafe {
68
- workgroup_memory_barrier_with_group_sync ( ) ;
69
- }
55
+ workgroup_memory_barrier_with_group_sync ( ) ;
70
56
71
57
// Write final result
72
58
if lid == 0 {
You can’t perform that action at this time.
0 commit comments