Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ValveSoftware/vkd3d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libs/vkd3d/device.c')
-rw-r--r--libs/vkd3d/device.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index d30c447c..2dee5e35 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -1823,37 +1823,46 @@ 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;
}
- if (!vkd3d_array_reserve((void **)&allocator->allocations, &allocator->allocations_size,
- allocator->allocation_count + 1, sizeof(*allocator->allocations)))
+ 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;
}
- if (size > ceiling || ceiling - size < allocator->floor)
+ 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)))
{
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);