Browse Source
video_core: Add sRGB to D24S8 depth-stencil conversion support
video_core: Add sRGB to D24S8 depth-stencil conversion support
Implements conversion from sRGB color formats to D24S8 depth-stencil format in the Vulkan renderer. This change includes: - New fragment shader convert_abgr8_srgb_to_d24s8.frag that handles proper sRGB to linear conversion before depth calculation - Added shader to CMake build system - Extended BlitImageHelper with new conversion pipeline and methods - Updated texture cache to handle sRGB to D24S8 format conversion paths The conversion properly handles sRGB color space by first converting to linear space before calculating luminance values for the depth component, while preserving alpha channel data for the stencil component.nce_cpp
committed by
MrPurple666
5 changed files with 132 additions and 12 deletions
-
2src/video_core/host_shaders/CMakeLists.txt
-
41src/video_core/host_shaders/convert_abgr8_srgb_to_d24s8.frag
-
85src/video_core/renderer_vulkan/blit_image.cpp
-
5src/video_core/renderer_vulkan/blit_image.h
-
11src/video_core/renderer_vulkan/vk_texture_cache.cpp
@ -0,0 +1,41 @@ |
|||
// SPDX-FileCopyrightText: 2025 citron Emulator Project |
|||
// SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
#version 450 |
|||
#extension GL_ARB_shader_stencil_export : require |
|||
|
|||
layout(binding = 0) uniform sampler2D color_texture; |
|||
|
|||
// Efficient sRGB to linear conversion |
|||
float srgbToLinear(float srgb) { |
|||
return srgb <= 0.04045 ? |
|||
srgb / 12.92 : |
|||
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 |
|||
vec3 linearColor = vec3( |
|||
srgbToLinear(srgbColor.r), |
|||
srgbToLinear(srgbColor.g), |
|||
srgbToLinear(srgbColor.b) |
|||
); |
|||
|
|||
// Calculate luminance using standard coefficients |
|||
float luminance = dot(linearColor, vec3(0.2126, 0.7152, 0.0722)); |
|||
|
|||
// Convert to 24-bit depth value |
|||
uint depth_val = uint(luminance * float(0xFFFFFF)); |
|||
|
|||
// Extract 8-bit stencil from alpha |
|||
uint stencil_val = uint(srgbColor.a * 255.0); |
|||
|
|||
// Pack values efficiently |
|||
uint depth_stencil = (stencil_val << 24) | (depth_val & 0x00FFFFFF); |
|||
|
|||
gl_FragDepth = float(depth_val) / float(0xFFFFFF); |
|||
gl_FragStencilRefARB = int(stencil_val); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue