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

Implement TextureFormat::Stencil8 + add stencil example #3343

Merged
merged 3 commits into from
Jan 2, 2023

Conversation

Dinnerbone
Copy link
Contributor

@Dinnerbone Dinnerbone commented Dec 31, 2022

Checklist

  • Run cargo clippy.
  • Run RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
Fixes #3196

Description
It's common for 2d applications to use the stencil buffer without depth buffers, but wgpu so far required you to allocate (at minimum) a Depth24PlusStencil8, which can be wasteful. Stencil8 will, on supported platforms, only contain the stencil buffer and nothing else.

It currently maps to:

Backend Texture Type Notes
Vulkan Either S8_UINT, D24_UNORM_S8_UINT or D32_SFLOAT_S8_UINT Left to right, first one supported
GLES GL_STENCIL_INDEX8 It's a required format in ES3
Metal MTLPixelFormat.stencil8 It appears to be required in Metal, there's no mention to it being feature gated.
DX12 DXGI_FORMAT_D24_UNORM_S8_UINT Effectively same as Depth24PlusStencil8
DX11 DXGI_FORMAT_D24_UNORM_S8_UINT Effectively same as Depth24PlusStencil8

Testing
In addition to adding the new format to the existing clear_texture_tests, I've added an example called stencil-triangles which shows how to use stencil testing in wgpu.

All tests* pass for me on Windows and Mac.
*except for shadow on Mac, and water on Windows. Those seem to be known bugs and unrelated to my code though.

I've also confirmed that a large project I contribute to, Ruffle, runs and passes all its visual tests using Stencil8 on DX12, Vulkan, and GLES. I'm not able to run it on Metal currently.

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2022

Codecov Report

Merging #3343 (826bc21) into master (aa46e82) will increase coverage by 0.32%.
The diff coverage is 90.62%.

@@            Coverage Diff             @@
##           master    #3343      +/-   ##
==========================================
+ Coverage   64.10%   64.42%   +0.32%     
==========================================
  Files          86       86              
  Lines       42591    42622      +31     
==========================================
+ Hits        27301    27461     +160     
+ Misses      15290    15161     -129     
Impacted Files Coverage Δ
wgpu-core/src/command/transfer.rs 75.14% <ø> (ø)
wgpu-core/src/validation.rs 58.87% <ø> (ø)
wgpu-hal/src/gles/adapter.rs 83.72% <ø> (ø)
wgpu-hal/src/vulkan/mod.rs 56.37% <ø> (ø)
wgpu-info/src/main.rs 76.41% <ø> (ø)
wgpu-hal/src/vulkan/conv.rs 74.72% <40.00%> (+2.95%) ⬆️
wgpu-hal/src/auxil/dxgi/conv.rs 76.02% <100.00%> (+0.33%) ⬆️
wgpu-hal/src/gles/conv.rs 75.28% <100.00%> (+0.93%) ⬆️
wgpu-hal/src/lib.rs 26.92% <100.00%> (+0.70%) ⬆️
wgpu-hal/src/vulkan/adapter.rs 76.77% <100.00%> (+0.33%) ⬆️
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@nical
Copy link
Contributor

nical commented Jan 2, 2023

Nice!

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.

Add stencil8 texture format
3 participants