Mesa (master): gallium/st: lower point-sprites if not supported

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 25 17:57:08 UTC 2021


Module: Mesa
Branch: master
Commit: 3b705ea511b38e064a482e1b27c1b89f86357f81
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3b705ea511b38e064a482e1b27c1b89f86357f81

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Wed Aug 26 18:48:52 2020 +0200

gallium/st: lower point-sprites if not supported

Not all drivers supports the texcoord replacement needed for
point-sprites, but all drivers support gl_PointCoord. So let's lower
this so we can support point-sprites for all drivers.

Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6473>

---

 src/mesa/state_tracker/st_atom_shader.c | 5 +++++
 src/mesa/state_tracker/st_context.c     | 8 +++++++-
 src/mesa/state_tracker/st_context.h     | 1 +
 src/mesa/state_tracker/st_extensions.c  | 3 +++
 src/mesa/state_tracker/st_program.c     | 7 +++++++
 src/mesa/state_tracker/st_program.h     | 1 +
 6 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 7f0a18ab53d..4e7bbb7aa21 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -115,6 +115,11 @@ st_update_fp( struct st_context *st )
       key.lower_two_sided_color = st->lower_two_sided_color &&
          _mesa_vertex_program_two_side_enabled(st->ctx);
 
+      /* _NEW_POINT | _NEW_PROGRAM */
+      if (st->lower_texcoord_replace && st->ctx->Point.PointSprite &&
+          st->ctx->Point.CoordReplace)
+         key.lower_texcoord_replace = st->ctx->Point.CoordReplace;
+
       /* gl_driver_flags::NewFragClamp */
       key.clamp_color = st->clamp_frag_color_in_shader &&
                         st->ctx->Color._ClampFragmentColor;
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index a035d792ce0..e5ca9de1288 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -234,6 +234,9 @@ st_invalidate_state(struct gl_context *ctx)
        st_user_clip_planes_enabled(ctx))
       st->dirty |= ST_NEW_CLIP_STATE;
 
+   if (new_state & _NEW_POINT && st->lower_texcoord_replace)
+      st->dirty |= ST_NEW_FS_STATE;
+
    if (new_state & _NEW_PIXEL)
       st->dirty |= ST_NEW_PIXEL_TRANSFER;
 
@@ -713,6 +716,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       screen->get_param(screen, PIPE_CAP_PREFER_REAL_BUFFER_IN_CONSTBUF0);
    st->has_conditional_render =
       screen->get_param(screen, PIPE_CAP_CONDITIONAL_RENDER);
+   st->lower_texcoord_replace =
+      !screen->get_param(screen, PIPE_CAP_POINT_SPRITE);
    st->allow_st_finalize_nir_twice = screen->finalize_nir != NULL;
 
    st->has_hw_atomics =
@@ -803,7 +808,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
          !st->clamp_frag_color_in_shader &&
          !st->clamp_frag_depth_in_shader &&
          !st->force_persample_in_shader &&
-         !st->lower_two_sided_color;
+         !st->lower_two_sided_color &&
+         !st->lower_texcoord_replace;
 
    st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
    st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] =
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index b8246ddb5dc..f7b5ef61d02 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -160,6 +160,7 @@ struct st_context
    boolean lower_ucp;
    boolean prefer_real_buffer_in_constbuf0;
    boolean has_conditional_render;
+   boolean lower_texcoord_replace;
 
    /* There are consequences for drivers wanting to call st_finalize_nir
     * twice, once before shader caching and once after lowering for shader
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 3712f70ab5b..68f36facc7a 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -1781,4 +1781,7 @@ void st_init_extensions(struct pipe_screen *screen,
        extensions->ARB_stencil_texturing &&
        !(nir_options->lower_doubles_options & nir_lower_fp64_full_software))
       extensions->NV_copy_depth_to_color = TRUE;
+
+   if (prefer_nir)
+         extensions->ARB_point_sprite = GL_TRUE;
 }
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index c8c812a6fe9..e1783e47b5e 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1290,6 +1290,13 @@ st_create_fp_variant(struct st_context *st,
           finalize = true;
       }
 
+      if (key->lower_texcoord_replace) {
+         bool point_coord_is_sysval = st->ctx->Const.GLSLPointCoordIsSysVal;
+         NIR_PASS_V(state.ir.nir, nir_lower_texcoord_replace,
+                    key->lower_texcoord_replace, point_coord_is_sysval);
+         finalize = true;
+      }
+
       assert(!(key->bitmap && key->drawpixels));
 
       /* glBitmap */
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 157339e34a3..f87339a5472 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -144,6 +144,7 @@ struct st_fp_variant_key
    GLuint lower_two_sided_color:1;
 
    GLuint lower_flatshade:1;
+   GLuint lower_texcoord_replace:MAX_TEXTURE_COORD_UNITS;
    unsigned lower_alpha_func:3;
 
    /** needed for ATI_fragment_shader */



More information about the mesa-commit mailing list