schell / schell/wgsl-rs

TextureSampleLevel i32/u32 overloads on sampled textures exceed WGSL spec; add textureGather for cube types

Open
#157 0 comments 0 reactions 0 assignees View on GitHub
bug P1
Dominant language
Rust
Stars
61
Forks
4
Avg merge
1d 21h
Merged PRs (30d)
9

Description

## Two follow-up items from PR #156

### 1. `TextureSampleLevel<_, i32>` and `<_, u32>` on non-depth sampled textures

Per [WGSL spec §17.7.13](https://www.w3.org/TR/WGSL/#texturesamplelevel), the `level` parameter for `textureSampleLevel` must be **`f32`** for sampled textures (`texture_1d`, `texture_2d`, `texture_2d_array`, `texture_3d`, `texture_cube`, `texture_cube_array`). Only **depth** textures accept `i32`/`u32` levels.

The codebase implements `TextureSampleLevel<_, i32>` and `TextureSampleLevel<_, u32>` for all of these, which means code that compiles in Rust world would fail WGSL validation. This is a pre-existing issue (already present on `Texture2D` before #156) and was propagated to the new types for consistency.

Affected (from #156): `Texture1D` (lines 369, 381), `Texture3D` (lines 1340, 1359), `TextureCube` (lines 1584, 1603).

### 2. `textureGather` for `TextureCube` and `TextureCubeArray`

Per [WGSL spec §17.7.2](https://www.w3.org/TR/WGSL/#texturegather), `textureGather` has overloads for `texture_cube` and `texture_cube_array` (with `ST` in {f32, i32, u32}). PR #156 implemented the `textureSample` family for cube types but did not add the `TextureGather` / `TextureGatherArray` trait impls.

### Proposed fix

- Remove the `i32`/`u32` level overloads from all **non-depth** sampled texture types (`Texture1D`, `Texture2D`, `Texture2DArray`, `Texture3D`, `TextureCube`, `TextureCubeArray`), keeping only `f32` for those. Depth textures keep `i32`/`u32`/`f32`.
- Add `TextureGather` impls for `TextureCube` and `TextureGatherArray` impls for `TextureCubeArray` with `u32`/`i32` array indices, including the CPU-side face selection and 4-texel gather logic.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the TextureSampleLevel implementations for Texture1D, Texture2D, Texture2DArray, Texture3D, TextureCube, and TextureCubeArray, then compare their overloads with the WGSL textureSampleLevel rules. Next locate the TextureGather and TextureGatherArray trait implementations and the cube texture code added by PR #156. Done means non-depth sampled textures retain only f32 level overloads, depth textures retain their permitted levels, and cube and cube-array gather implementations cover f32, i32, and u32 types with the specified indices and CPU-side gathering.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.