glsl: add plumbing for GL_ARB_texture_query_levels
authorChris Forbes <chrisf@ijw.co.nz>
Thu, 26 Sep 2013 07:37:30 +0000 (19:37 +1200)
committerChris Forbes <chrisf@ijw.co.nz>
Sat, 5 Oct 2013 06:16:32 +0000 (19:16 +1300)
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Matt Turner <mattst88@gmail.com>
14 files changed:
src/glsl/builtin_functions.cpp
src/glsl/glcpp/glcpp-parse.y
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_clone.cpp
src/glsl/ir_hv_accept.cpp
src/glsl/ir_print_visitor.cpp
src/glsl/ir_reader.cpp
src/glsl/ir_rvalue_visitor.cpp
src/glsl/opt_tree_grafting.cpp
src/glsl/standalone_scaffolding.cpp
src/mesa/program/ir_to_mesa.cpp

index df735ef31c98605d74f8a23e3ac1c21551d8999d..40084f79f51cea1d851bb2392f3c389689d50e63 100644 (file)
@@ -255,6 +255,13 @@ texture_cube_map_array(const _mesa_glsl_parse_state *state)
           state->ARB_texture_cube_map_array_enable;
 }
 
+static bool
+texture_query_levels(const _mesa_glsl_parse_state *state)
+{
+   return state->is_version(430, 0) ||
+          state->ARB_texture_query_levels_enable;
+}
+
 static bool
 texture_query_lod(const _mesa_glsl_parse_state *state)
 {
@@ -504,6 +511,7 @@ private:
    B0(EndPrimitive)
 
    B2(textureQueryLod);
+   B1(textureQueryLevels);
    B1(dFdx);
    B1(dFdy);
    B1(fwidth);
@@ -1603,6 +1611,39 @@ builtin_builder::create_builtins()
                 _textureQueryLod(glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
                 NULL);
 
+   add_function("textureQueryLevels",
+                _textureQueryLevels(glsl_type::sampler1D_type),
+                _textureQueryLevels(glsl_type::sampler2D_type),
+                _textureQueryLevels(glsl_type::sampler3D_type),
+                _textureQueryLevels(glsl_type::samplerCube_type),
+                _textureQueryLevels(glsl_type::sampler1DArray_type),
+                _textureQueryLevels(glsl_type::sampler2DArray_type),
+                _textureQueryLevels(glsl_type::samplerCubeArray_type),
+                _textureQueryLevels(glsl_type::sampler1DShadow_type),
+                _textureQueryLevels(glsl_type::sampler2DShadow_type),
+                _textureQueryLevels(glsl_type::samplerCubeShadow_type),
+                _textureQueryLevels(glsl_type::sampler1DArrayShadow_type),
+                _textureQueryLevels(glsl_type::sampler2DArrayShadow_type),
+                _textureQueryLevels(glsl_type::samplerCubeArrayShadow_type),
+
+                _textureQueryLevels(glsl_type::isampler1D_type),
+                _textureQueryLevels(glsl_type::isampler2D_type),
+                _textureQueryLevels(glsl_type::isampler3D_type),
+                _textureQueryLevels(glsl_type::isamplerCube_type),
+                _textureQueryLevels(glsl_type::isampler1DArray_type),
+                _textureQueryLevels(glsl_type::isampler2DArray_type),
+                _textureQueryLevels(glsl_type::isamplerCubeArray_type),
+
+                _textureQueryLevels(glsl_type::usampler1D_type),
+                _textureQueryLevels(glsl_type::usampler2D_type),
+                _textureQueryLevels(glsl_type::usampler3D_type),
+                _textureQueryLevels(glsl_type::usamplerCube_type),
+                _textureQueryLevels(glsl_type::usampler1DArray_type),
+                _textureQueryLevels(glsl_type::usampler2DArray_type),
+                _textureQueryLevels(glsl_type::usamplerCubeArray_type),
+
+                NULL);
+
    add_function("texture1D",
                 _texture(ir_tex, v110,         glsl_type::vec4_type,  glsl_type::sampler1D_type, glsl_type::float_type),
                 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type,  glsl_type::sampler1D_type, glsl_type::float_type),
@@ -3393,6 +3434,21 @@ builtin_builder::_textureQueryLod(const glsl_type *sampler_type,
    return sig;
 }
 
+ir_function_signature *
+builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
+{
+   ir_variable *s = in_var(sampler_type, "sampler");
+   const glsl_type *return_type = glsl_type::int_type;
+   MAKE_SIG(return_type, texture_query_levels, 1, s);
+
+   ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
+   tex->set_sampler(var_ref(s), return_type);
+
+   body.emit(ret(tex));
+
+   return sig;
+}
+
 UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
 UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
 
index c7ad3e9586487d3331ead2460027d46c4e9e27b8..02100ab0cd19ddd062dfaae7b3efa030836e1c13 100644 (file)
@@ -1234,6 +1234,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
              if (extensions->ARB_texture_multisample)
                 add_builtin_define(parser, "GL_ARB_texture_multisample", 1);
 
+              if (extensions->ARB_texture_query_levels)
+                 add_builtin_define(parser, "GL_ARB_texture_query_levels", 1);
+
              if (extensions->ARB_texture_query_lod)
                 add_builtin_define(parser, "GL_ARB_texture_query_lod", 1);
 
index 7368a7156884626c29f2e94855ab626572f613c6..ad85db9e307adf77d33199ef5db811a67f9db54a 100644 (file)
@@ -518,6 +518,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
    EXT(ARB_shading_language_packing,   true,  false,     ARB_shading_language_packing),
    EXT(ARB_shading_language_420pack,   true,  false,     ARB_shading_language_420pack),
    EXT(ARB_texture_multisample,        true,  false,     ARB_texture_multisample),
+   EXT(ARB_texture_query_levels,       true,  false,     ARB_texture_query_levels),
    EXT(ARB_texture_query_lod,          true,  false,     ARB_texture_query_lod),
    EXT(ARB_gpu_shader5,                true,  false,     ARB_gpu_shader5),
    EXT(AMD_vertex_shader_layer,        true,  false,     AMD_vertex_shader_layer),
index 9c3e88721f84a54e3b8dba877c0819abc8c83b0f..dba1a35e50946682e6fe1e8e25c23deea509875b 100644 (file)
@@ -304,6 +304,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_shading_language_packing_warn;
    bool ARB_texture_multisample_enable;
    bool ARB_texture_multisample_warn;
+   bool ARB_texture_query_levels_enable;
+   bool ARB_texture_query_levels_warn;
    bool ARB_texture_query_lod_enable;
    bool ARB_texture_query_lod_warn;
    bool ARB_gpu_shader5_enable;
index 81c6380cad03b8464ac35690d8be965f6d7fa949..ae67d6bddec9854e110af62ef41b717544c69529 100644 (file)
@@ -1374,7 +1374,7 @@ ir_dereference::is_lvalue() const
 }
 
 
-static const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod", "tg4" };
+static const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod", "tg4", "query_levels" };
 
 const char *ir_texture::opcode_string()
 {
@@ -1403,7 +1403,7 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
    this->sampler = sampler;
    this->type = type;
 
-   if (this->op == ir_txs) {
+   if (this->op == ir_txs || this->op == ir_query_levels) {
       assert(type->base_type == GLSL_TYPE_INT);
    } else if (this->op == ir_lod) {
       assert(type->vector_elements == 2);
index 885837a7ab7a5367432c24368835d91dd8b190d5..37f79f445885507ec075701d1ffa555da680254c 100644 (file)
@@ -1560,7 +1560,8 @@ enum ir_texture_opcode {
    ir_txf_ms,           /**< Multisample texture fetch */
    ir_txs,             /**< Texture size */
    ir_lod,             /**< Texture lod query */
-   ir_tg4              /**< Texture gather */
+   ir_tg4,             /**< Texture gather */
+   ir_query_levels      /**< Texture levels query */
 };
 
 
@@ -1586,6 +1587,7 @@ enum ir_texture_opcode {
  * (txs <type> <sampler> <lod>)
  * (lod <type> <sampler> <coordinate>)
  * (tg4 <type> <sampler> <coordinate> 0)
+ * (query_levels <type> <sampler>)
  */
 class ir_texture : public ir_rvalue {
 public:
index fe531a8e3065266e5d4c358241c82a6a7b218c46..8a40cb01b2fc5fd584b763c303049cd687b51dfd 100644 (file)
@@ -249,6 +249,7 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
    case ir_tex:
    case ir_lod:
    case ir_tg4:
+   case ir_query_levels:
       break;
    case ir_txb:
       new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht);
index 3877e721c24429bd728674239223c1a056212ae7..3aa008ac9829c595e56a57f7812ee0bd0e5cd71e 100644 (file)
@@ -215,6 +215,7 @@ ir_texture::accept(ir_hierarchical_visitor *v)
    case ir_tex:
    case ir_lod:
    case ir_tg4:
+   case ir_query_levels:
       break;
    case ir_txb:
       s = this->lod_info.bias->accept(v);
index 2c06b95f61a0b0f79a2503d02530176f37fd25d2..531adc2997d82035df00aabc8608af17d950e7ca 100644 (file)
@@ -252,7 +252,7 @@ void ir_print_visitor::visit(ir_texture *ir)
    ir->sampler->accept(this);
    printf(" ");
 
-   if (ir->op != ir_txs) {
+   if (ir->op != ir_txs && ir->op != ir_query_levels) {
       ir->coordinate->accept(this);
 
       printf(" ");
@@ -266,7 +266,9 @@ void ir_print_visitor::visit(ir_texture *ir)
       printf(" ");
    }
 
-   if (ir->op != ir_txf && ir->op != ir_txf_ms && ir->op != ir_txs && ir->op != ir_tg4) {
+   if (ir->op != ir_txf && ir->op != ir_txf_ms &&
+       ir->op != ir_txs && ir->op != ir_tg4 &&
+       ir->op != ir_query_levels) {
       if (ir->projector)
         ir->projector->accept(this);
       else
@@ -286,6 +288,7 @@ void ir_print_visitor::visit(ir_texture *ir)
    case ir_tex:
    case ir_lod:
    case ir_tg4:
+   case ir_query_levels:
       break;
    case ir_txb:
       ir->lod_info.bias->accept(this);
index 8038b8f5db26feb0144e549c45fa234e849fa648..ea0c09aebebd0bdcd9bc42b57a1b24af730b66fb 100644 (file)
@@ -949,6 +949,8 @@ ir_reader::read_texture(s_expression *expr)
       { "txs", s_type, s_sampler, s_lod };
    s_pattern tg4_pattern[] =
       { "tg4", s_type, s_sampler, s_coord, s_offset };
+   s_pattern query_levels_pattern[] =
+      { "query_levels", s_type, s_sampler };
    s_pattern other_pattern[] =
       { tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
 
@@ -964,6 +966,8 @@ ir_reader::read_texture(s_expression *expr)
       op = ir_txs;
    } else if (MATCH(expr, tg4_pattern)) {
       op = ir_tg4;
+   } else if (MATCH(expr, query_levels_pattern)) {
+      op = ir_query_levels;
    } else if (MATCH(expr, other_pattern)) {
       op = ir_texture::get_opcode(tag->value());
       if (op == -1)
@@ -1014,7 +1018,9 @@ ir_reader::read_texture(s_expression *expr)
       }
    }
 
-   if (op != ir_txf && op != ir_txf_ms && op != ir_txs && op != ir_lod && op != ir_tg4) {
+   if (op != ir_txf && op != ir_txf_ms &&
+       op != ir_txs && op != ir_lod && op != ir_tg4 &&
+       op != ir_query_levels) {
       s_int *proj_as_int = SX_AS_INT(s_proj);
       if (proj_as_int && proj_as_int->value() == 1) {
         tex->projector = NULL;
index 4c3d813206ca0b924564666fa7968cac0a32eba5..2a79e4d8fb996631df3bbdbf98e58a08b28cc0ee 100644 (file)
@@ -58,6 +58,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
    case ir_tex:
    case ir_lod:
    case ir_tg4:
+   case ir_query_levels:
       break;
    case ir_txb:
       handle_rvalue(&ir->lod_info.bias);
index 03b920d8a2f57097cfaae59b32c36e64a89bbded..bbdc437598366d049a92cdeae8ac9abcf5728bbc 100644 (file)
@@ -276,6 +276,7 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
    case ir_tex:
    case ir_lod:
    case ir_tg4:
+   case ir_query_levels:
       break;
    case ir_txb:
       if (do_graft(&ir->lod_info.bias))
index b03734c06938962d7a740a12d500b16275bf1bee..3b64f2cfc24f07c37053ddb1984a79a1fe5d113b 100644 (file)
@@ -103,6 +103,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
    ctx->Extensions.OES_standard_derivatives = true;
    ctx->Extensions.ARB_texture_cube_map_array = true;
    ctx->Extensions.ARB_texture_multisample = true;
+   ctx->Extensions.ARB_texture_query_levels = true;
    ctx->Extensions.ARB_texture_query_lod = true;
    ctx->Extensions.ARB_gpu_shader5 = true;
    ctx->Extensions.ARB_texture_gather = true;
index f180a7f6486c01ec58aa4653ee0d0edb63fd43c6..6b22b5074154e13c8453d84dd56322d15c21192b 100644 (file)
@@ -2069,6 +2069,9 @@ ir_to_mesa_visitor::visit(ir_texture *ir)
    case ir_tg4:
       assert(!"Unexpected ir_tg4 opcode");
       break;
+   case ir_query_levels:
+      assert(!"Unexpected ir_query_levels opcode");
+      break;
    }
 
    const glsl_type *sampler_type = ir->sampler->type;