[RFC PATCH 09/17] etnaviv: become independed of the used compiler backend

Christian Gmeiner christian.gmeiner at gmail.com
Fri May 10 09:09:07 UTC 2019


This change preps etnaviv to be able to swap the used compiler
backend easily. It takes care of uniform stuff and the actual
creation of shader variants. In the long run - if one backend
won - we can remove this again.

Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
---
 src/gallium/drivers/etnaviv/etnaviv_context.c | 16 ++++++++++++----
 src/gallium/drivers/etnaviv/etnaviv_context.h | 18 +++++++++++++++++-
 src/gallium/drivers/etnaviv/etnaviv_emit.c    | 16 ++++++++--------
 src/gallium/drivers/etnaviv/etnaviv_shader.c  |  5 +++--
 src/gallium/drivers/etnaviv/etnaviv_shader.h  |  4 ++--
 src/gallium/drivers/etnaviv/etnaviv_state.c   | 16 ++++++++++++++--
 .../drivers/etnaviv/etnaviv_uniforms.c        | 19 ++++++++++++++++++-
 .../drivers/etnaviv/etnaviv_uniforms.h        |  8 +++++++-
 8 files changed, 81 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c
index a59338490b6..d78d8941087 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -44,6 +44,7 @@
 #include "etnaviv_texture.h"
 #include "etnaviv_transfer.h"
 #include "etnaviv_translate.h"
+#include "etnaviv_uniforms.h"
 #include "etnaviv_zsa.h"
 
 #include "pipe/p_context.h"
@@ -119,9 +120,9 @@ etna_update_state_for_draw(struct etna_context *ctx, const struct pipe_draw_info
 static bool
 etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
 {
-   const struct etna_shader_variant *old = ctx->shader.vs;
+   const void *old = ctx->shader.vs;
 
-   ctx->shader.vs = etna_shader_variant(ctx->shader.bind_vs, key, &ctx->debug);
+   ctx->shader.vs = ctx->create_shader_variant(ctx->shader.bind_vs, key, &ctx->debug);
 
    if (!ctx->shader.vs)
       return false;
@@ -135,9 +136,9 @@ etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
 static bool
 etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
 {
-   const struct etna_shader_variant *old = ctx->shader.fs;
+   const void *old = ctx->shader.fs;
 
-   ctx->shader.fs = etna_shader_variant(ctx->shader.bind_fs, key, &ctx->debug);
+   ctx->shader.fs = ctx->create_shader_variant(ctx->shader.bind_fs, key, &ctx->debug);
 
    if (!ctx->shader.fs)
       return false;
@@ -465,6 +466,13 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    etna_texture_init(pctx);
    etna_transfer_init(pctx);
 
+   ctx->uniform_dirty_flags = etna_uniform_dirty_flags;
+   ctx->uniforms_write = etna_uniforms_write;
+   ctx->uniforms_const_count = etna_uniforms_const_count;
+   ctx->create_shader_variant = etna_shader_variant;
+   ctx->shader_link = etna_shader_link;
+   ctx->shader_update_vertex = etna_shader_update_vertex;
+
    ctx->blitter = util_blitter_create(pctx);
    if (!ctx->blitter)
       goto fail;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h b/src/gallium/drivers/etnaviv/etnaviv_context.h
index a79d739100d..a20f3d6cf79 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -31,6 +31,7 @@
 #include <stdint.h>
 
 #include "etnaviv_resource.h"
+#include "etnaviv_shader.h"
 #include "etnaviv_tiling.h"
 #include "indices/u_primconvert.h"
 #include "pipe/p_context.h"
@@ -82,7 +83,7 @@ struct etna_vertexbuf_state {
 
 struct etna_shader_state {
    void *bind_vs, *bind_fs;
-   struct etna_shader_variant *vs, *fs;
+   void *vs, *fs;
 };
 
 enum etna_immediate_contents {
@@ -191,6 +192,21 @@ struct etna_context {
 
    struct etna_bo *dummy_rt;
    struct etna_reloc dummy_rt_reloc;
+
+   /* abstraction to support different compilers backends */
+   uint32_t (*uniform_dirty_flags)(const void *sobj);
+   void (*uniforms_write)(const struct etna_context *ctx,
+                          const void *sobj,
+                          struct pipe_constant_buffer *cb,
+                          uint32_t *uniforms,
+                          unsigned *size);
+   uint32_t (*uniforms_const_count)(const void *sobj);
+
+   void *(*create_shader_variant)(void *shader,
+                                  struct etna_shader_key key,
+                                  struct pipe_debug_callback *debug);
+   bool (*shader_link)(struct etna_context *ctx);
+   bool (*shader_update_vertex)(struct etna_context *ctx);
 };
 
 static inline struct etna_context *
diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c b/src/gallium/drivers/etnaviv/etnaviv_emit.c
index ed7b7ee3cb8..f6f2d83e607 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_emit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c
@@ -105,8 +105,8 @@ required_stream_size(struct etna_context *ctx)
    size += ctx->vertex_elements->num_elements + 1;
 
    /* uniforms - worst case (2 words per uniform load) */
-   size += ctx->shader.vs->uniforms.const_count * 2;
-   size += ctx->shader.fs->uniforms.const_count * 2;
+   size += ctx->uniforms_const_count(ctx->shader.vs) * 2;
+   size += ctx->uniforms_const_count(ctx->shader.fs) * 2;
 
    /* shader */
    size += ctx->shader_state.vs_inst_mem_size + 1;
@@ -577,13 +577,13 @@ etna_emit_state(struct etna_context *ctx)
    static const uint32_t uniform_dirty_bits =
       ETNA_DIRTY_SHADER | ETNA_DIRTY_CONSTBUF;
 
-   if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits))
-      etna_uniforms_write(
+   if (dirty & (uniform_dirty_bits | ctx->uniform_dirty_flags(ctx->shader.vs)))
+      ctx->uniforms_write(
          ctx, ctx->shader.vs, &ctx->constant_buffer[PIPE_SHADER_VERTEX],
          ctx->shader_state.VS_UNIFORMS, &ctx->shader_state.vs_uniforms_size);
 
-   if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits))
-      etna_uniforms_write(
+   if (dirty & (uniform_dirty_bits | ctx->uniform_dirty_flags(ctx->shader.fs)))
+      ctx->uniforms_write(
          ctx, ctx->shader.fs, &ctx->constant_buffer[PIPE_SHADER_FRAGMENT],
          ctx->shader_state.PS_UNIFORMS, &ctx->shader_state.ps_uniforms_size);
 
@@ -694,7 +694,7 @@ etna_emit_state(struct etna_context *ctx)
       if (do_uniform_flush)
          etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH);
       etna_coalesce_start(stream, &coalesce);
-      for (int x = 0; x < ctx->shader.vs->uniforms.const_count; ++x) {
+      for (int x = 0; x < ctx->uniforms_const_count(ctx->shader.vs); ++x) {
          if (ctx->gpu3d.VS_UNIFORMS[x] != ctx->shader_state.VS_UNIFORMS[x]) {
             etna_coalsence_emit(stream, &coalesce, ctx->specs.vs_uniforms_offset + x*4, ctx->shader_state.VS_UNIFORMS[x]);
             ctx->gpu3d.VS_UNIFORMS[x] = ctx->shader_state.VS_UNIFORMS[x];
@@ -706,7 +706,7 @@ etna_emit_state(struct etna_context *ctx)
       if (do_uniform_flush)
          etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH | VIVS_VS_UNIFORM_CACHE_PS);
       etna_coalesce_start(stream, &coalesce);
-      for (int x = 0; x < ctx->shader.fs->uniforms.const_count; ++x) {
+      for (int x = 0; x < ctx->uniforms_const_count(ctx->shader.fs); ++x) {
          if (ctx->gpu3d.PS_UNIFORMS[x] != ctx->shader_state.PS_UNIFORMS[x]) {
             etna_coalsence_emit(stream, &coalesce, ctx->specs.ps_uniforms_offset + x*4, ctx->shader_state.PS_UNIFORMS[x]);
             ctx->gpu3d.PS_UNIFORMS[x] = ctx->shader_state.PS_UNIFORMS[x];
diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c b/src/gallium/drivers/etnaviv/etnaviv_shader.c
index 03ba94ff5fa..34c546c3c66 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_shader.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c
@@ -370,10 +370,11 @@ fail:
    return NULL;
 }
 
-struct etna_shader_variant *
-etna_shader_variant(struct etna_shader *shader, struct etna_shader_key key,
+void *
+etna_shader_variant(void *s, struct etna_shader_key key,
                    struct pipe_debug_callback *debug)
 {
+   struct etna_shader *shader = (struct etna_shader *)s;
    struct etna_shader_variant *v;
 
    for (v = shader->variants; v; v = v->next)
diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.h b/src/gallium/drivers/etnaviv/etnaviv_shader.h
index 121d5815ba0..af21d7017bc 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_shader.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_shader.h
@@ -72,8 +72,8 @@ etna_shader_link(struct etna_context *ctx);
 bool
 etna_shader_update_vertex(struct etna_context *ctx);
 
-struct etna_shader_variant *
-etna_shader_variant(struct etna_shader *shader, struct etna_shader_key key,
+void *
+etna_shader_variant(void *shader, struct etna_shader_key key,
                    struct pipe_debug_callback *debug);
 
 void
diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c
index e23722b0d2f..e3c0d019aa5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_state.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_state.c
@@ -621,6 +621,18 @@ etna_update_ts_config(struct etna_context *ctx)
    return true;
 }
 
+static inline bool
+shader_update_vertex(struct etna_context *ctx)
+{
+   return ctx->shader_update_vertex(ctx);
+}
+
+static inline bool
+shader_link(struct etna_context *ctx)
+{
+   return ctx->shader_link(ctx);
+}
+
 struct etna_state_updater {
    bool (*update)(struct etna_context *ctx);
    uint32_t dirty;
@@ -628,10 +640,10 @@ struct etna_state_updater {
 
 static const struct etna_state_updater etna_state_updates[] = {
    {
-      etna_shader_update_vertex, ETNA_DIRTY_SHADER | ETNA_DIRTY_VERTEX_ELEMENTS,
+      shader_update_vertex, ETNA_DIRTY_SHADER | ETNA_DIRTY_VERTEX_ELEMENTS,
    },
    {
-      etna_shader_link, ETNA_DIRTY_SHADER,
+      shader_link, ETNA_DIRTY_SHADER,
    },
    {
       etna_update_blend, ETNA_DIRTY_BLEND | ETNA_DIRTY_FRAMEBUFFER
diff --git a/src/gallium/drivers/etnaviv/etnaviv_uniforms.c b/src/gallium/drivers/etnaviv/etnaviv_uniforms.c
index a8d970d185a..aab2a5601a0 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_uniforms.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_uniforms.c
@@ -59,10 +59,11 @@ get_texrect_scale(const struct etna_context *ctx, bool frag,
 
 void
 etna_uniforms_write(const struct etna_context *ctx,
-                    const struct etna_shader_variant *sobj,
+                    const void *v,
                     struct pipe_constant_buffer *cb, uint32_t *uniforms,
                     unsigned *size)
 {
+   const struct etna_shader_variant *sobj = (const struct etna_shader_variant *)v;
    const struct etna_shader_uniform_info *uinfo = &sobj->uniforms;
    bool frag = false;
 
@@ -116,3 +117,19 @@ etna_set_shader_uniforms_dirty_flags(struct etna_shader_variant *sobj)
 
    sobj->uniforms_dirty_bits = dirty;
 }
+
+uint32_t
+etna_uniform_dirty_flags(const void *v)
+{
+   const struct etna_shader_variant *sobj = (const struct etna_shader_variant *)v;
+
+   return sobj->uniforms_dirty_bits;
+}
+
+uint32_t
+etna_uniforms_const_count(const void *v)
+{
+   const struct etna_shader_variant *sobj = (const struct etna_shader_variant *)v;
+
+   return sobj->uniforms.const_count;
+}
diff --git a/src/gallium/drivers/etnaviv/etnaviv_uniforms.h b/src/gallium/drivers/etnaviv/etnaviv_uniforms.h
index 1dacd2a85d8..5c381e30120 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_uniforms.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_uniforms.h
@@ -35,11 +35,17 @@ struct pipe_constant_buffer;
 
 void
 etna_uniforms_write(const struct etna_context *ctx,
-                    const struct etna_shader_variant *sobj,
+                    const void *sobj,
                     struct pipe_constant_buffer *cb, uint32_t *uniforms,
                     unsigned *size);
 
 void
 etna_set_shader_uniforms_dirty_flags(struct etna_shader_variant *sobj);
 
+uint32_t
+etna_uniforms_const_count(const void *v);
+
+uint32_t
+etna_uniform_dirty_flags(const void *v);
+
 #endif /* ETNAVIV_UNIFORMS_H_ */
-- 
2.21.0



More information about the etnaviv mailing list