mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-14 00:58:51 +02:00
Cleanup and unify handling of efb copy stride.
This commit is contained in:
@ -87,7 +87,7 @@ void PSTextureEncoder::Shutdown()
|
|||||||
SAFE_RELEASE(m_out);
|
SAFE_RELEASE(m_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat,
|
size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat, size_t dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf)
|
bool isIntensity, bool scaleByHalf)
|
||||||
{
|
{
|
||||||
@ -189,13 +189,13 @@ size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat,
|
|||||||
for (unsigned int y = 0; y < numBlocksY; ++y)
|
for (unsigned int y = 0; y < numBlocksY; ++y)
|
||||||
{
|
{
|
||||||
memcpy(dst, src, cacheLinesPerRow*32);
|
memcpy(dst, src, cacheLinesPerRow*32);
|
||||||
dst += bpmem.copyMipMapStrideChannels*32;
|
dst += dstStride;
|
||||||
src += map.RowPitch;
|
src += map.RowPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D::context->Unmap(m_outStage, 0);
|
D3D::context->Unmap(m_outStage, 0);
|
||||||
|
|
||||||
encodeSize = bpmem.copyMipMapStrideChannels*32 * numBlocksY;
|
encodeSize = dstStride * numBlocksY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore API
|
// Restore API
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
size_t Encode(u8* dst, unsigned int dstFormat,
|
size_t Encode(u8* dst, unsigned int dstFormat, size_t dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf);
|
bool isIntensity, bool scaleByHalf);
|
||||||
|
|
||||||
|
@ -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,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||||
const float *colmat)
|
const float *colmat)
|
||||||
@ -238,7 +238,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
|||||||
if (!g_ActiveConfig.bSkipEFBCopyToRam)
|
if (!g_ActiveConfig.bSkipEFBCopyToRam)
|
||||||
{
|
{
|
||||||
u8* dst = Memory::GetPointer(dstAddr);
|
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;
|
size_in_bytes = (u32)encoded_size;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ private:
|
|||||||
void Load(unsigned int width, unsigned int height,
|
void Load(unsigned int width, unsigned int height,
|
||||||
unsigned int expanded_width, unsigned int levels) override;
|
unsigned int expanded_width, unsigned int levels) override;
|
||||||
|
|
||||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||||
const float *colmat) override;
|
const float *colmat) override;
|
||||||
|
@ -111,7 +111,7 @@ public:
|
|||||||
virtual void Init() = 0;
|
virtual void Init() = 0;
|
||||||
virtual void Shutdown() = 0;
|
virtual void Shutdown() = 0;
|
||||||
// Returns size in bytes of encoded block of memory
|
// Returns size in bytes of encoded block of memory
|
||||||
virtual size_t Encode(u8* dst, unsigned int dstFormat,
|
virtual size_t Encode(u8* dst, unsigned int dstFormat, size_t dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf) = 0;
|
bool isIntensity, bool scaleByHalf) = 0;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
|||||||
TextureCache::SetStage();
|
TextureCache::SetStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||||
const float *colmat)
|
const float *colmat)
|
||||||
@ -272,7 +272,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
|||||||
dstFormat,
|
dstFormat,
|
||||||
scaleByHalf,
|
scaleByHalf,
|
||||||
srcRect,
|
srcRect,
|
||||||
copyMipMapStrideChannels * 32);
|
dstStride);
|
||||||
|
|
||||||
u8* dst = Memory::GetPointer(dstAddr);
|
u8* dst = Memory::GetPointer(dstAddr);
|
||||||
u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
||||||
|
@ -41,7 +41,7 @@ private:
|
|||||||
void Load(unsigned int width, unsigned int height,
|
void Load(unsigned int width, unsigned int height,
|
||||||
unsigned int expanded_width, unsigned int level) override;
|
unsigned int expanded_width, unsigned int level) override;
|
||||||
|
|
||||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||||
const float *colmat) override;
|
const float *colmat) override;
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "VideoCommon/BPFunctions.h"
|
#include "VideoCommon/BPFunctions.h"
|
||||||
#include "VideoCommon/RenderBase.h"
|
#include "VideoCommon/RenderBase.h"
|
||||||
#include "VideoCommon/TextureCacheBase.h"
|
|
||||||
#include "VideoCommon/VertexManagerBase.h"
|
#include "VideoCommon/VertexManagerBase.h"
|
||||||
#include "VideoCommon/VertexShaderManager.h"
|
#include "VideoCommon/VertexShaderManager.h"
|
||||||
#include "VideoCommon/VideoConfig.h"
|
#include "VideoCommon/VideoConfig.h"
|
||||||
@ -85,15 +84,6 @@ void SetColorMask()
|
|||||||
g_renderer->SetColorMask();
|
g_renderer->SetColorMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyEFB(u32 dstAddr, const EFBRectangle& srcRect,
|
|
||||||
unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
|
||||||
bool isIntensity, bool scaleByHalf)
|
|
||||||
{
|
|
||||||
// bpmem.zcontrol.pixel_format to PEControl::Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
|
|
||||||
TextureCache::CopyRenderTargetToTexture(dstAddr, dstFormat, srcFormat,
|
|
||||||
srcRect, isIntensity, scaleByHalf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Explanation of the magic behind ClearScreen:
|
/* Explanation of the magic behind ClearScreen:
|
||||||
There's numerous possible formats for the pixel data in the EFB.
|
There's numerous possible formats for the pixel data in the EFB.
|
||||||
However, in the HW accelerated backends we're always using RGBA8
|
However, in the HW accelerated backends we're always using RGBA8
|
||||||
|
@ -23,9 +23,6 @@ void SetBlendMode();
|
|||||||
void SetDitherMode();
|
void SetDitherMode();
|
||||||
void SetLogicOpMode();
|
void SetLogicOpMode();
|
||||||
void SetColorMask();
|
void SetColorMask();
|
||||||
void CopyEFB(u32 dstAddr, const EFBRectangle& srcRect,
|
|
||||||
unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
|
||||||
bool isIntensity, bool scaleByHalf);
|
|
||||||
void ClearScreen(const EFBRectangle &rc);
|
void ClearScreen(const EFBRectangle &rc);
|
||||||
void OnPixelFormatChange();
|
void OnPixelFormatChange();
|
||||||
void SetInterlacingMode(const BPCmd &bp);
|
void SetInterlacingMode(const BPCmd &bp);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "VideoCommon/PixelShaderManager.h"
|
#include "VideoCommon/PixelShaderManager.h"
|
||||||
#include "VideoCommon/RenderBase.h"
|
#include "VideoCommon/RenderBase.h"
|
||||||
#include "VideoCommon/Statistics.h"
|
#include "VideoCommon/Statistics.h"
|
||||||
|
#include "VideoCommon/TextureCacheBase.h"
|
||||||
#include "VideoCommon/TextureDecoder.h"
|
#include "VideoCommon/TextureDecoder.h"
|
||||||
#include "VideoCommon/VertexShaderManager.h"
|
#include "VideoCommon/VertexShaderManager.h"
|
||||||
#include "VideoCommon/VideoCommon.h"
|
#include "VideoCommon/VideoCommon.h"
|
||||||
@ -205,6 +206,7 @@ static void BPWritten(const BPCmd& bp)
|
|||||||
// The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function
|
// The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function
|
||||||
|
|
||||||
u32 destAddr = bpmem.copyTexDest << 5;
|
u32 destAddr = bpmem.copyTexDest << 5;
|
||||||
|
u32 destStride = bpmem.copyMipMapStrideChannels << 5;
|
||||||
|
|
||||||
EFBRectangle srcRect;
|
EFBRectangle srcRect;
|
||||||
srcRect.left = (int)bpmem.copyTexSrcXY.x;
|
srcRect.left = (int)bpmem.copyTexSrcXY.x;
|
||||||
@ -223,8 +225,9 @@ static void BPWritten(const BPCmd& bp)
|
|||||||
if (g_ActiveConfig.bShowEFBCopyRegions)
|
if (g_ActiveConfig.bShowEFBCopyRegions)
|
||||||
stats.efb_regions.push_back(srcRect);
|
stats.efb_regions.push_back(srcRect);
|
||||||
|
|
||||||
CopyEFB(destAddr, srcRect,
|
// bpmem.zcontrol.pixel_format to PEControl::Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
|
||||||
PE_copy.tp_realFormat(), bpmem.zcontrol.pixel_format,
|
TextureCache::CopyRenderTargetToTexture(destAddr, PE_copy.tp_realFormat(), destStride,
|
||||||
|
bpmem.zcontrol.pixel_format, srcRect,
|
||||||
!!PE_copy.intensity_fmt, !!PE_copy.half_scale);
|
!!PE_copy.intensity_fmt, !!PE_copy.half_scale);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -251,10 +254,9 @@ static void BPWritten(const BPCmd& bp)
|
|||||||
height = MAX_XFB_HEIGHT;
|
height = MAX_XFB_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 stride = bpmem.copyMipMapStrideChannels << 5;
|
|
||||||
DEBUG_LOG(VIDEO, "RenderToXFB: destAddr: %08x | srcRect {%d %d %d %d} | fbWidth: %u | fbStride: %u | fbHeight: %u",
|
DEBUG_LOG(VIDEO, "RenderToXFB: destAddr: %08x | srcRect {%d %d %d %d} | fbWidth: %u | fbStride: %u | fbHeight: %u",
|
||||||
destAddr, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, bpmem.copyTexSrcWH.x + 1, stride, height);
|
destAddr, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, bpmem.copyTexSrcWH.x + 1, destStride, height);
|
||||||
Renderer::RenderToXFB(destAddr, srcRect, stride, height, s_gammaLUT[PE_copy.gamma]);
|
Renderer::RenderToXFB(destAddr, srcRect, destStride, height, s_gammaLUT[PE_copy.gamma]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the rectangular region after copying it.
|
// Clear the rectangular region after copying it.
|
||||||
|
@ -243,7 +243,7 @@ TextureCache::TCacheEntryBase* TextureCache::DoPartialTextureUpdates(TexCache::i
|
|||||||
&& entry_to_update->addr <= entry->addr
|
&& entry_to_update->addr <= entry->addr
|
||||||
&& entry->addr + entry->size_in_bytes <= entry_to_update->addr + entry_to_update->size_in_bytes
|
&& entry->addr + entry->size_in_bytes <= entry_to_update->addr + entry_to_update->size_in_bytes
|
||||||
&& entry->frameCount == FRAMECOUNT_INVALID
|
&& entry->frameCount == FRAMECOUNT_INVALID
|
||||||
&& entry->copyMipMapStrideChannels * 32 == numBlocksX * block_size)
|
&& entry->copyStride == numBlocksX * block_size)
|
||||||
{
|
{
|
||||||
u32 block_offset = (entry->addr - entry_to_update->addr) / block_size;
|
u32 block_offset = (entry->addr - entry_to_update->addr) / block_size;
|
||||||
u32 block_x = block_offset % numBlocksX;
|
u32 block_x = block_offset % numBlocksX;
|
||||||
@ -693,7 +693,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage)
|
|||||||
return ReturnEntry(stage, entry);
|
return ReturnEntry(stage, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, u32 dstStride, PEControl::PixelFormat srcFormat,
|
||||||
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf)
|
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf)
|
||||||
{
|
{
|
||||||
// Emulation methods:
|
// Emulation methods:
|
||||||
@ -1004,9 +1004,9 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
|
|||||||
entry->frameCount = FRAMECOUNT_INVALID;
|
entry->frameCount = FRAMECOUNT_INVALID;
|
||||||
entry->is_efb_copy = true;
|
entry->is_efb_copy = true;
|
||||||
entry->is_custom_tex = false;
|
entry->is_custom_tex = false;
|
||||||
entry->copyMipMapStrideChannels = bpmem.copyMipMapStrideChannels;
|
entry->copyStride = dstStride;
|
||||||
|
|
||||||
entry->FromRenderTarget(dstAddr, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);
|
entry->FromRenderTarget(dstAddr, dstFormat, dstStride, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);
|
||||||
|
|
||||||
if (g_ActiveConfig.bDumpEFBTarget)
|
if (g_ActiveConfig.bDumpEFBTarget)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
u32 format;
|
u32 format;
|
||||||
bool is_efb_copy;
|
bool is_efb_copy;
|
||||||
bool is_custom_tex;
|
bool is_custom_tex;
|
||||||
u32 copyMipMapStrideChannels;
|
u32 copyStride;
|
||||||
|
|
||||||
unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
|
unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
|
||||||
unsigned int native_levels;
|
unsigned int native_levels;
|
||||||
@ -96,7 +96,7 @@ public:
|
|||||||
|
|
||||||
virtual void Load(unsigned int width, unsigned int height,
|
virtual void Load(unsigned int width, unsigned int height,
|
||||||
unsigned int expanded_width, unsigned int level) = 0;
|
unsigned int expanded_width, unsigned int level) = 0;
|
||||||
virtual void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
virtual void FromRenderTarget(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
|
||||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||||
const float *colmat) = 0;
|
const float *colmat) = 0;
|
||||||
@ -125,8 +125,8 @@ public:
|
|||||||
static TCacheEntryBase* Load(const u32 stage);
|
static TCacheEntryBase* Load(const u32 stage);
|
||||||
static void UnbindTextures();
|
static void UnbindTextures();
|
||||||
static void BindTextures();
|
static void BindTextures();
|
||||||
static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
|
||||||
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf);
|
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf);
|
||||||
|
|
||||||
static void RequestInvalidateTextureCache();
|
static void RequestInvalidateTextureCache();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user