The availability of allocation info makes it possible to check that the descriptor belongs to a heap of the correct type. This will be more important when Vulkan-backed descriptor heaps are added.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 15 ++++++++++++++- libs/vkd3d/device.c | 20 ++++++++++++++++++++ libs/vkd3d/vkd3d_private.h | 11 +++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 9fbde800..0090324f 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4178,11 +4178,24 @@ static void d3d12_command_list_set_descriptor_table(struct d3d12_command_list *l { struct vkd3d_pipeline_bindings *bindings = &list->pipeline_bindings[bind_point]; const struct d3d12_root_signature *root_signature = bindings->root_signature; + const struct d3d12_descriptor_heap *heap; + struct d3d12_desc *desc;
assert(root_signature_get_descriptor_table(root_signature, index));
assert(index < ARRAY_SIZE(bindings->descriptor_tables)); - bindings->descriptor_tables[index] = d3d12_desc_from_gpu_handle(base_descriptor); + desc = d3d12_desc_from_gpu_handle(base_descriptor); + + if (desc && !(heap = vkd3d_gpu_descriptor_allocator_heap_from_descriptor(&list->device->gpu_descriptor_allocator, + desc))) + { + /* Failure to find the heap means the descriptor handle is from the wrong heap type or not a handle at all. */ + ERR("Invalid heap for base descriptor %"PRIx64".\n", base_descriptor.ptr); + /* TODO: Mark list as invalid? */ + return; + } + + bindings->descriptor_tables[index] = desc; bindings->descriptor_table_dirty_mask |= (uint64_t)1 << index; bindings->descriptor_table_active_mask |= (uint64_t)1 << index; } diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 537bc7b2..fee6222d 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2272,6 +2272,26 @@ static struct vkd3d_gpu_descriptor_allocation *vkd3d_gpu_descriptor_allocator_bi return (desc >= allocations->base && desc < allocations->base + allocations->count) ? allocations : NULL; }
+struct vkd3d_gpu_descriptor_allocation *vkd3d_gpu_descriptor_allocator_allocation_from_descriptor( + struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc) +{ + struct vkd3d_gpu_descriptor_allocation *allocation; + int rc; + + assert(allocator->allocation_count); + + if ((rc = pthread_mutex_lock(&allocator->mutex))) + { + ERR("Failed to lock mutex, error %d.\n", rc); + return NULL; + } + + allocation = vkd3d_gpu_descriptor_allocator_binary_search(allocator, desc); + + pthread_mutex_unlock(&allocator->mutex); + + return allocation; +}
/* Return the available size from the specified descriptor to the heap end. */ size_t vkd3d_gpu_descriptor_allocator_range_size_from_descriptor( diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index f5cac0cc..305a003b 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -255,6 +255,8 @@ struct vkd3d_gpu_descriptor_allocator size_t allocation_count; };
+struct vkd3d_gpu_descriptor_allocation *vkd3d_gpu_descriptor_allocator_allocation_from_descriptor( + struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc); size_t vkd3d_gpu_descriptor_allocator_range_size_from_descriptor( struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc); bool vkd3d_gpu_descriptor_allocator_register_range(struct vkd3d_gpu_descriptor_allocator *allocator, @@ -636,6 +638,15 @@ struct d3d12_descriptor_heap HRESULT d3d12_descriptor_heap_create(struct d3d12_device *device, const D3D12_DESCRIPTOR_HEAP_DESC *desc, struct d3d12_descriptor_heap **descriptor_heap);
+static inline struct d3d12_descriptor_heap *vkd3d_gpu_descriptor_allocator_heap_from_descriptor( + struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc) +{ + struct vkd3d_gpu_descriptor_allocation *allocation + = vkd3d_gpu_descriptor_allocator_allocation_from_descriptor(allocator, desc); + return allocation ? CONTAINING_RECORD(allocation->base, struct d3d12_descriptor_heap, descriptors) + : NULL; +} + /* ID3D12QueryHeap */ struct d3d12_query_heap {