From 4563b6379d9927b9f5469250ef0db58440a72c69 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:49:08 -0800 Subject: [PATCH] amdgpu: Handle 8-bit float format case for stencil. (#2092) --- src/video_core/amdgpu/liverpool.h | 3 ++- src/video_core/amdgpu/resource.h | 4 ++-- src/video_core/amdgpu/types.h | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index 837b73d8..070253ca 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -899,7 +899,8 @@ struct Liverpool { // There is a small difference between T# and CB number types, account for it. return RemapNumberFormat(info.number_type == NumberFormat::SnormNz ? NumberFormat::Srgb - : info.number_type.Value()); + : info.number_type.Value(), + info.format); } [[nodiscard]] NumberConversion GetNumberConversion() const { diff --git a/src/video_core/amdgpu/resource.h b/src/video_core/amdgpu/resource.h index 3dc1eadd..467cecf1 100644 --- a/src/video_core/amdgpu/resource.h +++ b/src/video_core/amdgpu/resource.h @@ -54,7 +54,7 @@ struct Buffer { } NumberFormat GetNumberFmt() const noexcept { - return RemapNumberFormat(NumberFormat(num_format)); + return RemapNumberFormat(NumberFormat(num_format), DataFormat(data_format)); } DataFormat GetDataFmt() const noexcept { @@ -264,7 +264,7 @@ struct Image { } NumberFormat GetNumberFmt() const noexcept { - return RemapNumberFormat(NumberFormat(num_format)); + return RemapNumberFormat(NumberFormat(num_format), DataFormat(data_format)); } NumberConversion GetNumberConversion() const noexcept { diff --git a/src/video_core/amdgpu/types.h b/src/video_core/amdgpu/types.h index a19e5325..57f97418 100644 --- a/src/video_core/amdgpu/types.h +++ b/src/video_core/amdgpu/types.h @@ -252,7 +252,7 @@ inline DataFormat RemapDataFormat(const DataFormat format) { } } -inline NumberFormat RemapNumberFormat(const NumberFormat format) { +inline NumberFormat RemapNumberFormat(const NumberFormat format, const DataFormat data_format) { switch (format) { case NumberFormat::Uscaled: return NumberFormat::Uint; @@ -260,6 +260,14 @@ inline NumberFormat RemapNumberFormat(const NumberFormat format) { return NumberFormat::Sint; case NumberFormat::Ubnorm: return NumberFormat::Unorm; + case NumberFormat::Float: + if (data_format == DataFormat::Format8) { + // Games may ask for 8-bit float when they want to access the stencil component + // of a depth-stencil image. Change to unsigned int to match the stencil format. + // This is also the closest approximation to pass the bits through unconverted. + return NumberFormat::Uint; + } + [[fallthrough]]; default: return format; }