From 1700b792199a23abd4ee750fd919c891960d440c Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 22 Sep 2022 17:30:50 +0200 Subject: vkd3d: Add scratch pool for upload data. To be used for inline UBO replacement. Signed-off-by: Hans-Kristian Arntzen --- libs/vkd3d/command.c | 6 ++++++ libs/vkd3d/device.c | 18 ++++++++++++++++++ libs/vkd3d/vkd3d_private.h | 1 + 3 files changed, 25 insertions(+) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 4b7b1356..548ee121 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -2433,6 +2433,7 @@ struct vkd3d_scratch_allocation VkBuffer buffer; VkDeviceSize offset; VkDeviceAddress va; + void *host_ptr; }; static bool d3d12_command_allocator_allocate_scratch_memory(struct d3d12_command_allocator *allocator, @@ -2465,6 +2466,10 @@ static bool d3d12_command_allocator_allocate_scratch_memory(struct d3d12_command allocation->buffer = scratch->allocation.resource.vk_buffer; allocation->offset = scratch->allocation.offset + aligned_offset; allocation->va = scratch->allocation.resource.va + aligned_offset; + if (scratch->allocation.cpu_address) + allocation->host_ptr = void_ptr_offset(scratch->allocation.cpu_address, aligned_offset); + else + allocation->host_ptr = NULL; return true; } } @@ -2489,6 +2494,7 @@ static bool d3d12_command_allocator_allocate_scratch_memory(struct d3d12_command allocation->buffer = scratch->allocation.resource.vk_buffer; allocation->offset = scratch->allocation.offset; allocation->va = scratch->allocation.resource.va; + allocation->host_ptr = scratch->allocation.cpu_address; return true; } diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index b5baaebf..e12699f5 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2696,6 +2696,24 @@ static HRESULT d3d12_device_create_scratch_buffer(struct d3d12_device *device, e &alloc_info, &scratch->allocation))) return hr; } + else if (kind == VKD3D_SCRATCH_POOL_KIND_UNIFORM_UPLOAD) + { + struct vkd3d_allocate_heap_memory_info alloc_info; + + /* We only care about memory types for INDIRECT_PREPROCESS. */ + assert(memory_types == ~0u); + + memset(&alloc_info, 0, sizeof(alloc_info)); + alloc_info.heap_desc.Properties.Type = D3D12_HEAP_TYPE_UPLOAD; + alloc_info.heap_desc.SizeInBytes = size; + alloc_info.heap_desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; + alloc_info.heap_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS | D3D12_HEAP_FLAG_CREATE_NOT_ZEROED; + alloc_info.extra_allocation_flags = VKD3D_ALLOCATION_FLAG_INTERNAL_SCRATCH; + + if (FAILED(hr = vkd3d_allocate_heap_memory(device, &device->memory_allocator, + &alloc_info, &scratch->allocation))) + return hr; + } else { return E_INVALIDARG; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 797ca0a3..3fac5f43 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1989,6 +1989,7 @@ enum vkd3d_scratch_pool_kind { VKD3D_SCRATCH_POOL_KIND_DEVICE_STORAGE = 0, VKD3D_SCRATCH_POOL_KIND_INDIRECT_PREPROCESS, + VKD3D_SCRATCH_POOL_KIND_UNIFORM_UPLOAD, VKD3D_SCRATCH_POOL_KIND_COUNT }; -- cgit v1.2.3