Mesa (main): gallium: explicitly specify line rasterization mode

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 12 22:31:23 UTC 2021


Module: Mesa
Branch: main
Commit: 1c2690ec2049f82b431fe259b10b3397b36db4a1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1c2690ec2049f82b431fe259b10b3397b36db4a1

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Wed Jul  7 11:44:20 2021 +0200

gallium: explicitly specify line rasterization mode

Currently, drivers infer the line rasterization mode from the
multisampling and line_smooth rasterization state. This is always
correct for OpenGL, but is subtly incorrect for DirectX 9, 10 and
Vulkan (when VK_EXT_line_rasterization is supported).

So let's allow front-ends to choose freely between rectangle and
paralellogram rendering.

The reason why there's no added cap for this, is that the implicit
selection that drivers currently do will work just as well (or more
correclty, just as subtly wrong) as before. And there's nothing
reasonable the front-ends can do to get the correct behavior, so
there's really no fall-back code to write either.

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

---

 src/gallium/frontends/d3d10umd/Rasterizer.cpp | 1 +
 src/gallium/frontends/lavapipe/lvp_execute.c  | 1 +
 src/gallium/frontends/lavapipe/lvp_pipeline.c | 5 ++++-
 src/gallium/frontends/lavapipe/lvp_private.h  | 1 +
 src/gallium/frontends/nine/nine_pipe.c        | 1 +
 src/gallium/include/pipe/p_state.h            | 1 +
 src/mesa/state_tracker/st_atom_rasterizer.c   | 2 ++
 7 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/gallium/frontends/d3d10umd/Rasterizer.cpp b/src/gallium/frontends/d3d10umd/Rasterizer.cpp
index 9402f383b31..df127c793c5 100644
--- a/src/gallium/frontends/d3d10umd/Rasterizer.cpp
+++ b/src/gallium/frontends/d3d10umd/Rasterizer.cpp
@@ -232,6 +232,7 @@ CreateRasterizerState(
    state.point_tri_clip = 1;
 
    state.line_width = 1.0f;
+   state.line_rectangular = 0;
 
    pRasterizerState->handle = pipe->create_rasterizer_state(pipe, &state);
 }
diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c
index 044934ef04b..dc403b8a6c9 100644
--- a/src/gallium/frontends/lavapipe/lvp_execute.c
+++ b/src/gallium/frontends/lavapipe/lvp_execute.c
@@ -510,6 +510,7 @@ static void handle_graphics_pipeline(struct lvp_cmd_buffer_entry *cmd,
       state->rs_state.half_pixel_center = true;
       state->rs_state.scissor = true;
       state->rs_state.no_ms_sample_mask_out = true;
+      state->rs_state.line_rectangular = pipeline->line_rectangular;
 
       if (!dynamic_states[VK_DYNAMIC_STATE_LINE_WIDTH])
          state->rs_state.line_width = rsc->lineWidth;
diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c
index 6ab4bbac9ac..a2a54bd99c9 100644
--- a/src/gallium/frontends/lavapipe/lvp_pipeline.c
+++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c
@@ -815,11 +815,14 @@ lvp_graphics_pipeline_init(struct lvp_pipeline *pipeline,
       pipeline->line_smooth = line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
       pipeline->disable_multisample = line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT ||
                                       line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
+      pipeline->line_rectangular = line_state->lineRasterizationMode != VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT &&
+                                   line_state->lineRasterizationMode != VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
       if (!dynamic_state_contains(pipeline->graphics_create_info.pDynamicState, VK_DYNAMIC_STATE_LINE_STIPPLE_EXT)) {
          pipeline->line_stipple_factor = line_state->lineStippleFactor - 1;
          pipeline->line_stipple_pattern = line_state->lineStipplePattern;
       }
-   }
+   } else
+      pipeline->line_rectangular = false;
 
 
    for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h
index 830b2e78b06..6def9d3d36d 100644
--- a/src/gallium/frontends/lavapipe/lvp_private.h
+++ b/src/gallium/frontends/lavapipe/lvp_private.h
@@ -484,6 +484,7 @@ struct lvp_pipeline {
    bool line_stipple_enable;
    bool line_smooth;
    bool disable_multisample;
+   bool line_rectangular;
    bool gs_output_lines;
    bool provoking_vertex_last;
 };
diff --git a/src/gallium/frontends/nine/nine_pipe.c b/src/gallium/frontends/nine/nine_pipe.c
index 4792e784a65..84644567ee7 100644
--- a/src/gallium/frontends/nine/nine_pipe.c
+++ b/src/gallium/frontends/nine/nine_pipe.c
@@ -116,6 +116,7 @@ nine_convert_rasterizer_state(struct NineDevice9 *device,
  /* rast.line_stipple_pattern = 0; */
     rast.sprite_coord_enable = rs[D3DRS_POINTSPRITEENABLE] ? 0xff : 0x00;
     rast.line_width = 1.0f;
+    rast.line_rectangular = 0;
     if (rs[NINED3DRS_VSPOINTSIZE]) {
         rast.point_size = 1.0f;
     } else {
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index f9027908b39..9c44e22b5af 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -117,6 +117,7 @@ struct pipe_rasterizer_state
    unsigned line_smooth:1;
    unsigned line_stipple_enable:1;
    unsigned line_last_pixel:1;
+   unsigned line_rectangular:1; /** lines rasterized as rectangles or parallelograms */
    unsigned conservative_raster_mode:2; /**< PIPE_CONSERVATIVE_RASTER_x */
 
    /**
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index dec747b9ea7..3f8dd67da32 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -246,6 +246,8 @@ st_update_rasterizer(struct st_context *st)
                                  ctx->Const.MaxLineWidth);
    }
 
+   raster->line_rectangular = multisample || ctx->Line.SmoothFlag;
+
    /* When the pattern is all 1's, it means line stippling is disabled */
    raster->line_stipple_enable = ctx->Line.StippleFlag && ctx->Line.StipplePattern != 0xffff;
    raster->line_stipple_pattern = ctx->Line.StipplePattern;



More information about the mesa-commit mailing list