Skip to main content

versorc_math/gpu/
shaders.rs

1// ============================================================================
2// VERSORC-MATH: VULKAN & SPIR-V COMPUTE SHADERS FOR GEOMETRIC OPERATIONS
3// License: Apache-2.0
4//
5// Precompiled SPIR-V 1.3+ bytecode for GPU-accelerated versor, lattice,
6// and dense vector operations. Can be embedded directly by any Vulkan runtime
7// (including `versorc-tiering` and external graphics/compute pipelines).
8// ============================================================================
9
10pub const ROPE_SPV: &[u8] = include_bytes!("../../shaders/rope.spv");
11pub const SILU_MUL_SPV: &[u8] = include_bytes!("../../shaders/silu_mul.spv");
12pub const RMSNORM_SPV: &[u8] = include_bytes!("../../shaders/rmsnorm.spv");
13pub const VEC_ADD_SPV: &[u8] = include_bytes!("../../shaders/vec_add.spv");
14pub const HOT_STRATUM_E8_SPV: &[u8] = include_bytes!("../../shaders/hot_stratum_e8.spv");
15pub const PGA_TRANSFORM_SPV: &[u8] = include_bytes!("../../shaders/pga_transform.spv");
16pub const CGA_TRANSFORM_SPV: &[u8] = include_bytes!("../../shaders/cga_transform.spv");
17
18/// Push constant payload for Planar Spinor Bank (RoPE) compute shader.
19#[repr(C)]
20#[derive(Debug, Clone, Copy, PartialEq)]
21#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
22pub struct RopePushConstants {
23    pub pos: u32,
24    pub n_heads: u32,
25    pub head_dim: u32,
26    pub rope_theta: f32,
27    pub is_neox: u32,
28    pub _pad0: u32,
29    pub _pad1: u32,
30    pub _pad2: u32,
31}
32
33impl RopePushConstants {
34    pub fn new(pos: u32, n_heads: u32, head_dim: u32, rope_theta: f32, is_neox: bool) -> Self {
35        Self {
36            pos,
37            n_heads,
38            head_dim,
39            rope_theta,
40            is_neox: if is_neox { 1 } else { 0 },
41            _pad0: 0,
42            _pad1: 0,
43            _pad2: 0,
44        }
45    }
46}
47
48/// Push constant payload for SwiGLU / SiLU-Mul fused activation compute shader.
49#[repr(C)]
50#[derive(Debug, Clone, Copy, PartialEq)]
51#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
52pub struct SiluMulPushConstants {
53    pub num_elements: u32,
54    pub _pad0: u32,
55    pub _pad1: u32,
56    pub _pad2: u32,
57}
58
59impl SiluMulPushConstants {
60    pub fn new(num_elements: u32) -> Self {
61        Self {
62            num_elements,
63            _pad0: 0,
64            _pad1: 0,
65            _pad2: 0,
66        }
67    }
68}
69
70/// Push constant payload for RMSNorm compute shader.
71#[repr(C)]
72#[derive(Debug, Clone, Copy, PartialEq)]
73#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
74pub struct RmsNormPushConstants {
75    pub d_model: u32,
76    pub eps: f32,
77    pub gamma_offset_f32: u32,
78    pub _pad1: u32,
79}
80
81impl RmsNormPushConstants {
82    pub fn new(d_model: u32, eps: f32, gamma_offset_f32: u32) -> Self {
83        Self {
84            d_model,
85            eps,
86            gamma_offset_f32,
87            _pad1: 0,
88        }
89    }
90}
91
92/// Push constant payload for Vector Addition (Residual Stream Accumulation) compute shader.
93#[repr(C)]
94#[derive(Debug, Clone, Copy, PartialEq)]
95#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
96pub struct VecAddPushConstants {
97    pub num_elements: u32,
98    pub _pad0: u32,
99    pub _pad1: u32,
100    pub _pad2: u32,
101}
102
103impl VecAddPushConstants {
104    pub fn new(num_elements: u32) -> Self {
105        Self {
106            num_elements,
107            _pad0: 0,
108            _pad1: 0,
109            _pad2: 0,
110        }
111    }
112}
113
114/// Push constant payload for Gosset E8 Lattice projection on GPU.
115#[repr(C)]
116#[derive(Debug, Clone, Copy, PartialEq)]
117#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
118pub struct HotStratumE8PushConstants {
119    pub d_model: u32,
120    pub neuron_count: u32,
121    pub pass_id: u32,
122    pub layer_gamma: f32,
123    pub beta: f32,
124    pub gate_gamma: f32,
125    pub up_gamma: f32,
126    pub words_per_row: u32,
127}
128
129/// Push constant payload for 3D Projective Geometric Algebra (PGA) rigid tensor transform on GPU.
130#[repr(C)]
131#[derive(Debug, Clone, Copy, PartialEq)]
132#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
133pub struct PgaTransformPushConstants {
134    pub num_points: u32,
135    pub motor_s: f32,
136    pub motor_b23: f32,
137    pub motor_b31: f32,
138    pub motor_b12: f32,
139    pub motor_d01: f32,
140    pub motor_d02: f32,
141    pub motor_d03: f32,
142    pub motor_e0123: f32,
143    pub _pad0: u32,
144    pub _pad1: u32,
145    pub _pad2: u32,
146}
147
148impl PgaTransformPushConstants {
149    pub fn new(num_points: u32, motor: &crate::pga::PgaMotor) -> Self {
150        Self {
151            num_points,
152            motor_s: motor.s,
153            motor_b23: motor.b23,
154            motor_b31: motor.b31,
155            motor_b12: motor.b12,
156            motor_d01: motor.d01,
157            motor_d02: motor.d02,
158            motor_d03: motor.d03,
159            motor_e0123: motor.e0123,
160            _pad0: 0,
161            _pad1: 0,
162            _pad2: 0,
163        }
164    }
165}
166
167/// Push constant payload for 3D Conformal Geometric Algebra (CGA) spherical inversion on GPU.
168#[repr(C)]
169#[derive(Debug, Clone, Copy, PartialEq)]
170#[cfg_attr(feature = "vulkan", derive(bytemuck::Pod, bytemuck::Zeroable))]
171pub struct CgaTransformPushConstants {
172    pub num_points: u32,
173    pub op_type: u32,
174    pub sphere_cx: f32,
175    pub sphere_cy: f32,
176    pub sphere_cz: f32,
177    pub sphere_radius: f32,
178    pub param_lambda: f32,
179    pub param_dy: f32,
180    pub param_dz: f32,
181    pub _pad0: u32,
182    pub _pad1: u32,
183    pub _pad2: u32,
184}