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
//! WGSL shader source helpers for OxiGDAL GPU.
//!
//! This module provides utilities for generating type-parameterised WGSL
//! compute shader sources. The primary use-case is producing element-wise
//! pass-through shaders that can be composed into larger pipelines, with
//! optional half-precision support when `BufferElementType::F16` is
//! requested.
use crateBufferElementType;
/// Generate a single-pass element-wise identity compute shader for the given
/// element type.
///
/// The shader reads from `@binding(0)` (read-only storage) and writes the
/// same values to `@binding(1)` (read-write storage), dispatched over a
/// workgroup of size 64 in the X dimension.
///
/// When `element_type` is [`BufferElementType::F16`], the emitted WGSL
/// source begins with `enable f16;` so that `array<f16>` is a valid
/// storage type. On adapters that do not expose `wgpu::Features::SHADER_F16`
/// this shader will fail to compile — use
/// [`crate::buffer::from_f16_slice_widening`] instead.
///
/// For all other element types no extension directive is emitted, and the
/// array element type degrades to WGSL's native types (`f32`, `u32`, `i32`).
///
/// # Examples
///
/// ```
/// use oxigdal_gpu::{BufferElementType, make_element_wise_shader_source};
///
/// let src = make_element_wise_shader_source(BufferElementType::F32);
/// assert!(src.contains("array<f32>"));
/// assert!(!src.contains("enable f16"));
///
/// let src_f16 = make_element_wise_shader_source(BufferElementType::F16);
/// assert!(src_f16.contains("enable f16"));
/// assert!(src_f16.contains("array<f16>"));
/// ```