v3dv: implement VK_EXT_line_rasterization
authorJuan A. Suarez Romero <jasuarez@igalia.com>
Thu, 17 Mar 2022 11:20:41 +0000 (12:20 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 18 Mar 2022 09:38:38 +0000 (09:38 +0000)
Allow to choose the line rasterization algorithm. It supports
rectangular and Bresenham-style line rasterization.

v2 (Iago):
 - Update documentation.

Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15407>

docs/features.txt
src/broadcom/vulkan/v3dv_cmd_buffer.c
src/broadcom/vulkan/v3dv_device.c
src/broadcom/vulkan/v3dv_pipeline.c
src/broadcom/vulkan/v3dvx_pipeline.c
src/broadcom/vulkan/v3dvx_private.h

index 10221dd..f2e92f9 100644 (file)
@@ -550,7 +550,7 @@ Khronos extensions that are not part of any Vulkan version:
   VK_EXT_image_drm_format_modifier                      DONE (anv, radv/gfx9+, tu, v3dv, vn)
   VK_EXT_image_view_min_lod                             DONE (radv)
   VK_EXT_index_type_uint8                               DONE (anv, lvp, radv/gfx8+, v3dv, tu)
-  VK_EXT_line_rasterization                             DONE (anv, lvp, radv, tu)
+  VK_EXT_line_rasterization                             DONE (anv, lvp, radv, tu, v3dv)
   VK_EXT_memory_budget                                  DONE (anv, radv, tu)
   VK_EXT_memory_priority                                DONE (radv)
   VK_EXT_multi_draw                                     DONE (anv, lvp, radv)
index 5938654..ee0cfb7 100644 (file)
@@ -2823,6 +2823,14 @@ v3dv_CmdSetDepthBounds(VkCommandBuffer commandBuffer,
 }
 
 VKAPI_ATTR void VKAPI_CALL
+v3dv_CmdSetLineStippleEXT(VkCommandBuffer commandBuffer,
+                          uint32_t lineStippleFactor,
+                          uint16_t lineStipplePattern)
+{
+   /* We do not support stippled line rasterization so we just ignore this. */
+}
+
+VKAPI_ATTR void VKAPI_CALL
 v3dv_CmdSetLineWidth(VkCommandBuffer commandBuffer,
                      float lineWidth)
 {
index 9cc4511..bc83215 100644 (file)
@@ -157,6 +157,7 @@ get_device_extensions(const struct v3dv_physical_device *device,
       .EXT_host_query_reset                = true,
       .EXT_image_drm_format_modifier       = true,
       .EXT_index_type_uint8                = true,
+      .EXT_line_rasterization              = true,
       .EXT_physical_device_drm             = true,
       .EXT_pipeline_creation_cache_control = true,
       .EXT_pipeline_creation_feedback      = true,
@@ -1158,6 +1159,18 @@ v3dv_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
          break;
       }
 
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT: {
+         VkPhysicalDeviceLineRasterizationFeaturesEXT *features =
+            (VkPhysicalDeviceLineRasterizationFeaturesEXT *)ext;
+         features->rectangularLines = true;
+         features->bresenhamLines = true;
+         features->smoothLines = false;
+         features->stippledRectangularLines = false;
+         features->stippledBresenhamLines = false;
+         features->stippledSmoothLines = false;
+         break;
+      }
+
       case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT: {
           VkPhysicalDeviceColorWriteEnableFeaturesEXT *features = (void *) ext;
           features->colorWriteEnable = true;
@@ -1598,6 +1611,12 @@ v3dv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
          }
          break;
       }
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT: {
+         VkPhysicalDeviceLineRasterizationPropertiesEXT *props =
+            (VkPhysicalDeviceLineRasterizationPropertiesEXT *)ext;
+         props->lineSubPixelPrecisionBits = V3D_COORD_SHIFT;
+         break;
+      }
       case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
          VkPhysicalDeviceMaintenance3Properties *props =
             (VkPhysicalDeviceMaintenance3Properties *)ext;
index 31d5b6e..4a7d7ad 100644 (file)
@@ -2987,6 +2987,12 @@ pipeline_init(struct v3dv_pipeline *pipeline,
          PIPELINE_RASTERIZATION_PROVOKING_VERTEX_STATE_CREATE_INFO_EXT) :
             NULL;
 
+   const VkPipelineRasterizationLineStateCreateInfoEXT *ls_info =
+      rs_info ? vk_find_struct_const(
+         rs_info->pNext,
+         PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT) :
+            NULL;
+
    const VkPipelineColorBlendStateCreateInfo *cb_info =
       raster_enabled ? pCreateInfo->pColorBlendState : NULL;
 
@@ -3008,7 +3014,8 @@ pipeline_init(struct v3dv_pipeline *pipeline,
    assert(!ds_info || !ds_info->depthBoundsTestEnable);
 
    v3dv_X(device, pipeline_pack_state)(pipeline, cb_info, ds_info,
-                                       rs_info, pv_info, ms_info);
+                                       rs_info, pv_info, ls_info,
+                                       ms_info);
 
    pipeline_set_ez_state(pipeline, ds_info);
    enable_depth_bias(pipeline, rs_info);
index 1cf6b74..01f406a 100644 (file)
@@ -146,6 +146,7 @@ pack_cfg_bits(struct v3dv_pipeline *pipeline,
               const VkPipelineDepthStencilStateCreateInfo *ds_info,
               const VkPipelineRasterizationStateCreateInfo *rs_info,
               const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *pv_info,
+              const VkPipelineRasterizationLineStateCreateInfoEXT *ls_info,
               const VkPipelineMultisampleStateCreateInfo *ms_info)
 {
    assert(sizeof(pipeline->cfg_bits) == cl_packet_length(CFG_BITS));
@@ -170,14 +171,22 @@ pack_cfg_bits(struct v3dv_pipeline *pipeline,
        * exposing, at least, a minimum of 4-bits of subpixel precision
        * (the minimum requirement).
        */
-      config.line_rasterization = V3D_LINE_RASTERIZATION_PERP_END_CAPS;
+      if (ls_info &&
+          ls_info->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT)
+         config.line_rasterization = V3D_LINE_RASTERIZATION_DIAMOND_EXIT;
+      else
+         config.line_rasterization = V3D_LINE_RASTERIZATION_PERP_END_CAPS;
+
       if (rs_info && rs_info->polygonMode != VK_POLYGON_MODE_FILL) {
          config.direct3d_wireframe_triangles_mode = true;
          config.direct3d_point_fill_mode =
             rs_info->polygonMode == VK_POLYGON_MODE_POINT;
       }
 
-      config.rasterizer_oversample_mode = pipeline->msaa ? 1 : 0;
+      /* diamond-exit rasterization does not suport oversample */
+      config.rasterizer_oversample_mode =
+         (config.line_rasterization == V3D_LINE_RASTERIZATION_PERP_END_CAPS &&
+          pipeline->msaa) ? 1 : 0;
 
       /* From the Vulkan spec:
        *
@@ -341,10 +350,11 @@ v3dX(pipeline_pack_state)(struct v3dv_pipeline *pipeline,
                           const VkPipelineDepthStencilStateCreateInfo *ds_info,
                           const VkPipelineRasterizationStateCreateInfo *rs_info,
                           const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *pv_info,
+                          const VkPipelineRasterizationLineStateCreateInfoEXT *ls_info,
                           const VkPipelineMultisampleStateCreateInfo *ms_info)
 {
    pack_blend(pipeline, cb_info);
-   pack_cfg_bits(pipeline, ds_info, rs_info, pv_info, ms_info);
+   pack_cfg_bits(pipeline, ds_info, rs_info, pv_info, ls_info, ms_info);
    pack_stencil_cfg(pipeline, ds_info);
 }
 
index 2109daa..5945273 100644 (file)
@@ -300,6 +300,7 @@ v3dX(pipeline_pack_state)(struct v3dv_pipeline *pipeline,
                           const VkPipelineDepthStencilStateCreateInfo *ds_info,
                           const VkPipelineRasterizationStateCreateInfo *rs_info,
                           const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *pv_info,
+                          const VkPipelineRasterizationLineStateCreateInfoEXT *ls_info,
                           const VkPipelineMultisampleStateCreateInfo *ms_info);
 void
 v3dX(pipeline_pack_compile_state)(struct v3dv_pipeline *pipeline,