diff --git a/src/d3d11/d3d11_context_def.cpp b/src/d3d11/d3d11_context_def.cpp index 4f1d63d3..24f75a41 100644 --- a/src/d3d11/d3d11_context_def.cpp +++ b/src/d3d11/d3d11_context_def.cpp @@ -214,6 +214,9 @@ namespace dxvk { Logger::err("D3D11: Cannot map a device-local image"); return E_INVALIDARG; } + + if (unlikely(Subresource >= pTexture->CountSubresources())) + return E_INVALIDARG; VkFormat packedFormat = m_parent->LookupPackedFormat( pTexture->Desc()->Format, pTexture->GetFormatMode()).Format; diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 199714d4..e3560aa4 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -339,6 +339,9 @@ namespace dxvk { return E_INVALIDARG; } + if (unlikely(Subresource >= pResource->CountSubresources())) + return E_INVALIDARG; + pResource->SetMapType(Subresource, MapType); VkFormat packedFormat = m_parent->LookupPackedFormat( diff --git a/src/d3d11/d3d11_texture.h b/src/d3d11/d3d11_texture.h index 19dabd5f..33bff15d 100644 --- a/src/d3d11/d3d11_texture.h +++ b/src/d3d11/d3d11_texture.h @@ -74,6 +74,14 @@ namespace dxvk { const D3D11_COMMON_TEXTURE_DESC* Desc() const { return &m_desc; } + + /** + * \brief Counts number of subresources + * \returns Number of subresources + */ + UINT CountSubresources() const { + return m_desc.ArraySize * m_desc.MipLevels; + } /** * \brief Map mode