[Mesa-dev] [PATCH 4/8] glsl: Add new builtins required by GL_ARB_sample_shading

Anuj Phogat anuj.phogat at gmail.com
Thu Oct 24 00:35:58 CEST 2013


On Fri, Oct 18, 2013 at 2:57 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> On 14 October 2013 10:12, Anuj Phogat <anuj.phogat at gmail.com> wrote:
>>
>> New builtins added by GL_ARB_sample_shading:
>> in vec2 gl_SamplePosition
>> in int gl_SampleID
>> in int gl_NumSamples
>> out int gl_SampleMask[]
>>
>> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
>> ---
>>  src/glsl/builtin_variables.cpp | 11 +++++++++++
>>  src/glsl/link_varyings.cpp     |  2 ++
>>  src/mesa/main/mtypes.h         |  7 ++++++-
>>  src/mesa/program/prog_print.c  |  5 +++++
>>  4 files changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/glsl/builtin_variables.cpp
>> b/src/glsl/builtin_variables.cpp
>> index ae0a03f..c886840 100644
>> --- a/src/glsl/builtin_variables.cpp
>> +++ b/src/glsl/builtin_variables.cpp
>> @@ -30,6 +30,9 @@
>>  #include "program/prog_statevars.h"
>>  #include "program/prog_instruction.h"
>>
>> +static struct gl_builtin_uniform_element gl_NumSamples_elements[] = {
>> +   {NULL, {STATE_NUM_SAMPLES, 0, 0}, SWIZZLE_XYZW}
>> +};
>>
>>  static struct gl_builtin_uniform_element gl_DepthRange_elements[] = {
>>     {"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},
>> @@ -236,6 +239,7 @@ static struct gl_builtin_uniform_element
>> gl_NormalMatrix_elements[] = {
>>  #define STATEVAR(name) {#name, name ## _elements, Elements(name ##
>> _elements)}
>>
>>  static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[]
>> = {
>> +   STATEVAR(gl_NumSamples),
>>     STATEVAR(gl_DepthRange),
>>     STATEVAR(gl_ClipPlane),
>>     STATEVAR(gl_Point),
>> @@ -613,6 +617,7 @@ builtin_variable_generator::generate_constants()
>>  void
>>  builtin_variable_generator::generate_uniforms()
>>  {
>> +   add_uniform(int_t, "gl_NumSamples");
>>     add_uniform(type("gl_DepthRangeParameters"), "gl_DepthRange");
>>     add_uniform(array(vec4_t, VERT_ATTRIB_MAX),
>> "gl_CurrentAttribVertMESA");
>>     add_uniform(array(vec4_t, VARYING_SLOT_MAX),
>> "gl_CurrentAttribFragMESA");
>> @@ -789,6 +794,12 @@
>> builtin_variable_generator::generate_fs_special_vars()
>>        if (state->AMD_shader_stencil_export_warn)
>>           var->warn_extension = "GL_AMD_shader_stencil_export";
>>     }
>> +
>> +   if (state->ARB_sample_shading_enable) {
>> +      add_input(VARYING_SLOT_SAMPLE_ID, int_t, "gl_SampleID");
>> +      add_input(VARYING_SLOT_SAMPLE_POS, vec2_t, "gl_SamplePosition");
>
>
> Can we make gl_SampleID and gl_SamplePosition system values (like
> SYSTEM_VALUE_VERTEX_ID and SYSTEM_VALUE_INSTANCE_ID) instead of varyings?
> They aren't really varyings at all (since they don't appear in any shader
> stage except the fragment shader), and that way they won't take up space in
> all the data structures that we use to represent varyings (such as the i965
> VUE map).
>
Yes, making them system values make more sense. I'll fix it in my V2 series.

> With that fixed, and assuming that the other issues brought up by Ken and
> Ian are addressed, this patch is:
>
> Reviewed-by: Paul Berry <stereotype441 at gmail.com>
>
>>
>> +      add_output(FRAG_RESULT_SAMPLE_MASK, array(int_t, 1),
>> "gl_SampleMask");
>> +   }
>>  }
>>
>>
>> diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp
>> index 4ba6d8a..3595a58 100644
>> --- a/src/glsl/link_varyings.cpp
>> +++ b/src/glsl/link_varyings.cpp
>> @@ -938,6 +938,8 @@ is_varying_var(GLenum shaderType, const ir_variable
>> *var)
>>        case VARYING_SLOT_POS:
>>        case VARYING_SLOT_FACE:
>>        case VARYING_SLOT_PNTC:
>> +      case VARYING_SLOT_SAMPLE_ID:
>> +      case VARYING_SLOT_SAMPLE_POS:
>>           return false;
>>        default:
>>           return true;
>> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
>> index 5520e86..65ec829 100644
>> --- a/src/mesa/main/mtypes.h
>> +++ b/src/mesa/main/mtypes.h
>> @@ -236,6 +236,8 @@ typedef enum
>>     VARYING_SLOT_LAYER, /* Appears as VS or GS output */
>>     VARYING_SLOT_FACE, /* FS only */
>>     VARYING_SLOT_PNTC, /* FS only */
>> +   VARYING_SLOT_SAMPLE_ID, /* FS only */
>> +   VARYING_SLOT_SAMPLE_POS, /* FS only */
>>     VARYING_SLOT_VAR0, /* First generic varying slot */
>>     VARYING_SLOT_MAX = VARYING_SLOT_VAR0 + MAX_VARYING
>>  } gl_varying_slot;
>> @@ -272,6 +274,8 @@ typedef enum
>>  #define VARYING_BIT_FACE BITFIELD64_BIT(VARYING_SLOT_FACE)
>>  #define VARYING_BIT_PNTC BITFIELD64_BIT(VARYING_SLOT_PNTC)
>>  #define VARYING_BIT_VAR(V) BITFIELD64_BIT(VARYING_SLOT_VAR0 + (V))
>> +#define VARYING_BIT_SAMPLE_ID BITFIELD64_BIT(VARYING_SLOT_SAMPLE_ID)
>> +#define VARYING_BIT_SAMPLE_POS BITFIELD64_BIT(VARYING_SLOT_SAMPLE_POS)
>>  /*@}*/
>>
>>
>> @@ -306,12 +310,13 @@ typedef enum
>>      * register is written.  No FRAG_RESULT_DATAn will be written.
>>      */
>>     FRAG_RESULT_COLOR = 2,
>> +   FRAG_RESULT_SAMPLE_MASK = 3,
>>
>>     /* FRAG_RESULT_DATAn are the per-render-target (GLSL gl_FragData[n]
>>      * or ARB_fragment_program fragment.color[n]) color results.  If
>>      * any are written, FRAG_RESULT_COLOR will not be written.
>>      */
>> -   FRAG_RESULT_DATA0 = 3,
>> +   FRAG_RESULT_DATA0 = 4,
>>     FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
>>  } gl_frag_result;
>>
>> diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c
>> index cf85213..0c56ae6 100644
>> --- a/src/mesa/program/prog_print.c
>> +++ b/src/mesa/program/prog_print.c
>> @@ -150,6 +150,8 @@ arb_input_attrib_string(GLint index, GLenum progType)
>>        "fragment.(twenty)", /* VARYING_SLOT_LAYER */
>>        "fragment.(twenty-one)", /* VARYING_SLOT_FACE */
>>        "fragment.(twenty-two)", /* VARYING_SLOT_PNTC */
>> +      "fragment.(twenty-three)", /* VARYING_SLOT_SAMPLE_ID */
>> +      "fragment.(twenty-four)", /* VARYING_SLOT_SAMPLE_POS */
>>        "fragment.varying[0]",
>>        "fragment.varying[1]",
>>        "fragment.varying[2]",
>> @@ -274,6 +276,8 @@ arb_output_attrib_string(GLint index, GLenum progType)
>>        "result.(twenty)", /* VARYING_SLOT_LAYER */
>>        "result.(twenty-one)", /* VARYING_SLOT_FACE */
>>        "result.(twenty-two)", /* VARYING_SLOT_PNTC */
>> +      "result.(twenty-three)", /* VARYING_SLOT_SAMPLE_ID */
>> +      "result.(twenty-four)", /* VARYING_SLOT_SAMPLE_POS */
>>        "result.varying[0]",
>>        "result.varying[1]",
>>        "result.varying[2]",
>> @@ -311,6 +315,7 @@ arb_output_attrib_string(GLint index, GLenum progType)
>>        "result.depth", /* FRAG_RESULT_DEPTH */
>>        "result.(one)", /* FRAG_RESULT_STENCIL */
>>        "result.color", /* FRAG_RESULT_COLOR */
>> +      "result.sample_mask", /* FRAG_RESULT_SAMPLE_MASK */
>>        "result.color[0]", /* FRAG_RESULT_DATA0 (named for GLSL's
>> gl_FragData) */
>>        "result.color[1]",
>>        "result.color[2]",
>> --
>> 1.8.1.4
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
>


More information about the mesa-dev mailing list