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.
This commit is contained in:
Stenzek 2016-03-15 21:53:09 +10:00
parent 9bff187547
commit fde7dee652

View File

@ -106,33 +106,24 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture(
if (src_rect.GetWidth() == dst_rect.GetWidth() if (src_rect.GetWidth() == dst_rect.GetWidth()
&& src_rect.GetHeight() == dst_rect.GetHeight()) && src_rect.GetHeight() == dst_rect.GetHeight())
{ {
D3D12_BOX srcbox; // These assertions should hold true unless the base code is passing us sizes too large, in which case it should be fixed instead.
srcbox.left = src_rect.left; _assert_msg_(VIDEO,
srcbox.top = src_rect.top; static_cast<u32>(src_rect.GetWidth()) <= source->config.width &&
srcbox.right = src_rect.right; static_cast<u32>(src_rect.GetHeight()) <= source->config.height,
srcbox.bottom = src_rect.bottom; "Source rect is too large for CopyRectangleFromTexture");
srcbox.front = 0;
srcbox.back = srcentry->config.layers;
if (static_cast<u32>(src_rect.GetHeight()) > config.height || _assert_msg_(VIDEO,
static_cast<u32>(src_rect.GetWidth()) > config.width) static_cast<u32>(dst_rect.GetWidth()) <= config.width &&
{ static_cast<u32>(dst_rect.GetHeight()) <= config.height,
// To mimic D3D11 behavior, we're just going to drop the clear since it is invalid. "Dest rect is too large for CopyRectangleFromTexture");
// 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;
}
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 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); 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); 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); 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, &src_box);
D3D::current_command_list->CopyTextureRegion(&dst_location, dst_rect.left, dst_rect.top, 0, &src_location, &srcbox);
m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); 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); srcentry->m_texture->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);