On 10/14/2013 10:12 AM, Anuj Phogat 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.pho...@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"); > + add_output(FRAG_RESULT_SAMPLE_MASK, array(int_t, 1), "gl_SampleMask");
I don't see code anywhere in this patch series that correctly sizes this array. I thought gl_SampleMask.length() == gl_NumSamples... except you can't use .length() on gl_SampleMask because the size can't be known at compile-time. We should have a test that 'gl_SampleMask.length()' fails to compile. :) The only other array that works like this is gl_TexCoord. That array is sized to 0 (line 837 of builtin_variables.cpp). I believe gl_SampleMask should do the same. > + } > } > > > 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 */ Can we just call these "fragment.sampleid" and "fragment.samplepos"? > "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 */ Since these should never appear in a vertex shader, I think it's okay to leave these as "result.(twenty-...)". > "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 */ NV_gpu_shader5 doesn't have the _, so I think "result.samplemask" is slightly better. > "result.color[0]", /* FRAG_RESULT_DATA0 (named for GLSL's gl_FragData) > */ > "result.color[1]", > "result.color[2]", > _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev