From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d/resource.c | 8 ++++++++ libs/vkd3d/vkd3d_private.h | 5 +++++ 2 files changed, 13 insertions(+)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index be8bbed54072..80e7319ac30a 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -811,6 +811,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT const D3D12_RANGE *read_range, void **data) { struct d3d12_resource *resource = impl_from_ID3D12Resource(iface); + unsigned int sub_resource_count; struct d3d12_device *device; VkResult vr; HRESULT hr; @@ -826,6 +827,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT return E_INVALIDARG; }
+ sub_resource_count = d3d12_resource_desc_get_sub_resource_count(&resource->desc); + if (sub_resource >= sub_resource_count) + { + WARN("Sub-resource index %u is out of range (%u sub-resources).\n", sub_resource, sub_resource_count); + return E_INVALIDARG; + } + if (d3d12_resource_is_texture(resource)) { /* Textures seem to be mappable only on UMA adapters. */ diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index d6c821b75884..daa60cb74eaa 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -861,6 +861,11 @@ static inline unsigned int d3d12_resource_desc_get_layer_count(const D3D12_RESOU return desc->Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? desc->DepthOrArraySize : 1; }
+static inline unsigned int d3d12_resource_desc_get_sub_resource_count(const D3D12_RESOURCE_DESC *desc) +{ + return d3d12_resource_desc_get_layer_count(desc) * desc->MipLevels; +} + enum VkCompareOp vk_compare_op_from_d3d12(D3D12_COMPARISON_FUNC op) DECLSPEC_HIDDEN; VkSampleCountFlagBits vk_samples_from_dxgi_sample_desc(const DXGI_SAMPLE_DESC *desc) DECLSPEC_HIDDEN;