-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add MAY_DISCARD
shader def, enabling early depth tests for most cases
#6697
Add MAY_DISCARD
shader def, enabling early depth tests for most cases
#6697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good approach to me. It will conflict with the prepass, but that's only because the prepass PR also contains essentially the same logic. So this will help make the prepass PR that tiny bit simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simple and scoped change. I have got nothing to add here.
A benchmark would indeed be interesting, but should not be necessary for merging this PR.
Now that #6284 has been merged, we should be able to reap some noticeable benefit from early depth tests. @IceSentry just to confirm, did you include anything to the effect of this PR in #6284? I gave it a quick glance and couldn't find anything that specifically gates the It looks like #6644 might also be merged soon. I'll wait until then, so that I fix the conflicts all at once. Can someone help me come up with a good benchmark to verify early depth testing is benefiting us? I was thinking of something like a couple thousand complicated meshes, randomly positioned, overlapping each other, all opaque. Is there a recommended way to measure the amount of time spent running the shaders directly from the code? I'm thinking about using Metal System Trace on Instruments on macOS, but that only covers one platform and one API, ideally we'd have something more generic. |
No I didn't include this since I expected this PR to be merged. It would most likely help since currently the prepass has a pretty high negative performance impact. Right now the prepass only becomes a performance improvements when the fragment shader is really heavy, otherwise it's mostly useful for special effects. When you update this PR, make sure you also look at the prepass shaders, I think some of them use discard. |
…`ALPHA_MASK` flag
- It is only currently supported by the GLES3.1+ wgpu backend; - Enabling it would require special backend-specific code; - Using it in the shaders would require adding a `#define` specifically for it; - Only benefit is that it prevents adding accidental unguarded `discard;` statements that may harm performance.
Objective
discard
, even for situations where they are not necessary.Solution
MeshPipelineKey
and shader def,MAY_DISCARD
;discard
s being needed must setMAY_DISCARD
ahead of time:AlphaMode::Mask(f32)
, but in the future might include other options/effects; (e.g. one effect I'm personally interested in is bayer dither pseudo-transparency for LOD transitions of opaque meshes)discard
are guarded by an#ifdef MAY_DISCARD
preprocessor directive:alpha_discard()
;MAY_DISCARD
is not set, the@early_depth_test
attribute is added to the PBR fragment shader. This is a not yet documented, possibly non-standard WGSL extension I found browsing Naga's source code. I opened a PR to document it there. My understanding is that for backends where this attribute is supported, it will force an explicit opt-in to early depth test. (e.g. vialayout(early_fragment_tests) in;
in GLSL)Caveats
@early_depth_test
for the sake of us being explicit, and avoiding the need for the driver to be “smart” about enabling this feature. That way, if we make a mistake and include adiscard
unguarded byMAY_DISCARD
, it will either produce errors or noticeable visual artifacts so that we'll catch early, instead of causing a performance regression.Changelog
Changed
StandardMaterial
, reducing the number of fragments evaluated for scenes with lots of occlusions.