[Mesa-dev] [PATCH v2 2/5] glsl: add ARB_derivative control support
Ian Romanick
idr at freedesktop.org
Thu Aug 14 12:05:14 PDT 2014
This patch is
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
On 08/13/2014 10:48 PM, Ilia Mirkin wrote:
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>
> Oops :) The piglit tests caught these...
>
> v1 -> v2:
> - add constant expression handling
> - add name strings for new opcodes
> - add new opcodes into ir_expression constructor
>
> src/glsl/builtin_functions.cpp | 48 +++++++++++++++++++++++++++++++++++++
> 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 | 8 +++++++
> src/glsl/ir.h | 4 ++++
> src/glsl/ir_constant_expression.cpp | 4 ++++
> src/glsl/ir_validate.cpp | 4 ++++
> 8 files changed, 74 insertions(+)
>
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
> index 185fe98..c882ec8 100644
> --- a/src/glsl/builtin_functions.cpp
> +++ b/src/glsl/builtin_functions.cpp
> @@ -318,6 +318,14 @@ fs_oes_derivatives(const _mesa_glsl_parse_state *state)
> }
>
> static bool
> +fs_derivative_control(const _mesa_glsl_parse_state *state)
> +{
> + return state->stage == MESA_SHADER_FRAGMENT &&
> + (state->is_version(450, 0) ||
> + state->ARB_derivative_control_enable);
> +}
> +
> +static bool
> tex1d_lod(const _mesa_glsl_parse_state *state)
> {
> return !state->es_shader && lod_exists_in_stage(state);
> @@ -618,6 +626,12 @@ private:
> B1(dFdx);
> B1(dFdy);
> B1(fwidth);
> + B1(dFdxCoarse);
> + B1(dFdyCoarse);
> + B1(fwidthCoarse);
> + B1(dFdxFine);
> + B1(dFdyFine);
> + B1(fwidthFine);
> B1(noise1);
> B1(noise2);
> B1(noise3);
> @@ -2148,6 +2162,12 @@ builtin_builder::create_builtins()
> F(dFdx)
> F(dFdy)
> F(fwidth)
> + F(dFdxCoarse)
> + F(dFdyCoarse)
> + F(fwidthCoarse)
> + F(dFdxFine)
> + F(dFdyFine)
> + F(fwidthFine)
> F(noise1)
> F(noise2)
> F(noise3)
> @@ -4010,7 +4030,11 @@ builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
> }
>
> UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
> +UNOP(dFdxCoarse, ir_unop_dFdx_coarse, fs_derivative_control)
> +UNOP(dFdxFine, ir_unop_dFdx_fine, fs_derivative_control)
> UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
> +UNOP(dFdyCoarse, ir_unop_dFdy_coarse, fs_derivative_control)
> +UNOP(dFdyFine, ir_unop_dFdy_fine, fs_derivative_control)
>
> ir_function_signature *
> builtin_builder::_fwidth(const glsl_type *type)
> @@ -4024,6 +4048,30 @@ builtin_builder::_fwidth(const glsl_type *type)
> }
>
> ir_function_signature *
> +builtin_builder::_fwidthCoarse(const glsl_type *type)
> +{
> + ir_variable *p = in_var(type, "p");
> + MAKE_SIG(type, fs_derivative_control, 1, p);
> +
> + body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
> + abs(expr(ir_unop_dFdy_coarse, p)))));
> +
> + return sig;
> +}
> +
> +ir_function_signature *
> +builtin_builder::_fwidthFine(const glsl_type *type)
> +{
> + ir_variable *p = in_var(type, "p");
> + MAKE_SIG(type, fs_derivative_control, 1, p);
> +
> + body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
> + abs(expr(ir_unop_dFdy_fine, p)))));
> +
> + return sig;
> +}
> +
> +ir_function_signature *
> builtin_builder::_noise1(const glsl_type *type)
> {
> return unop(v110, ir_unop_noise, glsl_type::float_type, type);
> diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
> index a616973..f1119eb 100644
> --- a/src/glsl/glcpp/glcpp-parse.y
> +++ b/src/glsl/glcpp/glcpp-parse.y
> @@ -2469,6 +2469,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
>
> if (extensions->ARB_shader_image_load_store)
> add_builtin_define(parser, "GL_ARB_shader_image_load_store", 1);
> +
> + if (extensions->ARB_derivative_control)
> + add_builtin_define(parser, "GL_ARB_derivative_control", 1);
> }
> }
>
> diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
> index ad91c46..490c3c8 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -514,6 +514,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
> EXT(ARB_arrays_of_arrays, true, false, ARB_arrays_of_arrays),
> EXT(ARB_compute_shader, true, false, ARB_compute_shader),
> EXT(ARB_conservative_depth, true, false, ARB_conservative_depth),
> + EXT(ARB_derivative_control, true, false, ARB_derivative_control),
> EXT(ARB_draw_buffers, true, false, dummy_true),
> EXT(ARB_draw_instanced, true, false, ARB_draw_instanced),
> EXT(ARB_explicit_attrib_location, true, false, ARB_explicit_attrib_location),
> diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
> index ce66e2f..c8b9478 100644
> --- a/src/glsl/glsl_parser_extras.h
> +++ b/src/glsl/glsl_parser_extras.h
> @@ -393,6 +393,8 @@ struct _mesa_glsl_parse_state {
> bool ARB_compute_shader_warn;
> bool ARB_conservative_depth_enable;
> bool ARB_conservative_depth_warn;
> + bool ARB_derivative_control_enable;
> + bool ARB_derivative_control_warn;
> bool ARB_draw_buffers_enable;
> bool ARB_draw_buffers_warn;
> bool ARB_draw_instanced_enable;
> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
> index 28fd94b..4a4d304 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -248,7 +248,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
> case ir_unop_sin_reduced:
> case ir_unop_cos_reduced:
> case ir_unop_dFdx:
> + case ir_unop_dFdx_coarse:
> + case ir_unop_dFdx_fine:
> case ir_unop_dFdy:
> + case ir_unop_dFdy_coarse:
> + case ir_unop_dFdy_fine:
> case ir_unop_bitfield_reverse:
> case ir_unop_interpolate_at_centroid:
> this->type = op0->type;
> @@ -509,7 +513,11 @@ static const char *const operator_strs[] = {
> "sin_reduced",
> "cos_reduced",
> "dFdx",
> + "dFdxCoarse",
> + "dFdxFine",
> "dFdy",
> + "dFdyCoarse",
> + "dFdyFine",
> "packSnorm2x16",
> "packSnorm4x8",
> "packUnorm2x16",
> diff --git a/src/glsl/ir.h b/src/glsl/ir.h
> index 31c3545..18623b9 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1205,7 +1205,11 @@ enum ir_expression_operation {
> */
> /*@{*/
> ir_unop_dFdx,
> + ir_unop_dFdx_coarse,
> + ir_unop_dFdx_fine,
> ir_unop_dFdy,
> + ir_unop_dFdy_coarse,
> + ir_unop_dFdy_fine,
> /*@}*/
>
> /**
> diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
> index 5570ed4..9606021 100644
> --- a/src/glsl/ir_constant_expression.cpp
> +++ b/src/glsl/ir_constant_expression.cpp
> @@ -851,7 +851,11 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
> break;
>
> case ir_unop_dFdx:
> + case ir_unop_dFdx_coarse:
> + case ir_unop_dFdx_fine:
> case ir_unop_dFdy:
> + case ir_unop_dFdy_coarse:
> + case ir_unop_dFdy_fine:
> assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
> for (unsigned c = 0; c < op[0]->type->components(); c++) {
> data.f[c] = 0.0;
> diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
> index 4f85b7d..5b20677 100644
> --- a/src/glsl/ir_validate.cpp
> +++ b/src/glsl/ir_validate.cpp
> @@ -317,7 +317,11 @@ ir_validate::visit_leave(ir_expression *ir)
> case ir_unop_sin_reduced:
> case ir_unop_cos_reduced:
> case ir_unop_dFdx:
> + case ir_unop_dFdx_coarse:
> + case ir_unop_dFdx_fine:
> case ir_unop_dFdy:
> + case ir_unop_dFdy_coarse:
> + case ir_unop_dFdy_fine:
> assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
> assert(ir->operands[0]->type == ir->type);
> break;
>
More information about the mesa-dev
mailing list