From 1a5a2969be38b35a1b1e52e9c4eb9d9faccffb3a Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Thu, 3 Jul 2025 16:03:36 +0200 Subject: [PATCH] vkd3d/resource: Write null descriptors with their correct type when using mutable descriptor types. This fixes crashes in test_null_srv() and test_null_uav() with llvmpipe and NVIDIA GPUs. --- libs/vkd3d/resource.c | 15 +++++++++------ tests/d3d12.c | 18 ------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 0586423dc..7946445ad 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2513,19 +2513,20 @@ static enum vkd3d_vk_descriptor_set_index vkd3d_vk_descriptor_set_index_from_vk_ } static void d3d12_desc_write_vk_heap_null_descriptor(struct d3d12_descriptor_heap *descriptor_heap, - uint32_t dst_array_element, struct descriptor_writes *writes, struct d3d12_device *device) + uint32_t dst_array_element, struct descriptor_writes *writes, struct d3d12_device *device, + VkDescriptorType type) { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; struct d3d12_descriptor_heap_vk_set *descriptor_set; - enum vkd3d_vk_descriptor_set_index set, end; + enum vkd3d_vk_descriptor_set_index set; unsigned int i = writes->count; - end = device->vk_info.EXT_mutable_descriptor_type ? VKD3D_SET_INDEX_MUTABLE - : VKD3D_SET_INDEX_STORAGE_IMAGE; /* Binding a shader with the wrong null descriptor type works in Windows. * To support that here we must write one to all applicable Vulkan sets. */ - for (set = VKD3D_SET_INDEX_UNIFORM_BUFFER; set <= end; ++set) + for (set = VKD3D_SET_INDEX_UNIFORM_BUFFER; set <= VKD3D_SET_INDEX_STORAGE_IMAGE; ++set) { + if (device->vk_info.EXT_mutable_descriptor_type) + set = vkd3d_vk_descriptor_set_index_from_vk_descriptor_type(type); descriptor_set = &descriptor_heap->vk_descriptor_sets[set]; writes->vk_descriptor_writes[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writes->vk_descriptor_writes[i].pNext = NULL; @@ -2566,6 +2567,8 @@ static void d3d12_desc_write_vk_heap_null_descriptor(struct d3d12_descriptor_hea VK_CALL(vkUpdateDescriptorSets(device->vk_device, i, writes->vk_descriptor_writes, 0, NULL)); descriptor_writes_free_object_refs(writes, device); i = 0; + if (device->vk_info.EXT_mutable_descriptor_type) + break; } writes->count = i; @@ -2630,7 +2633,7 @@ static void d3d12_desc_write_vk_heap(struct d3d12_descriptor_heap *descriptor_he break; } if (is_null && device->vk_info.EXT_robustness2) - return d3d12_desc_write_vk_heap_null_descriptor(descriptor_heap, dst_array_element, writes, device); + return d3d12_desc_write_vk_heap_null_descriptor(descriptor_heap, dst_array_element, writes, device, type); ++i; if (u.header->magic == VKD3D_DESCRIPTOR_MAGIC_UAV && u.view->v.vk_counter_view) diff --git a/tests/d3d12.c b/tests/d3d12.c index c8658cb9f..eb6585353 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -19875,15 +19875,6 @@ static void test_null_srv(void) queue = context.queue; device = context.device; - if (is_llvmpipe_device_gte(device, 23, 2, 1)) - { - /* llvmpipe crashes when mutable descriptors are used. I don't - * know yet whether this is a bug in vkd3d or Mesa. */ - skip("Test crashes on llvmpipe, skipping.\n"); - destroy_test_context(&context); - return; - } - context.root_signature = create_texture_root_signature(context.device, D3D12_SHADER_VISIBILITY_PIXEL, 4, 0); @@ -20099,15 +20090,6 @@ static void test_null_uav(void) command_list = context.list; queue = context.queue; - if (is_llvmpipe_device_gte(device, 23, 2, 1)) - { - /* llvmpipe crashes when mutable descriptors are used. I don't - * know yet whether this is a bug in vkd3d or Mesa. */ - skip("Test crashes on llvmpipe, skipping.\n"); - destroy_test_context(&context); - return; - } - descriptor_ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; descriptor_ranges[0].NumDescriptors = 1; descriptor_ranges[0].BaseShaderRegister = 1;