From f71f527b4d4297e2b45bd0ba352bd8a5ac9cccc2 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 21 Apr 2018 20:34:41 +0200 Subject: [PATCH] [d3d11] Prevent mapping of depth-stencil textures We currently don't support this, and copying data back and forth with the wrong image aspect set crashes the RADV driver. --- src/d3d11/d3d11_context_def.cpp | 9 +++++++-- src/d3d11/d3d11_context_imm.cpp | 17 +++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/d3d11/d3d11_context_def.cpp b/src/d3d11/d3d11_context_def.cpp index 791ad197..5ade6238 100644 --- a/src/d3d11/d3d11_context_def.cpp +++ b/src/d3d11/d3d11_context_def.cpp @@ -177,11 +177,16 @@ namespace dxvk { return E_INVALIDARG; } - const DxvkFormatInfo* formatInfo = imageFormatInfo(image->info().format); + auto formatInfo = imageFormatInfo(image->info().format); + + if (formatInfo->aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { + Logger::err("D3D11: Cannot map a depth-stencil texture"); + return E_INVALIDARG; + } VkImageSubresource subresource = pTexture->GetSubresourceFromIndex( - VK_IMAGE_ASPECT_COLOR_BIT, Subresource); + formatInfo->aspectMask, Subresource); VkExtent3D levelExtent = image->mipLevelExtent(subresource.mipLevel); VkExtent3D blockCount = util::computeBlockCount( diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 404637de..b174d539 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -224,10 +224,16 @@ namespace dxvk { return E_INVALIDARG; } - // Parameter validation was successful + auto formatInfo = imageFormatInfo(mappedImage->info().format); + + if (formatInfo->aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { + Logger::err("D3D11: Cannot map a depth-stencil texture"); + return E_INVALIDARG; + } + VkImageSubresource subresource = pResource->GetSubresourceFromIndex( - VK_IMAGE_ASPECT_COLOR_BIT, Subresource); + formatInfo->aspectMask, Subresource); pResource->SetMappedSubresource(subresource); @@ -246,13 +252,8 @@ namespace dxvk { pMappedResource->DepthPitch = imageType >= VK_IMAGE_TYPE_3D ? layout.depthPitch : layout.size; return S_OK; } else { - // Query format info which we need to compute - // the row pitch and layer pitch properly. - const DxvkFormatInfo* formatInfo = imageFormatInfo(mappedImage->info().format); - const VkExtent3D levelExtent = mappedImage->mipLevelExtent(subresource.mipLevel); - const VkExtent3D blockCount = util::computeBlockCount( - levelExtent, formatInfo->blockSize); + const VkExtent3D blockCount = util::computeBlockCount(levelExtent, formatInfo->blockSize); DxvkPhysicalBufferSlice physicalSlice;