gallium/util: add _LZ and TXF options to simple shaders
authorMarek Olšák <marek.olsak@amd.com>
Tue, 30 May 2017 17:24:17 +0000 (19:24 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 7 Jun 2017 16:10:50 +0000 (18:10 +0200)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_simple_shaders.c
src/gallium/auxiliary/util/u_simple_shaders.h
src/gallium/auxiliary/util/u_tests.c
src/gallium/tests/trivial/quad-tex.c

index 6d8178ee5615c456842e74d3a0847ac1f2eaba42..3e49667029a08c8617ec74ea051975828cd92b05 100644 (file)
@@ -186,7 +186,7 @@ set_fragment_shader(struct blit_state *ctx, uint writemask,
          util_make_fragment_tex_shader_writemask(ctx->pipe, tgsi_tex,
                                                  TGSI_INTERPOLATE_LINEAR,
                                                  writemask,
-                                                 stype, stype);
+                                                 stype, stype, false, false);
    }
 
    cso_set_fragment_shader_handle(ctx->cso, ctx->fs[pipe_tex][writemask][idx]);
index 13fa9651392d42092f7a09e275eeafa59603c15b..1aef01376eefa445c05fef1e9a528cedf840d39e 100644 (file)
@@ -952,7 +952,8 @@ static void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
          assert(!ctx->cached_all_shaders);
          *shader = util_make_fragment_tex_shader(pipe, tgsi_tex,
                                                  TGSI_INTERPOLATE_LINEAR,
-                                                 stype, dtype);
+                                                 stype, dtype,
+                                                 false, false);
       }
 
       return *shader;
@@ -990,7 +991,8 @@ void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx,
          tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
          *shader =
             util_make_fragment_tex_shader_writedepth(pipe, tgsi_tex,
-                                                     TGSI_INTERPOLATE_LINEAR);
+                                                     TGSI_INTERPOLATE_LINEAR,
+                                                     false, false);
       }
 
       return *shader;
@@ -1028,7 +1030,9 @@ void *blitter_get_fs_texfetch_depthstencil(struct blitter_context_priv *ctx,
          tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
          *shader =
             util_make_fragment_tex_shader_writedepthstencil(pipe, tgsi_tex,
-                                                     TGSI_INTERPOLATE_LINEAR);
+                                                            TGSI_INTERPOLATE_LINEAR,
+                                                            false,
+                                                            false);
       }
 
       return *shader;
@@ -1066,7 +1070,8 @@ void *blitter_get_fs_texfetch_stencil(struct blitter_context_priv *ctx,
          tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
          *shader =
             util_make_fragment_tex_shader_writestencil(pipe, tgsi_tex,
-                                                       TGSI_INTERPOLATE_LINEAR);
+                                                       TGSI_INTERPOLATE_LINEAR,
+                                                       false, false);
       }
 
       return *shader;
index 613ec4ab98f288d1783729ec8f1d3bee15e308c0..5874d0e9aa4067cf08eb473f9a24b3d3b360baae 100644 (file)
@@ -205,6 +205,28 @@ void *util_make_layered_clear_geometry_shader(struct pipe_context *pipe)
    return pipe->create_gs_state(pipe, &state);
 }
 
+static void
+ureg_load_tex(struct ureg_program *ureg, struct ureg_dst out,
+              struct ureg_src coord, struct ureg_src sampler,
+              unsigned tex_target, bool load_level_zero, bool use_txf)
+{
+   if (use_txf) {
+      struct ureg_dst temp = ureg_DECL_temporary(ureg);
+
+      ureg_F2I(ureg, temp, coord);
+
+      if (load_level_zero)
+         ureg_TXF_LZ(ureg, out, tex_target, ureg_src(temp), sampler);
+      else
+         ureg_TXF(ureg, out, tex_target, ureg_src(temp), sampler);
+   } else {
+      if (load_level_zero)
+         ureg_TEX_LZ(ureg, out, tex_target, coord, sampler);
+      else
+         ureg_TEX(ureg, out, tex_target, coord, sampler);
+   }
+}
+
 /**
  * Make simple fragment texture shader:
  *  IMM {0,0,0,1}                         // (if writemask != 0xf)
@@ -224,7 +246,9 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
                                         unsigned interp_mode,
                                         unsigned writemask,
                                         enum tgsi_return_type stype,
-                                        enum tgsi_return_type dtype)
+                                        enum tgsi_return_type dtype,
+                                        bool load_level_zero,
+                                        bool use_txf)
 {
    struct ureg_program *ureg;
    struct ureg_src sampler;
@@ -265,9 +289,8 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
                ureg_writemask(temp, writemask),
                tex_target, tex, sampler);
    else
-      ureg_TEX(ureg,
-               ureg_writemask(temp, writemask),
-               tex_target, tex, sampler);
+      ureg_load_tex(ureg, ureg_writemask(temp, writemask), tex, sampler,
+                    tex_target, load_level_zero, use_txf);
 
    if (stype != dtype) {
       if (stype == TGSI_RETURN_TYPE_SINT) {
@@ -299,13 +322,16 @@ void *
 util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
                               unsigned interp_mode,
                               enum tgsi_return_type stype,
-                              enum tgsi_return_type dtype)
+                              enum tgsi_return_type dtype,
+                              bool load_level_zero,
+                              bool use_txf)
 {
    return util_make_fragment_tex_shader_writemask( pipe,
                                                    tex_target,
                                                    interp_mode,
                                                    TGSI_WRITEMASK_XYZW,
-                                                   stype, dtype );
+                                                   stype, dtype, load_level_zero,
+                                                   use_txf);
 }
 
 
@@ -316,7 +342,9 @@ util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
 void *
 util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
                                          unsigned tex_target,
-                                         unsigned interp_mode)
+                                         unsigned interp_mode,
+                                         bool load_level_zero,
+                                         bool use_txf)
 {
    struct ureg_program *ureg;
    struct ureg_src sampler;
@@ -352,9 +380,8 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
 
    ureg_MOV( ureg, out, imm );
 
-   ureg_TEX( ureg,
-             ureg_writemask(depth, TGSI_WRITEMASK_Z),
-             tex_target, tex, sampler );
+   ureg_load_tex(ureg, ureg_writemask(depth, TGSI_WRITEMASK_Z), tex, sampler,
+                 tex_target, load_level_zero, use_txf);
    ureg_END( ureg );
 
    return ureg_create_shader_and_destroy( ureg, pipe );
@@ -368,7 +395,9 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
 void *
 util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe,
                                                 unsigned tex_target,
-                                                unsigned interp_mode)
+                                                unsigned interp_mode,
+                                                bool load_level_zero,
+                                                bool use_txf)
 {
    struct ureg_program *ureg;
    struct ureg_src depth_sampler, stencil_sampler;
@@ -413,12 +442,10 @@ util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe,
 
    ureg_MOV( ureg, out, imm );
 
-   ureg_TEX( ureg,
-             ureg_writemask(depth, TGSI_WRITEMASK_Z),
-             tex_target, tex, depth_sampler );
-   ureg_TEX( ureg,
-             ureg_writemask(stencil, TGSI_WRITEMASK_Y),
-             tex_target, tex, stencil_sampler );
+   ureg_load_tex(ureg, ureg_writemask(depth, TGSI_WRITEMASK_Z), tex,
+                 depth_sampler, tex_target, load_level_zero, use_txf);
+   ureg_load_tex(ureg, ureg_writemask(stencil, TGSI_WRITEMASK_Y), tex,
+                 stencil_sampler, tex_target, load_level_zero, use_txf);
    ureg_END( ureg );
 
    return ureg_create_shader_and_destroy( ureg, pipe );
@@ -432,7 +459,9 @@ util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe,
 void *
 util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe,
                                            unsigned tex_target,
-                                           unsigned interp_mode)
+                                           unsigned interp_mode,
+                                           bool load_level_zero,
+                                           bool use_txf)
 {
    struct ureg_program *ureg;
    struct ureg_src stencil_sampler;
@@ -468,9 +497,8 @@ util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe,
 
    ureg_MOV( ureg, out, imm );
 
-   ureg_TEX( ureg,
-             ureg_writemask(stencil, TGSI_WRITEMASK_Y),
-             tex_target, tex, stencil_sampler );
+   ureg_load_tex(ureg, ureg_writemask(stencil, TGSI_WRITEMASK_Y), tex,
+                 stencil_sampler, tex_target, load_level_zero, use_txf);
    ureg_END( ureg );
 
    return ureg_create_shader_and_destroy( ureg, pipe );
index 04810982024f2b232b0b4c28d678ced7255c4abd..de05aad3a654d1d370145180bb7bca2407ccde22 100644 (file)
@@ -74,30 +74,40 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
                                         unsigned interp_mode,
                                         unsigned writemask,
                                         enum tgsi_return_type stype,
-                                        enum tgsi_return_type dtype);
+                                        enum tgsi_return_type dtype,
+                                        bool load_level_zero,
+                                        bool use_txf);
 
 extern void *
 util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
                               unsigned interp_mode,
                               enum tgsi_return_type stype,
-                              enum tgsi_return_type dtype);
+                              enum tgsi_return_type dtype,
+                              bool load_level_zero,
+                              bool use_txf);
 
 extern void *
 util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
                                          unsigned tex_target,
-                                         unsigned interp_mode);
+                                         unsigned interp_mode,
+                                         bool load_level_zero,
+                                         bool use_txf);
 
 
 extern void *
 util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe,
                                                 unsigned tex_target,
-                                                unsigned interp_mode);
+                                                unsigned interp_mode,
+                                                bool load_level_zero,
+                                                bool use_txf);
 
 
 extern void *
 util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe,
                                            unsigned tex_target,
-                                           unsigned interp_mode);
+                                           unsigned interp_mode,
+                                           bool load_level_zero,
+                                           bool use_txf);
 
 
 extern void *
index 30eb589b06fcf960d56dffb2956fb246dc3056b4..7ec8eef65fc5437d52a1b7ff78bc0f6cae745a22 100644 (file)
@@ -375,7 +375,7 @@ null_sampler_view(struct pipe_context *ctx, unsigned tgsi_tex_target)
    fs = util_make_fragment_tex_shader(ctx, tgsi_tex_target,
                                       TGSI_INTERPOLATE_LINEAR,
                                       TGSI_RETURN_TYPE_FLOAT,
-                                      TGSI_RETURN_TYPE_FLOAT);
+                                      TGSI_RETURN_TYPE_FLOAT, false, false);
    cso_set_fragment_shader_handle(cso, fs);
 
    /* Vertex shader. */
index 6e9957aac9c2f1ba7d59f97a18bd0cea18dd314c..2ee544a41294399f82ab0cd228aa936468652315 100644 (file)
@@ -273,7 +273,8 @@ static void init_prog(struct program *p)
        p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D,
                                              TGSI_INTERPOLATE_LINEAR,
                                              TGSI_RETURN_TYPE_FLOAT,
-                                             TGSI_RETURN_TYPE_FLOAT);
+                                             TGSI_RETURN_TYPE_FLOAT, false,
+                                              false);
 }
 
 static void close_prog(struct program *p)