Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config flag for forced no-suballocation #2234

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions libs/vkd3d/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -3955,10 +3955,10 @@ HRESULT d3d12_resource_create_placed(struct d3d12_device *device, const D3D12_RE

heap_offset = align(heap->allocation.offset + heap_offset, memory_requirements.alignment) - heap->allocation.offset;

if (heap_offset + memory_requirements.size > heap->allocation.resource.size)
if (heap_offset + memory_requirements.size > heap->desc.SizeInBytes)
{
ERR("Heap too small for the texture (heap=%"PRIu64", res=%"PRIu64".\n",
heap->allocation.resource.size, heap_offset + memory_requirements.size);
heap->desc.SizeInBytes, heap_offset + memory_requirements.size);
hr = E_INVALIDARG;
goto fail;
}
Expand Down Expand Up @@ -3989,10 +3989,10 @@ HRESULT d3d12_resource_create_placed(struct d3d12_device *device, const D3D12_RE
}
else
{
if (heap_offset + desc->Width > heap->allocation.resource.size)
if (heap_offset + desc->Width > heap->desc.SizeInBytes)
{
ERR("Heap too small for the buffer (heap=%"PRIu64", res=%"PRIu64".\n",
heap->allocation.resource.size, heap_offset + desc->Width);
heap->desc.SizeInBytes, heap_offset + desc->Width);
hr = E_INVALIDARG;
goto fail;
}
Expand Down