From c3250176759dc5d228abeaced44fd8e0825449de Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 11 Jul 2023 00:47:56 +0300 Subject: [PATCH] rsx: Preserve the texcoord transform around destructive modifications --- rpcs3/Emu/RSX/Common/TextureUtils.h | 51 ++++++++++++++------ rpcs3/Emu/RSX/Common/texture_cache.h | 6 +++ rpcs3/Emu/RSX/Common/texture_cache_helpers.h | 3 ++ rpcs3/Emu/RSX/GL/glutils/sampler.h | 2 +- rpcs3/Emu/RSX/RSXThread.h | 2 +- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.h b/rpcs3/Emu/RSX/Common/TextureUtils.h index de2cbf5f44..c4cb11b30e 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.h +++ b/rpcs3/Emu/RSX/Common/TextureUtils.h @@ -1,10 +1,11 @@ #pragma once +#include "io_buffer.h" #include "../RSXTexture.h" #include +#include #include -#include "io_buffer.h" namespace rsx { @@ -123,9 +124,39 @@ namespace rsx using namespace format_class_; - //Sampled image descriptor - struct sampled_image_descriptor_base + // Sampled image descriptor + class sampled_image_descriptor_base { +#pragma pack(push, 1) + struct texcoord_xform_t + { + f32 scale[3]; + f32 bias[3]; + f32 clamp_min[2]; + f32 clamp_max[2]; + bool clamp = false; + }; +#pragma pack(pop) + + // Texure matrix stack + std::stack m_texcoord_xform_stack; + + public: + virtual ~sampled_image_descriptor_base() = default; + virtual u32 encoded_component_map() const = 0; + + void push_texcoord_xform() + { + m_texcoord_xform_stack.push(texcoord_xform); + } + + void pop_texcoord_xform() + { + ensure(!m_texcoord_xform_stack.empty()); + std::memcpy(&texcoord_xform, &m_texcoord_xform_stack.top(), sizeof(texcoord_xform_t)); + m_texcoord_xform_stack.pop(); + } + texture_upload_context upload_context = texture_upload_context::shader_read; rsx::texture_dimension_extended image_type = texture_dimension_extended::texture_dimension_2d; rsx::format_class format_class = RSX_FORMAT_CLASS_UNDEFINED; @@ -134,19 +165,7 @@ namespace rsx u32 ref_address = 0; u64 surface_cache_tag = 0; -#pragma pack(push, 1) - struct - { - f32 scale[3]; - f32 bias[3]; - f32 clamp_min[2]; - f32 clamp_max[2]; - bool clamp = false; - } texcoord_xform; -#pragma pack(pop) - - virtual ~sampled_image_descriptor_base() = default; - virtual u32 encoded_component_map() const = 0; + texcoord_xform_t texcoord_xform; }; struct typeless_xfer diff --git a/rpcs3/Emu/RSX/Common/texture_cache.h b/rpcs3/Emu/RSX/Common/texture_cache.h index c3002ea7c8..664eb65d1a 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache.h +++ b/rpcs3/Emu/RSX/Common/texture_cache.h @@ -2416,6 +2416,12 @@ namespace rsx result.external_subresource_desc = { 0, deferred_request_command::mipmap_gather, attributes, {}, tex.decoded_remap() }; result.format_class = rsx::classify_format(attributes.gcm_format); + if (result.texcoord_xform.clamp) + { + // Revert clamp configuration + result.pop_texcoord_xform(); + } + if (use_upscaling) { // Grab the correct image dimensions from the base mipmap level diff --git a/rpcs3/Emu/RSX/Common/texture_cache_helpers.h b/rpcs3/Emu/RSX/Common/texture_cache_helpers.h index 4bd5f668ad..ea2196a876 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_helpers.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_helpers.h @@ -514,6 +514,9 @@ namespace rsx const size2i& desired_dimensions, const size2i& actual_dimensions) { + // Back up the transformation before we destructively modify it. + desc.push_texcoord_xform(); + desc.texcoord_xform.scale[0] *= f32(desired_dimensions.width) / actual_dimensions.width; desc.texcoord_xform.scale[1] *= f32(desired_dimensions.height) / actual_dimensions.height; desc.texcoord_xform.bias[0] += f32(offset.x) / actual_dimensions.width; diff --git a/rpcs3/Emu/RSX/GL/glutils/sampler.h b/rpcs3/Emu/RSX/GL/glutils/sampler.h index 10ed7e8d65..89200915f8 100644 --- a/rpcs3/Emu/RSX/GL/glutils/sampler.h +++ b/rpcs3/Emu/RSX/GL/glutils/sampler.h @@ -6,7 +6,7 @@ namespace rsx { class fragment_texture; class vertex_texture; - struct sampled_image_descriptor_base; + class sampled_image_descriptor_base; } namespace gl diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index a4cc71b640..ddd45213ee 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -138,7 +138,7 @@ namespace rsx bool supports_normalized_barycentrics; // Basically all GPUs except NVIDIA have properly normalized barycentrics }; - struct sampled_image_descriptor_base; + class sampled_image_descriptor_base; struct desync_fifo_cmd_info {