1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 01:24:11 +01:00

[d3d11] Properly validate map parameters for images

This commit is contained in:
Philip Rebohle 2024-11-02 13:12:19 +01:00 committed by Philip Rebohle
parent 2db10b0af8
commit bdd4956dd3
2 changed files with 39 additions and 13 deletions

View File

@ -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);

View File

@ -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