Skip to content

Commit 00f0224

Browse files
vkd3d: Add no_suballocation option.
Useful when aggressively debugging use-after-free. Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
1 parent 28876e0 commit 00f0224

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/vkd3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extern "C" {
111111
#define VKD3D_CONFIG_FLAG_INSTRUCTION_QA_CHECKS (1ull << 53)
112112
#define VKD3D_CONFIG_FLAG_TRANSFER_QUEUE (1ull << 54)
113113
#define VKD3D_CONFIG_FLAG_NO_GPU_UPLOAD_HEAP (1ull << 55)
114+
#define VKD3D_CONFIG_FLAG_NO_SUBALLOCATION (1ull << 56)
114115

115116
struct vkd3d_instance;
116117

libs/vkd3d/device.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ static const struct vkd3d_debug_option vkd3d_config_options[] =
982982
{"instruction_qa_checks", VKD3D_CONFIG_FLAG_INSTRUCTION_QA_CHECKS},
983983
{"transfer_queue", VKD3D_CONFIG_FLAG_TRANSFER_QUEUE},
984984
{"no_gpu_upload_heap", VKD3D_CONFIG_FLAG_NO_GPU_UPLOAD_HEAP},
985+
{"no_suballocation", VKD3D_CONFIG_FLAG_NO_SUBALLOCATION},
985986
};
986987

987988
static void vkd3d_config_flags_init_once(void)

libs/vkd3d/memory.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,9 @@ bool vkd3d_allocate_image_memory_prefers_dedicated(struct d3d12_device *device,
18391839
static bool vkd3d_memory_info_allow_suballocate(struct d3d12_device *device,
18401840
const struct vkd3d_allocate_memory_info *info)
18411841
{
1842+
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_NO_SUBALLOCATION)
1843+
return false;
1844+
18421845
/* pNext implies dedicated allocation or similar. Host pointer implies external memory import. */
18431846
if (info->pNext || info->host_ptr)
18441847
return false;
@@ -1912,6 +1915,19 @@ HRESULT vkd3d_allocate_memory(struct d3d12_device *device, struct vkd3d_memory_a
19121915
info = &tmp_info;
19131916
}
19141917

1918+
/* To avoid a potential collapse in CPU performance, force larger allocations
1919+
* when using NO_SUBALLOCATION. */
1920+
if ((vkd3d_config_flags & VKD3D_CONFIG_FLAG_NO_SUBALLOCATION) &&
1921+
!info->host_ptr &&
1922+
(info->flags & VKD3D_ALLOCATION_FLAG_GLOBAL_BUFFER) &&
1923+
info->memory_requirements.size < VKD3D_VA_BLOCK_SIZE)
1924+
{
1925+
if (&tmp_info != info)
1926+
tmp_info = *info;
1927+
info = &tmp_info;
1928+
tmp_info.memory_requirements.size = max(VKD3D_VA_BLOCK_SIZE, tmp_info.memory_requirements.size);
1929+
}
1930+
19151931
if (suballocate)
19161932
hr = vkd3d_suballocate_memory(device, allocator, info, allocation);
19171933
else

0 commit comments

Comments
 (0)