[Mesa-dev] [PATCH V4 02/13] glsl: add texture gather changes
Ian Romanick
idr at freedesktop.org
Mon Sep 30 11:03:40 PDT 2013
On 09/30/2013 03:08 AM, Chris Forbes wrote:
> From: Maxence Le Dore <maxence.ledore at gmail.com>
>
> V2 [Chris Forbes]:
> - Add new pattern, fixup parameter reading.
>
> V3: Rebase onto new builtins machinery
>
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
> src/glsl/builtin_functions.cpp | 35 +++++++++++++++++++++++++++++++++++
> 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 +++++
> 14 files changed, 62 insertions(+), 4 deletions(-)
>
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
> index 72054e0..df735ef 100644
> --- a/src/glsl/builtin_functions.cpp
> +++ b/src/glsl/builtin_functions.cpp
> @@ -262,6 +262,13 @@ texture_query_lod(const _mesa_glsl_parse_state *state)
> state->ARB_texture_query_lod_enable;
> }
>
> +static bool
> +texture_gather(const _mesa_glsl_parse_state *state)
> +{
> + return state->is_version(400, 0) ||
> + state->ARB_texture_gather_enable;
> +}
> +
This should be glsl_parser_state::has_texture_gather, like in Ken's
f91475d... though it looks like some of the rest of this file could be
modified to use that pattern. Hrm...
> /* Desktop GL or OES_standard_derivatives + fragment shader only */
> static bool
> fs_oes_derivatives(const _mesa_glsl_parse_state *state)
> @@ -1816,6 +1823,34 @@ builtin_builder::create_builtins()
> _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
> NULL);
>
> + add_function("textureGather",
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
> +
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
> +
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
> +
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
> + NULL);
> +
> + add_function("textureGatherOffset",
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
> +
> + _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
> + _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
> + _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
> + NULL);
> +
> F(dFdx)
> F(dFdy)
> F(fwidth)
> diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
> index 6eaa5f9..c7ad3e9 100644
> --- a/src/glsl/glcpp/glcpp-parse.y
> +++ b/src/glsl/glcpp/glcpp-parse.y
> @@ -1248,6 +1248,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
>
> if (extensions->EXT_shader_integer_mix)
> add_builtin_define(parser, "GL_EXT_shader_integer_mix", 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 e9922fc..813db6f 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -510,6 +510,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
> EXT(ARB_gpu_shader5, true, false, ARB_gpu_shader5),
> EXT(AMD_vertex_shader_layer, true, false, AMD_vertex_shader_layer),
> EXT(EXT_shader_integer_mix, true, true, EXT_shader_integer_mix),
> + EXT(ARB_texture_gather, true, false, ARB_texture_gather),
> };
>
> #undef EXT
> diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
> index cef4436..042deeb 100644
> --- a/src/glsl/glsl_parser_extras.h
> +++ b/src/glsl/glsl_parser_extras.h
> @@ -274,6 +274,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 b0f92cb..81c6380 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -1374,7 +1374,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 6c5630b..885837a 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1559,7 +1559,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 */
> };
>
>
> @@ -1584,6 +1585,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 fb303b0..fe531a8 100644
> --- a/src/glsl/ir_clone.cpp
> +++ b/src/glsl/ir_clone.cpp
> @@ -248,6 +248,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 76a607d..3877e72 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 b518310..2c06b95 100644
> --- a/src/glsl/ir_print_visitor.cpp
> +++ b/src/glsl/ir_print_visitor.cpp
> @@ -266,7 +266,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
> @@ -285,6 +285,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 f0318ea..8038b8f 100644
> --- a/src/glsl/ir_reader.cpp
> +++ b/src/glsl/ir_reader.cpp
> @@ -947,6 +947,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 };
>
> @@ -960,6 +962,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)
> @@ -1010,7 +1014,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 8eb1c62..4c3d813 100644
> --- a/src/glsl/ir_rvalue_visitor.cpp
> +++ b/src/glsl/ir_rvalue_visitor.cpp
> @@ -57,6 +57,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 6dec205..b03734c 100644
> --- a/src/glsl/standalone_scaffolding.cpp
> +++ b/src/glsl/standalone_scaffolding.cpp
> @@ -105,6 +105,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
> ctx->Extensions.ARB_texture_multisample = true;
> ctx->Extensions.ARB_texture_query_lod = true;
> ctx->Extensions.ARB_gpu_shader5 = 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 8cd42df..53042c9 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -2066,6 +2066,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;
>
More information about the mesa-dev
mailing list