[PATCH vkd3d v2 2/4] vkd3d: Validate the base descriptor handle in d3d12_command_list_set_descriptor_table().

Conor McCarthy cmccarthy at codeweavers.com
Tue Jan 4 22:54:51 CST 2022


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 at codeweavers.com>
---
v2: vkd3d_gpu_descriptor_allocator_heap_from_descriptor() must lock the
allocator.
---
 libs/vkd3d/command.c       | 15 ++++++++++++++-
 libs/vkd3d/device.c        | 23 +++++++++++++++++++++++
 libs/vkd3d/vkd3d_private.h |  2 ++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 9fbde800..b2565e1a 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;
+    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 && !vkd3d_gpu_descriptor_allocator_heap_from_descriptor(&list->device->gpu_descriptor_allocator,
+            desc))
+    {
+        /* Failure to find a 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 ec2eb73b..83cd2aa1 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -2305,6 +2305,29 @@ size_t vkd3d_gpu_descriptor_allocator_range_size_from_descriptor(
     return remaining;
 }
 
+struct d3d12_descriptor_heap *vkd3d_gpu_descriptor_allocator_heap_from_descriptor(
+        struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc)
+{
+    const struct vkd3d_gpu_descriptor_allocation *allocation;
+    int rc;
+
+    if (!allocator->allocation_count)
+        return NULL;
+
+    if ((rc = pthread_mutex_lock(&allocator->mutex)))
+    {
+        ERR("Failed to lock mutex, error %d.\n", rc);
+        return NULL;
+    }
+
+    allocation = vkd3d_gpu_descriptor_allocator_allocation_from_descriptor(allocator, desc);
+
+    pthread_mutex_unlock(&allocator->mutex);
+
+    return allocation ? CONTAINING_RECORD(allocation->base, struct d3d12_descriptor_heap, descriptors)
+            : NULL;
+}
+
 static bool vkd3d_gpu_descriptor_allocator_init(struct vkd3d_gpu_descriptor_allocator *allocator)
 {
     int rc;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 1bccb35d..454b066f 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -260,6 +260,8 @@ bool vkd3d_gpu_descriptor_allocator_register_range(struct vkd3d_gpu_descriptor_a
         const struct d3d12_desc *base, size_t count);
 bool vkd3d_gpu_descriptor_allocator_unregister_range(
         struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *base);
+struct d3d12_descriptor_heap *vkd3d_gpu_descriptor_allocator_heap_from_descriptor(
+        struct vkd3d_gpu_descriptor_allocator *allocator, const struct d3d12_desc *desc);
 
 struct vkd3d_render_pass_key
 {
-- 
2.33.0




More information about the wine-devel mailing list