Avoids value truncation in 32-bit builds and fixes clang warning: ``` ../libs/vkd3d/libs/vkd3d/device.c:2157:14: warning: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always true [-Wtautological-constant-out-of-range-compare] if (size <= VKD3D_VA_SLAB_SIZE && allocator->free_slab) ~~~~ ^ ~~~~~~~~~~~~~~~~~~ ```
-- v2: vkd3d: Use uint64_t for the size in vkd3d_gpu_va_allocator_allocate.
From: Jacek Caban jacek@codeweavers.com
Avoids value truncation in 32-bit builds. --- include/private/vkd3d_common.h | 2 +- libs/vkd3d/device.c | 14 +++++++------- libs/vkd3d/vkd3d_private.h | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index 46090eac1..01e219b30 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -71,7 +71,7 @@ #define TAG_XNAP VKD3D_MAKE_TAG('X', 'N', 'A', 'P') #define TAG_XNAS VKD3D_MAKE_TAG('X', 'N', 'A', 'S')
-static inline size_t align(size_t addr, size_t alignment) +static inline uint64_t align(uint64_t addr, size_t alignment) { return (addr + (alignment - 1)) & ~(alignment - 1); } diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 3f63e6040..b08eadc52 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2133,7 +2133,7 @@ static void d3d12_device_destroy_pipeline_cache(struct d3d12_device *device) #define VKD3D_VA_SLAB_COUNT (64 * 1024)
static D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate_slab(struct vkd3d_gpu_va_allocator *allocator, - size_t aligned_size, void *ptr) + uint64_t aligned_size, void *ptr) { struct vkd3d_gpu_va_slab *slab; D3D12_GPU_VIRTUAL_ADDRESS address; @@ -2149,13 +2149,13 @@ static D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate_slab(struct vkd slab_idx = slab - allocator->slabs; address = VKD3D_VA_SLAB_BASE + slab_idx * VKD3D_VA_SLAB_SIZE;
- TRACE("Allocated address %#"PRIx64", slab %u, size %zu.\n", address, slab_idx, aligned_size); + TRACE("Allocated address %#"PRIx64", slab %u, size %"PRIu64".\n", address, slab_idx, aligned_size);
return address; }
static D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate_fallback(struct vkd3d_gpu_va_allocator *allocator, - size_t alignment, size_t aligned_size, void *ptr) + size_t alignment, uint64_t aligned_size, void *ptr) { struct vkd3d_gpu_va_allocation *allocation; D3D12_GPU_VIRTUAL_ADDRESS base, ceiling; @@ -2181,17 +2181,17 @@ static D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate_fallback(struct * only fail once we have exhausted 63 bits of address space. */ allocator->fallback_floor = base + aligned_size;
- TRACE("Allocated address %#"PRIx64", size %zu.\n", base, aligned_size); + TRACE("Allocated address %#"PRIx64", size %"PRIu64".\n", base, aligned_size);
return base; }
D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_allocator *allocator, - size_t alignment, size_t size, void *ptr) + size_t alignment, uint64_t size, void *ptr) { D3D12_GPU_VIRTUAL_ADDRESS address;
- if (size > ~(size_t)0 - (alignment - 1)) + if (size > ~(uint64_t)0 - (alignment - 1)) return 0; size = align(size, alignment);
@@ -2227,7 +2227,7 @@ static void *vkd3d_gpu_va_allocator_dereference_slab(struct vkd3d_gpu_va_allocat base_offset -= slab_idx * VKD3D_VA_SLAB_SIZE; if (base_offset >= slab->size) { - ERR("Address %#"PRIx64" is %#"PRIx64" bytes into slab %u of size %zu.\n", + ERR("Address %#"PRIx64" is %#"PRIx64" bytes into slab %u of size %"PRIu64".\n", address, base_offset, slab_idx, slab->size); return NULL; } diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index ec83d350e..325cae826 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -493,13 +493,13 @@ struct vkd3d_fence_worker struct vkd3d_gpu_va_allocation { D3D12_GPU_VIRTUAL_ADDRESS base; - size_t size; + uint64_t size; void *ptr; };
struct vkd3d_gpu_va_slab { - size_t size; + uint64_t size; void *ptr; };
@@ -517,7 +517,7 @@ struct vkd3d_gpu_va_allocator };
D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_allocator *allocator, - size_t alignment, size_t size, void *ptr); + size_t alignment, uint64_t size, void *ptr); void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocator, D3D12_GPU_VIRTUAL_ADDRESS address); void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator, D3D12_GPU_VIRTUAL_ADDRESS address);
This merge request was approved by Henri Verbeet.