Gpuweb: Allow writeTexture into depth textures?

Created on 2 Sep 2020  路  4Comments  路  Source: gpuweb/gpuweb

Copying into depth textures is problematic today in WebGPU - see #997 .
First, because there are depth formats without concrete formats, like depth24plus*.
Secondly, because the native API require floating point depth to be in 0.0 to 1.0 range, or otherwise declare it to be undefined behavior.

This means we can't copy from buffers into even depth32float textures. We can't even copy from r32float into them, safely! Unless we do sophisticated on-GPU processing of the data, that is.

There is one place, however, where we do have a luxury of processing the data, practically for free. It's writeTexture. The implementation needs to copy the data anyway, so it may as well clamp the values into 0-1 range. Possibly, even convert the data into the format that the depth actually expects (e.g. D24X8).

This might as well be the only way to upload data into depth textures. Should we make it possible?

enhancement question

Most helpful comment

I agree this is not super necessary for MVP since it's still possible to write use a shader to blit a buffer or texture into a depth texture.

How do you see this possible? Depth textures don't support STORAGE, and you can't copy from a different GPU resource into them.

Edit; answering my own question - bind the buffer as storage readonly, and write gl_FragDepth in da shader

All 4 comments

For depth32float and depth24plus, maybe, although I'd argue that's a feature that's not super necessary for MVP and can go on the pile of additional flexibility to add later.

For depth24plus-stencil8 we need to figure out if it is possible to copy in only the depth aspect and not the stencil one.

I agree this is not super necessary for MVP since it's still possible to write use a shader to blit a buffer or texture into a depth texture.

Do you think this covers most usecases? Seems like it works for uploading shadow maps; I don't imagine B2T/T2T would be needed for uploading shadow maps unless you have a compressed format that's decoded on the GPU. (Even if you did you could theoretically still use a shader to blit into the depth texture.)

I agree this is not super necessary for MVP since it's still possible to write use a shader to blit a buffer or texture into a depth texture.

How do you see this possible? Depth textures don't support STORAGE, and you can't copy from a different GPU resource into them.

Edit; answering my own question - bind the buffer as storage readonly, and write gl_FragDepth in da shader

Also if we add this capability, we should make sure that in the future we're able to writeTexture into a depth texture without clamping so the entrypoint would need an additional boolean or metadata.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ben-clayton picture ben-clayton  路  6Comments

Kangz picture Kangz  路  4Comments

CrazyPython picture CrazyPython  路  4Comments

krogovin picture krogovin  路  5Comments

litherum picture litherum  路  6Comments