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

sokol_gfx.h d3d11: fix depth-stencil pixel format problems #937

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
## Updates

#### 06-Nov-2023

A bugfix in the sokol_gfx.h D3D11 backend, and some related cleanup when creating depth-stencil
render target images and resource views:

- fixed: render target images with format SG_PIXELFORMAT_DEPTH_STENCIL triggered a validation
error because the pixel format capabilities code marked them as non-renderable. Now
the SG_PIXELFORMAT_DEPTH_STENCIL pixel format is properly reported as renderable.
- the DXGIFormats for SG_PIXELFORMAT_DEPTH_STENCIL images are now as follows:
- D3D11 texture object: DXGI_FORMAT_R24G8_TYPELESS
- D3D11 shader-resource-view object: DXGI_FORMAT_R24_UNORM_X8_TYPELESS
- D3D11 depth-stencil-view object: DXGI_FORMAT_D24_UNORM_S8_UINT

#### 30-Oct-2023

Some sokol_gfx.h backend-specific updates and tweaks (very minor chance that this is breaking if you are injecting textures into the D3D11 backend).
Expand Down
14 changes: 11 additions & 3 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9554,7 +9554,7 @@ _SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_texture_pixel_format(sg_pixel_format fmt) {
case SG_PIXELFORMAT_RGBA32SI: return DXGI_FORMAT_R32G32B32A32_SINT;
case SG_PIXELFORMAT_RGBA32F: return DXGI_FORMAT_R32G32B32A32_FLOAT;
case SG_PIXELFORMAT_DEPTH: return DXGI_FORMAT_R32_TYPELESS;
case SG_PIXELFORMAT_DEPTH_STENCIL: return DXGI_FORMAT_D24_UNORM_S8_UINT;
case SG_PIXELFORMAT_DEPTH_STENCIL: return DXGI_FORMAT_R24G8_TYPELESS;
case SG_PIXELFORMAT_BC1_RGBA: return DXGI_FORMAT_BC1_UNORM;
case SG_PIXELFORMAT_BC2_RGBA: return DXGI_FORMAT_BC2_UNORM;
case SG_PIXELFORMAT_BC3_RGBA: return DXGI_FORMAT_BC3_UNORM;
Expand All @@ -9572,6 +9572,8 @@ _SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_texture_pixel_format(sg_pixel_format fmt) {
_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_srv_pixel_format(sg_pixel_format fmt) {
if (fmt == SG_PIXELFORMAT_DEPTH) {
return DXGI_FORMAT_R32_FLOAT;
} else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) {
return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
} else {
return _sg_d3d11_texture_pixel_format(fmt);
}
Expand All @@ -9580,6 +9582,8 @@ _SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_srv_pixel_format(sg_pixel_format fmt) {
_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_dsv_pixel_format(sg_pixel_format fmt) {
if (fmt == SG_PIXELFORMAT_DEPTH) {
return DXGI_FORMAT_D32_FLOAT;
} else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) {
return DXGI_FORMAT_D24_UNORM_S8_UINT;
} else {
return _sg_d3d11_texture_pixel_format(fmt);
}
Expand All @@ -9588,6 +9592,8 @@ _SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_dsv_pixel_format(sg_pixel_format fmt) {
_SOKOL_PRIVATE DXGI_FORMAT _sg_d3d11_rtv_pixel_format(sg_pixel_format fmt) {
if (fmt == SG_PIXELFORMAT_DEPTH) {
return DXGI_FORMAT_R32_FLOAT;
} else if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) {
return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
} else {
return _sg_d3d11_texture_pixel_format(fmt);
}
Expand Down Expand Up @@ -9811,12 +9817,14 @@ _SOKOL_PRIVATE void _sg_d3d11_init_caps(void) {
const UINT rtv_dxgi_fmt_caps = _sg_d3d11_dxgi_fmt_caps(_sg_d3d11_rtv_pixel_format((sg_pixel_format)fmt));
const UINT dsv_dxgi_fmt_caps = _sg_d3d11_dxgi_fmt_caps(_sg_d3d11_dsv_pixel_format((sg_pixel_format)fmt));
sg_pixelformat_info* info = &_sg.formats[fmt];
const bool render = 0 != (rtv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_RENDER_TARGET);
const bool depth = 0 != (dsv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL);
info->sample = 0 != (srv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_TEXTURE2D);
info->filter = 0 != (srv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
info->render = 0 != (rtv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_RENDER_TARGET);
info->render = render || depth;
info->blend = 0 != (rtv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_BLENDABLE);
info->msaa = 0 != (rtv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET);
info->depth = 0 != (dsv_dxgi_fmt_caps & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL);
info->depth = depth;
}
}

Expand Down
Loading