Skip to content

Commit f0ca67f

Browse files
committed
feat: implement essential numeric and logical builtin functions (issue #12)
Adds 13 WGSL builtin functions: Numeric functions: - dot: Dot product for Vec{2,3,4}f/i/u - normalize: Unit vector for Vec{2,3,4}f - cross: Cross product for Vec3f - clamp: Value clamping for f32/i32/u32 and vectors - mix: Linear interpolation for f32 and Vec{2,3,4}f - floor: Floor for f32 and Vec{2,3,4}f - ceil: Ceiling for f32 and Vec{2,3,4}f - exp: Natural exponentiation for f32 and Vec{2,3,4}f - exp2: Base-2 exponentiation for f32 and Vec{2,3,4}f - degrees: Radians to degrees for f32 and Vec{2,3,4}f Logical functions: - all: Returns true if all components are true (Vec{2,3,4}b) - any: Returns true if any component is true (Vec{2,3,4}b) - select: Conditional select for all scalar and vector types Closes #12
1 parent c820af4 commit f0ca67f

2 files changed

Lines changed: 698 additions & 11 deletions

File tree

SESSION.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Session: Essential Numeric and Logical Builtin Functions
2+
3+
## Selected Issue
4+
5+
**Issue #12 - Essential Numeric and Logical Builtin Functions (Priority 1)**
6+
https://github.com/schell/wgsl-rs/issues/12
7+
8+
## Functions Implemented
9+
10+
### Numeric Functions (10)
11+
- [x] `dot(e1: vecN<T>, e2: vecN<T>) -> T` - Dot product
12+
- [x] `normalize(e: vecN<T>) -> vecN<T>` - Unit vector
13+
- [x] `cross(e1: vec3<T>, e2: vec3<T>) -> vec3<T>` - Cross product (vec3 only)
14+
- [x] `clamp(e: T, low: T, high: T) -> T` - Value clamping
15+
- [x] `mix(e1: T, e2: T, e3: T) -> T` - Linear interpolation
16+
- [x] `floor(e: T) -> T` - Floor
17+
- [x] `ceil(e: T) -> T` - Ceiling
18+
- [x] `exp(e: T) -> T` - Natural exponentiation (e^x)
19+
- [x] `exp2(e: T) -> T` - Base-2 exponentiation (2^x)
20+
- [x] `degrees(e: T) -> T` - Radians to degrees
21+
22+
### Logical Functions (3)
23+
- [x] `all(e: vecN<bool>) -> bool` - Returns true if all components are true
24+
- [x] `any(e: vecN<bool>) -> bool` - Returns true if any component is true
25+
- [x] `select(f: T, t: T, cond: bool) -> T` - Conditional select
26+
27+
## Type Support
28+
29+
| Function | f32 | i32 | u32 | Vec{2,3,4}f | Vec{2,3,4}i | Vec{2,3,4}u | Vec{2,3,4}b |
30+
|----------|-----|-----|-----|-------------|-------------|-------------|-------------|
31+
| dot | - | - | - | Yes | Yes | Yes | - |
32+
| normalize | - | - | - | Yes | - | - | - |
33+
| cross | - | - | - | Vec3f only | - | - | - |
34+
| clamp | Yes | Yes | Yes | Yes | Yes | Yes | - |
35+
| mix | Yes | - | - | Yes | - | - | - |
36+
| floor | Yes | - | - | Yes | - | - | - |
37+
| ceil | Yes | - | - | Yes | - | - | - |
38+
| exp | Yes | - | - | Yes | - | - | - |
39+
| exp2 | Yes | - | - | Yes | - | - | - |
40+
| degrees | Yes | - | - | Yes | - | - | - |
41+
| all | - | - | - | - | - | - | Yes (returns bool) |
42+
| any | - | - | - | - | - | - | Yes (returns bool) |
43+
| select | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
44+
45+
## Implementation Summary
46+
47+
### File Modified
48+
`crates/wgsl-rs/src/std/numeric_builtin_functions.rs`
49+
50+
### Changes Made
51+
1. Added 13 new trait/function pairs
52+
2. Added 13 sanity tests
53+
3. Updated doc comment table to mark all 13 functions as implemented (`x`)
54+
55+
### Verification
56+
- `cargo test` - 39 tests pass (13 new)
57+
- `cargo clippy` - No warnings
58+
- `cargo fmt` - Applied
59+
60+
## Reference
61+
62+
- WGSL Spec Numeric: https://gpuweb.github.io/gpuweb/wgsl/#numeric-builtin-functions
63+
- WGSL Spec Logical: https://gpuweb.github.io/gpuweb/wgsl/#logical-builtin-functions

0 commit comments

Comments
 (0)