floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
7.1k stars 500 forks source link

gfx proposal: support for floating point depth buffer with a stencil component #1122

Open kcbanner opened 1 month ago

kcbanner commented 1 month ago

Currently, both SG_PIXELFORMAT_DEPTH and SG_PIXELFORMAT_DEPTH_STENCIL are supported, with the former being a 32 bit floating point depth buffer, and the latter being a 24 bit unsigned depth buffer and 8 bit stencil.

OpenGL 4.3 and ES 3.0 have: DEPTH32F_STENCIL8
D3D11 has: DXGI_FORMAT_D32_FLOAT_S8X24_UINT Metal has: MTLPixelFormatDepth32Float_Stencil8 (https://developer.apple.com/documentation/metal/mtlpixelformat/mtlpixelformatdepth32float_stencil8)

Is there room for an SG_PIXELFORMAT that maps to this format, if so what would it be called? I'm not sure how it would map onto the current naming convention.

I'm happy to implement this, although I won't be able to test the Metal version.

floooh commented 1 month ago

Hmm, yeah, I tiptoed around being able to select a specific depth- or depth-stencil format, and tbh, I would like to allow some wiggle room in the future too (at least for the 'basic' DEPTH and DEPTH_STENCIL pixelformats which don't explicitly specify a precision).

For instance in WebGPU the float32+stencil8 format is behind a feature flag because it's not supported everywhere.

In general, we should use the WebGPU naming convention for explicit depth- and depth-stencil formats (because I also used WebGPU as reference for the entire pixel formats list in sokol-gfx), converted to the sokol-gfx style it would be:

...and if we want other explicit formats too:

...I think we can leave out WebGPU's depth16unorm and stencil8 formats, since 16-bit depth is hopefully irrelevant by now, and a stencil8 without depth seems fairly exotic.

The 'flexible' SG_PIXELFORMAT_DEPTH and SG_PIXELFORMAT_DEPTH_STENCIL should stay though which allows us to provide a 'recommended' explicit format for a specific backend / target platform.

kcbanner commented 1 month ago

That all sounds good to me, I'll take a look at implementing this.