turnip: implement VK_EXT_vertex_attribute_divisor
authorJonathan Marek <jonathan@marek.ca>
Wed, 24 Jun 2020 23:56:01 +0000 (19:56 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 25 Jun 2020 00:10:11 +0000 (00:10 +0000)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5640>

src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_extensions.py
src/freedreno/vulkan/tu_pipeline.c

index 63d33e531b4f8eb346f5b39055e78ed8de011ab8..225cfee376565c2e1deb7fc66a6170aec9a26b2f 100644 (file)
@@ -722,6 +722,13 @@ tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
          features->indexTypeUint8 = true;
          break;
       }
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
+         VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features =
+            (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *)ext;
+         features->vertexAttributeInstanceRateDivisor = true;
+         features->vertexAttributeInstanceRateZeroDivisor = true;
+         break;
+      }
       default:
          break;
       }
@@ -964,7 +971,12 @@ tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
          properties->quadOperationsInAllStages = false;
          break;
       }
-
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
+         VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *props =
+            (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *)ext;
+         props->maxVertexAttribDivisor = UINT32_MAX;
+         break;
+      }
       default:
          break;
       }
index 20539c7367e83b18a3df9f47370535efce4e06a6..9a14bb6c89f86a6f5fae352f93920d73db72d496 100644 (file)
@@ -80,6 +80,7 @@ EXTENSIONS = [
     Extension('VK_IMG_filter_cubic',                      1, 'device->gpu_id == 650'),
     Extension('VK_EXT_filter_cubic',                      1, 'device->gpu_id == 650'),
     Extension('VK_EXT_index_type_uint8',                  1, True),
+    Extension('VK_EXT_vertex_attribute_divisor',          1, True),
 ]
 
 MAX_API_VERSION = VkVersion(MAX_API_VERSION)
index 30c5361c56db6abd790f442fa1f8b9ba95020906..add032bcc74b6d28e804ac62681a2daca6248152 100644 (file)
@@ -1401,6 +1401,7 @@ tu6_emit_vertex_input(struct tu_cs *cs,
 {
    uint32_t vfd_decode_idx = 0;
    uint32_t binding_instanced = 0; /* bitmask of instanced bindings */
+   uint32_t step_rate[MAX_VBS];
 
    for (uint32_t i = 0; i < info->vertexBindingDescriptionCount; i++) {
       const VkVertexInputBindingDescription *binding =
@@ -1413,6 +1414,17 @@ tu6_emit_vertex_input(struct tu_cs *cs,
          binding_instanced |= 1 << binding->binding;
 
       *bindings_used |= 1 << binding->binding;
+      step_rate[binding->binding] = 1;
+   }
+
+   const VkPipelineVertexInputDivisorStateCreateInfoEXT *div_state =
+      vk_find_struct_const(info->pNext, PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT);
+   if (div_state) {
+      for (uint32_t i = 0; i < div_state->vertexBindingDivisorCount; i++) {
+         const VkVertexInputBindingDivisorDescriptionEXT *desc =
+            &div_state->pVertexBindingDivisors[i];
+         step_rate[desc->binding] = desc->divisor;
+      }
    }
 
    /* TODO: emit all VFD_DECODE/VFD_DEST_CNTL in same (two) pkt4 */
@@ -1422,6 +1434,8 @@ tu6_emit_vertex_input(struct tu_cs *cs,
          &info->pVertexAttributeDescriptions[i];
       uint32_t input_idx;
 
+      assert(*bindings_used & BIT(attr->binding));
+
       for (input_idx = 0; input_idx < vs->inputs_count; input_idx++) {
          if ((vs->inputs[input_idx].slot - VERT_ATTRIB_GENERIC0) == attr->location)
             break;
@@ -1441,7 +1455,7 @@ tu6_emit_vertex_input(struct tu_cs *cs,
                         .swap = format.swap,
                         .unk30 = 1,
                         ._float = !vk_format_is_int(attr->format)),
-                      A6XX_VFD_DECODE_STEP_RATE(vfd_decode_idx, 1));
+                      A6XX_VFD_DECODE_STEP_RATE(vfd_decode_idx, step_rate[attr->binding]));
 
       tu_cs_emit_regs(cs,
                       A6XX_VFD_DEST_CNTL_INSTR(vfd_decode_idx,