Browse Source

WHAT ARE THESE GARBAGE SHADERS

pull/3432/head
lizzie 2 months ago
parent
commit
dcb5f91585
  1. 6
      src/video_core/host_shaders/CMakeLists.txt
  2. 46
      src/video_core/host_shaders/convert_abgr8_srgb_to_d24s8.frag
  3. 28
      src/video_core/host_shaders/convert_astc_hdr_to_rgba16f.comp
  4. 29
      src/video_core/host_shaders/convert_bc7_to_rgba8.comp
  5. 31
      src/video_core/host_shaders/convert_rgba16f_to_rgba8.frag
  6. 30
      src/video_core/host_shaders/convert_yuv420_to_rgb.comp
  7. 67
      src/video_core/renderer_vulkan/blit_image.cpp
  8. 19
      src/video_core/renderer_vulkan/blit_image.h
  9. 20
      src/video_core/renderer_vulkan/vk_texture_cache.cpp

6
src/video_core/host_shaders/CMakeLists.txt

@ -19,7 +19,6 @@ set(SHADER_FILES
block_linear_unswizzle_2d.comp
block_linear_unswizzle_3d.comp
block_linear_unswizzle_3d_bcn.comp
convert_abgr8_srgb_to_d24s8.frag
convert_abgr8_to_d24s8.frag
convert_abgr8_to_d32f.frag
convert_d32f_to_abgr8.frag
@ -78,11 +77,6 @@ set(SHADER_FILES
vulkan_turbo_mode.comp
vulkan_uint8.comp
convert_rgba8_to_bgra8.frag
convert_yuv420_to_rgb.comp
convert_rgb_to_yuv420.comp
convert_bc7_to_rgba8.comp
convert_astc_hdr_to_rgba16f.comp
convert_rgba16f_to_rgba8.frag
dither_temporal.frag
dynamic_resolution_scale.comp
)

46
src/video_core/host_shaders/convert_abgr8_srgb_to_d24s8.frag

@ -1,46 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#version 450
#extension GL_ARB_shader_stencil_export : require
layout(binding = 0) uniform sampler2D color_texture;
// Even more accurate sRGB to linear conversion
// https://entropymine.com/imageworsener/srgbformula/
float srgbToLinear(float srgb) {
if (srgb <= 0.0404482362771082f) { //assumes it's >= 0
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 sRGB to linear space with proper gamma correction
vec3 linearColor = vec3(
srgbToLinear(srgbColor.r),
srgbToLinear(srgbColor.g),
srgbToLinear(srgbColor.b)
);
// 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));
// 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);
}

28
src/video_core/host_shaders/convert_astc_hdr_to_rgba16f.comp

@ -1,28 +0,0 @@
#version 450
layout(local_size_x = 8, local_size_y = 8) in;
layout(binding = 0) uniform samplerBuffer astc_data;
layout(binding = 1, rgba16f) uniform writeonly image2D output_image;
// Note: This is a simplified version. Real ASTC HDR decompression is more complex
void main() {
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(output_image);
if (pos.x >= size.x || pos.y >= size.y) {
return;
}
// Calculate block and pixel within block
ivec2 block = pos / 8; // Assuming 8x8 ASTC blocks
ivec2 pixel = pos % 8;
// Each ASTC block is 16 bytes
int block_index = block.y * (size.x / 8) + block.x;
// Simplified ASTC HDR decoding - you'll need to implement full ASTC decoding
vec4 color = texelFetch(astc_data, block_index * 8 + pixel.y * 8 + pixel.x);
imageStore(output_image, pos, color);
}

29
src/video_core/host_shaders/convert_bc7_to_rgba8.comp

@ -1,29 +0,0 @@
#version 450
#extension GL_ARB_shader_ballot : require
layout(local_size_x = 8, local_size_y = 8) in;
layout(binding = 0) uniform samplerBuffer bc7_data;
layout(binding = 1, rgba8) uniform writeonly image2D output_image;
// Note: This is a simplified version. Real BC7 decompression is more complex
void main() {
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(output_image);
if (pos.x >= size.x || pos.y >= size.y) {
return;
}
// Calculate block and pixel within block
ivec2 block = pos / 4;
ivec2 pixel = pos % 4;
// Each BC7 block is 16 bytes
int block_index = block.y * (size.x / 4) + block.x;
// Simplified BC7 decoding - you'll need to implement full BC7 decoding
vec4 color = texelFetch(bc7_data, block_index * 4 + pixel.y * 4 + pixel.x);
imageStore(output_image, pos, color);
}

31
src/video_core/host_shaders/convert_rgba16f_to_rgba8.frag

@ -1,31 +0,0 @@
#version 450
layout(location = 0) in vec2 texcoord;
layout(location = 0) out vec4 color;
layout(binding = 0) uniform sampler2D input_texture;
layout(push_constant) uniform PushConstants {
float exposure;
float gamma;
} constants;
vec3 tonemap(vec3 hdr) {
// Reinhard tonemapping
return hdr / (hdr + vec3(1.0));
}
void main() {
vec4 hdr = texture(input_texture, texcoord);
// Apply exposure
vec3 exposed = hdr.rgb * constants.exposure;
// Tonemap
vec3 tonemapped = tonemap(exposed);
// Gamma correction
vec3 gamma_corrected = pow(tonemapped, vec3(1.0 / constants.gamma));
color = vec4(gamma_corrected, hdr.a);
}

30
src/video_core/host_shaders/convert_yuv420_to_rgb.comp

@ -1,30 +0,0 @@
#version 450
layout(local_size_x = 8, local_size_y = 8) in;
layout(binding = 0) uniform sampler2D y_texture;
layout(binding = 1) uniform sampler2D u_texture;
layout(binding = 2) uniform sampler2D v_texture;
layout(binding = 3, rgba8) uniform writeonly image2D output_image;
void main() {
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(output_image);
if (pos.x >= size.x || pos.y >= size.y) {
return;
}
vec2 tex_coord = vec2(pos) / vec2(size);
float y = texture(y_texture, tex_coord).r;
float u = texture(u_texture, tex_coord).r - 0.5;
float v = texture(v_texture, tex_coord).r - 0.5;
// YUV to RGB conversion
vec3 rgb;
rgb.r = y + 1.402 * v;
rgb.g = y - 0.344 * u - 0.714 * v;
rgb.b = y + 1.772 * u;
imageStore(output_image, pos, vec4(rgb, 1.0));
}

67
src/video_core/renderer_vulkan/blit_image.cpp

@ -31,13 +31,7 @@
#include "video_core/surface.h"
#include "video_core/vulkan_common/vulkan_device.h"
#include "video_core/vulkan_common/vulkan_wrapper.h"
#include "video_core/host_shaders/convert_abgr8_srgb_to_d24s8_frag_spv.h"
#include "video_core/host_shaders/convert_rgba8_to_bgra8_frag_spv.h"
#include "video_core/host_shaders/convert_yuv420_to_rgb_comp_spv.h"
#include "video_core/host_shaders/convert_rgb_to_yuv420_comp_spv.h"
#include "video_core/host_shaders/convert_bc7_to_rgba8_comp_spv.h"
#include "video_core/host_shaders/convert_astc_hdr_to_rgba16f_comp_spv.h"
#include "video_core/host_shaders/convert_rgba16f_to_rgba8_frag_spv.h"
#include "video_core/host_shaders/dither_temporal_frag_spv.h"
#include "video_core/host_shaders/dynamic_resolution_scale_comp_spv.h"
@ -540,15 +534,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
convert_d32f_to_abgr8_frag(BuildShader(device, CONVERT_D32F_TO_ABGR8_FRAG_SPV)),
convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
convert_abgr8_srgb_to_d24s8_frag(device.IsExtShaderStencilExportSupported()
? BuildShader(device, CONVERT_ABGR8_SRGB_TO_D24S8_FRAG_SPV)
: vk::ShaderModule{}),
convert_rgba_to_bgra_frag(BuildShader(device, CONVERT_RGBA8_TO_BGRA8_FRAG_SPV)),
convert_yuv420_to_rgb_comp(BuildShader(device, CONVERT_YUV420_TO_RGB_COMP_SPV)),
convert_rgb_to_yuv420_comp(BuildShader(device, CONVERT_RGB_TO_YUV420_COMP_SPV)),
convert_bc7_to_rgba8_comp(BuildShader(device, CONVERT_BC7_TO_RGBA8_COMP_SPV)),
convert_astc_hdr_to_rgba16f_comp(BuildShader(device, CONVERT_ASTC_HDR_TO_RGBA16F_COMP_SPV)),
convert_rgba16f_to_rgba8_frag(BuildShader(device, CONVERT_RGBA16F_TO_RGBA8_FRAG_SPV)),
dither_temporal_frag(BuildShader(device, DITHER_TEMPORAL_FRAG_SPV)),
dynamic_resolution_scale_comp(BuildShader(device, DYNAMIC_RESOLUTION_SCALE_COMP_SPV)),
linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
@ -711,19 +697,6 @@ void BlitImageHelper::ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer,
ConvertDepthStencil(*convert_s8d24_to_abgr8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertABGR8SRGBToD24S8(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
if (!device.IsExtShaderStencilExportSupported()) {
// Shader requires VK_EXT_shader_stencil_export which is not available
LOG_WARNING(Render_Vulkan, "ConvertABGR8SRGBToD24S8 requires shader_stencil_export, skipping");
return;
}
ConvertPipelineDepthTargetEx(convert_abgr8_srgb_to_d24s8_pipeline,
dst_framebuffer->RenderPass(),
convert_abgr8_srgb_to_d24s8_frag);
Convert(*convert_abgr8_srgb_to_d24s8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
const std::array<f32, 4>& clear_color,
const Region2D& dst_region) {
@ -1200,46 +1173,6 @@ void BlitImageHelper::ConvertRGBAtoGBRA(const Framebuffer* dst_framebuffer,
Convert(*convert_rgba_to_bgra_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertYUV420toRGB(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_yuv420_to_rgb_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_yuv420_to_rgb_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertRGBtoYUV420(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_rgb_to_yuv420_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_rgb_to_yuv420_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertBC7toRGBA8(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_bc7_to_rgba8_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_bc7_to_rgba8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertASTCHDRtoRGBA16F(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_astc_hdr_to_rgba16f_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_astc_hdr_to_rgba16f_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertRGBA16FtoRGBA8(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_rgba16f_to_rgba8_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_rgba16f_to_rgba8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ApplyDitherTemporal(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(dither_temporal_pipeline,

19
src/video_core/renderer_vulkan/blit_image.h

@ -70,8 +70,6 @@ public:
void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertABGR8SRGBToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertD32FToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
@ -88,11 +86,6 @@ public:
const Region2D& dst_region);
void ConvertRGBAtoGBRA(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertYUV420toRGB(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertRGBtoYUV420(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertBC7toRGBA8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertASTCHDRtoRGBA16F(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertRGBA16FtoRGBA8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ApplyDitherTemporal(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ApplyDynamicResolutionScale(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
@ -150,13 +143,7 @@ private:
vk::ShaderModule convert_d32f_to_abgr8_frag;
vk::ShaderModule convert_d24s8_to_abgr8_frag;
vk::ShaderModule convert_s8d24_to_abgr8_frag;
vk::ShaderModule convert_abgr8_srgb_to_d24s8_frag;
vk::ShaderModule convert_rgba_to_bgra_frag;
vk::ShaderModule convert_yuv420_to_rgb_comp;
vk::ShaderModule convert_rgb_to_yuv420_comp;
vk::ShaderModule convert_bc7_to_rgba8_comp;
vk::ShaderModule convert_astc_hdr_to_rgba16f_comp;
vk::ShaderModule convert_rgba16f_to_rgba8_frag;
vk::ShaderModule dither_temporal_frag;
vk::ShaderModule dynamic_resolution_scale_comp;
vk::Sampler linear_sampler;
@ -179,13 +166,7 @@ private:
vk::Pipeline convert_d32f_to_abgr8_pipeline;
vk::Pipeline convert_d24s8_to_abgr8_pipeline;
vk::Pipeline convert_s8d24_to_abgr8_pipeline;
vk::Pipeline convert_abgr8_srgb_to_d24s8_pipeline;
vk::Pipeline convert_rgba_to_bgra_pipeline;
vk::Pipeline convert_yuv420_to_rgb_pipeline;
vk::Pipeline convert_rgb_to_yuv420_pipeline;
vk::Pipeline convert_bc7_to_rgba8_pipeline;
vk::Pipeline convert_astc_hdr_to_rgba16f_pipeline;
vk::Pipeline convert_rgba16f_to_rgba8_pipeline;
vk::Pipeline dither_temporal_pipeline;
vk::Pipeline dynamic_resolution_scale_pipeline;
};

20
src/video_core/renderer_vulkan/vk_texture_cache.cpp

@ -1254,25 +1254,13 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
switch (dst_view.format) {
case PixelFormat::D24_UNORM_S8_UINT:
// Handle sRGB source formats
if (src_view.format == PixelFormat::A8B8G8R8_SRGB ||
src_view.format == PixelFormat::B8G8R8A8_SRGB) {
// Verify format support before conversion
if (device.IsFormatSupported(VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,
FormatType::Optimal)) {
return blit_image_helper.ConvertABGR8SRGBToD24S8(dst, src_view);
} else {
// Fallback to regular ABGR8 conversion if sRGB not supported
return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view);
}
}
if (src_view.format == PixelFormat::A8B8G8R8_UNORM ||
src_view.format == PixelFormat::B8G8R8A8_UNORM) {
if (src_view.format == PixelFormat::A8B8G8R8_UNORM
|| src_view.format == PixelFormat::B8G8R8A8_UNORM
|| src_view.format == PixelFormat::A8B8G8R8_SRGB
|| src_view.format == PixelFormat::B8G8R8A8_SRGB) {
return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view);
}
break;
case PixelFormat::A8B8G8R8_UNORM:
case PixelFormat::A8B8G8R8_SNORM:
case PixelFormat::A8B8G8R8_SINT:

Loading…
Cancel
Save