From 32599559dbdcbebf3f13e7e7dc6a815ff308811c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 5 Mar 2016 20:22:08 +1000 Subject: D3D12: Use helper method for binding EFB render targets --- Source/Core/VideoBackends/D3D12/TextureCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D12/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D12/TextureCache.cpp b/Source/Core/VideoBackends/D3D12/TextureCache.cpp index f4a57eb3e1..a62606c371 100644 --- a/Source/Core/VideoBackends/D3D12/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D12/TextureCache.cpp @@ -168,7 +168,7 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture( FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE); - D3D::current_command_list->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV12(), FALSE, &FramebufferManager::GetEFBDepthTexture()->GetDSV12()); + FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } @@ -308,7 +308,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE); - D3D::current_command_list->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV12(), FALSE, &FramebufferManager::GetEFBDepthTexture()->GetDSV12()); + FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } @@ -490,7 +490,7 @@ void TextureCache::ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* uncon FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE ); - D3D::current_command_list->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV12(), FALSE, &FramebufferManager::GetEFBDepthTexture()->GetDSV12()); + FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } -- cgit v1.2.3 From acfa93372ec58faac05f9ed7c8ac0d6ed5ad403e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 5 Mar 2016 22:38:14 +1000 Subject: D3D12: Refactoring and cleanups Moves render target restoring to RestoreAPIState, this also means no need to manually restore after allocating in a buffer that caused execution, because the manager restores it for us. Remove a method that wasn't used from D3DUtil.cpp, and fixes a few errors in EFB poke drawing. --- Source/Core/VideoBackends/D3D12/TextureCache.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D12/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D12/TextureCache.cpp b/Source/Core/VideoBackends/D3D12/TextureCache.cpp index a62606c371..48f335af2c 100644 --- a/Source/Core/VideoBackends/D3D12/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D12/TextureCache.cpp @@ -168,7 +168,6 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture( FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE); - FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } @@ -308,7 +307,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE); - FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } @@ -490,7 +488,6 @@ void TextureCache::ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* uncon FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE ); - FramebufferManager::RestoreEFBRenderTargets(); g_renderer->RestoreAPIState(); } -- cgit v1.2.3 From 25d5da0ea38a405c7fe4d1e3e4207701035c4fd2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 6 Mar 2016 19:36:40 +1000 Subject: D3D12: Remove D3D11 header references --- Source/Core/VideoBackends/D3D12/TextureCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D12/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D12/TextureCache.cpp b/Source/Core/VideoBackends/D3D12/TextureCache.cpp index 48f335af2c..a52d0e540e 100644 --- a/Source/Core/VideoBackends/D3D12/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D12/TextureCache.cpp @@ -184,8 +184,8 @@ TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntry if (config.rendertarget) { D3DTexture2D* texture = D3DTexture2D::Create(config.width, config.height, - static_cast((static_cast(D3D11_BIND_RENDER_TARGET) | static_cast(D3D11_BIND_SHADER_RESOURCE))), - D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, config.layers); + TEXTURE_BIND_FLAG_SHADER_RESOURCE | TEXTURE_BIND_FLAG_RENDER_TARGET, + DXGI_FORMAT_R8G8B8A8_UNORM, 1, config.layers); TCacheEntry* entry = new TCacheEntry(config, texture); @@ -215,7 +215,7 @@ TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntry D3DTexture2D* texture = new D3DTexture2D( texture_resource, - D3D11_BIND_SHADER_RESOURCE, + TEXTURE_BIND_FLAG_SHADER_RESOURCE, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, -- cgit v1.2.3 From fde7dee652674f3d42d80e2f4a3ae0ff30ecaa06 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 15 Mar 2016 21:53:09 +1000 Subject: D3D12: Fix invalid CopyTextureRegion call in CopyRectangleFromTexture This was occuring when the source texture was larger than the destination texture, but the source rect was <= dest rect, so the copy is valid. --- Source/Core/VideoBackends/D3D12/TextureCache.cpp | 35 +++++++++--------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'Source/Core/VideoBackends/D3D12/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D12/TextureCache.cpp b/Source/Core/VideoBackends/D3D12/TextureCache.cpp index a52d0e540e..ceabf01734 100644 --- a/Source/Core/VideoBackends/D3D12/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D12/TextureCache.cpp @@ -106,33 +106,24 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture( if (src_rect.GetWidth() == dst_rect.GetWidth() && src_rect.GetHeight() == dst_rect.GetHeight()) { - D3D12_BOX srcbox; - srcbox.left = src_rect.left; - srcbox.top = src_rect.top; - srcbox.right = src_rect.right; - srcbox.bottom = src_rect.bottom; - srcbox.front = 0; - srcbox.back = srcentry->config.layers; - - if (static_cast(src_rect.GetHeight()) > config.height || - static_cast(src_rect.GetWidth()) > config.width) - { - // To mimic D3D11 behavior, we're just going to drop the clear since it is invalid. - // This invalid copy needs to be fixed above the Backend level. - - // On D3D12, instead of silently dropping this invalid clear, the runtime throws an exception - // so we need to filter it out ourselves. - - return; - } - + // These assertions should hold true unless the base code is passing us sizes too large, in which case it should be fixed instead. + _assert_msg_(VIDEO, + static_cast(src_rect.GetWidth()) <= source->config.width && + static_cast(src_rect.GetHeight()) <= source->config.height, + "Source rect is too large for CopyRectangleFromTexture"); + + _assert_msg_(VIDEO, + static_cast(dst_rect.GetWidth()) <= config.width && + static_cast(dst_rect.GetHeight()) <= config.height, + "Dest rect is too large for CopyRectangleFromTexture"); + + CD3DX12_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, srcentry->config.layers); D3D12_TEXTURE_COPY_LOCATION dst_location = CD3DX12_TEXTURE_COPY_LOCATION(m_texture->GetTex12(), 0); D3D12_TEXTURE_COPY_LOCATION src_location = CD3DX12_TEXTURE_COPY_LOCATION(srcentry->m_texture->GetTex12(), 0); m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_COPY_DEST); srcentry->m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_COPY_SOURCE); - - D3D::current_command_list->CopyTextureRegion(&dst_location, dst_rect.left, dst_rect.top, 0, &src_location, &srcbox); + D3D::current_command_list->CopyTextureRegion(&dst_location, dst_rect.left, dst_rect.top, 0, &src_location, &src_box); m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); srcentry->m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); -- cgit v1.2.3 From ccf9470241309114bdc46d9dc80bb9b99aed4a41 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 15 Mar 2016 22:26:01 +1000 Subject: D3D12: Specify read/write ranges when calling Map/Unmap --- Source/Core/VideoBackends/D3D12/TextureCache.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/D3D12/TextureCache.cpp') diff --git a/Source/Core/VideoBackends/D3D12/TextureCache.cpp b/Source/Core/VideoBackends/D3D12/TextureCache.cpp index ceabf01734..4b235d1037 100644 --- a/Source/Core/VideoBackends/D3D12/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D12/TextureCache.cpp @@ -83,7 +83,8 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l // Map readback buffer and save to file. void* readback_texture_map; - CheckHR(s_texture_cache_entry_readback_buffer->Map(0, nullptr, &readback_texture_map)); + D3D12_RANGE read_range = { 0, required_readback_buffer_size }; + CheckHR(s_texture_cache_entry_readback_buffer->Map(0, &read_range, &readback_texture_map)); bool saved = TextureToPng( static_cast(readback_texture_map), @@ -93,7 +94,8 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l dst_location.PlacedFootprint.Footprint.Height ); - s_texture_cache_entry_readback_buffer->Unmap(0, nullptr); + D3D12_RANGE write_range = {}; + s_texture_cache_entry_readback_buffer->Unmap(0, &write_range); return saved; } -- cgit v1.2.3