From 27c76b0a48168a4fbff12630e9b7a6b2a5010f01 Mon Sep 17 00:00:00 2001 From: DarthMew Date: Thu, 9 Feb 2023 01:51:40 +0100 Subject: [PATCH] Revert https://github.com/libretro/swanstation/commit/28d4d33b2ceaa81a62ec6014ea999251b340255e https://github.com/libretro/swanstation/commit/3bfe5959da904077157fcc089536841f293e0854 https://github.com/libretro/swanstation/commit/0d47de2dd7e5c964f760e19fe4743ee6d2185607 & https://github.com/libretro/swanstation/commit/826d58355ce47e2709c6385e66d8833b3125c8e8 --- src/core/gpu_hw.cpp | 11 +-- src/core/gpu_hw.h | 8 +- src/core/gpu_hw_d3d11.cpp | 3 +- src/core/gpu_hw_d3d12.cpp | 3 +- src/core/gpu_hw_opengl.cpp | 5 +- src/core/gpu_hw_shadergen.cpp | 20 ++-- src/core/gpu_hw_shadergen.h | 3 +- src/core/gpu_hw_vulkan.cpp | 3 +- src/core/gpu_sw.cpp | 13 +-- src/core/gpu_types.h | 26 ++--- src/core/host_interface.cpp | 2 - src/core/mdec.cpp | 116 +++++++---------------- src/core/mdec.h | 3 - src/core/settings.cpp | 3 - src/core/settings.h | 3 - src/core/shadergen.cpp | 34 ++++--- src/core/shadergen.h | 5 +- src/libretro/libretro_core_options.h | 33 +------ src/libretro/libretro_game_settings.cpp | 21 +--- src/libretro/libretro_game_settings.h | 39 +++++++- src/libretro/libretro_host_interface.cpp | 2 - 21 files changed, 129 insertions(+), 227 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 5f64c1d0..3513f57f 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -26,11 +26,6 @@ ALWAYS_INLINE static bool ShouldUseUVLimits() return g_settings.gpu_pgxp_enable || g_settings.gpu_texture_filter != GPUTextureFilter::Nearest; } -ALWAYS_INLINE static bool ShouldDisableColorPerspective() -{ - return g_settings.gpu_pgxp_enable && g_settings.gpu_pgxp_texture_correction && !g_settings.gpu_pgxp_color_correction; -} - GPU_HW::GPU_HW() : GPU() { m_vram_ptr = m_vram_shadow.data(); @@ -60,7 +55,6 @@ bool GPU_HW::Initialize(HostDisplay* host_display) m_using_uv_limits = ShouldUseUVLimits(); m_chroma_smoothing = g_settings.gpu_24bit_chroma_smoothing; m_downsample_mode = GetDownsampleMode(m_resolution_scale); - m_disable_color_perspective = m_supports_disable_color_perspective && ShouldDisableColorPerspective(); if (m_multisamples != g_settings.gpu_multisamples) { @@ -139,7 +133,6 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed) const bool per_sample_shading = g_settings.gpu_per_sample_shading && m_supports_per_sample_shading; const GPUDownsampleMode downsample_mode = GetDownsampleMode(resolution_scale); const bool use_uv_limits = ShouldUseUVLimits(); - const bool disable_color_perspective = m_supports_disable_color_perspective && ShouldDisableColorPerspective(); *framebuffer_changed = (m_resolution_scale != resolution_scale || m_multisamples != multisamples || m_downsample_mode != downsample_mode); @@ -148,8 +141,7 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed) m_true_color != g_settings.gpu_true_color || m_per_sample_shading != per_sample_shading || m_scaled_dithering != g_settings.gpu_scaled_dithering || m_texture_filtering != g_settings.gpu_texture_filter || m_using_uv_limits != use_uv_limits || m_chroma_smoothing != g_settings.gpu_24bit_chroma_smoothing || - m_downsample_mode != downsample_mode || m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer() || - m_disable_color_perspective != disable_color_perspective); + m_downsample_mode != downsample_mode || m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer()); if (m_resolution_scale != resolution_scale) { @@ -184,7 +176,6 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed) m_using_uv_limits = use_uv_limits; m_chroma_smoothing = g_settings.gpu_24bit_chroma_smoothing; m_downsample_mode = downsample_mode; - m_disable_color_perspective = disable_color_perspective; if (!m_supports_dual_source_blend && TextureFilterRequiresDualSourceBlend(m_texture_filtering)) m_texture_filtering = GPUTextureFilter::Nearest; diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index be2eacff..43cb200f 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -364,11 +364,9 @@ protected: BitField m_supports_per_sample_shading; BitField m_supports_dual_source_blend; BitField m_supports_adaptive_downsampling; - BitField m_supports_disable_color_perspective; - BitField m_per_sample_shading; - BitField m_scaled_dithering; - BitField m_chroma_smoothing; - BitField m_disable_color_perspective; + BitField m_per_sample_shading; + BitField m_scaled_dithering; + BitField m_chroma_smoothing; u8 bits = 0; }; diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index 335ceb33..d64c89a3 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -227,7 +227,6 @@ void GPU_HW_D3D11::SetCapabilities() m_supports_dual_source_blend = true; m_supports_per_sample_shading = (m_device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_1); m_supports_adaptive_downsampling = true; - m_supports_disable_color_perspective = true; m_max_multisamples = 1; for (u32 multisamples = 2; multisamples < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; multisamples++) @@ -503,7 +502,7 @@ bool GPU_HW_D3D11::CompileShaders() GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_multisamples, m_per_sample_shading, m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, - m_pgxp_depth_buffer, m_disable_color_perspective, m_supports_dual_source_blend); + m_pgxp_depth_buffer, m_supports_dual_source_blend); ShaderCompileProgressTracker progress("Compiling Shaders", 1 + 1 + 2 + (4 * 9 * 2 * 2) + 1 + (2 * 2) + 4 + (2 * 3) + 1); diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp index af4133e2..f587082a 100644 --- a/src/core/gpu_hw_d3d12.cpp +++ b/src/core/gpu_hw_d3d12.cpp @@ -233,7 +233,6 @@ void GPU_HW_D3D12::SetCapabilities() m_supports_dual_source_blend = true; m_supports_per_sample_shading = true; - m_supports_disable_color_perspective = true; Log_InfoPrintf("Dual-source blend: %s", m_supports_dual_source_blend ? "supported" : "not supported"); Log_InfoPrintf("Per-sample shading: %s", m_supports_per_sample_shading ? "supported" : "not supported"); Log_InfoPrintf("Max multisamples: %u", m_max_multisamples); @@ -411,7 +410,7 @@ bool GPU_HW_D3D12::CompilePipelines() GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_multisamples, m_per_sample_shading, m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, - m_pgxp_depth_buffer, m_disable_color_perspective, m_supports_dual_source_blend); + m_pgxp_depth_buffer, m_supports_dual_source_blend); ShaderCompileProgressTracker progress("Compiling Pipelines", 2 + (4 * 9 * 2 * 2) + (2 * 4 * 5 * 9 * 2 * 2) + 1 + (2 * 2) + 2 + 2 + 1 + 1 + (2 * 3) + 1); diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index 3c43623c..e45b188f 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -383,9 +383,6 @@ void GPU_HW_OpenGL::SetCapabilities() // adaptive smoothing would require texture views, which aren't in GLES. m_supports_adaptive_downsampling = false; - - // noperspective is not supported in GLSL ES. - m_supports_disable_color_perspective = (m_host_display->GetRenderAPI() == HostDisplay::RenderAPI::OpenGL); } bool GPU_HW_OpenGL::CreateFramebuffer() @@ -516,7 +513,7 @@ bool GPU_HW_OpenGL::CompilePrograms() const bool use_binding_layout = GPU_HW_ShaderGen::UseGLSLBindingLayout(); GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_multisamples, m_per_sample_shading, m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, - m_pgxp_depth_buffer, m_disable_color_perspective, m_supports_dual_source_blend); + m_pgxp_depth_buffer, m_supports_dual_source_blend); ShaderCompileProgressTracker progress("Compiling Programs", (4 * 9 * 2 * 2) + (2 * 3) + (2 * 2) + 1 + 1 + 1 + 1 + 1); diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 776d9d3b..532e1fe6 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -5,11 +5,11 @@ GPU_HW_ShaderGen::GPU_HW_ShaderGen(HostDisplay::RenderAPI render_api, u32 resolution_scale, u32 multisamples, bool per_sample_shading, bool true_color, bool scaled_dithering, GPUTextureFilter texture_filtering, bool uv_limits, bool pgxp_depth, - bool disable_color_perspective, bool supports_dual_source_blend) + bool supports_dual_source_blend) : ShaderGen(render_api, supports_dual_source_blend), m_resolution_scale(resolution_scale), m_multisamples(multisamples), m_per_sample_shading(per_sample_shading), m_true_color(true_color), m_scaled_dithering(scaled_dithering), m_texture_filter(texture_filtering), m_uv_limits(uv_limits), - m_pgxp_depth(pgxp_depth), m_disable_color_perspective(disable_color_perspective) + m_pgxp_depth(pgxp_depth) { } @@ -109,19 +109,19 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured) DeclareVertexEntryPoint( ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage", "float4 a_uv_limits"}, 1, 1, {{"nointerpolation", "uint4 v_texpage"}, {"nointerpolation", "float4 v_uv_limits"}}, false, "", UsingMSAA(), - UsingPerSampleShading(), m_disable_color_perspective); + UsingPerSampleShading()); } else { DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage"}, 1, 1, - {{"nointerpolation", "uint4 v_texpage"}}, false, "", UsingMSAA(), UsingPerSampleShading(), - m_disable_color_perspective); + {{"nointerpolation", "uint4 v_texpage"}}, false, "", UsingMSAA(), + UsingPerSampleShading()); } } else { DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0"}, 1, 0, {}, false, "", UsingMSAA(), - UsingPerSampleShading(), m_disable_color_perspective); + UsingPerSampleShading()); } ss << R"( @@ -805,20 +805,18 @@ float4 SampleFromVRAM(uint4 texpage, float2 coords) { DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", "uint4 v_texpage"}, {"nointerpolation", "float4 v_uv_limits"}}, - true, use_dual_source ? 2 : 1, !m_pgxp_depth, UsingMSAA(), UsingPerSampleShading(), - false, m_disable_color_perspective); + true, use_dual_source ? 2 : 1, !m_pgxp_depth, UsingMSAA(), UsingPerSampleShading()); } else { DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", "uint4 v_texpage"}}, true, use_dual_source ? 2 : 1, - !m_pgxp_depth, UsingMSAA(), UsingPerSampleShading(), false, - m_disable_color_perspective); + !m_pgxp_depth, UsingMSAA(), UsingPerSampleShading()); } } else { DeclareFragmentEntryPoint(ss, 1, 0, {}, true, use_dual_source ? 2 : 1, !m_pgxp_depth, UsingMSAA(), - UsingPerSampleShading(), false, m_disable_color_perspective); + UsingPerSampleShading()); } ss << R"( diff --git a/src/core/gpu_hw_shadergen.h b/src/core/gpu_hw_shadergen.h index b3b45873..92b86382 100644 --- a/src/core/gpu_hw_shadergen.h +++ b/src/core/gpu_hw_shadergen.h @@ -7,7 +7,7 @@ class GPU_HW_ShaderGen : public ShaderGen public: GPU_HW_ShaderGen(HostDisplay::RenderAPI render_api, u32 resolution_scale, u32 multisamples, bool per_sample_shading, bool true_color, bool scaled_dithering, GPUTextureFilter texture_filtering, bool uv_limits, - bool pgxp_depth, bool disable_color_perspective, bool supports_dual_source_blend); + bool pgxp_depth, bool supports_dual_source_blend); ~GPU_HW_ShaderGen(); std::string GenerateBatchVertexShader(bool textured); @@ -42,5 +42,4 @@ private: GPUTextureFilter m_texture_filter; bool m_uv_limits; bool m_pgxp_depth; - bool m_disable_color_perspective; }; diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp index 009e8f22..e9901fd2 100644 --- a/src/core/gpu_hw_vulkan.cpp +++ b/src/core/gpu_hw_vulkan.cpp @@ -317,7 +317,6 @@ void GPU_HW_Vulkan::SetCapabilities() m_supports_dual_source_blend = g_vulkan_context->GetDeviceFeatures().dualSrcBlend; m_supports_per_sample_shading = g_vulkan_context->GetDeviceFeatures().sampleRateShading; m_supports_adaptive_downsampling = true; - m_supports_disable_color_perspective = true; Log_InfoPrintf("Dual-source blend: %s", m_supports_dual_source_blend ? "supported" : "not supported"); Log_InfoPrintf("Per-sample shading: %s", m_supports_per_sample_shading ? "supported" : "not supported"); @@ -828,7 +827,7 @@ bool GPU_HW_Vulkan::CompilePipelines() GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_multisamples, m_per_sample_shading, m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, - m_pgxp_depth_buffer, m_disable_color_perspective, m_supports_dual_source_blend); + m_pgxp_depth_buffer, m_supports_dual_source_blend); ShaderCompileProgressTracker progress("Compiling Pipelines", 2 + (4 * 9 * 2 * 2) + (3 * 4 * 5 * 9 * 2 * 2) + 1 + 2 + (2 * 2) + 2 + 1 + 1 + (2 * 3) + 1); diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index bf5c909f..4bd495c6 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -112,21 +112,16 @@ ALWAYS_INLINE u16 VRAM16ToOutput(u16 value) template<> ALWAYS_INLINE u32 VRAM16ToOutput(u16 value) { - const u32 value32 = ZeroExtend32(value); - const u32 r = (value32 & 31u) << 3; - const u32 g = ((value32 >> 5) & 31u) << 3; - const u32 b = ((value32 >> 10) & 31u) << 3; - const u32 a = ((value >> 15) != 0) ? 255 : 0; - return ZeroExtend32(r) | (ZeroExtend32(g) << 8) | (ZeroExtend32(b) << 16) | (ZeroExtend32(a) << 24); + return VRAMRGBA5551ToRGBA8888(value); } template<> ALWAYS_INLINE u32 VRAM16ToOutput(u16 value) { const u32 value32 = ZeroExtend32(value); - const u32 r = (value32 & 31u) << 3; - const u32 g = ((value32 >> 5) & 31u) << 3; - const u32 b = ((value32 >> 10) & 31u) << 3; + const u32 r = VRAMConvert5To8(value32 & 31u); + const u32 g = VRAMConvert5To8((value32 >> 5) & 31u); + const u32 b = VRAMConvert5To8((value32 >> 10) & 31u); return ZeroExtend32(b) | (ZeroExtend32(g) << 8) | (ZeroExtend32(r) << 16) | (0xFF000000u); } diff --git a/src/core/gpu_types.h b/src/core/gpu_types.h index 34f613b3..56353817 100644 --- a/src/core/gpu_types.h +++ b/src/core/gpu_types.h @@ -114,25 +114,29 @@ union GPURenderCommand } }; +// Helper/format conversion functions - constants from https://stackoverflow.com/a/9069480 +ALWAYS_INLINE static constexpr u32 VRAMConvert5To8(u32 color) +{ + return (((color * 527u) + 23u) >> 6); +} +ALWAYS_INLINE static constexpr u32 VRAMConvert8To5(u32 color) +{ + return (((color * 249u) + 1014u) >> 11); +} ALWAYS_INLINE static constexpr u32 VRAMRGBA5551ToRGBA8888(u32 color) { - // Helper/format conversion functions - constants from https://stackoverflow.com/a/9069480 -#define E5TO8(color) ((((color) * 527u) + 23u) >> 6) - - const u32 r = E5TO8(color & 31u); - const u32 g = E5TO8((color >> 5) & 31u); - const u32 b = E5TO8((color >> 10) & 31u); + const u32 r = VRAMConvert5To8(color & 31u); + const u32 g = VRAMConvert5To8((color >> 5) & 31u); + const u32 b = VRAMConvert5To8((color >> 10) & 31u); const u32 a = ((color >> 15) != 0) ? 255 : 0; return ZeroExtend32(r) | (ZeroExtend32(g) << 8) | (ZeroExtend32(b) << 16) | (ZeroExtend32(a) << 24); - -#undef E5TO8 } ALWAYS_INLINE static constexpr u16 VRAMRGBA8888ToRGBA5551(u32 color) { - const u32 r = (color & 0xFFu) >> 3; - const u32 g = ((color >> 8) & 0xFFu) >> 3; - const u32 b = ((color >> 16) & 0xFFu) >> 3; + const u32 r = VRAMConvert8To5(color & 0xFFu); + const u32 g = VRAMConvert8To5((color >> 8) & 0xFFu); + const u32 b = VRAMConvert8To5((color >> 16) & 0xFFu); const u32 a = ((color >> 24) & 0x01u); return Truncate16(r | (g << 5) | (b << 10) | (a << 15)); } diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 9e682e2c..6682efdb 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -384,8 +384,6 @@ void HostInterface::CheckForSettingsChanges(const Settings& old_settings) g_settings.display_crop_mode != old_settings.display_crop_mode || g_settings.display_aspect_ratio != old_settings.display_aspect_ratio || g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable || - g_settings.gpu_pgxp_texture_correction != old_settings.gpu_pgxp_texture_correction || - g_settings.gpu_pgxp_color_correction != old_settings.gpu_pgxp_color_correction || g_settings.gpu_pgxp_depth_buffer != old_settings.gpu_pgxp_depth_buffer || g_settings.display_active_start_offset != old_settings.display_active_start_offset || g_settings.display_active_end_offset != old_settings.display_active_end_offset || diff --git a/src/core/mdec.cpp b/src/core/mdec.cpp index 44ffc425..d40d5f15 100644 --- a/src/core/mdec.cpp +++ b/src/core/mdec.cpp @@ -2,7 +2,6 @@ #include "common/state_wrapper.h" #include "cpu_core.h" #include "dma.h" -#include "gpu_types.h" #include "interrupt_controller.h" #include "system.h" @@ -324,6 +323,14 @@ bool MDEC::HandleDecodeMacroblockCommand() return DecodeColoredMacroblock(); } +// Parasite Eve needs slightly higher timing in 16bpp mode, Disney's Treasure Planet needs lower timing in 24bpp mode. +static constexpr std::array s_ticks_per_block = {{ + 448, // 4bpp + 448, // 8bpp + 448, // 24bpp + 550, // 16bpp +}}; + bool MDEC::DecodeMonoMacroblock() { // TODO: This should guard the output not the input @@ -340,7 +347,7 @@ bool MDEC::DecodeMonoMacroblock() y_to_mono(m_blocks[0]); - ScheduleBlockCopyOut(TICKS_PER_BLOCK * 6); + ScheduleBlockCopyOut(s_ticks_per_block[static_cast(m_status.data_output_depth)] * 6); m_total_blocks_decoded++; return true; @@ -369,7 +376,7 @@ bool MDEC::DecodeColoredMacroblock() yuv_to_rgb(8, 8, m_blocks[0], m_blocks[1], m_blocks[5]); m_total_blocks_decoded += 4; - ScheduleBlockCopyOut(TICKS_PER_BLOCK * 6); + ScheduleBlockCopyOut(s_ticks_per_block[static_cast(m_status.data_output_depth)] * 6); return true; } @@ -457,47 +464,22 @@ void MDEC::CopyOutBlock() case DataOutputDepth_15Bit: { - if (!g_settings.use_old_mdec_routines) + const u16 a = ZeroExtend16(m_status.data_output_bit15.GetValue()); + for (u32 i = 0; i < static_cast(m_block_rgb.size());) { - const u32 a = ZeroExtend32(m_status.data_output_bit15.GetValue()) << 15; - for (u32 i = 0; i < static_cast(m_block_rgb.size());) - { -#define E8TO5(color) (std::min((((color) + 4) >> 3), 0x1F)) - u32 color = m_block_rgb[i++]; - u32 r = E8TO5(color & 0xFFu); - u32 g = E8TO5((color >> 8) & 0xFFu); - u32 b = E8TO5((color >> 16) & 0xFFu); - const u32 color15a = r | (g << 5) | (b << 10) | a; + u32 color = m_block_rgb[i++]; + u16 r = Truncate16((color >> 3) & 0x1Fu); + u16 g = Truncate16((color >> 11) & 0x1Fu); + u16 b = Truncate16((color >> 19) & 0x1Fu); + const u16 color15a = r | (g << 5) | (b << 10) | (a << 15); - color = m_block_rgb[i++]; - r = E8TO5(color & 0xFFu); - g = E8TO5((color >> 8) & 0xFFu); - b = E8TO5((color >> 16) & 0xFFu); - const u32 color15b = r | (g << 5) | (b << 10) | a; -#undef E8TO5 + color = m_block_rgb[i++]; + r = Truncate16((color >> 3) & 0x1Fu); + g = Truncate16((color >> 11) & 0x1Fu); + b = Truncate16((color >> 19) & 0x1Fu); + const u16 color15b = r | (g << 5) | (b << 10) | (a << 15); - m_data_out_fifo.Push(color15a | (color15b << 16)); - } - } - else - { - const u16 a = ZeroExtend16(m_status.data_output_bit15.GetValue()) << 15; - for (u32 i = 0; i < static_cast(m_block_rgb.size());) - { - u32 color = m_block_rgb[i++]; - u16 r = Truncate16((color >> 3) & 0x1Fu); - u16 g = Truncate16((color >> 11) & 0x1Fu); - u16 b = Truncate16((color >> 19) & 0x1Fu); - const u16 color15a = r | (g << 5) | (b << 10) | (a << 15); - - color = m_block_rgb[i++]; - r = Truncate16((color >> 3) & 0x1Fu); - g = Truncate16((color >> 11) & 0x1Fu); - b = Truncate16((color >> 19) & 0x1Fu); - const u16 color15b = r | (g << 5) | (b << 10) | (a << 15); - - m_data_out_fifo.Push(ZeroExtend32(color15a) | (ZeroExtend32(color15b) << 16)); - } + m_data_out_fifo.Push(ZeroExtend32(color15a) | (ZeroExtend32(color15b) << 16)); } } break; @@ -549,7 +531,7 @@ bool MDEC::rl_decode_block(s16* blk, const u8* qt) val = std::clamp(val, -0x400, 0x3FF); if (m_current_q_scale > 0) blk[zagzig[m_current_coefficient]] = static_cast(val); - else + else if (m_current_q_scale == 0) blk[m_current_coefficient] = static_cast(val); } @@ -572,7 +554,7 @@ bool MDEC::rl_decode_block(s16* blk, const u8* qt) val = std::clamp(val, -0x400, 0x3FF); if (m_current_q_scale > 0) blk[zagzig[m_current_coefficient]] = static_cast(val); - else + else if (m_current_q_scale == 0) blk[m_current_coefficient] = static_cast(val); } @@ -587,42 +569,6 @@ bool MDEC::rl_decode_block(s16* blk, const u8* qt) } void MDEC::IDCT(s16* blk) -{ - // people have made texture packs using the old conversion routines.. best to just leave them be. - if (!g_settings.use_old_mdec_routines) - IDCT_New(blk); - else - IDCT_Old(blk); -} - -void MDEC::IDCT_New(s16* blk) -{ - std::array temp; - for (u32 x = 0; x < 8; x++) - { - for (u32 y = 0; y < 8; y++) - { - // TODO: We could alter zigzag and invert scale_table to get these in row-major order, - // in which case we could do optimize this to a vector multiply. - s32 sum = 0; - for (u32 z = 0; z < 8; z++) - sum += s32(blk[y + z * 8]) * s32(m_scale_table[x + z * 8] / 8); - temp[x + y * 8] = static_cast((sum + 0xfff) / 0x2000); - } - } - for (u32 x = 0; x < 8; x++) - { - for (u32 y = 0; y < 8; y++) - { - s32 sum = 0; - for (u32 z = 0; z < 8; z++) - sum += temp[y + z * 8] * s32(m_scale_table[x + z * 8] / 8); - blk[x + y * 8] = static_cast(std::clamp((sum + 0xfff) / 0x2000, -128, 127)); - } - } -} - -void MDEC::IDCT_Old(s16* blk) { std::array temp_buffer; for (u32 x = 0; x < 8; x++) @@ -652,7 +598,6 @@ void MDEC::IDCT_Old(s16* blk) void MDEC::yuv_to_rgb(u32 xx, u32 yy, const std::array& Crblk, const std::array& Cbblk, const std::array& Yblk) { - const s16 addval = m_status.data_output_signed ? 0 : 0x80; for (u32 y = 0; y < 8; y++) { for (u32 x = 0; x < 8; x++) @@ -665,9 +610,14 @@ void MDEC::yuv_to_rgb(u32 xx, u32 yy, const std::array& Crblk, const st B = static_cast(1.772f * static_cast(B)); s16 Y = Yblk[x + y * 8]; - R = static_cast(std::clamp(static_cast(Y) + R, -128, 127)) + addval; - G = static_cast(std::clamp(static_cast(Y) + G, -128, 127)) + addval; - B = static_cast(std::clamp(static_cast(Y) + B, -128, 127)) + addval; + R = static_cast(std::clamp(static_cast(Y) + R, -128, 127)); + G = static_cast(std::clamp(static_cast(Y) + G, -128, 127)); + B = static_cast(std::clamp(static_cast(Y) + B, -128, 127)); + + // TODO: Signed output + R += 128; + G += 128; + B += 128; m_block_rgb[(x + xx) + ((y + yy) * 16)] = ZeroExtend32(static_cast(R)) | (ZeroExtend32(static_cast(G)) << 8) | diff --git a/src/core/mdec.h b/src/core/mdec.h index da00db4b..21d376c2 100644 --- a/src/core/mdec.h +++ b/src/core/mdec.h @@ -31,7 +31,6 @@ private: static constexpr u32 DATA_IN_FIFO_SIZE = 1024; static constexpr u32 DATA_OUT_FIFO_SIZE = 768; static constexpr u32 NUM_BLOCKS = 6; - static constexpr TickCount TICKS_PER_BLOCK = 448; enum DataOutputDepth : u8 { @@ -116,8 +115,6 @@ private: // from nocash spec bool rl_decode_block(s16* blk, const u8* qt); void IDCT(s16* blk); - void IDCT_New(s16* blk); - void IDCT_Old(s16* blk); void yuv_to_rgb(u32 xx, u32 yy, const std::array& Crblk, const std::array& Cbblk, const std::array& Yblk); void y_to_mono(const std::array& Yblk); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 68eb1d27..89a25997 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -189,7 +189,6 @@ void Settings::Load(SettingsInterface& si) gpu_pgxp_enable = si.GetBoolValue("GPU", "PGXPEnable", false); gpu_pgxp_culling = si.GetBoolValue("GPU", "PGXPCulling", true); gpu_pgxp_texture_correction = si.GetBoolValue("GPU", "PGXPTextureCorrection", true); - gpu_pgxp_color_correction = si.GetBoolValue("GPU", "PGXPColorCorrection", false); gpu_pgxp_vertex_cache = si.GetBoolValue("GPU", "PGXPVertexCache", false); gpu_pgxp_cpu = si.GetBoolValue("GPU", "PGXPCPU", false); gpu_pgxp_preserve_proj_fp = si.GetBoolValue("GPU", "PGXPPreserveProjFP", false); @@ -229,8 +228,6 @@ void Settings::Load(SettingsInterface& si) audio_buffer_size = si.GetIntValue("Audio", "BufferSize", HostInterface::DEFAULT_AUDIO_BUFFER_SIZE); - use_old_mdec_routines = si.GetBoolValue("Hacks", "UseOldMDECRoutines", false); - dma_max_slice_ticks = si.GetIntValue("Hacks", "DMAMaxSliceTicks", DEFAULT_DMA_MAX_SLICE_TICKS); dma_halt_ticks = si.GetIntValue("Hacks", "DMAHaltTicks", DEFAULT_DMA_HALT_TICKS); gpu_fifo_size = static_cast(si.GetIntValue("Hacks", "GPUFIFOSize", DEFAULT_GPU_FIFO_SIZE)); diff --git a/src/core/settings.h b/src/core/settings.h index 2e0d5369..6d5547c0 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -95,7 +95,6 @@ struct Settings bool gpu_pgxp_enable = false; bool gpu_pgxp_culling = true; bool gpu_pgxp_texture_correction = true; - bool gpu_pgxp_color_correction = false; bool gpu_pgxp_vertex_cache = false; bool gpu_pgxp_cpu = false; bool gpu_pgxp_preserve_proj_fp = false; @@ -127,8 +126,6 @@ struct Settings u32 audio_buffer_size = 2048; - bool use_old_mdec_routines = false; - // timing hacks section TickCount dma_max_slice_ticks = 1000; TickCount dma_halt_ticks = 100; diff --git a/src/core/shadergen.cpp b/src/core/shadergen.cpp index 1b028720..af3f23d7 100644 --- a/src/core/shadergen.cpp +++ b/src/core/shadergen.cpp @@ -329,8 +329,8 @@ const char* ShaderGen::GetInterpolationQualifier(bool interface_block, bool cent void ShaderGen::DeclareVertexEntryPoint( std::stringstream& ss, const std::initializer_list& attributes, u32 num_color_outputs, u32 num_texcoord_outputs, const std::initializer_list>& additional_outputs, - bool declare_vertex_id /* = false */, const char* output_block_suffix /* = "" */, bool msaa /* = false */, - bool ssaa /* = false */, bool noperspective_color /* = false */) + bool declare_vertex_id /* = false */, const char* output_block_suffix /* = "" */, + bool centroid_interpolation /* = false */, bool sample_interpolation /* = false */) { if (m_glsl) { @@ -351,14 +351,14 @@ void ShaderGen::DeclareVertexEntryPoint( if (m_use_glsl_interface_blocks) { - const char* qualifier = GetInterpolationQualifier(true, msaa, ssaa, true); + const char* qualifier = GetInterpolationQualifier(true, centroid_interpolation, sample_interpolation, true); if (IsVulkan()) ss << "layout(location = 0) "; ss << "out VertexData" << output_block_suffix << " {\n"; for (u32 i = 0; i < num_color_outputs; i++) - ss << " " << (noperspective_color ? "noperspective " : "") << qualifier << "float4 v_col" << i << ";\n"; + ss << " " << qualifier << "float4 v_col" << i << ";\n"; for (u32 i = 0; i < num_texcoord_outputs; i++) ss << " " << qualifier << "float2 v_tex" << i << ";\n"; @@ -372,10 +372,10 @@ void ShaderGen::DeclareVertexEntryPoint( } else { - const char* qualifier = GetInterpolationQualifier(false, msaa, ssaa, true); + const char* qualifier = GetInterpolationQualifier(false, centroid_interpolation, sample_interpolation, true); for (u32 i = 0; i < num_color_outputs; i++) - ss << qualifier << (noperspective_color ? "noperspective " : "") << "out float4 v_col" << i << ";\n"; + ss << qualifier << "out float4 v_col" << i << ";\n"; for (u32 i = 0; i < num_texcoord_outputs; i++) ss << qualifier << "out float2 v_tex" << i << ";\n"; @@ -401,7 +401,7 @@ void ShaderGen::DeclareVertexEntryPoint( } else { - const char* qualifier = GetInterpolationQualifier(false, msaa, ssaa, true); + const char* qualifier = GetInterpolationQualifier(false, centroid_interpolation, sample_interpolation, true); ss << "void main(\n"; @@ -416,8 +416,7 @@ void ShaderGen::DeclareVertexEntryPoint( } for (u32 i = 0; i < num_color_outputs; i++) - ss << " " << qualifier << (noperspective_color ? "noperspective " : "") << "out float4 v_col" << i << " : COLOR" - << i << ",\n"; + ss << " " << qualifier << "out float4 v_col" << i << " : COLOR" << i << ",\n"; for (u32 i = 0; i < num_texcoord_outputs; i++) ss << " " << qualifier << "out float2 v_tex" << i << " : TEXCOORD" << i << ",\n"; @@ -438,21 +437,21 @@ void ShaderGen::DeclareFragmentEntryPoint( std::stringstream& ss, u32 num_color_inputs, u32 num_texcoord_inputs, const std::initializer_list>& additional_inputs, bool declare_fragcoord /* = false */, u32 num_color_outputs /* = 1 */, bool depth_output /* = false */, - bool msaa /* = false */, bool ssaa /* = false */, bool declare_sample_id /* = false */, - bool noperspective_color /* = false */) + bool centroid_interpolation /* = false */, bool sample_interpolation /* = false */, + bool declare_sample_id /* = false */) { if (m_glsl) { if (m_use_glsl_interface_blocks) { - const char* qualifier = GetInterpolationQualifier(true, msaa, ssaa, false); + const char* qualifier = GetInterpolationQualifier(true, centroid_interpolation, sample_interpolation, false); if (IsVulkan()) ss << "layout(location = 0) "; ss << "in VertexData {\n"; for (u32 i = 0; i < num_color_inputs; i++) - ss << " " << qualifier << (noperspective_color ? "noperspective " : "") << "float4 v_col" << i << ";\n"; + ss << " " << qualifier << "float4 v_col" << i << ";\n"; for (u32 i = 0; i < num_texcoord_inputs; i++) ss << " " << qualifier << "float2 v_tex" << i << ";\n"; @@ -466,10 +465,10 @@ void ShaderGen::DeclareFragmentEntryPoint( } else { - const char* qualifier = GetInterpolationQualifier(false, msaa, ssaa, false); + const char* qualifier = GetInterpolationQualifier(false, centroid_interpolation, sample_interpolation, false); for (u32 i = 0; i < num_color_inputs; i++) - ss << qualifier << (noperspective_color ? "noperspective " : "") << "in float4 v_col" << i << ";\n"; + ss << qualifier << "in float4 v_col" << i << ";\n"; for (u32 i = 0; i < num_texcoord_inputs; i++) ss << qualifier << "in float2 v_tex" << i << ";\n"; @@ -515,13 +514,12 @@ void ShaderGen::DeclareFragmentEntryPoint( } else { - const char* qualifier = GetInterpolationQualifier(false, msaa, ssaa, false); + const char* qualifier = GetInterpolationQualifier(false, centroid_interpolation, sample_interpolation, false); ss << "void main(\n"; for (u32 i = 0; i < num_color_inputs; i++) - ss << " " << qualifier << (noperspective_color ? "noperspective " : "") << "in float4 v_col" << i << " : COLOR" - << i << ",\n"; + ss << " " << qualifier << "in float4 v_col" << i << " : COLOR" << i << ",\n"; for (u32 i = 0; i < num_texcoord_inputs; i++) ss << " " << qualifier << "in float2 v_tex" << i << " : TEXCOORD" << i << ",\n"; diff --git a/src/core/shadergen.h b/src/core/shadergen.h index 6df9d68d..f3a9196c 100644 --- a/src/core/shadergen.h +++ b/src/core/shadergen.h @@ -36,12 +36,11 @@ protected: u32 num_color_outputs, u32 num_texcoord_outputs, const std::initializer_list>& additional_outputs, bool declare_vertex_id = false, const char* output_block_suffix = "", bool msaa = false, - bool ssaa = false, bool noperspective_color = false); + bool ssaa = false); void DeclareFragmentEntryPoint(std::stringstream& ss, u32 num_color_inputs, u32 num_texcoord_inputs, const std::initializer_list>& additional_inputs, bool declare_fragcoord = false, u32 num_color_outputs = 1, bool depth_output = false, - bool msaa = false, bool ssaa = false, bool declare_sample_id = false, - bool noperspective_color = false); + bool msaa = false, bool ssaa = false, bool declare_sample_id = false); HostDisplay::RenderAPI m_render_api; bool m_glsl; diff --git a/src/libretro/libretro_core_options.h b/src/libretro/libretro_core_options.h index 678a601f..2a43efc6 100644 --- a/src/libretro/libretro_core_options.h +++ b/src/libretro/libretro_core_options.h @@ -557,9 +557,9 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, { "duckstation_GPU.PGXPTextureCorrection", - "PGXP Perspective Correct Textures", + "PGXP Texture Correction", NULL, - "Uses perspective-correct interpolation for texture coordinates, straightening out warped textures. " + "Uses perspective-correct interpolation for texture coordinates and colors, straightening out warped textures. " "Requires geometry correction enabled.", NULL, "enhancement", @@ -570,21 +570,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "true" }, - { - "duckstation_GPU.PGXPColorCorrection", - "PGXP Perspective Correct Colors", - NULL, - "Uses perspective-correct interpolation for vertex colors, which can improve visuals in some games, but cause rendering errors in others. " - "Requires geometry correction enabled.", - NULL, - "enhancement", - { - { "true", "Enabled" }, - { "false", "Disabled" }, - { NULL, NULL }, - }, - "false" - }, { "duckstation_GPU.PGXPDepthBuffer", "PGXP Depth Buffer", @@ -4552,20 +4537,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "false" }, - { - "duckstation_Hacks.UseOldMDECRoutines", - "Use Old MDEC Routines", - NULL, - "Use old routines for MDEC content.", - NULL, - "advanced", - { - { "true", "Enabled" }, - { "false", "Disabled" }, - { NULL, NULL }, - }, - "false" - }, { NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL }, }; diff --git a/src/libretro/libretro_game_settings.cpp b/src/libretro/libretro_game_settings.cpp index e061674d..1fa637f9 100644 --- a/src/libretro/libretro_game_settings.cpp +++ b/src/libretro/libretro_game_settings.cpp @@ -132,22 +132,12 @@ void Entry::ApplySettings(bool display_osd_messages) const { if (g_settings.gpu_pgxp_enable && g_settings.gpu_pgxp_texture_correction) { - gamesettings_message.append("PGXP perspective corrected textures disabled by game settings. ", 63); + gamesettings_message.append("PGXP texture correction disabled by game settings. ", 51); } g_settings.gpu_pgxp_texture_correction = false; } - if (HasTrait(Trait::DisablePGXPColorCorrection)) - { - if (g_settings.gpu_pgxp_enable && g_settings.gpu_pgxp_color_correction) - { - gamesettings_message.append("PGXP perspective corrected colors disabled by game settings. ", 61); - } - - g_settings.gpu_pgxp_color_correction = false; - } - if (HasTrait(Trait::ForcePGXPVertexCache)) { if (g_settings.gpu_pgxp_enable && !g_settings.gpu_pgxp_vertex_cache) @@ -251,15 +241,6 @@ std::unique_ptr GetSettingsForGame(const std::string& game_ return gs; } - if ( game_code == "SCUS-94244" /* Crash Bandicoot - Warped (NTSC-U) */ - || game_code == "SCES-01420" /* Crash Bandicoot 3 - Warped (PAL) */ - || game_code == "SCPS-10073" /* Crash Bandicoot 3 - Buttobi! Sekai Isshuu (NTSC-J) */ - ) - { - gs->AddTrait(GameSettings::Trait::DisablePGXPColorCorrection); - return gs; - } - if ( game_code == "SLPM-87089" /* Pop'n Music 6 (NTSC-J) */ || game_code == "SLPS-03336" /* Mr. Driller G (NTSC-J) */ || game_code == "SLUS-00952" /* Arcade Party Pak (NTSC-U) */ diff --git a/src/libretro/libretro_game_settings.h b/src/libretro/libretro_game_settings.h index d765eb31..3c450cf3 100644 --- a/src/libretro/libretro_game_settings.h +++ b/src/libretro/libretro_game_settings.h @@ -23,7 +23,6 @@ enum class Trait : u32 DisablePGXP, DisablePGXPCulling, DisablePGXPTextureCorrection, - DisablePGXPColorCorrection, DisablePGXPDepthBuffer, ForcePGXPVertexCache, ForcePGXPCPUMode, @@ -37,6 +36,10 @@ enum class Trait : u32 struct Entry { std::bitset(Trait::Count)> traits{}; + std::optional display_active_start_offset; + std::optional display_active_end_offset; + std::optional display_line_start_offset; + std::optional display_line_end_offset; std::optional dma_max_slice_ticks; std::optional dma_halt_ticks; std::optional gpu_fifo_size; @@ -44,6 +47,40 @@ struct Entry std::optional gpu_pgxp_tolerance; std::optional gpu_pgxp_depth_threshold; + // user settings + std::optional runahead_frames; + std::optional cpu_overclock_numerator; + std::optional cpu_overclock_denominator; + std::optional cpu_overclock_enable; + std::optional enable_8mb_ram; + std::optional cdrom_read_speedup; + std::optional cdrom_seek_speedup; + std::optional display_crop_mode; + std::optional display_aspect_ratio; + std::optional gpu_renderer; + std::optional gpu_use_software_renderer_for_readbacks; + std::optional gpu_downsample_mode; + std::optional display_linear_upscaling; + std::optional display_force_4_3_for_24bit; + std::optional display_aspect_ratio_custom_numerator; + std::optional display_aspect_ratio_custom_denominator; + std::optional gpu_resolution_scale; + std::optional gpu_multisamples; + std::optional gpu_per_sample_shading; + std::optional gpu_true_color; + std::optional gpu_scaled_dithering; + std::optional gpu_force_ntsc_timings; + std::optional gpu_texture_filter; + std::optional gpu_widescreen_hack; + std::optional gpu_pgxp; + std::optional gpu_pgxp_projection_precision; + std::optional gpu_pgxp_depth_buffer; + std::optional multitap_mode; + std::optional controller_1_type; + std::optional controller_2_type; + std::optional memory_card_1_type; + std::optional memory_card_2_type; + ALWAYS_INLINE bool HasTrait(Trait trait) const { return traits[static_cast(trait)]; } ALWAYS_INLINE void AddTrait(Trait trait) { traits[static_cast(trait)] = true; } diff --git a/src/libretro/libretro_host_interface.cpp b/src/libretro/libretro_host_interface.cpp index c6ac8107..4454b6de 100644 --- a/src/libretro/libretro_host_interface.cpp +++ b/src/libretro/libretro_host_interface.cpp @@ -940,8 +940,6 @@ bool LibretroHostInterface::UpdateCoreOptionsDisplay(bool controller) g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); option_display.key = "duckstation_GPU.PGXPTextureCorrection"; g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); - option_display.key = "duckstation_GPU.PGXPColorCorrection"; - g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); option_display.key = "duckstation_GPU.PGXPDepthBuffer"; g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); option_display.key = "duckstation_GPU.PGXPVertexCache";