[Mesa-dev] [PATCH 10/17] glsl: Define a gl_LastFragData built-in for GLSL versions that have gl_FragData.

Kenneth Graunke kenneth at whitecape.org
Fri Jul 22 22:20:54 UTC 2016


On Wednesday, July 20, 2016 9:49:40 PM PDT Francisco Jerez wrote:
> The EXT_shader_framebuffer_fetch extension defines alternative
> language for GLES2 shaders where user-defined fragment outputs are not
> allowed.  Instead of using inout user-defined fragment outputs the
> shader is expected to read from the gl_LastFragData built-in array.
> In addition this allows using the same language on desktop GLSL
> versions prior to 4.2 that support the deprecated gl_FragData built-in
> in preparation for the MESA_shader_framebuffer_fetch desktop GL
> extension.
> 
> Both legacy and user-defined inout outputs have a common
> representation at the GLSL IR level, so it shouldn't make any
> difference for optimization passes and back-ends whether the
> application is using gl_LastFragData or user-defined outputs, all
> they'll see is a variable dereference of a fragment output at a
> certain interface location with the fb_fetch_output bit set to one.
> ---
>  src/compiler/glsl/builtin_variables.cpp | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp
> index f63dc3a..6a756ed 100644
> --- a/src/compiler/glsl/builtin_variables.cpp
> +++ b/src/compiler/glsl/builtin_variables.cpp
> @@ -1136,6 +1136,16 @@ builtin_variable_generator::generate_fs_special_vars()
>                   array(vec4_t, state->Const.MaxDrawBuffers), "gl_FragData");
>     }
>  
> +   if (state->has_framebuffer_fetch() && !state->is_version(420, 300)) {
> +      ir_variable *const var =
> +         add_output(FRAG_RESULT_DATA0,
> +                    array(vec4_t, state->Const.MaxDrawBuffers),
> +                    "gl_LastFragData");
> +      var->data.precision = GLSL_PRECISION_MEDIUM;
> +      var->data.read_only = 1;
> +      var->data.fb_fetch_output = 1;
> +   }
> +

Personally, I'd only create gl_LastFragData in desktop 1.10/1.20,
and not 1.30+ where it's deprecated.  Sure, you /can/ use it, but
you can also do the 'inout' syntax that's the preferred way going
forward, so we may as well just require shader authors to do so.

>     if (state->es_shader && state->language_version == 100 && state->EXT_blend_func_extended_enable) {
>        /* We make an assumption here that there will only ever be one dual-source draw buffer
>         * In case this assumption is ever proven to be false, make sure to assert here
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160722/a248f5af/attachment-0001.sig>


More information about the mesa-dev mailing list