Mesa (master): gallium/hud: don't use cso_context to restore VBs, constbuf 0 and sampler views

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 10:07:39 UTC 2021


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Dec 20 02:49:07 2020 -0500

gallium/hud: don't use cso_context to restore VBs, constbuf 0 and sampler views

These cso_context capabilities will be removed.

Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Zoltán Böszörményi <zboszor at gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8180>

---

 src/gallium/auxiliary/hud/hud_context.c | 52 ++++++++++++++++++++-------------
 src/gallium/auxiliary/hud/hud_context.h |  4 ++-
 src/gallium/auxiliary/hud/hud_private.h |  1 +
 src/gallium/frontends/dri/dri_context.c |  2 +-
 src/gallium/frontends/glx/xlib/xm_api.c |  2 +-
 src/gallium/frontends/nine/device9.c    |  2 +-
 src/gallium/frontends/wgl/stw_context.c |  2 +-
 7 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index bb614f76a95..cf98c59f087 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -40,6 +40,7 @@
 #include "hud/hud_context.h"
 #include "hud/hud_private.h"
 
+#include "frontend/api.h"
 #include "cso_cache/cso_context.h"
 #include "util/u_draw_quad.h"
 #include "util/format/u_format.h"
@@ -73,6 +74,7 @@ hud_draw_colored_prims(struct hud_context *hud, unsigned prim,
                        int xoffset, int yoffset, float yscale)
 {
    struct cso_context *cso = hud->cso;
+   struct pipe_context *pipe = hud->pipe;
    struct pipe_vertex_buffer vbuffer = {0};
 
    hud->constants.color[0] = r;
@@ -83,7 +85,7 @@ hud_draw_colored_prims(struct hud_context *hud, unsigned prim,
    hud->constants.translate[1] = (float) (yoffset * hud_scale);
    hud->constants.scale[0] = hud_scale;
    hud->constants.scale[1] = yscale * hud_scale;
-   cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
+   pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
    u_upload_data(hud->pipe->stream_uploader, 0,
                  num_vertices * 2 * sizeof(float), 16, buffer,
@@ -479,7 +481,6 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
                         CSO_BIT_BLEND |
                         CSO_BIT_DEPTH_STENCIL_ALPHA |
                         CSO_BIT_FRAGMENT_SHADER |
-                        CSO_BIT_FRAGMENT_SAMPLER_VIEWS |
                         CSO_BIT_FRAGMENT_SAMPLERS |
                         CSO_BIT_RASTERIZER |
                         CSO_BIT_VIEWPORT |
@@ -489,10 +490,8 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
                         CSO_BIT_TESSEVAL_SHADER |
                         CSO_BIT_VERTEX_SHADER |
                         CSO_BIT_VERTEX_ELEMENTS |
-                        CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
                         CSO_BIT_PAUSE_QUERIES |
                         CSO_BIT_RENDER_CONDITION));
-   cso_save_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
 
    /* set states */
    memset(&surf_templ, 0, sizeof(surf_templ));
@@ -538,10 +537,10 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
    cso_set_vertex_shader_handle(cso, hud->vs);
    cso_set_vertex_elements(cso, &hud->velems);
    cso_set_render_condition(cso, NULL, FALSE, 0);
-   cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, 1,
-                         &hud->font_sampler_view);
+   pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1,
+                           &hud->font_sampler_view);
    cso_set_samplers(cso, PIPE_SHADER_FRAGMENT, 1, sampler_states);
-   cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
+   pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
    /* draw accumulated vertices for background quads */
    cso_set_blend(cso, &hud->alpha_blend);
@@ -557,7 +556,7 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
       hud->constants.scale[0] = hud_scale;
       hud->constants.scale[1] = hud_scale;
 
-      cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
+      pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
       cso_set_vertex_buffers(cso, 0, 1, &hud->bg.vbuf);
       cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->bg.num_vertices);
@@ -572,13 +571,8 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
    }
    pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
 
-   if (hud->simple) {
-      cso_restore_state(cso);
-      cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
-
-      pipe_surface_reference(&surf, NULL);
-      return;
-   }
+   if (hud->simple)
+      goto done;
 
    /* draw accumulated vertices for white lines */
    cso_set_blend(cso, &hud->no_blend);
@@ -591,7 +585,7 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
    hud->constants.translate[1] = 0;
    hud->constants.scale[0] = hud_scale;
    hud->constants.scale[1] = hud_scale;
-   cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
+   pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
    if (hud->whitelines.num_vertices) {
       cso_set_vertex_buffers(cso, 0, 1, &hud->whitelines.vbuf);
@@ -608,8 +602,21 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
          hud_pane_draw_colored_objects(hud, pane);
    }
 
+done:
    cso_restore_state(cso);
-   cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
+
+   /* Unbind resources that we have bound. */
+   pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, NULL);
+   pipe->set_vertex_buffers(pipe, 0, 1, NULL);
+   pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, NULL);
+
+   /* restore states not restored by cso */
+   if (hud->st) {
+      hud->st->invalidate_state(hud->st,
+                                ST_INVALIDATE_FS_SAMPLER_VIEWS |
+                                ST_INVALIDATE_VS_CONSTBUF0 |
+                                ST_INVALIDATE_VERTEX_BUFFERS);
+   }
 
    pipe_surface_reference(&surf, NULL);
 }
@@ -1638,13 +1645,15 @@ hud_unset_draw_context(struct hud_context *hud)
 }
 
 static bool
-hud_set_draw_context(struct hud_context *hud, struct cso_context *cso)
+hud_set_draw_context(struct hud_context *hud, struct cso_context *cso,
+                     struct st_context_iface *st)
 {
    struct pipe_context *pipe = cso_get_pipe_context(cso);
 
    assert(!hud->pipe);
    hud->pipe = pipe;
    hud->cso = cso;
+   hud->st = st;
 
    struct pipe_sampler_view view_templ;
    u_sampler_view_default_template(
@@ -1770,7 +1779,8 @@ hud_set_record_context(struct hud_context *hud, struct pipe_context *pipe)
  * record queries in one context and draw them in another.
  */
 struct hud_context *
-hud_create(struct cso_context *cso, struct hud_context *share)
+hud_create(struct cso_context *cso, struct st_context_iface *st,
+           struct hud_context *share)
 {
    const char *share_env = debug_get_option("GALLIUM_HUD_SHARE", NULL);
    unsigned record_ctx = 0, draw_ctx = 0;
@@ -1794,7 +1804,7 @@ hud_create(struct cso_context *cso, struct hud_context *share)
 
       if (context_id == draw_ctx) {
          assert(!share->pipe);
-         hud_set_draw_context(share, cso);
+         hud_set_draw_context(share, cso, st);
       }
 
       return share;
@@ -1901,7 +1911,7 @@ hud_create(struct cso_context *cso, struct hud_context *share)
    if (record_ctx == 0)
       hud_set_record_context(hud, cso_get_pipe_context(cso));
    if (draw_ctx == 0)
-      hud_set_draw_context(hud, cso);
+      hud_set_draw_context(hud, cso, st);
 
    hud_parse_env_var(hud, screen, env);
    return hud;
diff --git a/src/gallium/auxiliary/hud/hud_context.h b/src/gallium/auxiliary/hud/hud_context.h
index 99e6f8d7e67..ed5dd5dbff2 100644
--- a/src/gallium/auxiliary/hud/hud_context.h
+++ b/src/gallium/auxiliary/hud/hud_context.h
@@ -33,9 +33,11 @@ struct cso_context;
 struct pipe_context;
 struct pipe_resource;
 struct util_queue_monitoring;
+struct st_context_iface;
 
 struct hud_context *
-hud_create(struct cso_context *cso, struct hud_context *share);
+hud_create(struct cso_context *cso, struct st_context_iface *st,
+           struct hud_context *share);
 
 void
 hud_destroy(struct hud_context *hud, struct cso_context *cso);
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index c95f4c42b44..4caa99f3c72 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -50,6 +50,7 @@ struct hud_context {
    /* Context where the HUD is drawn: */
    struct pipe_context *pipe;
    struct cso_context *cso;
+   struct st_context_iface *st;
 
    struct hud_batch_query_context *batch_query;
    struct list_head pane_list;
diff --git a/src/gallium/frontends/dri/dri_context.c b/src/gallium/frontends/dri/dri_context.c
index 6e53ca90ad4..a40efa8658d 100644
--- a/src/gallium/frontends/dri/dri_context.c
+++ b/src/gallium/frontends/dri/dri_context.c
@@ -193,7 +193,7 @@ dri_create_context(gl_api api, const struct gl_config * visual,
 
    if (ctx->st->cso_context) {
       ctx->pp = pp_init(ctx->st->pipe, screen->pp_enabled, ctx->st->cso_context);
-      ctx->hud = hud_create(ctx->st->cso_context,
+      ctx->hud = hud_create(ctx->st->cso_context, ctx->st,
                             share_ctx ? share_ctx->hud : NULL);
    }
 
diff --git a/src/gallium/frontends/glx/xlib/xm_api.c b/src/gallium/frontends/glx/xlib/xm_api.c
index c3ce20faba4..458d7d42696 100644
--- a/src/gallium/frontends/glx/xlib/xm_api.c
+++ b/src/gallium/frontends/glx/xlib/xm_api.c
@@ -1029,7 +1029,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list,
 
    c->st->st_manager_private = (void *) c;
 
-   c->hud = hud_create(c->st->cso_context, NULL);
+   c->hud = hud_create(c->st->cso_context, c->st, NULL);
 
    return c;
 
diff --git a/src/gallium/frontends/nine/device9.c b/src/gallium/frontends/nine/device9.c
index 30791ab914a..badf65258b5 100644
--- a/src/gallium/frontends/nine/device9.c
+++ b/src/gallium/frontends/nine/device9.c
@@ -233,7 +233,7 @@ NineDevice9_ctor( struct NineDevice9 *This,
     if (!This->cso_sw) { return E_OUTOFMEMORY; }
 
     /* Create first, it messes up our state. */
-    This->hud = hud_create(This->context.cso, NULL); /* NULL result is fine */
+    This->hud = hud_create(This->context.cso, NULL, NULL); /* NULL result is fine */
 
     /* Available memory counter. Updated only for allocations with this device
      * instance. This is the Win 7 behavior.
diff --git a/src/gallium/frontends/wgl/stw_context.c b/src/gallium/frontends/wgl/stw_context.c
index 8f7150eb6df..9a909ebfcc0 100644
--- a/src/gallium/frontends/wgl/stw_context.c
+++ b/src/gallium/frontends/wgl/stw_context.c
@@ -278,7 +278,7 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, DHGLRC hShareContext,
    ctx->st->st_manager_private = (void *) ctx;
 
    if (ctx->st->cso_context) {
-      ctx->hud = hud_create(ctx->st->cso_context, NULL);
+      ctx->hud = hud_create(ctx->st->cso_context, ctx->st, NULL);
    }
 
    stw_lock_contexts(stw_dev);



More information about the mesa-commit mailing list