zink: implement Vk_EXT_index_type_uint8
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 1 Jul 2020 13:13:35 +0000 (09:13 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Jul 2020 07:11:27 +0000 (07:11 +0000)
this is a simple extension that enables using uint8-sized index buffers,
which lets us avoid having those go through primconvert

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5712>

src/gallium/drivers/zink/zink_draw.c
src/gallium/drivers/zink/zink_screen.c
src/gallium/drivers/zink/zink_screen.h

index 7d73a1231ea5d745647366f27c524104deb68d7e..7ffd3e800c6425a75c27bc21a6fa69bcea52cb7b 100644 (file)
@@ -210,7 +210,7 @@ zink_draw_vbo(struct pipe_context *pctx,
 
    if (dinfo->mode >= PIPE_PRIM_QUADS ||
        dinfo->mode == PIPE_PRIM_LINE_LOOP ||
-       dinfo->index_size == 1) {
+       (dinfo->index_size == 1 && !screen->have_EXT_index_type_uint8)) {
       if (!u_trim_pipe_prim(dinfo->mode, (unsigned *)&dinfo->count))
          return;
 
@@ -424,8 +424,21 @@ zink_draw_vbo(struct pipe_context *pctx,
    }
 
    if (dinfo->index_size > 0) {
-      assert(dinfo->index_size != 1);
-      VkIndexType index_type = dinfo->index_size == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;
+      VkIndexType index_type;
+      switch (dinfo->index_size) {
+      case 1:
+         assert(screen->have_EXT_index_type_uint8);
+         index_type = VK_INDEX_TYPE_UINT8_EXT;
+         break;
+      case 2:
+         index_type = VK_INDEX_TYPE_UINT16;
+         break;
+      case 4:
+         index_type = VK_INDEX_TYPE_UINT32;
+         break;
+      default:
+         unreachable("unknown index size!");
+      }
       struct zink_resource *res = zink_resource(index_buffer);
       vkCmdBindIndexBuffer(batch->cmdbuf, res->buffer, index_offset, index_type);
       zink_batch_reference_resoure(batch, res);
index 6e5f969fcdc522c45b4537a21ae342a71364af2b..ba75b57bcc805af797f06f5758c8e75fbae99894 100644 (file)
@@ -759,7 +759,7 @@ static struct pipe_screen *
 zink_internal_create_screen(struct sw_winsys *winsys, int fd)
 {
    struct zink_screen *screen = CALLOC_STRUCT(zink_screen);
-   bool have_tf_ext = false, have_cond_render_ext = false;
+   bool have_tf_ext = false, have_cond_render_ext = false, have_EXT_index_type_uint8 = false;
    if (!screen)
       return NULL;
 
@@ -798,6 +798,9 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
             if (!strcmp(extensions[i].extensionName,
                         VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME))
                have_tf_ext = true;
+            if (!strcmp(extensions[i].extensionName,
+                        VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME))
+               have_EXT_index_type_uint8 = true;
 
          }
          FREE(extensions);
@@ -806,6 +809,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
    VkPhysicalDeviceFeatures2 feats = {};
    VkPhysicalDeviceTransformFeedbackFeaturesEXT tf_feats = {};
    VkPhysicalDeviceConditionalRenderingFeaturesEXT cond_render_feats = {};
+   VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_uint8_feats = {};
 
    feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
    if (have_tf_ext) {
@@ -818,12 +822,19 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
       cond_render_feats.pNext = feats.pNext;
       feats.pNext = &cond_render_feats;
    }
+   if (have_EXT_index_type_uint8) {
+      index_uint8_feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
+      index_uint8_feats.pNext = feats.pNext;
+      feats.pNext = &index_uint8_feats;
+   }
    vkGetPhysicalDeviceFeatures2(screen->pdev, &feats);
    memcpy(&screen->feats, &feats.features, sizeof(screen->feats));
    if (have_tf_ext && tf_feats.transformFeedback)
       screen->have_EXT_transform_feedback = true;
    if (have_cond_render_ext && cond_render_feats.conditionalRendering)
       screen->have_EXT_conditional_rendering = true;
+   if (have_EXT_index_type_uint8 && index_uint8_feats.indexTypeUint8)
+      screen->have_EXT_index_type_uint8 = true;
 
    VkPhysicalDeviceProperties2 props = {};
    props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
@@ -855,7 +866,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
     * this requires us to pass the whole VkPhysicalDeviceFeatures2 struct
     */
    dci.pNext = &feats;
-   const char *extensions[5] = {
+   const char *extensions[6] = {
       VK_KHR_MAINTENANCE1_EXTENSION_NAME,
    };
    num_extensions = 1;
@@ -873,6 +884,9 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
    if (screen->have_EXT_conditional_rendering)
       extensions[num_extensions++] = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME;
 
+   if (screen->have_EXT_index_type_uint8)
+      extensions[num_extensions++] = VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME;
+
    if (screen->have_EXT_transform_feedback)
       extensions[num_extensions++] = VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME;
    assert(num_extensions <= ARRAY_SIZE(extensions));
index e1138c9249f825621ee0cc02fa5acfcfb64208bc..4625116c80b8ba1de87932703227959250831edf 100644 (file)
@@ -54,6 +54,7 @@ struct zink_screen {
    bool have_KHR_external_memory_fd;
    bool have_EXT_conditional_rendering;
    bool have_EXT_transform_feedback;
+   bool have_EXT_index_type_uint8;
 
    bool have_X8_D24_UNORM_PACK32;
    bool have_D24_UNORM_S8_UINT;