Add ability to dump xfb copies to texture for debugging purposes

This commit is contained in:
iwubcode
2017-06-02 20:33:26 -05:00
parent a9f0d1783b
commit 198d3b69b4
10 changed files with 35 additions and 37 deletions

View File

@ -181,31 +181,6 @@ static void TeardownDeviceObjects()
s_gx_state_cache.Clear();
}
static void CreateScreenshotTexture()
{
// We can't render anything outside of the backbuffer anyway, so use the backbuffer size as the
// screenshot buffer size.
// This texture is released to be recreated when the window is resized in Renderer::SwapImpl.
D3D11_TEXTURE2D_DESC scrtex_desc = CD3D11_TEXTURE2D_DESC(
DXGI_FORMAT_R8G8B8A8_UNORM, D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight(), 1, 1, 0,
D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE);
HRESULT hr = D3D::device->CreateTexture2D(&scrtex_desc, nullptr, &s_screenshot_texture);
CHECK(hr == S_OK, "Create screenshot staging texture");
D3D::SetDebugObjectName(s_screenshot_texture, "staging screenshot texture");
}
static D3D11_BOX GetScreenshotSourceBox(const TargetRectangle& targetRc)
{
// Since the screenshot buffer is copied back to the CPU via Map(), we can't access pixels that
// fall outside the backbuffer bounds. Therefore, when crop is enabled and the target rect is
// off-screen to the top/left, we clamp the origin at zero, as well as the bottom/right
// coordinates at the backbuffer dimensions. This will result in a rectangle that can be
// smaller than the backbuffer, but never larger.
return CD3D11_BOX(std::max(targetRc.left, 0), std::max(targetRc.top, 0), 0,
std::min(D3D::GetBackBufferWidth(), (unsigned int)targetRc.right),
std::min(D3D::GetBackBufferHeight(), (unsigned int)targetRc.bottom), 1);
}
static void Create3DVisionTexture(int width, int height)
{
// Create a staging texture for 3D vision with signature information in the last row.
@ -654,10 +629,10 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
// activate linear filtering for the buffer copies
D3D::SetLinearCopySampler();
auto* xfb_texture = static_cast<DXTexture*>(texture);
TargetRectangle source_rc = xfb_texture->config.Rect();
TargetRectangle source_rc = xfb_texture->GetConfig().GetRect();
BlitScreen(source_rc, targetRc, xfb_texture->GetRawTexIdentifier(), xfb_texture->config.width,
xfb_texture->config.height, Gamma);
BlitScreen(source_rc, targetRc, xfb_texture->GetRawTexIdentifier(), xfb_texture->GetConfig().width,
xfb_texture->GetConfig().height, Gamma);
// Reset viewport for drawing text
D3D11_VIEWPORT vp =
@ -676,7 +651,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
g_texture_cache->OnConfigChanged(g_ActiveConfig);
VertexShaderCache::RetreiveAsyncShaders();
SetWindowSize(xfb_texture->config.width, xfb_texture->config.height);
SetWindowSize(xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
const bool window_resized = CheckForResize();
const bool fullscreen = D3D::GetFullscreenState();

View File

@ -1344,8 +1344,8 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
TargetRectangle sourceRc = ConvertEFBRectangle(rc);
sourceRc.left = 0;
sourceRc.right = xfb_texture->config.width;
sourceRc.top = xfb_texture->config.height;
sourceRc.right = xfb_texture->GetConfig().width;
sourceRc.top = xfb_texture->GetConfig().height;
sourceRc.bottom = 0;
ResetAPIState();
@ -1358,7 +1358,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
// Copy the framebuffer to screen.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
BlitScreen(sourceRc, flipped_trc, xfb_texture->GetRawTexIdentifier(), xfb_texture->config.width, xfb_texture->config.height);
BlitScreen(sourceRc, flipped_trc, xfb_texture->GetRawTexIdentifier(), xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
// The FlushFrameDump call here is necessary even after frame dumping is stopped.
// If left out, screenshots are "one frame" behind, as an extra frame is dumped and buffered.
@ -1383,7 +1383,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
// Finish up the current frame, print some stats
SetWindowSize(xfb_texture->config.width, xfb_texture->config.height);
SetWindowSize(xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
GLInterface->Update(); // just updates the render window position and the backbuffer size

View File

@ -554,7 +554,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& rc, u64 ti
// Update the window size based on the frame that was just rendered.
// Due to depending on guest state, we need to call this every frame.
SetWindowSize(xfb_texture->config.width, xfb_texture->config.height);
SetWindowSize(xfb_texture->GetConfig().width, xfb_texture->GetConfig().height);
// Clean up stale textures.
TextureCache::GetInstance()->Cleanup(frameCount);
@ -731,7 +731,7 @@ void Renderer::DrawScreen(VKTexture* xfb_texture)
VK_SUBPASS_CONTENTS_INLINE);
// Draw
TargetRectangle source_rc = xfb_texture->config.Rect();
TargetRectangle source_rc = xfb_texture->GetConfig().GetRect();
BlitScreen(m_swap_chain->GetRenderPass(), GetTargetRectangle(), source_rc, xfb_texture->GetRawTexIdentifier());
// Draw OSD