zink: rework missing feature warnings
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 6 Apr 2022 18:24:03 +0000 (14:24 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 6 Apr 2022 22:52:12 +0000 (22:52 +0000)
the previous methodology triggered warnings any time a rasterizer state
was created with unsupported features without determining whether those
features would actually be used

a more optimal process is to check for missing features at pipeline creation,
as all the necessary info is now available, and spurious warnings can be avoided

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15778>

src/gallium/drivers/zink/zink_pipeline.c
src/gallium/drivers/zink/zink_state.c

index 978ee27aecd58a81ec1890ff2cee7336de0376d4..9ea46bd227ace3a6d526d280bb440c227b24a932 100644 (file)
@@ -242,12 +242,62 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
       rast_line_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
       rast_line_state.pNext = rast_state.pNext;
       rast_line_state.stippledLineEnable = VK_FALSE;
-      rast_line_state.lineRasterizationMode = hw_rast_state->line_mode;
+      rast_line_state.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
+
+      bool check_warn = false;
+      switch (primitive_topology) {
+      case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+      case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+      case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
+      case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
+         check_warn = true;
+         break;
+      default: break;
+      }
+      if (prog->nir[PIPE_SHADER_TESS_EVAL]) {
+         check_warn |= !prog->nir[PIPE_SHADER_TESS_EVAL]->info.tess.point_mode &&
+                       prog->nir[PIPE_SHADER_TESS_EVAL]->info.tess._primitive_mode == TESS_PRIMITIVE_ISOLINES;
+      }
+      if (prog->nir[PIPE_SHADER_GEOMETRY]) {
+         switch (prog->nir[PIPE_SHADER_GEOMETRY]->info.gs.output_primitive) {
+         case SHADER_PRIM_LINES:
+         case SHADER_PRIM_LINE_LOOP:
+         case SHADER_PRIM_LINE_STRIP:
+         case SHADER_PRIM_LINES_ADJACENCY:
+         case SHADER_PRIM_LINE_STRIP_ADJACENCY:
+            check_warn = true;
+            break;
+         default: break;
+         }
+      }
+
+      if (check_warn) {
+         const char *features[4][2] = {
+            [VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT] = {"",""},
+            [VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT] = {"rectangularLines", "stippledRectangularLines"},
+            [VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT] = {"bresenhamLines", "stippledBresenhamLines"},
+            [VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT] = {"smoothLines", "stippledSmoothLines"},
+         };
+         static bool warned[6] = {0};
+         const VkPhysicalDeviceLineRasterizationFeaturesEXT *line_feats = &screen->info.line_rast_feats;
+         /* line features can be represented as an array VkBool32[6],
+          * with the 3 base features preceding the 3 (matching) stippled features
+          */
+         const VkBool32 *feat = &line_feats->rectangularLines;
+         unsigned mode_idx = hw_rast_state->line_mode - VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
+         /* add base mode index, add 3 if stippling is enabled */
+         mode_idx += hw_rast_state->line_stipple_enable * 3;
+         if (*(feat + mode_idx))
+            rast_line_state.lineRasterizationMode = hw_rast_state->line_mode;
+         else
+            warn_missing_feature(warned[mode_idx], features[hw_rast_state->line_mode][hw_rast_state->line_stipple_enable]);
+      }
 
       if (hw_rast_state->line_stipple_enable) {
          dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_LINE_STIPPLE_EXT;
          rast_line_state.stippledLineEnable = VK_TRUE;
       }
+
       rast_state.pNext = &rast_line_state;
    }
    assert(state_count < ARRAY_SIZE(dynamicStateEnables));
index 0012a2933563d17f91855c327544337652c659a5..a9cb615cc37c620715f2f7d4bcec4f11b046754e 100644 (file)
@@ -561,18 +561,6 @@ line_width(float width, float granularity, const float range[2])
    return CLAMP(width, range[0], range[1]);
 }
 
-#define warn_line_feature(feat) \
-   do { \
-      static bool warned = false; \
-      if (!warned) { \
-         fprintf(stderr, "WARNING: Incorrect rendering will happen, " \
-                         "because the Vulkan device doesn't support " \
-                         "the %s feature of " \
-                         "VK_EXT_line_rasterization\n", feat); \
-         warned = true; \
-      } \
-   } while (0)
-
 static void *
 zink_create_rasterizer_state(struct pipe_context *pctx,
                              const struct pipe_rasterizer_state *rs_state)
@@ -603,56 +591,17 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
                        VK_FRONT_FACE_COUNTER_CLOCKWISE :
                        VK_FRONT_FACE_CLOCKWISE;
 
-   VkPhysicalDeviceLineRasterizationFeaturesEXT *line_feats =
-            &screen->info.line_rast_feats;
-   state->hw_state.line_mode =
-      VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
-
-   if (rs_state->line_stipple_enable) {
-      if (screen->info.have_EXT_line_rasterization) {
-         if (rs_state->line_rectangular) {
-            if (rs_state->line_smooth) {
-               if (line_feats->stippledSmoothLines)
-                  state->hw_state.line_mode =
-                     VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
-               else
-                  warn_line_feature("stippledSmoothLines");
-            } else if (line_feats->stippledRectangularLines)
-               state->hw_state.line_mode =
-                  VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
-            else
-               warn_line_feature("stippledRectangularLines");
-         } else if (line_feats->stippledBresenhamLines)
-            state->hw_state.line_mode =
-               VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
-         else {
-            warn_line_feature("stippledBresenhamLines");
-
-            /* no suitable mode that supports line stippling */
-            state->base.line_stipple_factor = 0;
-            state->base.line_stipple_pattern = UINT16_MAX;
-         }
-      }
+   state->hw_state.line_mode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
+   if (rs_state->line_rectangular) {
+      if (rs_state->line_smooth)
+         state->hw_state.line_mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
+      else
+         state->hw_state.line_mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
    } else {
-      if (screen->info.have_EXT_line_rasterization) {
-         if (rs_state->line_rectangular) {
-            if (rs_state->line_smooth) {
-               if (line_feats->smoothLines)
-                  state->hw_state.line_mode =
-                     VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
-               else
-                  warn_line_feature("smoothLines");
-            } else if (line_feats->rectangularLines)
-               state->hw_state.line_mode =
-                  VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
-            else
-               warn_line_feature("rectangularLines");
-         } else if (line_feats->bresenhamLines)
-            state->hw_state.line_mode =
-               VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
-         else
-            warn_line_feature("bresenhamLines");
-      }
+      state->hw_state.line_mode = VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
+   }
+
+   if (!rs_state->line_stipple_enable) {
       state->base.line_stipple_factor = 0;
       state->base.line_stipple_pattern = UINT16_MAX;
    }