diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 160301c3bf..9cb2d04d0f 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -206,6 +206,8 @@ public: return PSP_CoreParameter().compat.flags().FakeMipmapChange && gstate.getTexLevelMode() == GE_TEXLEVEL_MODE_CONST; } + virtual bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { return false; } + protected: virtual void BindTexture(TexCacheEntry *entry) = 0; virtual void Unbind() = 0; diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 0c500cebbf..718581931c 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -1054,10 +1054,7 @@ bool GPU_D3D11::GetCurrentTexture(GPUDebugBuffer &buffer, int level) { if (!gstate.isTextureMapEnabled()) { return false; } - - // TODO: Implement! - - return false; + return textureCacheD3D11_->GetCurrentTextureDebug(buffer, level); } bool GPU_D3D11::GetCurrentClut(GPUDebugBuffer &buffer) { diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 6676415e7f..0f0bb7ec75 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -769,3 +769,48 @@ bool TextureCacheD3D11::DecodeTexture(u8 *output, const GPUgstate &state) { OutputDebugStringA("TextureCache::DecodeTexture : FixMe\r\n"); return true; } + +bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { + ApplyTexture(); + SetTexture(false); + if (!nextTexture_) + return false; + + ID3D11Texture2D *texture = (ID3D11Texture2D *)nextTexture_->texturePtr; + if (!texture) + return false; + + D3D11_TEXTURE2D_DESC desc; + texture->GetDesc(&desc); + + if (desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM) { + // TODO: Support the other formats + return false; + } + + desc.BindFlags = 0; + desc.Usage = D3D11_USAGE_STAGING; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + + ID3D11Texture2D *stagingCopy = nullptr; + device_->CreateTexture2D(&desc, nullptr, &stagingCopy); + context_->CopyResource(stagingCopy, texture); + + int width = desc.Width >> level; + int height = desc.Height >> level; + buffer.Allocate(width, height, GPU_DBG_FORMAT_8888); + + D3D11_MAPPED_SUBRESOURCE map; + if (FAILED(context_->Map(stagingCopy, level, D3D11_MAP_READ, 0, &map))) { + stagingCopy->Release(); + return false; + } + + for (int y = 0; y < height; y++) { + memcpy(buffer.GetData() + 4 * width * y, (const uint8_t *)map.pData + map.RowPitch * y, 4 * width); + } + + context_->Unmap(stagingCopy, level); + stagingCopy->Release(); + return true; +} diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 0d10c012f8..e4f96a26fe 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -64,6 +64,7 @@ public: void InvalidateLastTexture(TexCacheEntry *entry = nullptr) override; void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key); + bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; protected: void BindTexture(TexCacheEntry *entry) override; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 8379a035ef..c9106b5b06 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2149,3 +2149,7 @@ bool GPUCommon::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { bool GPUCommon::GetOutputFramebuffer(GPUDebugBuffer &buffer) { return framebufferManager_->GetOutputFramebuffer(buffer); } + +bool GPUCommon::GetCurrentTexture(GPUDebugBuffer &buffer, int level) { + return textureCache_->GetCurrentTextureDebug(buffer, level); +} \ No newline at end of file diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index f4a3bb3969..06893f08b0 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -165,6 +165,7 @@ public: bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) override; bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override; bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override; + bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) override; bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override; std::vector ActiveDisplayLists() override;