gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.13k stars 881 forks source link

[glsl-in] Figure out how to handle depth textures #4358

Open magcius opened 2 years ago

magcius commented 2 years ago

GLSL does not differentiate between depth textures and float textures, while WGSL does. Currently, a texture2D converts to a Sampled, and there's no way to declare a Depth texture AFAICT.

There's possibly a WGSL spec change happening in gpuweb/gpuweb#2094, however it seems likely that texture_2d_depth will remain for use with comparison samplers, which is a restriction from Metal.

If gpuweb/gpuweb#2094 gets approved, then we'll only need to handle this for comparison samplers, which we can probably do by tracking whether a shadow sampler is used on a given texture (this is what SPIRV-Cross and glsl-optimizer do in their Metal backends).

If gpuweb/gpuweb#2094 does not get approved, then we'll need a way of flagging a texture as a depth texture. A basic option could be a layout pragma, e.g. layout(depth, set = 0, binding = 0)

JCapucho commented 2 years ago

Currently it's tracked by usage in the glsl frontend it's not entirely uniplemented, the solution isn't elegant though since the glsl spec defines thing in a very permissive way, you should use samplerShadow for operations of that kind but it's not strictly needed and textures can be used in both depth and sampled contexts, this is impossible to implement with the current IR and there's no real benefit in changing since some targets wouldn't be able to use it then.