From 05266333a0e977368a3ddc596bac0129640ee450 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Tue, 26 Jul 2022 12:09:36 +0200 Subject: [PATCH] tu: Fix descriptor set size bounds This old code looks like it was left around from anv. Make it use the limits the rest of the code uses. Part-of: --- src/freedreno/vulkan/tu_descriptor_set.c | 6 +++--- src/freedreno/vulkan/tu_descriptor_set.h | 8 ++++++++ src/freedreno/vulkan/tu_device.c | 14 ++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/freedreno/vulkan/tu_descriptor_set.c b/src/freedreno/vulkan/tu_descriptor_set.c index 7ddcd0eaffd..6b69f1ab064 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.c +++ b/src/freedreno/vulkan/tu_descriptor_set.c @@ -334,16 +334,16 @@ tu_GetDescriptorSetLayoutSupport( } else { descriptor_sz = descriptor_size(device, binding->descriptorType); } - uint64_t descriptor_alignment = 8; + uint64_t descriptor_alignment = 4 * A6XX_TEX_CONST_DWORDS; if (size && !ALIGN_POT(size, descriptor_alignment)) { supported = false; } size = ALIGN_POT(size, descriptor_alignment); - uint64_t max_count = UINT64_MAX; + uint64_t max_count = MAX_SET_SIZE; if (descriptor_sz) - max_count = (UINT64_MAX - size) / descriptor_sz; + max_count = (MAX_SET_SIZE - size) / descriptor_sz; if (max_count < binding->descriptorCount) { supported = false; diff --git a/src/freedreno/vulkan/tu_descriptor_set.h b/src/freedreno/vulkan/tu_descriptor_set.h index a45a065fbee..115f11355d3 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.h +++ b/src/freedreno/vulkan/tu_descriptor_set.h @@ -13,6 +13,14 @@ */ #define MAX_SETS 4 +/* I have no idea what the maximum size is, but the hardware supports very + * large numbers of descriptors (at least 2^16). This limit is based on + * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that + * we don't have to think about what to do if that overflows, but really + * nothing is likely to get close to this. + */ +#define MAX_SET_SIZE ((1 << 28) * 4) + struct tu_descriptor_set_binding_layout { VkDescriptorType type; diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index f58a576f9eb..1a67ac9466d 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -934,23 +934,17 @@ tu_get_physical_device_properties_1_1(struct tu_physical_device *pdevice, p->maxMultiviewViewCount = MAX_VIEWS; p->maxMultiviewInstanceIndex = INT_MAX; p->protectedNoFault = false; - /* Make sure everything is addressable by a signed 32-bit int, and - * our largest descriptors are 96 bytes. + /* Our largest descriptors are 2 texture descriptors, or a texture and + * sampler descriptor. */ - p->maxPerSetDescriptors = (1ull << 31) / 96; + p->maxPerSetDescriptors = MAX_SET_SIZE / (2 * A6XX_TEX_CONST_DWORDS * 4); /* Our buffer size fields allow only this much */ p->maxMemoryAllocationSize = 0xFFFFFFFFull; } -/* I have no idea what the maximum size is, but the hardware supports very - * large numbers of descriptors (at least 2^16). This limit is based on - * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that - * we don't have to think about what to do if that overflows, but really - * nothing is likely to get close to this. - */ -static const size_t max_descriptor_set_size = (1 << 28) / A6XX_TEX_CONST_DWORDS; +static const size_t max_descriptor_set_size = MAX_SET_SIZE / (4 * A6XX_TEX_CONST_DWORDS); static const VkSampleCountFlags sample_counts = VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT;