-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
75 lines (64 loc) · 1.83 KB
/
lib.rs
File metadata and controls
75 lines (64 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#![cfg_attr(target_arch = "spirv", no_std)]
#[cfg_attr(target_arch = "spirv", global_allocator)]
static _ALLOCATOR: shared_alloc::BumpAllocViaBufs</*DESCRIPTOR_SET*/ 0> =
shared_alloc::BumpAllocViaBufs;
#[macro_use]
extern crate alloc;
use alloc::boxed::Box;
use alloc::rc::Rc;
use spirv_std::glam::UVec3;
use spirv_std::spirv;
#[spirv(compute(threads(128)))]
pub fn box_or_vec_1_u32(#[spirv(global_invocation_id)] id: UVec3) {
match id.x % 8 {
0 => {
let _ = Box::new(id.x);
}
1 => {
let _ = vec![id.x];
}
_ => {}
}
}
#[spirv(compute(threads(128)))]
pub fn box_new_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 4 == 0 {
let _ = Box::new(id.x);
}
}
// FIXME(eddyb) incorporate into the big example, and `README`.
#[spirv(compute(threads(128)))]
pub fn rc_new_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 4 == 0 {
let _ = Rc::new(id.x);
}
}
#[spirv(compute(threads(128)))]
pub fn vec_1_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 4 == 0 {
let _ = vec![id.x];
}
}
// FIXME(eddyb) incorporate into the big example, and `README`.
#[spirv(compute(threads(128)))]
pub fn vec_2_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 4 == 0 {
let mut v = vec![id.x, id.x];
v[(id.x / 4) as usize % 2] |= 0xabcd_0000;
}
}
#[spirv(compute(threads(128)))]
pub fn vec_new_push_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 4 == 0 {
let mut v = vec![];
v.push(id.x);
}
}
// NOTE(eddyb) this forces `realloc` to trigger with 1 `push` call and 0 loops.
#[spirv(compute(threads(128)))]
pub fn vec_cap1_push_u32(#[spirv(global_invocation_id)] id: UVec3) {
if id.x % 16 == 0 {
let mut v = vec![id.x];
v.push(id.x | 0x1111_0000);
}
}