vkd3d: Align allocated GPU address ranges to the requested resource alignment.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans-Kristian Arntzen 2019-10-24 18:03:40 +03:30 committed by Alexandre Julliard
parent 2155748c41
commit c7916314dc
3 changed files with 21 additions and 11 deletions

View File

@ -1823,18 +1823,33 @@ static void d3d12_device_destroy_pipeline_cache(struct d3d12_device *device)
}
D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_allocator *allocator,
size_t size, void *ptr)
size_t alignment, size_t size, void *ptr)
{
D3D12_GPU_VIRTUAL_ADDRESS ceiling = ~(D3D12_GPU_VIRTUAL_ADDRESS)0;
struct vkd3d_gpu_va_allocation *allocation;
D3D12_GPU_VIRTUAL_ADDRESS base, ceiling;
int rc;
if (size > ~(size_t)0 - (alignment - 1))
return 0;
size = align(size, alignment);
if ((rc = pthread_mutex_lock(&allocator->mutex)))
{
ERR("Failed to lock mutex, error %d.\n", rc);
return 0;
}
base = allocator->floor;
ceiling = ~(D3D12_GPU_VIRTUAL_ADDRESS)0;
ceiling -= alignment - 1;
if (size > ceiling || ceiling - size < base)
{
pthread_mutex_unlock(&allocator->mutex);
return 0;
}
base = (base + (alignment - 1)) & ~((D3D12_GPU_VIRTUAL_ADDRESS)alignment - 1);
if (!vkd3d_array_reserve((void **)&allocator->allocations, &allocator->allocations_size,
allocator->allocation_count + 1, sizeof(*allocator->allocations)))
{
@ -1842,18 +1857,12 @@ D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_al
return 0;
}
if (size > ceiling || ceiling - size < allocator->floor)
{
pthread_mutex_unlock(&allocator->mutex);
return 0;
}
allocation = &allocator->allocations[allocator->allocation_count++];
allocation->base = allocator->floor;
allocation->base = base;
allocation->size = size;
allocation->ptr = ptr;
allocator->floor += size;
allocator->floor = base + size;
pthread_mutex_unlock(&allocator->mutex);

View File

@ -1684,6 +1684,7 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12
&resource->desc, &resource->u.vk_buffer)))
return hr;
if (!(resource->gpu_address = vkd3d_gpu_va_allocator_allocate(&device->gpu_va_allocator,
desc->Alignment ? desc->Alignment : D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
desc->Width, resource)))
{
ERR("Failed to allocate GPU VA.\n");

View File

@ -219,7 +219,7 @@ struct vkd3d_gpu_va_allocator
};
D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_allocator *allocator,
size_t size, void *ptr) DECLSPEC_HIDDEN;
size_t alignment, size_t size, void *ptr) DECLSPEC_HIDDEN;
void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocator,
D3D12_GPU_VIRTUAL_ADDRESS address) DECLSPEC_HIDDEN;
void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator,