vkd3d: Use vkd3d_memory_allocation for scratch buffers.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
This commit is contained in:
parent
db1b425d2a
commit
9792b02b26
|
@ -1850,13 +1850,13 @@ static bool d3d12_command_allocator_allocate_scratch_memory(struct d3d12_command
|
|||
scratch = &allocator->scratch_buffers[i - 1];
|
||||
aligned_offset = align(scratch->offset, alignment);
|
||||
|
||||
if (aligned_offset + aligned_size <= scratch->size)
|
||||
if (aligned_offset + aligned_size <= scratch->allocation.resource.size)
|
||||
{
|
||||
scratch->offset = aligned_offset + aligned_size;
|
||||
|
||||
allocation->buffer = scratch->vk_buffer;
|
||||
allocation->offset = aligned_offset;
|
||||
allocation->va = scratch->va + aligned_offset;
|
||||
allocation->buffer = scratch->allocation.resource.vk_buffer;
|
||||
allocation->offset = scratch->allocation.offset + aligned_offset;
|
||||
allocation->va = scratch->allocation.resource.va + aligned_offset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1878,9 +1878,9 @@ static bool d3d12_command_allocator_allocate_scratch_memory(struct d3d12_command
|
|||
allocator->scratch_buffer_count += 1;
|
||||
scratch->offset = aligned_size;
|
||||
|
||||
allocation->buffer = scratch->vk_buffer;
|
||||
allocation->offset = 0;
|
||||
allocation->va = scratch->va;
|
||||
allocation->buffer = scratch->allocation.resource.vk_buffer;
|
||||
allocation->offset = scratch->allocation.offset;
|
||||
allocation->va = scratch->allocation.resource.va;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2355,57 +2355,30 @@ static void d3d12_remove_device_singleton(LUID luid)
|
|||
|
||||
static HRESULT d3d12_device_create_scratch_buffer(struct d3d12_device *device, VkDeviceSize size, struct vkd3d_scratch_buffer *scratch)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
VkDeviceMemory vk_memory = VK_NULL_HANDLE;
|
||||
VkBuffer vk_buffer = VK_NULL_HANDLE;
|
||||
D3D12_RESOURCE_DESC resource_desc;
|
||||
D3D12_HEAP_PROPERTIES heap_desc;
|
||||
struct vkd3d_allocate_heap_memory_info alloc_info;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("device %p, size %llu, scratch %p.\n", device, size, scratch);
|
||||
|
||||
memset(&heap_desc, 0, sizeof(heap_desc));
|
||||
heap_desc.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
memset(&alloc_info, 0, sizeof(alloc_info));
|
||||
alloc_info.heap_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
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;
|
||||
|
||||
resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
resource_desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
|
||||
resource_desc.Width = size;
|
||||
resource_desc.Height = 1;
|
||||
resource_desc.DepthOrArraySize = 1;
|
||||
resource_desc.MipLevels = 1;
|
||||
resource_desc.Format = DXGI_FORMAT_UNKNOWN;
|
||||
resource_desc.SampleDesc.Count = 1;
|
||||
resource_desc.SampleDesc.Quality = 0;
|
||||
resource_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||
|
||||
if (FAILED(hr = vkd3d_create_buffer(device, &heap_desc, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS, &resource_desc, &vk_buffer)))
|
||||
if (FAILED(hr = vkd3d_allocate_heap_memory_2(device, &device->memory_allocator,
|
||||
&alloc_info, &scratch->allocation)))
|
||||
return hr;
|
||||
|
||||
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, vk_buffer, NULL,
|
||||
&heap_desc, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS, &vk_memory, NULL, NULL)))
|
||||
{
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, vk_buffer, NULL));
|
||||
return hr;
|
||||
}
|
||||
|
||||
scratch->vk_buffer = vk_buffer;
|
||||
scratch->vk_memory = vk_memory;
|
||||
scratch->size = size;
|
||||
scratch->offset = 0;
|
||||
scratch->va = device->device_info.buffer_device_address_features.bufferDeviceAddress
|
||||
? vkd3d_get_buffer_device_address(device, vk_buffer) : 0ull;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void d3d12_device_destroy_scratch_buffer(struct d3d12_device *device, const struct vkd3d_scratch_buffer *scratch)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
|
||||
TRACE("device %p, scratch %p.\n", device, scratch);
|
||||
|
||||
VK_CALL(vkFreeMemory(device->vk_device, scratch->vk_memory, NULL));
|
||||
VK_CALL(vkDestroyBuffer(device->vk_device, scratch->vk_buffer, NULL));
|
||||
vkd3d_free_memory_2(device, &device->memory_allocator, &scratch->allocation);
|
||||
}
|
||||
|
||||
HRESULT d3d12_device_get_scratch_buffer(struct d3d12_device *device, VkDeviceSize min_size, struct vkd3d_scratch_buffer *scratch)
|
||||
|
@ -2433,7 +2406,8 @@ void d3d12_device_return_scratch_buffer(struct d3d12_device *device, const struc
|
|||
{
|
||||
pthread_mutex_lock(&device->mutex);
|
||||
|
||||
if (scratch->size == VKD3D_SCRATCH_BUFFER_SIZE && device->scratch_buffer_count < VKD3D_SCRATCH_BUFFER_COUNT)
|
||||
if (scratch->allocation.resource.size == VKD3D_SCRATCH_BUFFER_SIZE &&
|
||||
device->scratch_buffer_count < VKD3D_SCRATCH_BUFFER_COUNT)
|
||||
{
|
||||
device->scratch_buffers[device->scratch_buffer_count++] = *scratch;
|
||||
pthread_mutex_unlock(&device->mutex);
|
||||
|
|
|
@ -1351,11 +1351,8 @@ enum vkd3d_descriptor_pool_types
|
|||
|
||||
struct vkd3d_scratch_buffer
|
||||
{
|
||||
VkBuffer vk_buffer;
|
||||
VkDeviceMemory vk_memory;
|
||||
VkDeviceSize size;
|
||||
struct vkd3d_memory_allocation allocation;
|
||||
VkDeviceSize offset;
|
||||
VkDeviceAddress va;
|
||||
};
|
||||
|
||||
#define VKD3D_QUERY_TYPE_INDEX_OCCLUSION (0u)
|
||||
|
|
Loading…
Reference in New Issue