UINT_MAX is valid for specifying all remaining layers in all view types, although it's only documented for TEXTURE3D RTVs. If unhandled, UINT_MAX will be passed to vkd3d_compute_workgroup_count() during UAV clears, leading to nasty results in RADV.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 1ca23a90..16dd07db 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2477,6 +2477,25 @@ static bool init_default_texture_view_desc(struct vkd3d_texture_view_desc *desc, return true; }
+static unsigned int vkd3d_get_texture_layer_count(unsigned int layer_idx, unsigned int layer_count, + const D3D12_RESOURCE_DESC *desc) +{ + if (desc->DepthOrArraySize > layer_idx) + { + unsigned int max_layer_count = desc->DepthOrArraySize - layer_idx; + + if (layer_count <= max_layer_count) + return layer_count; + + if (layer_count != UINT_MAX) + WARN("Layer count %u exceeds maximum %u.\n", layer_count, max_layer_count); + return max_layer_count; + } + + WARN("Layer index %u exceeds maximum available layer %u.\n", layer_idx, desc->DepthOrArraySize - 1); + return 1; +} + bool vkd3d_create_texture_view(struct d3d12_device *device, VkImage vk_image, const struct vkd3d_texture_view_desc *desc, struct vkd3d_view **view) { @@ -2758,6 +2777,7 @@ void d3d12_desc_create_srv(struct d3d12_desc *descriptor, default: FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension); } + /* Allow a UINT_MAX layer count through as it equals VK_REMAINING_ARRAY_LAYERS. */ }
if (!vkd3d_create_texture_view(device, resource->u.vk_image, &vkd3d_desc, &view)) @@ -2931,6 +2951,9 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, default: FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension); } + /* Prevent problems with UAV clears where the layer count is UINT_MAX. */ + vkd3d_desc.layer_count = vkd3d_get_texture_layer_count(vkd3d_desc.layer_idx, + vkd3d_desc.layer_count, &resource->desc); }
if (!vkd3d_create_texture_view(device, resource->u.vk_image, &vkd3d_desc, &view))