From: Conor McCarthy cmccarthy@codeweavers.com
Passing UINT_MAX as layer count to Direct3D behaves similar to passing VK_REMAINING_ARRAY_LAYERS to Vulkan. Since these have the same value, everything usually works out even without normalisation. However, there are some exceptions; for example, we calculate workgroup counts for UAV clears from layer counts using vkd3d_compute_workgroup_count(), which doesn't handle UINT_MAX. Normalising layer counts during view creation avoids having to handle this issue in the rest of the code.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- v2: - Introduce a helper to normalise the view instead of a helper for the layer count. - Some improvements to the commit message.
This supersedes patch 215654.
libs/vkd3d/resource.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index a51f5795..854e73a3 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2477,6 +2477,27 @@ static bool init_default_texture_view_desc(struct vkd3d_texture_view_desc *desc, return true; }
+static void vkd3d_texture_view_desc_normalise(struct vkd3d_texture_view_desc *desc, + const D3D12_RESOURCE_DESC *resource_desc) +{ + unsigned int max_layer_count = resource_desc->DepthOrArraySize; + + if (desc->layer_idx >= max_layer_count) + { + WARN("Layer index %u exceeds maximum available layer %u.\n", desc->layer_idx, max_layer_count - 1); + desc->layer_count = 1; + return; + } + + max_layer_count -= desc->layer_idx; + if (desc->layer_count <= max_layer_count) + return; + + if (desc->layer_count != UINT_MAX) + WARN("Layer count %u exceeds maximum %u.\n", desc->layer_count, max_layer_count); + desc->layer_count = max_layer_count; +} + bool vkd3d_create_texture_view(struct d3d12_device *device, VkImage vk_image, const struct vkd3d_texture_view_desc *desc, struct vkd3d_view **view) { @@ -2920,6 +2941,7 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, vkd3d_desc.layer_count = desc->u.Texture2DArray.ArraySize; if (desc->u.Texture2DArray.PlaneSlice) FIXME("Ignoring plane slice %u.\n", desc->u.Texture2DArray.PlaneSlice); + vkd3d_texture_view_desc_normalise(&vkd3d_desc, &resource->desc); break; case D3D12_UAV_DIMENSION_TEXTURE3D: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_3D;