[Mesa-dev] [PATCH 2/6] glsl: add texture gather changes

Chris Forbes chrisf at ijw.co.nz
Sun Mar 31 02:10:50 PDT 2013


From: Maxence Le Dore <maxence.ledore at gmail.com>

From: Maxence Le Dore <maxence.ledore at gmail.com>

V2 [Chris Forbes]:
   - Add new pattern, fixup parameter reading.
---
 src/glsl/builtins/profiles/ARB_texture_gather.glsl | 27 ++++++++++++++++++++++
 src/glsl/builtins/tools/generate_builtins.py       |  1 +
 src/glsl/builtins/tools/texture_builtins.py        | 14 ++++++++++-
 src/glsl/glcpp/glcpp-parse.y                       |  3 +++
 src/glsl/glsl_parser_extras.cpp                    |  1 +
 src/glsl/glsl_parser_extras.h                      |  2 ++
 src/glsl/ir.cpp                                    |  2 +-
 src/glsl/ir.h                                      |  4 +++-
 src/glsl/ir_clone.cpp                              |  1 +
 src/glsl/ir_hv_accept.cpp                          |  1 +
 src/glsl/ir_print_visitor.cpp                      |  3 ++-
 src/glsl/ir_reader.cpp                             |  6 ++++-
 src/glsl/ir_rvalue_visitor.cpp                     |  1 +
 src/glsl/opt_tree_grafting.cpp                     |  1 +
 src/glsl/standalone_scaffolding.cpp                |  1 +
 src/mesa/program/ir_to_mesa.cpp                    |  5 ++++
 16 files changed, 68 insertions(+), 5 deletions(-)
 create mode 100644 src/glsl/builtins/profiles/ARB_texture_gather.glsl

diff --git a/src/glsl/builtins/profiles/ARB_texture_gather.glsl b/src/glsl/builtins/profiles/ARB_texture_gather.glsl
new file mode 100644
index 0000000..d8716a6
--- /dev/null
+++ b/src/glsl/builtins/profiles/ARB_texture_gather.glsl
@@ -0,0 +1,27 @@
+#version 130
+#extension GL_ARB_texture_gather: enable
+#extension GL_ARB_texture_cube_map_array: enable
+
+ vec4 textureGather( sampler2D sampler, vec2 coord);
+ivec4 textureGather(isampler2D sampler, vec2 coord);
+uvec4 textureGather(usampler2D sampler, vec2 coord);
+
+ vec4 textureGather( sampler2DArray sampler, vec3 coord);
+ivec4 textureGather(isampler2DArray sampler, vec3 coord);
+uvec4 textureGather(usampler2DArray sampler, vec3 coord);
+
+ vec4 textureGather( samplerCube sampler, vec3 coord);
+ivec4 textureGather(isamplerCube sampler, vec3 coord);
+uvec4 textureGather(usamplerCube sampler, vec3 coord);
+
+ vec4 textureGather( samplerCubeArray sampler, vec4 coord);
+ivec4 textureGather(isamplerCubeArray sampler, vec4 coord);
+uvec4 textureGather(usamplerCubeArray sampler, vec4 coord);
+
+ vec4 textureGatherOffset( sampler2D sampler, vec2 coord, ivec2 offset);
+ivec4 textureGatherOffset(isampler2D sampler, vec2 coord, ivec2 offset);
+uvec4 textureGatherOffset(usampler2D sampler, vec2 coord, ivec2 offset);
+
+ vec4 textureGatherOffset( sampler2DArray sampler, vec3 coord, ivec2 offset);
+ivec4 textureGatherOffset(isampler2DArray sampler, vec3 coord, ivec2 offset);
+uvec4 textureGatherOffset(usampler2DArray sampler, vec3 coord, ivec2 offset);
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index 75d3c21..ac475c5 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -192,6 +192,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne
    st->ARB_shading_language_packing_enable = true;
    st->ARB_texture_multisample_enable = true;
    st->ARB_texture_query_lod_enable = true;
+   st->ARB_texture_gather_enable = true;
    _mesa_glsl_initialize_types(st);
 
    sh->ir = new(sh) exec_list;
diff --git a/src/glsl/builtins/tools/texture_builtins.py b/src/glsl/builtins/tools/texture_builtins.py
index 6ef20d5..12481f4 100755
--- a/src/glsl/builtins/tools/texture_builtins.py
+++ b/src/glsl/builtins/tools/texture_builtins.py
@@ -117,7 +117,7 @@ def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
         else:
             print "0",
 
-    if tex_inst not in ['txf', 'txf_ms', 'txs', 'lod']:
+    if tex_inst not in ['txf', 'txf_ms', 'txs', 'lod', 'tg4']:
         # Projective divisor
         if variant & Proj:
             print "(swiz " + "xyzw"[coord_dim + extra_dim-1] + " (var_ref P))",
@@ -653,6 +653,18 @@ def generate_texture_functions(fs):
     generate_sigs("", "lod", "CubeArrayShadow")
     end_function(fs, "textureQueryLOD")
 
+    start_function("textureGather")
+    generate_fiu_sigs("tg4", "2D")
+    generate_fiu_sigs("tg4", "2DArray")
+    generate_fiu_sigs("tg4", "Cube")
+    generate_fiu_sigs("tg4", "CubeArray")
+    end_function(fs, "textureGather")
+
+    start_function("textureGatherOffset")
+    generate_fiu_sigs("tg4", "2D", Offset)
+    generate_fiu_sigs("tg4", "2DArray", Offset)
+    end_function(fs, "textureGatherOffset")
+
     sys.stdout = sys.__stdout__
     return fs
 
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 00edbbf..cda8aad 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -1236,6 +1236,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
 
 	      if (extensions->ARB_texture_query_lod)
 	         add_builtin_define(parser, "GL_ARB_texture_query_lod", 1);
+
+	      if (extensions->ARB_texture_gather)
+	         add_builtin_define(parser, "GL_ARB_texture_gather", 1);
 	   }
 	}
 
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 9740903..706f72e 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -468,6 +468,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
    EXT(ARB_shading_language_packing,   true,  false, true,  true,  false,     ARB_shading_language_packing),
    EXT(ARB_texture_multisample,        true,  false, true,  true,  false,     ARB_texture_multisample),
    EXT(ARB_texture_query_lod,          false, false, true,  true,  false,     ARB_texture_query_lod),
+   EXT(ARB_texture_gather,             true,  false, true,  true,  false,     ARB_texture_gather),
 };
 
 #undef EXT
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 95891b5..7872bbc 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -254,6 +254,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_fragment_coord_conventions_warn;
    bool ARB_texture_rectangle_enable;
    bool ARB_texture_rectangle_warn;
+   bool ARB_texture_gather_enable;
+   bool ARB_texture_gather_warn;
    bool EXT_texture_array_enable;
    bool EXT_texture_array_warn;
    bool ARB_shader_texture_lod_enable;
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 05b77da..55d3aa8 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1307,7 +1307,7 @@ ir_dereference::is_lvalue() const
 }
 
 
-static const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod" };
+static const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod", "tg4" };
 
 const char *ir_texture::opcode_string()
 {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 0c3e399..fdd28d2 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1427,7 +1427,8 @@ enum ir_texture_opcode {
    ir_txf,		/**< Texel fetch with explicit LOD */
    ir_txf_ms,           /**< Multisample texture fetch */
    ir_txs,		/**< Texture size */
-   ir_lod		/**< Texture lod query */
+   ir_lod,		/**< Texture lod query */
+   ir_tg4		/**< Texture gather */
 };
 
 
@@ -1452,6 +1453,7 @@ enum ir_texture_opcode {
  *      <type> <sampler> <coordinate>         <sample_index>)
  * (txs <type> <sampler> <lod>)
  * (lod <type> <sampler> <coordinate>)
+ * (tg4 <type> <sampler> <coordinate> 0)
  */
 class ir_texture : public ir_rvalue {
 public:
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 5b42935..ef26166 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -244,6 +244,7 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
    switch (this->op) {
    case ir_tex:
    case ir_lod:
+   case ir_tg4:
       break;
    case ir_txb:
       new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht);
diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index 559b71a..dd29e41 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -214,6 +214,7 @@ ir_texture::accept(ir_hierarchical_visitor *v)
    switch (this->op) {
    case ir_tex:
    case ir_lod:
+   case ir_tg4:
       break;
    case ir_txb:
       s = this->lod_info.bias->accept(v);
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index 597d281..04fc5e8 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -260,7 +260,7 @@ void ir_print_visitor::visit(ir_texture *ir)
       printf(" ");
    }
 
-   if (ir->op != ir_txf && ir->op != ir_txf_ms && ir->op != ir_txs) {
+   if (ir->op != ir_txf && ir->op != ir_txf_ms && ir->op != ir_txs && ir->op != ir_tg4) {
       if (ir->projector)
 	 ir->projector->accept(this);
       else
@@ -279,6 +279,7 @@ void ir_print_visitor::visit(ir_texture *ir)
    {
    case ir_tex:
    case ir_lod:
+   case ir_tg4:
       break;
    case ir_txb:
       ir->lod_info.bias->accept(this);
diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
index 16fdc41..7f6c911 100644
--- a/src/glsl/ir_reader.cpp
+++ b/src/glsl/ir_reader.cpp
@@ -925,6 +925,8 @@ ir_reader::read_texture(s_expression *expr)
       { "txf_ms", s_type, s_sampler, s_coord, s_sample_index };
    s_pattern txs_pattern[] =
       { "txs", s_type, s_sampler, s_lod };
+   s_pattern tg4_pattern[] =
+      { "tg4", s_type, s_sampler, s_coord, s_offset };
    s_pattern other_pattern[] =
       { tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
 
@@ -938,6 +940,8 @@ ir_reader::read_texture(s_expression *expr)
       op = ir_txf_ms;
    } else if (MATCH(expr, txs_pattern)) {
       op = ir_txs;
+   } else if (MATCH(expr, tg4_pattern)) {
+      op = ir_tg4;
    } else if (MATCH(expr, other_pattern)) {
       op = ir_texture::get_opcode(tag->value());
       if (op == -1)
@@ -988,7 +992,7 @@ ir_reader::read_texture(s_expression *expr)
       }
    }
 
-   if (op != ir_txf && op != ir_txf_ms && op != ir_txs && op != ir_lod) {
+   if (op != ir_txf && op != ir_txf_ms && op != ir_txs && op != ir_lod && op != ir_tg4) {
       s_int *proj_as_int = SX_AS_INT(s_proj);
       if (proj_as_int && proj_as_int->value() == 1) {
 	 tex->projector = NULL;
diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
index 3504a4d..ae3291b 100644
--- a/src/glsl/ir_rvalue_visitor.cpp
+++ b/src/glsl/ir_rvalue_visitor.cpp
@@ -58,6 +58,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
    switch (ir->op) {
    case ir_tex:
    case ir_lod:
+   case ir_tg4:
       break;
    case ir_txb:
       handle_rvalue(&ir->lod_info.bias);
diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp
index 9aceb13..03b920d 100644
--- a/src/glsl/opt_tree_grafting.cpp
+++ b/src/glsl/opt_tree_grafting.cpp
@@ -275,6 +275,7 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
    switch (ir->op) {
    case ir_tex:
    case ir_lod:
+   case ir_tg4:
       break;
    case ir_txb:
       if (do_graft(&ir->lod_info.bias))
diff --git a/src/glsl/standalone_scaffolding.cpp b/src/glsl/standalone_scaffolding.cpp
index 0c1f52f..76cebe6 100644
--- a/src/glsl/standalone_scaffolding.cpp
+++ b/src/glsl/standalone_scaffolding.cpp
@@ -104,6 +104,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
    ctx->Extensions.ARB_texture_cube_map_array = true;
    ctx->Extensions.ARB_texture_multisample = true;
    ctx->Extensions.ARB_texture_query_lod = true;
+   ctx->Extensions.ARB_texture_gather = true;
 
    ctx->Const.GLSLVersion = 120;
 
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 14cf5ba..280a18c 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2051,6 +2051,11 @@ ir_to_mesa_visitor::visit(ir_texture *ir)
    case ir_lod:
       assert(!"Unexpected ir_lod opcode");
       break;
+   case ir_tg4:
+      assert(!"Unexpected ir_tg4 opcode");
+      break;
+   default:
+     assert(!"Invalid texture opcode.");
    }
 
    const glsl_type *sampler_type = ir->sampler->type;
-- 
1.8.2



More information about the mesa-dev mailing list