Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using illegal negative values for wgpu::SamplerDescriptor::lod_min_clamp. #436

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

James2022-rgb
Copy link
Contributor

Negative values like -100.0 are illegal for GPUSamplerDescriptor.lodMinClamp.

More specifically, WebGPU valid usage states that lodMinClamp must not be negative, and lodMaxClamp must be >= lodMinClamp:

descriptor.lodMinClamp ≥ 0.
descriptor.lodMaxClamp ≥ descriptor.lodMinClamp.

Indeed, Chrome's WebGPU implementation complains:

LOD clamp bounds [-100.000000, 100.000000] contain contain a negative number.
 - While validating [SamplerDescriptor]
 - While calling [Device].CreateSampler([SamplerDescriptor]).

It dislikes it even more when we actually try to sample using this illegal sampler:

[Invalid Sampler] is invalid.
 - While validating entries[1] as a Sampler.
Expected entry layout: { binding: 1, visibility: ShaderStage::Fragment, sampler: { type: SamplerBindingType::Filtering } }
 - While validating [BindGroupDescriptor "material_bind_group"] against [BindGroupLayout "material_bind_group_layout"]
 - While calling [Device].CreateBindGroup([BindGroupDescriptor "material_bind_group"]).
[Invalid BindGroup "material_bind_group"] is invalid.
 - While encoding [RenderPassEncoder "Render Pass"].SetBindGroup(1, [BindGroup], 0, ...).
[Invalid CommandBuffer] is invalid.
    at ValidateObject (..\..\third_party\dawn\src\dawn\native\Device.cpp:651)
    at ValidateSubmit (..\..\third_party\dawn\src\dawn\native\Queue.cpp:393)

This PR changes all the illegal negative values to 0.0.

The value of 0.0 is the default value for ``wgpu::SamplerDescriptor::lod_min_clamp` anyway so technically it can be omitted,
but I think being explicit here helps for documentation purposes.

…min_clamp`.

WebGPU valid usage states `lodMinClamp` must not be negative, and `lodMaxClamp` must be >= `lodMinClamp`
@James2022-rgb
Copy link
Contributor Author

Note that this is a hard error now on wgpu master branch:
gfx-rs/wgpu#3353

Not sure when it will be on crates.io.

Copy link
Owner

@sotrh sotrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks!

@sotrh sotrh merged commit fc21a0f into sotrh:master Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants