@@ -39,5 +39,75 @@ struct DeviceBuffer {
3939 has_alignment: bool // True if vec2, vec3, int2 and int3 are expected to be like vec4 or int4 in memory
4040}
4141
42+ fn @make_null_device_buffer() = DeviceBuffer {
43+ add_atomic_i32 = @|_, _| 0:i32,
44+ add_atomic_f32 = @|_, _| 0:f32,
45+ min_atomic_i32 = @|_, _| 0:i32,
46+ max_atomic_i32 = @|_, _| 0:i32,
47+ load_i32_host = @|_| 0:i32,
48+ store_i32_host = @|_, _| {},
49+ copy_from_host = @|_, _, _| {},
50+ copy_to_host = @|_, _, _| {},
51+ load_i32 = @|_| 0:i32,
52+ load_f32 = @|_| 0:f32,
53+ load_vec2 = @|_| make_vec2(0,0),
54+ load_vec3 = @|_| make_vec3(0,0,0),
55+ load_vec4 = @|_| make_vec4(0,0,0,0),
56+ load_int2 = @|_| (0,0),
57+ load_int3 = @|_| (0,0,0),
58+ load_int4 = @|_| (0,0,0,0),
59+ load_mat3x3 = @|_| mat3x3_identity(),
60+ load_mat3x4 = @|_| mat3x4_identity(),
61+ load_mat4x4 = @|_| mat4x4_identity(),
62+ store_i32 = @|_, _| {},
63+ store_f32 = @|_, _| {},
64+ store_vec2 = @|_, _| {},
65+ store_vec3 = @|_, _| {},
66+ store_vec4 = @|_, _| {},
67+ store_int2 = @|_, _, _| {},
68+ store_int3 = @|_, _, _, _| {},
69+ store_int4 = @|_, _, _, _, _| {},
70+ store_mat3x3 = @|_, _| {},
71+ store_mat3x4 = @|_, _| {},
72+ store_mat4x4 = @|_, _| {},
73+ count = 0,
74+ has_alignment = true
75+ };
76+
77+ fn @shift_device_buffer(off: i32, count: i32, buffer: DeviceBuffer) = DeviceBuffer {
78+ add_atomic_i32 = @|id, v| buffer.add_atomic_i32(id + off, v),
79+ add_atomic_f32 = @|id, v| buffer.add_atomic_f32(id + off, v),
80+ min_atomic_i32 = @|id, v| buffer.min_atomic_i32(id + off, v),
81+ max_atomic_i32 = @|id, v| buffer.max_atomic_i32(id + off, v),
82+ load_i32_host = @|id| buffer.load_i32_host(id + off),
83+ store_i32_host = @|id, v| buffer.store_i32_host(id + off, v),
84+ copy_from_host = @|s, e, ptr| buffer.copy_from_host(s + off, e + off, ptr),
85+ copy_to_host = @|s, e, ptr| buffer.copy_to_host(s + off, e + off, ptr),
86+ load_i32 = @|id| buffer.load_i32(id + off),
87+ load_f32 = @|id| buffer.load_f32(id + off),
88+ load_vec2 = @|id| buffer.load_vec2(id + off),
89+ load_vec3 = @|id| buffer.load_vec3(id + off),
90+ load_vec4 = @|id| buffer.load_vec4(id + off),
91+ load_int2 = @|id| buffer.load_int2(id + off),
92+ load_int3 = @|id| buffer.load_int3(id + off),
93+ load_int4 = @|id| buffer.load_int4(id + off),
94+ load_mat3x3 = @|id| buffer.load_mat3x3(id + off),
95+ load_mat3x4 = @|id| buffer.load_mat3x4(id + off),
96+ load_mat4x4 = @|id| buffer.load_mat4x4(id + off),
97+ store_i32 = @|id, v| buffer.store_i32(id + off, v),
98+ store_f32 = @|id, v| buffer.store_f32(id + off, v),
99+ store_vec2 = @|id, v| buffer.store_vec2(id + off, v),
100+ store_vec3 = @|id, v| buffer.store_vec3(id + off, v),
101+ store_vec4 = @|id, v| buffer.store_vec4(id + off, v),
102+ store_int2 = @|id, v1, v2| buffer.store_int2(id + off, v1, v2),
103+ store_int3 = @|id, v1, v2, v3| buffer.store_int3(id + off, v1, v2, v3),
104+ store_int4 = @|id, v1, v2, v3, v4| buffer.store_int4(id + off, v1, v2, v3, v4),
105+ store_mat3x3 = @|id, v| buffer.store_mat3x3(id + off, v),
106+ store_mat3x4 = @|id, v| buffer.store_mat3x4(id + off, v),
107+ store_mat4x4 = @|id, v| buffer.store_mat4x4(id + off, v),
108+ count = count,
109+ has_alignment = buffer.has_alignment
110+ };
111+
42112// Unsized device buffer accessor
43113type DeviceBufferAccessor = fn (&[u8]) -> DeviceBuffer;
0 commit comments