vkd3d: Refactor VkDeviceMemory allocation to keep track of type/size.
We will need to consider some form of budgeting, so make sure that all allocation and freeing is done in a central place. Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
parent
a590db2508
commit
69d4f55219
|
@ -9887,7 +9887,7 @@ static void STDMETHODCALLTYPE d3d12_command_queue_UpdateTileMappings(ID3D12Comma
|
|||
}
|
||||
else
|
||||
{
|
||||
bind->vk_memory = memory_heap->allocation.vk_memory;
|
||||
bind->vk_memory = memory_heap->allocation.device_allocation.vk_memory;
|
||||
bind->vk_offset = memory_heap->allocation.offset + VKD3D_TILE_SIZE * range_offset;
|
||||
|
||||
if (range_flag != D3D12_TILE_RANGE_FLAG_REUSE_SINGLE_TILE)
|
||||
|
|
|
@ -234,7 +234,7 @@ HRESULT vkd3d_shader_debug_ring_init(struct vkd3d_shader_debug_ring *ring,
|
|||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &ring->device_atomic_buffer_memory)))
|
||||
goto err_free_buffers;
|
||||
|
||||
if (VK_CALL(vkMapMemory(device->vk_device, ring->host_buffer_memory, 0, VK_WHOLE_SIZE, 0, &ring->mapped)) != VK_SUCCESS)
|
||||
if (VK_CALL(vkMapMemory(device->vk_device, ring->host_buffer_memory.vk_memory, 0, VK_WHOLE_SIZE, 0, &ring->mapped)) != VK_SUCCESS)
|
||||
goto err_free_buffers;
|
||||
|
||||
ring->atomic_device_address = vkd3d_get_buffer_device_address(device, ring->device_atomic_buffer);
|
||||
|
@ -259,8 +259,8 @@ err_destroy_cond:
|
|||
err_free_buffers:
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, ring->host_buffer, NULL));
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, ring->device_atomic_buffer, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, ring->host_buffer_memory, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, ring->device_atomic_buffer_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &ring->host_buffer_memory);
|
||||
vkd3d_free_device_memory(device, &ring->device_atomic_buffer_memory);
|
||||
memset(ring, 0, sizeof(*ring));
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
@ -282,8 +282,8 @@ void vkd3d_shader_debug_ring_cleanup(struct vkd3d_shader_debug_ring *ring,
|
|||
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, ring->host_buffer, NULL));
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, ring->device_atomic_buffer, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, ring->host_buffer_memory, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, ring->device_atomic_buffer_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &ring->host_buffer_memory);
|
||||
vkd3d_free_device_memory(device, &ring->device_atomic_buffer_memory);
|
||||
}
|
||||
|
||||
void vkd3d_shader_debug_ring_end_command_buffer(struct d3d12_command_list *list)
|
||||
|
|
|
@ -35,7 +35,7 @@ struct vkd3d_descriptor_qa_global_info
|
|||
struct vkd3d_descriptor_qa_global_buffer_data *data;
|
||||
VkDescriptorBufferInfo descriptor;
|
||||
VkBuffer vk_buffer;
|
||||
VkDeviceMemory vk_memory;
|
||||
struct vkd3d_device_memory_allocation device_allocation;
|
||||
unsigned int num_cookies;
|
||||
|
||||
pthread_t ring_thread;
|
||||
|
@ -232,13 +232,13 @@ HRESULT vkd3d_descriptor_debug_alloc_global_info(
|
|||
|
||||
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, global_info->vk_buffer,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
&global_info->vk_memory)))
|
||||
&global_info->device_allocation)))
|
||||
{
|
||||
vkd3d_descriptor_debug_free_global_info(global_info, device);
|
||||
return hr;
|
||||
}
|
||||
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, global_info->vk_memory,
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, global_info->device_allocation.vk_memory,
|
||||
0, VK_WHOLE_SIZE, 0, (void**)&global_info->data))))
|
||||
{
|
||||
ERR("Failed to map buffer, vr %d.\n", vr);
|
||||
|
@ -289,7 +289,7 @@ void vkd3d_descriptor_debug_free_global_info(
|
|||
pthread_cond_destroy(&global_info->ring_cond);
|
||||
}
|
||||
|
||||
VK_CALL(vkFreeMemory(device->vk_device, global_info->vk_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &global_info->device_allocation);
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, global_info->vk_buffer, NULL));
|
||||
vkd3d_free(global_info);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ static void d3d12_heap_destroy(struct d3d12_heap *heap)
|
|||
static void d3d12_heap_set_name(struct d3d12_heap *heap, const char *name)
|
||||
{
|
||||
if (!heap->allocation.chunk)
|
||||
vkd3d_set_vk_object_name(heap->device, (uint64_t)heap->allocation.vk_memory,
|
||||
vkd3d_set_vk_object_name(heap->device, (uint64_t)heap->allocation.device_allocation.vk_memory,
|
||||
VK_OBJECT_TYPE_DEVICE_MEMORY, name);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,9 +140,15 @@ static HRESULT vkd3d_create_global_buffer(struct d3d12_device *device, VkDeviceS
|
|||
return vkd3d_create_buffer(device, heap_properties, heap_flags, &resource_desc, vk_buffer);
|
||||
}
|
||||
|
||||
void vkd3d_free_device_memory(struct d3d12_device *device, const struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
VK_CALL(vkFreeMemory(device->vk_device, allocation->vk_memory, NULL));
|
||||
}
|
||||
|
||||
static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device,
|
||||
VkDeviceSize size, VkMemoryPropertyFlags type_flags, uint32_t type_mask,
|
||||
void *pNext, VkDeviceMemory *vk_memory, uint32_t *vk_memory_type)
|
||||
void *pNext, struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
const VkMemoryPropertyFlags optional_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
const VkPhysicalDeviceMemoryProperties *memory_info = &device->memory_properties;
|
||||
|
@ -167,10 +173,10 @@ static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device,
|
|||
|
||||
allocate_info.memoryTypeIndex = type_index;
|
||||
|
||||
if (VK_CALL(vkAllocateMemory(device->vk_device, &allocate_info, NULL, vk_memory)) == VK_SUCCESS)
|
||||
if (VK_CALL(vkAllocateMemory(device->vk_device, &allocate_info, NULL, &allocation->vk_memory)) == VK_SUCCESS)
|
||||
{
|
||||
if (vk_memory_type)
|
||||
*vk_memory_type = type_index;
|
||||
allocation->vk_memory_type = type_index;
|
||||
allocation->size = size;
|
||||
return S_OK;
|
||||
}
|
||||
else if (type_flags & optional_flags)
|
||||
|
@ -189,20 +195,19 @@ static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device,
|
|||
|
||||
HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
|
||||
VkDeviceSize size, VkMemoryPropertyFlags type_flags, uint32_t type_mask,
|
||||
void *pNext, VkDeviceMemory *vk_memory, uint32_t *vk_memory_type)
|
||||
void *pNext, struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
const VkMemoryPropertyFlags optional_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
HRESULT hr;
|
||||
|
||||
hr = vkd3d_try_allocate_device_memory(device, size, type_flags,
|
||||
type_mask, pNext, vk_memory, vk_memory_type);
|
||||
type_mask, pNext, allocation);
|
||||
|
||||
if (FAILED(hr) && (type_flags & optional_flags))
|
||||
{
|
||||
WARN("Memory allocation failed, falling back to system memory.\n");
|
||||
hr = vkd3d_try_allocate_device_memory(device, size,
|
||||
type_flags & ~optional_flags, type_mask, pNext,
|
||||
vk_memory, vk_memory_type);
|
||||
type_flags & ~optional_flags, type_mask, pNext, allocation);
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
|
@ -216,7 +221,7 @@ HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
|
|||
|
||||
static HRESULT vkd3d_import_host_memory(struct d3d12_device *device, void *host_address,
|
||||
VkDeviceSize size, VkMemoryPropertyFlags type_flags, uint32_t type_mask,
|
||||
void *pNext, VkDeviceMemory *vk_memory, uint32_t *vk_memory_type)
|
||||
void *pNext, struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
VkImportMemoryHostPointerInfoEXT import_info;
|
||||
HRESULT hr;
|
||||
|
@ -227,7 +232,7 @@ static HRESULT vkd3d_import_host_memory(struct d3d12_device *device, void *host_
|
|||
import_info.pHostPointer = host_address;
|
||||
|
||||
if (FAILED(hr = vkd3d_try_allocate_device_memory(device, size,
|
||||
type_flags, type_mask, &import_info, vk_memory, vk_memory_type)))
|
||||
type_flags, type_mask, &import_info, allocation)))
|
||||
{
|
||||
WARN("Failed to import host memory, hr %#x.\n", hr);
|
||||
/* If we failed, fall back to a host-visible allocation. Generally
|
||||
|
@ -235,7 +240,7 @@ static HRESULT vkd3d_import_host_memory(struct d3d12_device *device, void *host_
|
|||
* so it's fine. */
|
||||
hr = vkd3d_try_allocate_device_memory(device, size,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
type_mask, &import_info, vk_memory, vk_memory_type);
|
||||
type_mask, &import_info, allocation);
|
||||
}
|
||||
|
||||
return hr;
|
||||
|
@ -353,7 +358,7 @@ static void vkd3d_memory_allocation_free(const struct vkd3d_memory_allocation *a
|
|||
if (allocation->flags & VKD3D_ALLOCATION_FLAG_GLOBAL_BUFFER)
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, allocation->resource.vk_buffer, NULL));
|
||||
|
||||
VK_CALL(vkFreeMemory(device->vk_device, allocation->vk_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &allocation->device_allocation);
|
||||
}
|
||||
|
||||
static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allocation, struct d3d12_device *device,
|
||||
|
@ -431,12 +436,12 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
|
|||
if (host_ptr)
|
||||
{
|
||||
hr = vkd3d_import_host_memory(device, host_ptr, memory_requirements.size,
|
||||
type_flags, type_mask, &flags_info, &allocation->vk_memory, &allocation->vk_memory_type);
|
||||
type_flags, type_mask, &flags_info, &allocation->device_allocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = vkd3d_allocate_device_memory(device, memory_requirements.size, type_flags,
|
||||
type_mask, &flags_info, &allocation->vk_memory, &allocation->vk_memory_type);
|
||||
type_mask, &flags_info, &allocation->device_allocation);
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
|
@ -456,7 +461,7 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
|
|||
{
|
||||
allocation->flags |= VKD3D_ALLOCATION_FLAG_CPU_ACCESS;
|
||||
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, allocation->vk_memory,
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, allocation->device_allocation.vk_memory,
|
||||
0, VK_WHOLE_SIZE, 0, &allocation->cpu_address))))
|
||||
{
|
||||
ERR("Failed to map memory, vr %d.\n", vr);
|
||||
|
@ -469,7 +474,7 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
|
|||
if (allocation->resource.vk_buffer)
|
||||
{
|
||||
if ((vr = VK_CALL(vkBindBufferMemory(device->vk_device,
|
||||
allocation->resource.vk_buffer, allocation->vk_memory, 0))) < 0)
|
||||
allocation->resource.vk_buffer, allocation->device_allocation.vk_memory, 0))) < 0)
|
||||
{
|
||||
ERR("Failed to bind buffer memory, vr %d.\n", vr);
|
||||
vkd3d_memory_allocation_free(allocation, device, allocator);
|
||||
|
@ -492,7 +497,7 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
|
|||
allocation->resource.cookie, info);
|
||||
|
||||
TRACE("Created allocation %p on memory type %u (%"PRIu64" bytes).\n",
|
||||
allocation, allocation->vk_memory_type, allocation->resource.size);
|
||||
allocation, allocation->device_allocation.vk_memory_type, allocation->resource.size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -1170,7 +1175,7 @@ static HRESULT vkd3d_memory_allocator_try_suballocate_memory(struct vkd3d_memory
|
|||
continue;
|
||||
|
||||
/* Filter out unsupported memory types */
|
||||
if (!(type_mask & (1u << chunk->allocation.vk_memory_type)))
|
||||
if (!(type_mask & (1u << chunk->allocation.device_allocation.vk_memory_type)))
|
||||
continue;
|
||||
|
||||
if (SUCCEEDED(hr = vkd3d_memory_chunk_allocate_range(chunk, memory_requirements, allocation)))
|
||||
|
@ -1278,7 +1283,8 @@ HRESULT vkd3d_allocate_heap_memory(struct d3d12_device *device, struct vkd3d_mem
|
|||
}
|
||||
|
||||
HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
|
||||
VkMemoryPropertyFlags type_flags, VkDeviceMemory *vk_memory)
|
||||
VkMemoryPropertyFlags type_flags,
|
||||
struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
VkMemoryRequirements memory_requirements;
|
||||
|
@ -1296,17 +1302,18 @@ HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_bu
|
|||
VK_CALL(vkGetBufferMemoryRequirements(device->vk_device, vk_buffer, &memory_requirements));
|
||||
|
||||
if (FAILED(hr = vkd3d_allocate_device_memory(device, memory_requirements.size,
|
||||
type_flags, memory_requirements.memoryTypeBits, &flags_info, vk_memory, NULL)))
|
||||
type_flags, memory_requirements.memoryTypeBits, &flags_info, allocation)))
|
||||
return hr;
|
||||
|
||||
if (FAILED(vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, *vk_memory, 0))))
|
||||
if (FAILED(vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, allocation->vk_memory, 0))))
|
||||
return hresult_from_vk_result(vr);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_image,
|
||||
VkMemoryPropertyFlags type_flags, VkDeviceMemory *vk_memory)
|
||||
VkMemoryPropertyFlags type_flags,
|
||||
struct vkd3d_device_memory_allocation *allocation)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
VkMemoryRequirements memory_requirements;
|
||||
|
@ -1316,10 +1323,10 @@ HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_imag
|
|||
VK_CALL(vkGetImageMemoryRequirements(device->vk_device, vk_image, &memory_requirements));
|
||||
|
||||
if (FAILED(hr = vkd3d_allocate_device_memory(device, memory_requirements.size,
|
||||
type_flags, memory_requirements.memoryTypeBits, NULL, vk_memory, NULL)))
|
||||
type_flags, memory_requirements.memoryTypeBits, NULL, allocation)))
|
||||
return hr;
|
||||
|
||||
if (FAILED(vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, *vk_memory, 0))))
|
||||
if (FAILED(vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, allocation->vk_memory, 0))))
|
||||
return hresult_from_vk_result(vr);
|
||||
|
||||
return hr;
|
||||
|
|
|
@ -1401,12 +1401,12 @@ static bool d3d12_resource_get_mapped_memory_range(struct d3d12_resource *resour
|
|||
if (range && range->End <= range->Begin)
|
||||
return false;
|
||||
|
||||
if (device->memory_properties.memoryTypes[resource->mem.vk_memory_type].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
||||
if (device->memory_properties.memoryTypes[resource->mem.device_allocation.vk_memory_type].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
||||
return false;
|
||||
|
||||
vk_mapped_range->sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
vk_mapped_range->pNext = NULL;
|
||||
vk_mapped_range->memory = resource->mem.vk_memory;
|
||||
vk_mapped_range->memory = resource->mem.device_allocation.vk_memory;
|
||||
|
||||
if (resource->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||
{
|
||||
|
@ -2151,7 +2151,7 @@ static HRESULT d3d12_resource_bind_sparse_metadata(struct d3d12_resource *resour
|
|||
VK_CALL(vkGetImageMemoryRequirements(device->vk_device, resource->res.vk_image, &memory_requirements));
|
||||
|
||||
if ((vr = vkd3d_allocate_device_memory(device, metadata_size, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
memory_requirements.memoryTypeBits, NULL, &sparse->vk_metadata_memory, NULL)))
|
||||
memory_requirements.memoryTypeBits, NULL, &sparse->vk_metadata_memory)))
|
||||
{
|
||||
ERR("Failed to allocate device memory for sparse metadata, vr %d.\n", vr);
|
||||
hr = hresult_from_vk_result(vr);
|
||||
|
@ -2184,7 +2184,7 @@ static HRESULT d3d12_resource_bind_sparse_metadata(struct d3d12_resource *resour
|
|||
VkSparseMemoryBind *bind = &memory_binds[j++];
|
||||
bind->resourceOffset = req->imageMipTailOffset + req->imageMipTailStride * k;
|
||||
bind->size = req->imageMipTailSize;
|
||||
bind->memory = sparse->vk_metadata_memory;
|
||||
bind->memory = sparse->vk_metadata_memory.vk_memory;
|
||||
bind->memoryOffset = metadata_size;
|
||||
bind->flags = VK_SPARSE_MEMORY_BIND_METADATA_BIT;
|
||||
|
||||
|
@ -2361,8 +2361,7 @@ static void d3d12_resource_destroy(struct d3d12_resource *resource, struct d3d12
|
|||
|
||||
if (resource->flags & VKD3D_RESOURCE_RESERVED)
|
||||
{
|
||||
VK_CALL(vkFreeMemory(device->vk_device, resource->sparse.vk_metadata_memory, NULL));
|
||||
|
||||
vkd3d_free_device_memory(device, &resource->sparse.vk_metadata_memory);
|
||||
vkd3d_free(resource->sparse.tiles);
|
||||
vkd3d_free(resource->sparse.tilings);
|
||||
|
||||
|
@ -2380,7 +2379,7 @@ static void d3d12_resource_destroy(struct d3d12_resource *resource, struct d3d12
|
|||
else if (resource->flags & VKD3D_RESOURCE_RESERVED)
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, resource->res.vk_buffer, NULL));
|
||||
|
||||
if ((resource->flags & VKD3D_RESOURCE_ALLOCATION) && resource->mem.vk_memory)
|
||||
if ((resource->flags & VKD3D_RESOURCE_ALLOCATION) && resource->mem.device_allocation.vk_memory)
|
||||
vkd3d_free_memory(device, &device->memory_allocator, &resource->mem);
|
||||
|
||||
if (resource->vrs_view)
|
||||
|
@ -2554,7 +2553,7 @@ HRESULT d3d12_resource_create_committed(struct d3d12_device *device, const D3D12
|
|||
goto fail;
|
||||
|
||||
if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, object->res.vk_image,
|
||||
object->mem.vk_memory, object->mem.offset))))
|
||||
object->mem.device_allocation.vk_memory, object->mem.offset))))
|
||||
{
|
||||
ERR("Failed to bind image memory, vr %d.\n", vr);
|
||||
hr = hresult_from_vk_result(vr);
|
||||
|
@ -2673,7 +2672,7 @@ HRESULT d3d12_resource_create_placed(struct d3d12_device *device, const D3D12_RE
|
|||
if (d3d12_resource_is_texture(object))
|
||||
{
|
||||
if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, object->res.vk_image,
|
||||
object->mem.vk_memory, object->mem.offset)) < 0))
|
||||
object->mem.device_allocation.vk_memory, object->mem.offset)) < 0))
|
||||
{
|
||||
ERR("Failed to bind image memory, vr %d.\n", vr);
|
||||
hr = hresult_from_vk_result(vr);
|
||||
|
@ -5300,10 +5299,10 @@ static HRESULT d3d12_descriptor_heap_init_data_buffer(struct d3d12_descriptor_he
|
|||
property_flags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
|
||||
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, descriptor_heap->vk_buffer,
|
||||
property_flags, &descriptor_heap->vk_memory)))
|
||||
property_flags, &descriptor_heap->device_allocation)))
|
||||
return hr;
|
||||
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, descriptor_heap->vk_memory,
|
||||
if ((vr = VK_CALL(vkMapMemory(device->vk_device, descriptor_heap->device_allocation.vk_memory,
|
||||
0, VK_WHOLE_SIZE, 0, &descriptor_heap->host_memory))))
|
||||
{
|
||||
ERR("Failed to map buffer, vr %d.\n", vr);
|
||||
|
@ -5312,7 +5311,7 @@ static HRESULT d3d12_descriptor_heap_init_data_buffer(struct d3d12_descriptor_he
|
|||
}
|
||||
else
|
||||
{
|
||||
descriptor_heap->vk_memory = VK_NULL_HANDLE;
|
||||
memset(&descriptor_heap->device_allocation, 0, sizeof(descriptor_heap->device_allocation));
|
||||
descriptor_heap->vk_buffer = VK_NULL_HANDLE;
|
||||
descriptor_heap->host_memory = vkd3d_calloc(1, buffer_size);
|
||||
}
|
||||
|
@ -5589,14 +5588,14 @@ void d3d12_descriptor_heap_cleanup(struct d3d12_descriptor_heap *descriptor_heap
|
|||
const struct vkd3d_vk_device_procs *vk_procs = &descriptor_heap->device->vk_procs;
|
||||
struct d3d12_device *device = descriptor_heap->device;
|
||||
|
||||
if (!descriptor_heap->vk_memory)
|
||||
if (!descriptor_heap->device_allocation.vk_memory)
|
||||
vkd3d_free(descriptor_heap->host_memory);
|
||||
|
||||
if (descriptor_heap->gpu_va != 0)
|
||||
d3d12_device_return_descriptor_heap_gpu_va(device, descriptor_heap->gpu_va);
|
||||
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, descriptor_heap->vk_buffer, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, descriptor_heap->vk_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &descriptor_heap->device_allocation);
|
||||
|
||||
VK_CALL(vkDestroyDescriptorPool(device->vk_device, descriptor_heap->vk_descriptor_pool, NULL));
|
||||
|
||||
|
@ -5671,7 +5670,7 @@ static ULONG STDMETHODCALLTYPE d3d12_query_heap_Release(ID3D12QueryHeap *iface)
|
|||
|
||||
VK_CALL(vkDestroyQueryPool(device->vk_device, heap->vk_query_pool, NULL));
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, heap->vk_buffer, NULL));
|
||||
VK_CALL(vkFreeMemory(device->vk_device, heap->vk_memory, NULL));
|
||||
vkd3d_free_device_memory(device, &heap->device_allocation);
|
||||
|
||||
vkd3d_free(heap);
|
||||
|
||||
|
@ -5850,7 +5849,7 @@ HRESULT d3d12_query_heap_create(struct d3d12_device *device, const D3D12_QUERY_H
|
|||
}
|
||||
|
||||
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, object->vk_buffer,
|
||||
VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, &object->vk_memory)))
|
||||
VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, &object->device_allocation)))
|
||||
{
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, object->vk_buffer, NULL));
|
||||
vkd3d_free(object);
|
||||
|
|
|
@ -634,16 +634,22 @@ struct vkd3d_unique_resource
|
|||
struct vkd3d_view_map *view_map;
|
||||
};
|
||||
|
||||
struct vkd3d_device_memory_allocation
|
||||
{
|
||||
VkDeviceMemory vk_memory;
|
||||
uint32_t vk_memory_type;
|
||||
VkDeviceSize size;
|
||||
};
|
||||
|
||||
struct vkd3d_memory_allocation
|
||||
{
|
||||
struct vkd3d_unique_resource resource;
|
||||
VkDeviceMemory vk_memory;
|
||||
struct vkd3d_device_memory_allocation device_allocation;
|
||||
VkDeviceSize offset;
|
||||
void *cpu_address;
|
||||
|
||||
D3D12_HEAP_TYPE heap_type;
|
||||
D3D12_HEAP_FLAGS heap_flags;
|
||||
uint32_t vk_memory_type;
|
||||
uint32_t flags;
|
||||
|
||||
uint64_t clear_semaphore_value;
|
||||
|
@ -787,7 +793,7 @@ struct d3d12_sparse_info
|
|||
D3D12_TILE_SHAPE tile_shape;
|
||||
D3D12_PACKED_MIP_INFO packed_mips;
|
||||
D3D12_SUBRESOURCE_TILING *tilings;
|
||||
VkDeviceMemory vk_metadata_memory;
|
||||
struct vkd3d_device_memory_allocation vk_metadata_memory;
|
||||
};
|
||||
|
||||
struct vkd3d_view_map
|
||||
|
@ -885,11 +891,15 @@ struct d3d12_resource *unsafe_impl_from_ID3D12Resource(ID3D12Resource *iface);
|
|||
|
||||
HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
|
||||
VkDeviceSize size, VkMemoryPropertyFlags type_flags, uint32_t type_mask,
|
||||
void *pNext, VkDeviceMemory *vk_memory, uint32_t *vk_memory_type);
|
||||
void *pNext, struct vkd3d_device_memory_allocation *allocation);
|
||||
void vkd3d_free_device_memory(struct d3d12_device *device,
|
||||
const struct vkd3d_device_memory_allocation *allocation);
|
||||
HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
|
||||
VkMemoryPropertyFlags type_flags, VkDeviceMemory *vk_memory);
|
||||
VkMemoryPropertyFlags type_flags,
|
||||
struct vkd3d_device_memory_allocation *allocation);
|
||||
HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_image,
|
||||
VkMemoryPropertyFlags type_flags, VkDeviceMemory *vk_memory);
|
||||
VkMemoryPropertyFlags type_flags,
|
||||
struct vkd3d_device_memory_allocation *allocation);
|
||||
HRESULT vkd3d_create_buffer(struct d3d12_device *device,
|
||||
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
|
||||
const D3D12_RESOURCE_DESC *desc, VkBuffer *vk_buffer);
|
||||
|
@ -1111,7 +1121,7 @@ struct d3d12_descriptor_heap
|
|||
VkDescriptorPool vk_descriptor_pool;
|
||||
VkDescriptorSet vk_descriptor_sets[VKD3D_MAX_BINDLESS_DESCRIPTOR_SETS];
|
||||
|
||||
VkDeviceMemory vk_memory;
|
||||
struct vkd3d_device_memory_allocation device_allocation;
|
||||
VkBuffer vk_buffer;
|
||||
void *host_memory;
|
||||
|
||||
|
@ -1154,7 +1164,7 @@ struct d3d12_query_heap
|
|||
|
||||
D3D12_QUERY_HEAP_DESC desc;
|
||||
VkQueryPool vk_query_pool;
|
||||
VkDeviceMemory vk_memory;
|
||||
struct vkd3d_device_memory_allocation device_allocation;
|
||||
VkBuffer vk_buffer;
|
||||
uint32_t initialized;
|
||||
|
||||
|
@ -2087,8 +2097,8 @@ struct vkd3d_shader_debug_ring
|
|||
VkBuffer host_buffer;
|
||||
VkBuffer device_atomic_buffer;
|
||||
|
||||
VkDeviceMemory host_buffer_memory;
|
||||
VkDeviceMemory device_atomic_buffer_memory;
|
||||
struct vkd3d_device_memory_allocation host_buffer_memory;
|
||||
struct vkd3d_device_memory_allocation device_atomic_buffer_memory;
|
||||
|
||||
void *mapped;
|
||||
VkDeviceAddress ring_device_address;
|
||||
|
|
Loading…
Reference in New Issue