diff --git a/src/d3d11/d3d11_context_def.cpp b/src/d3d11/d3d11_context_def.cpp index 52cd02dc..19db6052 100644 --- a/src/d3d11/d3d11_context_def.cpp +++ b/src/d3d11/d3d11_context_def.cpp @@ -292,17 +292,16 @@ namespace dxvk { D3D11_MAPPED_SUBRESOURCE* pMappedResource) { D3D11CommonTexture* pTexture = GetCommonTexture(pResource); - if (unlikely(pTexture->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_NONE)) { - Logger::err("D3D11: Cannot map a device-local image"); - pMappedResource->pData = nullptr; - return E_INVALIDARG; - } - if (unlikely(Subresource >= pTexture->CountSubresources())) { pMappedResource->pData = nullptr; return E_INVALIDARG; } - + + if (unlikely(pTexture->Desc()->Usage != D3D11_USAGE_DYNAMIC)) { + pMappedResource->pData = nullptr; + return E_INVALIDARG; + } + VkFormat packedFormat = pTexture->GetPackedFormat(); auto formatInfo = lookupFormatInfo(packedFormat); auto layout = pTexture->GetSubresourceLayout(formatInfo->aspectMask, Subresource); diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index b1987b72..9a067452 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -422,14 +422,41 @@ namespace dxvk { if (pMappedResource) pMappedResource->pData = nullptr; - if (unlikely(mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_NONE)) { - Logger::err("D3D11: Cannot map a device-local image"); - return E_INVALIDARG; - } - if (unlikely(Subresource >= pResource->CountSubresources())) return E_INVALIDARG; - + + switch (MapType) { + case D3D11_MAP_READ: { + if (!(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_READ)) + return E_INVALIDARG; + } break; + + case D3D11_MAP_READ_WRITE: { + if (!(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_READ) + || !(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE)) + return E_INVALIDARG; + } break; + + case D3D11_MAP_WRITE: { + if (!(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) + || (pResource->Desc()->Usage == D3D11_USAGE_DYNAMIC)) + return E_INVALIDARG; + } break; + + case D3D11_MAP_WRITE_DISCARD: { + if (!(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) + || pResource->Desc()->Usage != D3D11_USAGE_DYNAMIC) + return E_INVALIDARG; + } break; + + case D3D11_MAP_WRITE_NO_OVERWRITE: { + // NO_OVERWRITE is explcitly banned for dynamic images + if (!(pResource->Desc()->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) + || (pResource->Desc()->Usage != D3D11_USAGE_DEFAULT)) + return E_INVALIDARG; + } break; + } + if (likely(pMappedResource != nullptr)) { // Resources with an unknown memory layout cannot return a pointer if (pResource->Desc()->Usage == D3D11_USAGE_DEFAULT