[Mesa-dev] [PATCH v2 2/5] glsl: add ARB_derivative control support
Signed-off-by: Ilia Mirkin --- 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_w
Re: [Mesa-dev] [PATCH v2 2/5] glsl: add ARB_derivative control support
Reviewed-by: Matt Turner ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 2/5] glsl: add ARB_derivative control support
This patch is Reviewed-by: Ian Romanick On 08/13/2014 10:48 PM, Ilia Mirkin wrote: > Signed-off-by: Ilia Mirkin > --- > > 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 > ---