From 74275bdfe3e46008969e13e6bdee968c573132b5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 23 Feb 2016 22:21:09 +1000 Subject: [PATCH] D3D12: Don't keep screenshot/encoder buffers mapped Readback heaps do not support persistent mapping. See D3D12 docs. --- Source/Core/VideoBackends/D3D12/D3DBase.cpp | 4 ---- .../VideoBackends/D3D12/PSTextureEncoder.cpp | 8 +++++--- .../VideoBackends/D3D12/PSTextureEncoder.h | 1 - Source/Core/VideoBackends/D3D12/Render.cpp | 18 ++++++++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoBackends/D3D12/D3DBase.cpp b/Source/Core/VideoBackends/D3D12/D3DBase.cpp index 22abfef574..637b11b059 100644 --- a/Source/Core/VideoBackends/D3D12/D3DBase.cpp +++ b/Source/Core/VideoBackends/D3D12/D3DBase.cpp @@ -486,11 +486,7 @@ HRESULT Create(HWND wnd) D3D12_MESSAGE_ID_CREATEGRAPHICSPIPELINESTATE_DEPTHSTENCILVIEW_NOT_SET, // Benign. D3D12_MESSAGE_ID_CREATEGRAPHICSPIPELINESTATE_RENDERTARGETVIEW_NOT_SET, // Benign. D3D12_MESSAGE_ID_CREATEINPUTLAYOUT_TYPE_MISMATCH, // Benign. - D3D12_MESSAGE_ID_DRAW_EMPTY_SCISSOR_RECTANGLE, // Benign. Probably. - D3D12_MESSAGE_ID_INVALID_SUBRESOURCE_STATE, D3D12_MESSAGE_ID_MAP_INVALID_NULLRANGE, // Benign. - D3D12_MESSAGE_ID_EXECUTECOMMANDLISTS_GPU_WRITTEN_READBACK_RESOURCE_MAPPED, // Benign. - D3D12_MESSAGE_ID_RESOURCE_BARRIER_BEFORE_AFTER_MISMATCH // Benign. Probably. }; filter.DenyList.NumIDs = ARRAYSIZE(id_list); filter.DenyList.pIDList = id_list; diff --git a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp index bd1610adb3..5c27244bdd 100644 --- a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp +++ b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp @@ -89,8 +89,6 @@ void PSTextureEncoder::Init() D3D::SetDebugObjectName12(m_out_readback_buffer, "efb encoder output staging buffer"); - CheckHR(m_out_readback_buffer->Map(0, nullptr, &m_out_readback_buffer_data)); - // Create constant buffer for uploading data to shaders. Need to align to 256 bytes. unsigned int encode_params_buffer_size = (sizeof(EFBEncodeParams) + 0xff) & ~0xff; @@ -220,8 +218,10 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p D3D::command_list_mgr->ExecuteQueuedWork(true); // Transfer staging buffer to GameCube/Wii RAM + void* readback_data_map; + CheckHR(m_out_readback_buffer->Map(0, nullptr, &readback_data_map)); - u8* src = static_cast(m_out_readback_buffer_data); + u8* src = static_cast(readback_data_map); u32 read_stride = std::min(bytes_per_row, dst_location.PlacedFootprint.Footprint.RowPitch); for (unsigned int y = 0; y < num_blocks_y; ++y) { @@ -231,6 +231,8 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p src += dst_location.PlacedFootprint.Footprint.RowPitch; } + m_out_readback_buffer->Unmap(0, nullptr); + // Restores proper viewport/scissor settings. g_renderer->RestoreAPIState(); diff --git a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.h b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.h index c8f05788e8..1e42a87f6a 100644 --- a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.h +++ b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.h @@ -29,7 +29,6 @@ private: D3D12_CPU_DESCRIPTOR_HANDLE m_out_rtv_cpu = {}; ID3D12Resource* m_out_readback_buffer = nullptr; - void* m_out_readback_buffer_data = nullptr; ID3D12Resource* m_encode_params_buffer = nullptr; void* m_encode_params_buffer_data = nullptr; diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index de63d406a0..4881fec717 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -76,7 +76,6 @@ D3D12_DEPTH_STENCIL_DESC g_reset_depth_desc = {}; D3D12_RASTERIZER_DESC g_reset_rast_desc = {}; static ID3D12Resource* s_screenshot_texture = nullptr; -static void* s_screenshot_texture_data = nullptr; // Nvidia stereo blitting struct defined in "nvstereo.h" from the Nvidia SDK typedef struct _Nv_Stereo_Image_Header @@ -162,7 +161,6 @@ static void SetupDeviceObjects() g_reset_rast_desc = rast_desc; s_screenshot_texture = nullptr; - s_screenshot_texture_data = nullptr; } // Kill off all device objects @@ -200,8 +198,6 @@ void CreateScreenshotTexture() IID_PPV_ARGS(&s_screenshot_texture) ) ); - - CheckHR(s_screenshot_texture->Map(0, nullptr, &s_screenshot_texture_data)); } static D3D12_BOX GetScreenshotSourceBox(const TargetRectangle& target_rc) @@ -677,7 +673,12 @@ bool Renderer::SaveScreenshot(const std::string& filename, const TargetRectangle D3D::command_list_mgr->ExecuteQueuedWork(true); - saved_png = TextureToPng(static_cast(s_screenshot_texture_data), dst_location.PlacedFootprint.Footprint.RowPitch, filename, source_box.right - source_box.left, source_box.bottom - source_box.top, false); + void* screenshot_texture_map; + CheckHR(s_screenshot_texture->Map(0, nullptr, &screenshot_texture_map)); + + saved_png = TextureToPng(static_cast(screenshot_texture_map), dst_location.PlacedFootprint.Footprint.RowPitch, filename, source_box.right - source_box.left, source_box.bottom - source_box.top, false); + + s_screenshot_texture->Unmap(0, nullptr); if (saved_png) { @@ -877,7 +878,12 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height w = s_record_width; h = s_record_height; } - formatBufferDump(static_cast(s_screenshot_texture_data), &frame_data[0], source_width, source_height, dst_location.PlacedFootprint.Footprint.RowPitch); + + void* screenshot_texture_map; + CheckHR(s_screenshot_texture->Map(0, nullptr, &screenshot_texture_map)); + formatBufferDump(static_cast(screenshot_texture_map), &frame_data[0], source_width, source_height, dst_location.PlacedFootprint.Footprint.RowPitch); + s_screenshot_texture->Unmap(0, nullptr); + FlipImageData(&frame_data[0], w, h); AVIDump::AddFrame(&frame_data[0], source_width, source_height); }