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:
authorHans-Kristian Arntzen <post@arntzen-software.no>2019-10-24 17:33:40 +0300
committerAlexandre Julliard <julliard@winehq.org>2019-10-27 21:15:31 +0300
commitc7916314dc7ab0a379077773751331d323d946e0 (patch)
tree432ebfade8fa527811061194968ee48944ab8ff2
parent2155748c418e862a906c8c43ead382f30dd40de1 (diff)
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>
-rw-r--r--libs/vkd3d/device.c23
-rw-r--r--libs/vkd3d/resource.c1
-rw-r--r--libs/vkd3d/vkd3d_private.h2
3 files changed, 18 insertions, 8 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);
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 626772e9..f15c371e 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -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");
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 69b08a2d..520dab14 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -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,