shame
shame copied to clipboard
sampling `sm::Texture<_, _, sm::Multi>` with `MipFn::Level` needs nicer error messages
trafficstars
this program creates an error message that is technically correct, but not ideal for guiding the user to the required fix:
use shame as sm;
fn main() -> Result<(), sm::EncodingErrors> {
let _pipeline = {
let mut enc = sm::start_encoding(Default::default())?;
let mut dispatch = enc.new_compute_pipeline([4, 4]);
let mut bindings = dispatch.bind_groups.next();
let ms_tex: sm::Texture<sm::tf::Rg8Unorm, _, sm::Multi> = bindings.next();
let filter: sm::Sampler<sm::Filtering> = bindings.next();
filter.sample(ms_tex, sm::MipFn::zero(), sm::f32x2::zero());
enc.finish()?
};
Ok(())
}
yields error:
shame encoding error:
--> src/main.rs:12:16
|
12 > filter.sample(ms_tex, sm::MipFn::zero(), sm::f32x2::zero());
| ^
|
no matching function call for `TextureSampleLevel { uvw_offset: None }` with argument types
[Store(Handle(SampledTexture(_2D, Nearest { len: X2, channel_type: F32 }, Multi))), Store(Handle(Sampler(Filtering))), Store(Sized(Vector(X2, F32))), Store(Sized(Vector(X1, F32)))]
a 2ch nearest f32-sampled texture is incompatible with a filtering sampler
the texture format sm::tf::Rg8Unorm itself causes no nearest requirement on the sampler, but sm::Multi-sampling does.
once the sampler type is adjusted to Sampler<Nearest> the real issue is presented, which is
no matching function call for `TextureSampleLevel { uvw_offset: None }` with argument types
[Store(Handle(SampledTexture(_2D, Nearest { len: X2, channel_type: F32 }, Multi))), Store(Handle(Sampler(NonFiltering))), Store(Sized(Vector(X2, F32))), Store(Sized(Vector(X1, F32)))]
first argument must be a sampleable texture with a single sample per pixel
Once Multi is changed back to Single the pipeline encoding succeeds.
Encountering a runtime typechecker error is always a bug if encountered through use of the statically typed rust api.
Potential solutions:
- add a custom error message before the runtime typechecker is entered for multisampled textures in particular
- make
fn samplerequire single sampled textures and provide a separate function for multisampled textures which offers an alternativeMipFn-like enum for the subset of mip functions supported by those textures (if there are multiple). - switch the order of error generation in the runtime typechecker somehow, so that the "first argument must be a sampleable texture with a single sample per pixel" error check happens before the "a 2ch nearest f32-sampled texture is incompatible with a filtering sampler" error