tu: Fix descriptor set size bounds
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 26 Jul 2022 10:09:36 +0000 (12:09 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 14 Sep 2022 12:46:00 +0000 (12:46 +0000)
This old code looks like it was left around from anv. Make it use the
limits the rest of the code uses.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17960>

src/freedreno/vulkan/tu_descriptor_set.c
src/freedreno/vulkan/tu_descriptor_set.h
src/freedreno/vulkan/tu_device.c

index 7ddcd0e..6b69f1a 100644 (file)
@@ -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;
index a45a065..115f113 100644 (file)
  */
 #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;
index f58a576..1a67ac9 100644 (file)
@@ -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;