From: Kenneth Graunke Date: Wed, 9 Jun 2010 21:42:41 +0000 (-0700) Subject: Implement dFdx, dFdy, and fwidth via new expression opcodes. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b843c7a20c2d65494f30eb82622ae7db380f581a;p=mesa.git Implement dFdx, dFdy, and fwidth via new expression opcodes. --- diff --git a/builtin_function.cpp b/builtin_function.cpp index 377fd509551..4ee43df5dc2 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -2496,6 +2496,82 @@ static const char *functions_for_110 [] = { /* 110_fs builtins */ +static const char *builtins_110_fs_derivatives = { + "((function dFdx\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float dFdx (var_ref p)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 dFdx (var_ref p)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 dFdx (var_ref p)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 dFdx (var_ref p)))))\n" + " )\n" + "\n" + " (function dFdy\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float dFdy (var_ref p)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 dFdy (var_ref p)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 dFdy (var_ref p)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 dFdy (var_ref p)))))\n" + " )\n" + "\n" + " (function fwidth\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float +\n" + " (expression float abs (expression float dFdx (var_ref p)))\n" + " (expression float abs (expression float dFdy (var_ref p)))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 +\n" + " (expression vec2 abs (expression vec2 dFdx (var_ref p)))\n" + " (expression vec2 abs (expression vec2 dFdy (var_ref p)))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 +\n" + " (expression vec3 abs (expression vec3 dFdx (var_ref p)))\n" + " (expression vec3 abs (expression vec3 dFdy (var_ref p)))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 +\n" + " (expression vec4 abs (expression vec4 dFdx (var_ref p)))\n" + " (expression vec4 abs (expression vec4 dFdy (var_ref p)))))))\n" + "))\n" +}; + static const char *builtins_110_fs_textures = { "((function texture1D\n" " (signature vec4\n" @@ -2613,6 +2689,7 @@ static const char *builtins_110_fs_textures = { }; static const char *functions_for_110_fs [] = { + builtins_110_fs_derivatives, builtins_110_fs_textures, }; diff --git a/builtins/110_fs/derivatives b/builtins/110_fs/derivatives new file mode 100644 index 00000000000..b79852ee1ff --- /dev/null +++ b/builtins/110_fs/derivatives @@ -0,0 +1,73 @@ +((function dFdx + (signature float + (parameters + (declare (in) float p)) + ((return (expression float dFdx (var_ref p))))) + + (signature vec2 + (parameters + (declare (in) vec2 p)) + ((return (expression vec2 dFdx (var_ref p))))) + + (signature vec3 + (parameters + (declare (in) vec3 p)) + ((return (expression vec3 dFdx (var_ref p))))) + + (signature vec4 + (parameters + (declare (in) vec4 p)) + ((return (expression vec4 dFdx (var_ref p))))) + ) + + (function dFdy + (signature float + (parameters + (declare (in) float p)) + ((return (expression float dFdy (var_ref p))))) + + (signature vec2 + (parameters + (declare (in) vec2 p)) + ((return (expression vec2 dFdy (var_ref p))))) + + (signature vec3 + (parameters + (declare (in) vec3 p)) + ((return (expression vec3 dFdy (var_ref p))))) + + (signature vec4 + (parameters + (declare (in) vec4 p)) + ((return (expression vec4 dFdy (var_ref p))))) + ) + + (function fwidth + (signature float + (parameters + (declare (in) float p)) + ((return (expression float + + (expression float abs (expression float dFdx (var_ref p))) + (expression float abs (expression float dFdy (var_ref p))))))) + + (signature vec2 + (parameters + (declare (in) vec2 p)) + ((return (expression vec2 + + (expression vec2 abs (expression vec2 dFdx (var_ref p))) + (expression vec2 abs (expression vec2 dFdy (var_ref p))))))) + + (signature vec3 + (parameters + (declare (in) vec3 p)) + ((return (expression vec3 + + (expression vec3 abs (expression vec3 dFdx (var_ref p))) + (expression vec3 abs (expression vec3 dFdy (var_ref p))))))) + + (signature vec4 + (parameters + (declare (in) vec4 p)) + ((return (expression vec4 + + (expression vec4 abs (expression vec4 dFdx (var_ref p))) + (expression vec4 abs (expression vec4 dFdy (var_ref p))))))) +)) diff --git a/ir.cpp b/ir.cpp index ca34c247192..c5eb94d2d50 100644 --- a/ir.cpp +++ b/ir.cpp @@ -76,6 +76,9 @@ ir_expression::get_num_operands(ir_expression_operation op) 1, /* ir_unop_sin */ 1, /* ir_unop_cos */ + 1, /* ir_unop_dFdx */ + 1, /* ir_unop_dFdy */ + 2, /* ir_binop_add */ 2, /* ir_binop_sub */ 2, /* ir_binop_mul */ @@ -136,6 +139,8 @@ static const char *const operator_strs[] = { "floor", "sin", "cos", + "dFdx", + "dFdy", "+", "-", "*", diff --git a/ir.h b/ir.h index 78ea196ffbc..ea4f5494689 100644 --- a/ir.h +++ b/ir.h @@ -494,6 +494,14 @@ enum ir_expression_operation { ir_unop_cos, /*@}*/ + /** + * \name Partial derivatives. + */ + /*@{*/ + ir_unop_dFdx, + ir_unop_dFdy, + /*@}*/ + ir_binop_add, ir_binop_sub, ir_binop_mul,