[Mesa-dev] [PATCH 7/7] mesa/st: support for YUV in VS/VS/GS/TCS/TEC..

Rob Clark robdclark at gmail.com
Thu Sep 8 20:30:40 UTC 2016


maybe we don't keep these bits?

Signed-off-by: Rob Clark <robdclark at gmail.com>
---
 src/mesa/state_tracker/st_atom_shader.c |  2 ++
 src/mesa/state_tracker/st_context.c     | 20 +++++++++++
 src/mesa/state_tracker/st_program.c     | 63 ++++++++++++++++++++++++++++++---
 src/mesa/state_tracker/st_program.h     |  4 +++
 4 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index f0970ae..b340609 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -196,6 +196,8 @@ update_vp( struct st_context *st )
                        VARYING_SLOT_BFC0 |
                        VARYING_SLOT_BFC1));
 
+   key.external = st_get_external_sampler_key(st, &stvp->Base.Base);
+
    st->vp_variant = st_get_vp_variant(st, stvp, &key);
 
    st_reference_vertprog(st, &st->vp, stvp);
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 2571fae..9d62cf7 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -259,10 +259,30 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
                    (ST_NEW_SAMPLER_VIEWS |
                     ST_NEW_SAMPLERS |
                     ST_NEW_IMAGE_UNITS);
+      if (ctx->VertexProgram._Current &&
+          ctx->VertexProgram._Current->Base.ExternalSamplersUsed) {
+         st->dirty |= ST_NEW_VS_STATE;
+      }
       if (ctx->FragmentProgram._Current &&
           ctx->FragmentProgram._Current->Base.ExternalSamplersUsed) {
          st->dirty |= ST_NEW_FS_STATE;
       }
+      if (ctx->GeometryProgram._Current &&
+          ctx->GeometryProgram._Current->Base.ExternalSamplersUsed) {
+         st->dirty |= ST_NEW_GS_STATE;
+      }
+      if (ctx->ComputeProgram._Current &&
+          ctx->ComputeProgram._Current->Base.ExternalSamplersUsed) {
+         st->dirty |= ST_NEW_CS_STATE;
+      }
+      if (ctx->TessCtrlProgram._Current &&
+          ctx->TessCtrlProgram._Current->Base.ExternalSamplersUsed) {
+         st->dirty |= ST_NEW_TCS_STATE;
+      }
+      if (ctx->TessEvalProgram._Current &&
+          ctx->TessEvalProgram._Current->Base.ExternalSamplersUsed) {
+         st->dirty |= ST_NEW_TES_STATE;
+      }
    }
 
    if (new_state & _NEW_PROGRAM_CONSTANTS)
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index f8be835..1c8cf89 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -489,8 +489,23 @@ st_create_vp_variant(struct st_context *st,
       if (key->passthrough_edgeflags)
          NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_passthrough_edgeflags);
 
+      if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
+         nir_lower_tex_options options = {0};
+         options.lower_y_uv_external = key->external.lower_nv12;
+         options.lower_y_u_v_external = key->external.lower_iyuv;
+         NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_tex, &options);
+      }
+
       st_finalize_nir(st, &stvp->Base.Base, vpv->tgsi.ir.nir);
 
+      if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
+         /* This pass needs to happen *after* nir_lower_sampler */
+         NIR_PASS_V(vpv->tgsi.ir.nir, st_nir_lower_tex_src_plane,
+                    ~stvp->Base.Base.SamplersUsed,
+                    key->external.lower_nv12,
+                    key->external.lower_iyuv);
+      }
+
       vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
       /* driver takes ownership of IR: */
       vpv->tgsi.ir.nir = NULL;
@@ -518,6 +533,21 @@ st_create_vp_variant(struct st_context *st,
          fprintf(stderr, "mesa: cannot emulate deprecated features\n");
    }
 
+   if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
+      const struct tgsi_token *tokens;
+
+      tokens = st_tgsi_lower_yuv(vpv->tgsi.tokens,
+                                 ~stvp->Base.Base.SamplersUsed,
+                                 key->external.lower_nv12,
+                                 key->external.lower_iyuv);
+      if (tokens) {
+         tgsi_free_tokens(vpv->tgsi.tokens);
+         vpv->tgsi.tokens = tokens;
+      } else {
+         fprintf(stderr, "mesa: cannot create a shader for samplerExternalOES\n");
+      }
+   }
+
    if (ST_DEBUG & DEBUG_TGSI) {
       tgsi_dump(vpv->tgsi.tokens, 0);
       debug_printf("\n");
@@ -1550,16 +1580,25 @@ st_get_basic_variant(struct st_context *st,
       /* create new */
       v = CALLOC_STRUCT(st_basic_variant);
       if (v) {
+         struct pipe_shader_state cso = *tgsi;
+
+         if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
+            assert(cso.type == PIPE_SHADER_IR_TGSI);
+            cso.tokens = st_tgsi_lower_yuv(cso.tokens, ~prog->SamplersUsed,
+                                           key->external.lower_nv12,
+                                           key->external.lower_iyuv);
+         }
+
          /* fill in new variant */
          switch (prog->Target) {
          case GL_TESS_CONTROL_PROGRAM_NV:
-            v->driver_shader = pipe->create_tcs_state(pipe, tgsi);
+            v->driver_shader = pipe->create_tcs_state(pipe, &cso);
             break;
          case GL_TESS_EVALUATION_PROGRAM_NV:
-            v->driver_shader = pipe->create_tes_state(pipe, tgsi);
+            v->driver_shader = pipe->create_tes_state(pipe, &cso);
             break;
          case GL_GEOMETRY_PROGRAM_NV:
-            v->driver_shader = pipe->create_gs_state(pipe, tgsi);
+            v->driver_shader = pipe->create_gs_state(pipe, &cso);
             break;
          default:
             assert(!"unhandled shader type");
@@ -1572,6 +1611,9 @@ st_get_basic_variant(struct st_context *st,
          /* insert into list */
          v->next = *variants;
          *variants = v;
+
+         if (cso.tokens != tgsi->tokens)
+            tgsi_free_tokens(cso.tokens);
       }
    }
 
@@ -1703,13 +1745,26 @@ st_get_cp_variant(struct st_context *st,
       /* create new */
       v = CALLOC_STRUCT(st_basic_variant);
       if (v) {
+         struct pipe_compute_state cso = *tgsi;
+
+         if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
+            assert(cso.ir_type == PIPE_SHADER_IR_TGSI);
+            cso.prog = st_tgsi_lower_yuv(cso.prog,
+                                         ~stcp->Base.Base.SamplersUsed,
+                                         key->external.lower_nv12,
+                                         key->external.lower_iyuv);
+         }
+
          /* fill in new variant */
-         v->driver_shader = pipe->create_compute_state(pipe, tgsi);
+         v->driver_shader = pipe->create_compute_state(pipe, &cso);
          v->key = *key;
 
          /* insert into list */
          v->next = stcp->variants;
          stcp->variants = v;
+
+         if (cso.prog != tgsi->prog)
+            tgsi_free_tokens(cso.prog);
       }
    }
 
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 9cf492c..35b6a3c 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -162,6 +162,8 @@ struct st_vp_variant_key
 
    /** for ARB_color_buffer_float */
    boolean clamp_color;
+
+   struct st_external_sampler_key external;
 };
 
 
@@ -228,6 +230,7 @@ struct st_vertex_program
 struct st_basic_variant_key
 {
    struct st_context *st;          /**< variants are per-context */
+   struct st_external_sampler_key external;
 };
 
 static inline struct st_basic_variant_key
@@ -237,6 +240,7 @@ st_get_basic_variant_key(struct st_context *st, struct gl_program *prog)
 
    memset(&key, 0, sizeof(key));
    key.st = st->has_shareable_shaders ? NULL : st;
+   key.external = st_get_external_sampler_key(st, prog);
 
    return key;
 }
-- 
2.7.4



More information about the mesa-dev mailing list