Browse Source
[vk] remove unused vk_texture_manager.cpp and unused shader conversions (#3432)
[vk] remove unused vk_texture_manager.cpp and unused shader conversions (#3432)
- Trivial dead code removal, also these shaders are useless TODO: maybe in a future do YUV280 or whatever in shader for vic :) Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3432 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: DraVee <dravee@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>fixup-android
committed by
crueter
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
14 changed files with 7 additions and 600 deletions
-
11src/video_core/host_shaders/CMakeLists.txt
-
46src/video_core/host_shaders/convert_abgr8_srgb_to_d24s8.frag
-
28src/video_core/host_shaders/convert_astc_hdr_to_rgba16f.comp
-
29src/video_core/host_shaders/convert_bc7_to_rgba8.comp
-
29src/video_core/host_shaders/convert_rgb_to_yuv420.comp
-
31src/video_core/host_shaders/convert_rgba16f_to_rgba8.frag
-
11src/video_core/host_shaders/convert_rgba8_to_bgra8.frag
-
30src/video_core/host_shaders/convert_yuv420_to_rgb.comp
-
29src/video_core/host_shaders/dither_temporal.frag
-
68src/video_core/host_shaders/dynamic_resolution_scale.comp
-
99src/video_core/renderer_vulkan/blit_image.cpp
-
32src/video_core/renderer_vulkan/blit_image.h
-
20src/video_core/renderer_vulkan/vk_texture_cache.cpp
-
144src/video_core/renderer_vulkan/vk_texture_manager.cpp
@ -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); |
|||
} |
|||
@ -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); |
|||
} |
|||
@ -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); |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
#version 450 |
|||
|
|||
layout(local_size_x = 8, local_size_y = 8) in; |
|||
|
|||
layout(binding = 0) uniform sampler2D input_texture; |
|||
layout(binding = 1, r8) uniform writeonly image2D y_output; |
|||
layout(binding = 2, r8) uniform writeonly image2D u_output; |
|||
layout(binding = 3, r8) uniform writeonly image2D v_output; |
|||
|
|||
void main() { |
|||
ivec2 pos = ivec2(gl_GlobalInvocationID.xy); |
|||
ivec2 size = imageSize(y_output); |
|||
|
|||
if (pos.x >= size.x || pos.y >= size.y) { |
|||
return; |
|||
} |
|||
|
|||
vec2 tex_coord = vec2(pos) / vec2(size); |
|||
vec3 rgb = texture(input_texture, tex_coord).rgb; |
|||
|
|||
// RGB to YUV conversion |
|||
float y = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b; |
|||
float u = -0.147 * rgb.r - 0.289 * rgb.g + 0.436 * rgb.b + 0.5; |
|||
float v = 0.615 * rgb.r - 0.515 * rgb.g - 0.100 * rgb.b + 0.5; |
|||
|
|||
imageStore(y_output, pos, vec4(y)); |
|||
imageStore(u_output, pos / 2, vec4(u)); |
|||
imageStore(v_output, pos / 2, vec4(v)); |
|||
} |
|||
@ -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); |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
#version 450 |
|||
|
|||
layout(location = 0) in vec2 texcoord; |
|||
layout(location = 0) out vec4 color; |
|||
|
|||
layout(binding = 0) uniform sampler2D input_texture; |
|||
|
|||
void main() { |
|||
vec4 rgba = texture(input_texture, texcoord); |
|||
color = rgba.bgra; // Swap red and blue channels |
|||
} |
|||
@ -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)); |
|||
} |
|||
@ -1,29 +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 frame_count; |
|||
float dither_strength; |
|||
} constants; |
|||
|
|||
// Pseudo-random number generator |
|||
float rand(vec2 co) { |
|||
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); |
|||
} |
|||
|
|||
void main() { |
|||
vec4 input_color = texture(input_texture, texcoord); |
|||
|
|||
// Generate temporal noise based on frame count |
|||
vec2 noise_coord = gl_FragCoord.xy + vec2(constants.frame_count); |
|||
float noise = rand(noise_coord) * 2.0 - 1.0; |
|||
|
|||
// Apply dithering |
|||
vec3 dithered = input_color.rgb + noise * constants.dither_strength; |
|||
|
|||
color = vec4(dithered, input_color.a); |
|||
} |
|||
@ -1,68 +0,0 @@ |
|||
#version 450 |
|||
|
|||
layout(local_size_x = 8, local_size_y = 8) in; |
|||
|
|||
layout(binding = 0) uniform sampler2D input_texture; |
|||
layout(binding = 1, rgba8) uniform writeonly image2D output_image; |
|||
|
|||
layout(push_constant) uniform PushConstants { |
|||
vec2 scale_factor; |
|||
vec2 input_size; |
|||
} constants; |
|||
|
|||
vec4 cubic(float v) { |
|||
vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v; |
|||
vec4 s = n * n * n; |
|||
float x = s.x; |
|||
float y = s.y - 4.0 * s.x; |
|||
float z = s.z - 4.0 * s.y + 6.0 * s.x; |
|||
float w = s.w - 4.0 * s.z + 6.0 * s.y - 4.0 * s.x; |
|||
return vec4(x, y, z, w) * (1.0/6.0); |
|||
} |
|||
|
|||
vec4 bicubic_sample(sampler2D tex, vec2 tex_coord) { |
|||
vec2 tex_size = constants.input_size; |
|||
vec2 inv_tex_size = 1.0 / tex_size; |
|||
|
|||
tex_coord = tex_coord * tex_size - 0.5; |
|||
|
|||
vec2 fxy = fract(tex_coord); |
|||
tex_coord -= fxy; |
|||
|
|||
vec4 xcubic = cubic(fxy.x); |
|||
vec4 ycubic = cubic(fxy.y); |
|||
|
|||
vec4 c = tex_coord.xxyy + vec2(-0.5, +1.5).xyxy; |
|||
vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw); |
|||
vec4 offset = c + vec4(xcubic.yw, ycubic.yw) / s; |
|||
|
|||
offset *= inv_tex_size.xxyy; |
|||
|
|||
vec4 sample0 = texture(tex, offset.xz); |
|||
vec4 sample1 = texture(tex, offset.yz); |
|||
vec4 sample2 = texture(tex, offset.xw); |
|||
vec4 sample3 = texture(tex, offset.yw); |
|||
|
|||
float sx = s.x / (s.x + s.y); |
|||
float sy = s.z / (s.z + s.w); |
|||
|
|||
return mix( |
|||
mix(sample3, sample2, sx), |
|||
mix(sample1, sample0, sx), |
|||
sy |
|||
); |
|||
} |
|||
|
|||
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); |
|||
vec4 color = bicubic_sample(input_texture, tex_coord); |
|||
|
|||
imageStore(output_image, pos, color); |
|||
} |
|||
@ -1,144 +0,0 @@ |
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include <filesystem>
|
|||
|
|||
#include "common/assert.h"
|
|||
#include "common/logging/log.h"
|
|||
#include "video_core/renderer_vulkan/vk_texture_manager.h"
|
|||
#include "video_core/vulkan_common/vulkan_device.h"
|
|||
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
|||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
|||
|
|||
namespace Vulkan { |
|||
|
|||
TextureManager::TextureManager(const Device& device_, MemoryAllocator& memory_allocator_) |
|||
: device(device_), memory_allocator(memory_allocator_) { |
|||
|
|||
// Create a default texture for fallback in case of errors
|
|||
default_texture = CreateDefaultTexture(); |
|||
} |
|||
|
|||
TextureManager::~TextureManager() { |
|||
std::lock_guard<std::mutex> lock(texture_mutex); |
|||
// Clear all cached textures
|
|||
texture_cache.clear(); |
|||
|
|||
// Default texture will be cleaned up automatically by vk::Image's destructor
|
|||
} |
|||
|
|||
VkImage TextureManager::GetTexture(const std::string& texture_path) { |
|||
std::lock_guard<std::mutex> lock(texture_mutex); |
|||
|
|||
// Check if the texture is already in the cache
|
|||
auto it = texture_cache.find(texture_path); |
|||
if (it != texture_cache.end()) { |
|||
return *it->second; |
|||
} |
|||
|
|||
// Load the texture and add it to the cache
|
|||
vk::Image new_texture = LoadTexture(texture_path); |
|||
if (new_texture) { |
|||
VkImage raw_handle = *new_texture; |
|||
texture_cache.emplace(texture_path, std::move(new_texture)); |
|||
return raw_handle; |
|||
} |
|||
|
|||
// If loading fails, return the default texture if it exists
|
|||
LOG_WARNING(Render_Vulkan, "Failed to load texture: {}, using default", texture_path); |
|||
if (default_texture.has_value()) { |
|||
return *(*default_texture); |
|||
} |
|||
return VK_NULL_HANDLE; |
|||
} |
|||
|
|||
void TextureManager::ReloadTexture(const std::string& texture_path) { |
|||
std::lock_guard<std::mutex> lock(texture_mutex); |
|||
|
|||
// Remove the texture from cache if it exists
|
|||
auto it = texture_cache.find(texture_path); |
|||
if (it != texture_cache.end()) { |
|||
LOG_INFO(Render_Vulkan, "Reloading texture: {}", texture_path); |
|||
texture_cache.erase(it); |
|||
} |
|||
|
|||
// The texture will be reloaded on next GetTexture call
|
|||
} |
|||
|
|||
bool TextureManager::IsTextureLoadedCorrectly(VkImage texture) { |
|||
// Check if the texture handle is valid
|
|||
static const VkImage null_handle = VK_NULL_HANDLE; |
|||
return texture != null_handle; |
|||
} |
|||
|
|||
void TextureManager::CleanupTextureCache() { |
|||
std::lock_guard<std::mutex> lock(texture_mutex); |
|||
|
|||
// TODO: track usage and remove unused textures [ZEP]
|
|||
|
|||
LOG_INFO(Render_Vulkan, "Handling texture cache cleanup, current size: {}", texture_cache.size()); |
|||
} |
|||
|
|||
void TextureManager::HandleTextureRendering(const std::string& texture_path, |
|||
std::function<void(VkImage)> render_callback) { |
|||
VkImage texture = GetTexture(texture_path); |
|||
|
|||
if (!IsTextureLoadedCorrectly(texture)) { |
|||
LOG_ERROR(Render_Vulkan, "Texture failed to load correctly: {}, attempting reload", texture_path); |
|||
ReloadTexture(texture_path); |
|||
texture = GetTexture(texture_path); |
|||
} |
|||
|
|||
// Execute the rendering callback with the texture
|
|||
render_callback(texture); |
|||
} |
|||
|
|||
vk::Image TextureManager::LoadTexture(const std::string& texture_path) { |
|||
// TODO: load image data from disk
|
|||
// and create a proper Vulkan texture [ZEP]
|
|||
|
|||
if (!std::filesystem::exists(texture_path)) { |
|||
LOG_ERROR(Render_Vulkan, "Texture file not found: {}", texture_path); |
|||
return {}; |
|||
} |
|||
|
|||
try { |
|||
|
|||
LOG_INFO(Render_Vulkan, "Loaded texture: {}", texture_path); |
|||
|
|||
// TODO: create an actual VkImage [ZEP]
|
|||
return CreateDefaultTexture(); |
|||
} catch (const std::exception& e) { |
|||
LOG_ERROR(Render_Vulkan, "Error loading texture {}: {}", texture_path, e.what()); |
|||
return {}; |
|||
} |
|||
} |
|||
|
|||
vk::Image TextureManager::CreateDefaultTexture() { |
|||
// Create a small default texture (1x1 pixel) to use as a fallback
|
|||
// const VkExtent2D extent{1, 1};
|
|||
|
|||
/* // Create image
|
|||
const VkImageCreateInfo image_ci{ |
|||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
|||
.pNext = nullptr, |
|||
.flags = 0, |
|||
.imageType = VK_IMAGE_TYPE_2D, |
|||
.format = texture_format, |
|||
.extent = {extent.width, extent.height, 1}, |
|||
.mipLevels = 1, |
|||
.arrayLayers = 1, |
|||
.samples = VK_SAMPLE_COUNT_1_BIT, |
|||
.tiling = VK_IMAGE_TILING_OPTIMAL, |
|||
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, |
|||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, |
|||
.queueFamilyIndexCount = 0, |
|||
.pQueueFamilyIndices = nullptr, |
|||
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, |
|||
}; */ |
|||
|
|||
// TODO: create an actual VkImage [ZEP]
|
|||
LOG_INFO(Render_Vulkan, "Created default fallback texture"); |
|||
return {}; |
|||
} |
|||
|
|||
} // namespace Vulkan
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue