video_core/vulkan: Improve texture format conversion handling

Refactors and improves the texture format conversion system in the Vulkan
renderer:

- Adds proper sRGB to linear conversion for depth formats
- Improves shader accuracy for ABGR8 SRGB to D24S8 conversion
- Adds gamma correction and proper depth range clamping
- Moves GetSupportedFormat implementation to header
- Cleans up format conversion switch statement
- Removes redundant format conversion paths

The changes improve accuracy when converting between color and depth
formats, particularly for sRGB sources. The shader improvements ensure
proper gamma correction and depth range handling.

Technical changes:
- Improves sRGB to linear conversion in fragment shader
- Adds proper depth value clamping
- Consolidates format conversion logic
- Removes duplicate GetSupportedFormat implementation
This commit is contained in:
Zephyron 2025-02-03 17:17:22 +10:00 committed by MrPurple666
parent 3e835ac3aa
commit 45683a4034
3 changed files with 136 additions and 52 deletions

View file

@ -6,27 +6,32 @@
layout(binding = 0) uniform sampler2D color_texture;
// Efficient sRGB to linear conversion
// More accurate sRGB to linear conversion
float srgbToLinear(float srgb) {
return srgb <= 0.04045 ?
srgb / 12.92 :
pow((srgb + 0.055) / 1.055, 2.4);
if (srgb <= 0.04045) {
return srgb / 12.92;
} else {
return pow((srgb + 0.055) / 1.055, 2.4);
}
}
void main() {
ivec2 coord = ivec2(gl_FragCoord.xy);
vec4 srgbColor = texelFetch(color_texture, coord, 0);
// Convert RGB components to linear space
// Convert sRGB to linear space with proper gamma correction
vec3 linearColor = vec3(
srgbToLinear(srgbColor.r),
srgbToLinear(srgbColor.g),
srgbToLinear(srgbColor.b)
);
// Calculate luminance using standard coefficients
// Use standard luminance coefficients
float luminance = dot(linearColor, vec3(0.2126, 0.7152, 0.0722));
// Ensure proper depth range
luminance = clamp(luminance, 0.0, 1.0);
// Convert to 24-bit depth value
uint depth_val = uint(luminance * float(0xFFFFFF));