Conor McCarthy : vkd3d: Validate the base descriptor handle in d3d12_command_list_set_descriptor_table().
Alexandre Julliard
julliard at winehq.org
Fri Jan 7 15:01:22 CST 2022
Module: vkd3d
Branch: master
Commit: 711378ea31dd624526466c0b534d00346d024557
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=711378ea31dd624526466c0b534d00346d024557
Author: Conor McCarthy <cmccarthy at codeweavers.com>
Date: Wed Jan 5 14:54:51 2022 +1000
vkd3d: Validate the base descriptor handle in d3d12_command_list_set_descriptor_table().
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>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 9fbde80..b2565e1 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 7d0922e..4a9a0c7 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 1bccb35..454b066 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
{
More information about the wine-cvs
mailing list