Skip to content

Commit

Permalink
vkd3d: Add no_suballocation option.
Browse files Browse the repository at this point in the history
Useful when aggressively debugging use-after-free.

Signed-off-by: Hans-Kristian Arntzen <[email protected]>
  • Loading branch information
HansKristian-Work committed Nov 27, 2024
1 parent 28876e0 commit 00f0224
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/vkd3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ extern "C" {
#define VKD3D_CONFIG_FLAG_INSTRUCTION_QA_CHECKS (1ull << 53)
#define VKD3D_CONFIG_FLAG_TRANSFER_QUEUE (1ull << 54)
#define VKD3D_CONFIG_FLAG_NO_GPU_UPLOAD_HEAP (1ull << 55)
#define VKD3D_CONFIG_FLAG_NO_SUBALLOCATION (1ull << 56)

struct vkd3d_instance;

Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ static const struct vkd3d_debug_option vkd3d_config_options[] =
{"instruction_qa_checks", VKD3D_CONFIG_FLAG_INSTRUCTION_QA_CHECKS},
{"transfer_queue", VKD3D_CONFIG_FLAG_TRANSFER_QUEUE},
{"no_gpu_upload_heap", VKD3D_CONFIG_FLAG_NO_GPU_UPLOAD_HEAP},
{"no_suballocation", VKD3D_CONFIG_FLAG_NO_SUBALLOCATION},
};

static void vkd3d_config_flags_init_once(void)
Expand Down
16 changes: 16 additions & 0 deletions libs/vkd3d/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,9 @@ bool vkd3d_allocate_image_memory_prefers_dedicated(struct d3d12_device *device,
static bool vkd3d_memory_info_allow_suballocate(struct d3d12_device *device,
const struct vkd3d_allocate_memory_info *info)
{
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_NO_SUBALLOCATION)
return false;

/* pNext implies dedicated allocation or similar. Host pointer implies external memory import. */
if (info->pNext || info->host_ptr)
return false;
Expand Down Expand Up @@ -1912,6 +1915,19 @@ HRESULT vkd3d_allocate_memory(struct d3d12_device *device, struct vkd3d_memory_a
info = &tmp_info;
}

/* To avoid a potential collapse in CPU performance, force larger allocations
* when using NO_SUBALLOCATION. */
if ((vkd3d_config_flags & VKD3D_CONFIG_FLAG_NO_SUBALLOCATION) &&
!info->host_ptr &&
(info->flags & VKD3D_ALLOCATION_FLAG_GLOBAL_BUFFER) &&
info->memory_requirements.size < VKD3D_VA_BLOCK_SIZE)
{
if (&tmp_info != info)
tmp_info = *info;
info = &tmp_info;
tmp_info.memory_requirements.size = max(VKD3D_VA_BLOCK_SIZE, tmp_info.memory_requirements.size);
}

if (suballocate)
hr = vkd3d_suballocate_memory(device, allocator, info, allocation);
else
Expand Down

0 comments on commit 00f0224

Please sign in to comment.