From d8cd2c3252ab6f2ce6c1656b5eb194863e834f52 Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Mon, 29 Jun 2015 22:19:19 -0300 Subject: Implement scaled partial texture updates --- Source/Core/VideoBackends/D3D/TextureCache.cpp | 62 ++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index 2c820849d5..de204fa2af 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -77,11 +77,67 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l return saved_png; } -void TextureCache::TCacheEntry::DoPartialTextureUpdate(TCacheEntryBase* entry_, u32 x, u32 y) +void TextureCache::TCacheEntry::CopyRectangleFromTexture( + const TCacheEntryBase* source, + const MathUtil::Rectangle &srcrect, + const MathUtil::Rectangle &dstrect) { - TCacheEntry* entry = (TCacheEntry*)entry_; + TCacheEntry* srcentry = (TCacheEntry*)source; + if (srcrect.GetWidth() == dstrect.GetWidth() + && srcrect.GetHeight() == dstrect.GetHeight()) + { + const D3D11_BOX *psrcbox = nullptr; + D3D11_BOX srcbox; + if (srcrect.left != 0 || srcrect.top != 0) + { + srcbox.left = srcrect.left; + srcbox.top = srcrect.top; + srcbox.right = srcrect.right; + srcbox.bottom = srcrect.bottom; + psrcbox = &srcbox; + } + D3D::context->CopySubresourceRegion( + texture->GetTex(), + 0, + dstrect.left, + dstrect.top, + 0, + srcentry->texture->GetTex(), + 0, + psrcbox); + return; + } + else if (!config.rendertarget) + { + return; + } + g_renderer->ResetAPIState(); // reset any game specific settings - D3D::context->CopySubresourceRegion(texture->GetTex(), 0, x , y , 0, entry->texture->GetTex(), 0, NULL); + const D3D11_VIEWPORT vp = CD3D11_VIEWPORT( + float(dstrect.left), + float(dstrect.top), + float(dstrect.GetWidth()), + float(dstrect.GetHeight())); + + D3D::context->OMSetRenderTargets(1, &texture->GetRTV(), nullptr); + D3D::context->RSSetViewports(1, &vp); + D3D::SetLinearCopySampler(); + D3D11_RECT srcRC; + srcRC.left = srcrect.left; + srcRC.right = srcrect.right; + srcRC.top = srcrect.top; + srcRC.bottom = srcrect.bottom; + D3D::drawShadedTexQuad(srcentry->texture->GetSRV(), &srcRC, + srcentry->config.width, srcentry->config.height, + PixelShaderCache::GetColorCopyProgram(false), + VertexShaderCache::GetSimpleVertexShader(), + VertexShaderCache::GetSimpleInputLayout(), nullptr, 1.0, 0); + + D3D::context->OMSetRenderTargets(1, + &FramebufferManager::GetEFBColorTexture()->GetRTV(), + FramebufferManager::GetEFBDepthTexture()->GetDSV()); + + g_renderer->RestoreAPIState(); } void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, -- cgit v1.2.3 From 52948bb3ef016abd7e35e775b17b7cf3f487d49c Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Tue, 1 Sep 2015 02:41:16 +1200 Subject: Cleanup and unify handling of efb copy stride. --- Source/Core/VideoBackends/D3D/TextureCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index de204fa2af..5616a833e2 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -185,7 +185,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConf } } -void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat, +void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat, u32 dstStride, PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf, unsigned int cbufid, const float *colmat) @@ -238,7 +238,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo if (!g_ActiveConfig.bSkipEFBCopyToRam) { u8* dst = Memory::GetPointer(dstAddr); - size_t encoded_size = g_encoder->Encode(dst, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf); + size_t encoded_size = g_encoder->Encode(dst, dstFormat, dstStride, srcFormat, srcRect, isIntensity, scaleByHalf); size_in_bytes = (u32)encoded_size; -- cgit v1.2.3 From b9be3245e1bcd3929baf4d1c66fe5a14b336cdbc Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 5 Sep 2015 02:45:29 +1200 Subject: Move common EFB copy code into VideoCommon Addded a few duplicated depth copy texture formats to the enum in TextureDecoder.h. These texture formats were already implemented in TextureCacheBase and the ogl/dx11 texture cache implementations. --- Source/Core/VideoBackends/D3D/TextureCache.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index 5616a833e2..60a5922f29 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "Core/HW/Memmap.h" #include "VideoBackends/D3D/D3DBase.h" #include "VideoBackends/D3D/D3DShader.h" #include "VideoBackends/D3D/D3DState.h" @@ -185,7 +184,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConf } } -void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat, u32 dstStride, +void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, unsigned int dstFormat, u32 dstStride, PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf, unsigned int cbufid, const float *colmat) @@ -226,10 +225,13 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo // Create texture copy D3D::drawShadedTexQuad( - (srcFormat == PEControl::Z24) ? FramebufferManager::GetEFBDepthTexture()->GetSRV() : FramebufferManager::GetEFBColorTexture()->GetSRV(), - &sourcerect, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), - (srcFormat == PEControl::Z24) ? PixelShaderCache::GetDepthMatrixProgram(true) : PixelShaderCache::GetColorMatrixProgram(true), - VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader()); + (srcFormat == PEControl::Z24 ? FramebufferManager::GetEFBDepthTexture() : FramebufferManager::GetEFBColorTexture())->GetSRV(), + &sourcerect, Renderer::GetTargetWidth(), + Renderer::GetTargetHeight(), + srcFormat == PEControl::Z24 ? PixelShaderCache::GetDepthMatrixProgram(true) : PixelShaderCache::GetColorMatrixProgram(true), + VertexShaderCache::GetSimpleVertexShader(), + VertexShaderCache::GetSimpleInputLayout(), + GeometryShaderCache::GetCopyGeometryShader()); D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); @@ -237,14 +239,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo if (!g_ActiveConfig.bSkipEFBCopyToRam) { - u8* dst = Memory::GetPointer(dstAddr); - size_t encoded_size = g_encoder->Encode(dst, dstFormat, dstStride, srcFormat, srcRect, isIntensity, scaleByHalf); - - size_in_bytes = (u32)encoded_size; - - TextureCache::MakeRangeDynamic(dstAddr, (u32)encoded_size); - - this->hash = GetHash64(dst, (int)encoded_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + g_encoder->Encode(dst, this, srcFormat, srcRect, isIntensity, scaleByHalf); } } -- cgit v1.2.3 From 137856bd00a58da905d95ff92adf40e3c160822a Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 6 Sep 2015 21:02:51 +1200 Subject: Fix palette conversions for 4 bit efb copies. Fixes purple shadow in THPS4 and many other things. --- Source/Core/VideoBackends/D3D/TextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index 60a5922f29..603084dd33 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -337,7 +337,7 @@ void TextureCache::ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* uncon D3D::stateman->SetTexture(1, palette_buf_srv); // TODO: Add support for C14X2 format. (Different multiplier, more palette entries.) - float params[4] = { unconverted->format == 0 ? 15.f : 255.f }; + float params[4] = { (unconverted->format & 0xf) == 0 ? 15.f : 255.f }; D3D::context->UpdateSubresource(palette_uniform, 0, nullptr, ¶ms, 0, 0); D3D::stateman->SetPixelConstants(palette_uniform); -- cgit v1.2.3 From ee649c6d9f38510b2acad42dcce894400a8b4d4b Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 6 Sep 2015 02:03:49 +1200 Subject: Make efb2tex behave more like efb2ram. Instead of having special case code for efb2tex that ignores hashes, the only diffence between efb2tex and efb2ram now is that efb2tex writes zeros to the memory instead of actual texture data. Though keep in mind, all efb2tex copies will have hashes of zero as their hash. --- Source/Core/VideoBackends/D3D/TextureCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index 603084dd33..602c00cb18 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -237,10 +237,10 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, unsigned int dstFormat g_renderer->RestoreAPIState(); - if (!g_ActiveConfig.bSkipEFBCopyToRam) - { + if (g_ActiveConfig.bSkipEFBCopyToRam) + this->Zero(dst); + else g_encoder->Encode(dst, this, srcFormat, srcRect, isIntensity, scaleByHalf); - } } const char palette_shader[] = -- cgit v1.2.3