From b8fa97e1a701fabc2dbbd5ceadda2f9d6f34db27 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 23 Dec 2024 23:47:58 +1000 Subject: [PATCH] GPU: Fix sprite texture filtering with TC enabled --- src/core/gpu_hw.cpp | 32 ++++++++++++++++++++------------ src/core/gpu_hw.h | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index a0578a68e..64c4a8d53 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -58,8 +58,8 @@ static constexpr const std::array s_transparency_modes = { }; static constexpr const std::array s_batch_texture_modes = { - "Palette4Bit", "Palette8Bit", "Direct16Bit", "PageTexture", - "Disabled", "SpritePalette4Bit", "SpritePalette8Bit", "SpriteDirect16Bit", + "Palette4Bit", "Palette8Bit", "Direct16Bit", "PageTexture", "Disabled", + "SpritePalette4Bit", "SpritePalette8Bit", "SpriteDirect16Bit", "SpritePageTexture", }; static_assert(s_batch_texture_modes.size() == static_cast(GPU_HW::BatchTextureMode::MaxCount)); @@ -1123,8 +1123,10 @@ bool GPU_HW::CompilePipelines(Error* error) const u32 max_active_texture_modes = (m_allow_sprite_mode ? NUM_TEXTURE_MODES : (NUM_TEXTURE_MODES - (NUM_TEXTURE_MODES - static_cast(BatchTextureMode::SpriteStart)))); - const u32 num_active_texture_modes = (max_active_texture_modes - BoolToUInt32(!needs_page_texture)); - const u32 total_vertex_shaders = ((m_allow_sprite_mode ? 7 : 4) - BoolToUInt32(!needs_page_texture)); + const u32 num_active_texture_modes = + (max_active_texture_modes - (BoolToUInt32(!needs_page_texture) * (BoolToUInt32(m_allow_sprite_mode) + 1))); + const u32 total_vertex_shaders = + ((m_allow_sprite_mode ? 7 : 4) - (BoolToUInt32(!needs_page_texture) * (BoolToUInt32(m_allow_sprite_mode) + 1))); const u32 total_fragment_shaders = ((1 + BoolToUInt32(needs_rov_depth)) * 5 * 5 * num_active_texture_modes * 2 * (1 + BoolToUInt32(!true_color)) * (1 + BoolToUInt32(!force_progressive_scan))); const u32 total_items = @@ -1232,8 +1234,11 @@ bool GPU_HW::CompilePipelines(Error* error) for (u8 texture_mode = 0; texture_mode < max_active_texture_modes; texture_mode++) { - if (texture_mode == static_cast(BatchTextureMode::PageTexture) && !needs_page_texture) + if (!needs_page_texture && (texture_mode == static_cast(BatchTextureMode::PageTexture) || + texture_mode == static_cast(BatchTextureMode::SpritePageTexture))) + { continue; + } for (u8 check_mask = 0; check_mask < 2; check_mask++) { @@ -1353,8 +1358,11 @@ bool GPU_HW::CompilePipelines(Error* error) for (u8 texture_mode = 0; texture_mode < max_active_texture_modes; texture_mode++) { - if (texture_mode == static_cast(BatchTextureMode::PageTexture) && !needs_page_texture) + if (!needs_page_texture && (texture_mode == static_cast(BatchTextureMode::PageTexture) || + texture_mode == static_cast(BatchTextureMode::SpritePageTexture))) + { continue; + } for (u8 dithering = 0; dithering < 2; dithering++) { @@ -1377,7 +1385,8 @@ bool GPU_HW::CompilePipelines(Error* error) static_cast(texture_mode) == BatchTextureMode::SpritePalette4Bit || static_cast(texture_mode) == BatchTextureMode::SpritePalette8Bit); const bool page_texture = - (static_cast(texture_mode) == BatchTextureMode::PageTexture); + (static_cast(texture_mode) == BatchTextureMode::PageTexture || + static_cast(texture_mode) == BatchTextureMode::SpritePageTexture); const bool sprite = (static_cast(texture_mode) >= BatchTextureMode::SpriteStart); const bool uv_limits = ShouldClampUVs(sprite ? m_sprite_texture_filtering : m_texture_filtering); const bool use_shader_blending = (render_mode == static_cast(BatchRenderMode::ShaderBlend)); @@ -2044,11 +2053,10 @@ ALWAYS_INLINE_RELEASE void GPU_HW::DrawBatchVertices(BatchRenderMode render_mode u32 base_vertex, const GPUTextureCache::Source* texture) { // [depth_test][transparency_mode][render_mode][texture_mode][dithering][interlacing][check_mask] - const u8 texture_mode = texture ? static_cast(BatchTextureMode::PageTexture) : - (static_cast(m_batch.texture_mode) + - ((m_batch.texture_mode < BatchTextureMode::PageTexture && m_batch.sprite_mode) ? - static_cast(BatchTextureMode::SpriteStart) : - 0)); + const u8 texture_mode = (static_cast(m_batch.texture_mode) + + ((m_batch.texture_mode < BatchTextureMode::Disabled && m_batch.sprite_mode) ? + static_cast(BatchTextureMode::SpriteStart) : + 0)); const u8 depth_test = BoolToUInt8(m_batch.use_depth_buffer); const u8 check_mask = BoolToUInt8(m_batch.check_mask_before_draw); g_gpu_device->SetPipeline(m_batch_pipelines[depth_test][static_cast(m_batch.transparency_mode)][static_cast( diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index b1fa04534..7d7263ef8 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -48,6 +48,7 @@ public: SpritePalette4Bit, SpritePalette8Bit, SpriteDirect16Bit, + SpritePageTexture, MaxCount,