<div dir="ltr">On 28 August 2013 11:49, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 08/28/2013 10:57 AM, Paul Berry wrote:<br>
> On 28 August 2013 10:55, Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a><br>
</div><div class="im">> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>> wrote:<br>
><br>
> On 08/28/2013 09:36 AM, Paul Berry wrote:<br>
> > On 27 August 2013 18:45, Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a><br>
> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>><br>
</div><div class="im">> > <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>>> wrote:<br>
> ><br>
> > From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a><br>
> <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
</div>> > <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a><br>
<div class="im">> <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>>>><br>
> ><br>
> > This will be used in future commits.<br>
> ><br>
> > v2: Use current program state to determine whether to use<br>
> fixed-function<br>
> > attributes. There are two proposals in this patch. Hopefully<br>
> reviewers<br>
> > will pick one. The first method checks whether the current<br>
> program<br>
> > contains an attribute named "piglit_vertex". If it does,<br>
> fixed-function<br>
> > attributes are not used. The other method check whether the<br>
> current<br>
> > program contains an attribute whose name starts with "gl_".<br>
> If it does,<br>
> > fixed-function attributes are used.<br>
> ><br>
> > Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a><br>
> <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
</div>> > <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a><br>
<div class="im">> <mailto:<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>>>><br>
> > Cc: Matt Turner <<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a><br>
</div>> <mailto:<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>> <mailto:<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a><br>
<div class="im">> <mailto:<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>>>><br>
> > Cc: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a><br>
> <mailto:<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div>> > <mailto:<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a> <mailto:<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>>>><br>
<div class="im">> > Cc: Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a> <mailto:<a href="mailto:eric@anholt.net">eric@anholt.net</a>><br>
</div>> <mailto:<a href="mailto:eric@anholt.net">eric@anholt.net</a> <mailto:<a href="mailto:eric@anholt.net">eric@anholt.net</a>>>><br>
<div><div class="h5">> > ---<br>
> > tests/util/piglit-util-gl-common.c | 123<br>
> > ++++++++++++++++++++++++++++---------<br>
> > 1 file changed, 95 insertions(+), 28 deletions(-)<br>
> ><br>
> > diff --git a/tests/util/piglit-util-gl-common.c<br>
> > b/tests/util/piglit-util-gl-common.c<br>
> > index b5e87bf..ec66a65 100644<br>
> > --- a/tests/util/piglit-util-gl-common.c<br>
> > +++ b/tests/util/piglit-util-gl-common.c<br>
> > @@ -603,42 +603,109 @@<br>
> > required_gl_version_from_glsl_version(unsigned glsl_version)<br>
> > void<br>
> > piglit_draw_rect_from_arrays(const void *verts, const void *tex)<br>
> > {<br>
> > -#if defined(PIGLIT_USE_OPENGL_ES1) || defined(PIGLIT_USE_OPENGL)<br>
> > - if (verts) {<br>
> > - glVertexPointer(4, GL_FLOAT, 0, verts);<br>
> > - glEnableClientState(GL_VERTEX_ARRAY);<br>
> > - }<br>
> > +#if defined(PIGLIT_USE_OPENGL_ES1)<br>
> > + static const bool use_fixed_function_attributes = true;<br>
> > +#elif defined(PIGLIT_USE_OPENGL_ES2) ||<br>
> defined(PIGLIT_USE_OPENGL_ES3)<br>
> > + static const bool use_fixed_function_attributes = false;<br>
> ><br>
> ><br>
> > I realize I'm quibbling here, but using "static" on these consts seems<br>
> > strange to me. Since the compiler is going to optimize them away<br>
> > anyhow, it seems silly to ask it to put them in the data segment. In<br>
> > fact, it makes me worry that it might defeat constant folding for some<br>
> > stupid reason.<br>
> ><br>
> ><br>
> > +#elif defined(PIGLIT_USE_OPENGL)<br>
> > + bool use_fixed_function_attributes = true;<br>
> > +#else<br>
> > +#error "don't know how to draw arrays"<br>
> > +#endif<br>
> ><br>
> > - if (tex) {<br>
> > - glTexCoordPointer(2, GL_FLOAT, 0, tex);<br>
> > - glEnableClientState(GL_TEXTURE_COORD_ARRAY);<br>
> > +#if defined(PIGLIT_USE_OPENGL)<br>
> > + if (piglit_get_gl_version() >= 20<br>
> > + ||<br>
> piglit_is_extension_supported("GL_ARB_shader_objects")) {<br>
> > + GLuint prog;<br>
> > +<br>
> > + glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)<br>
> &prog);<br>
> > +<br>
> > +#define PLAN_A<br>
> > +#ifdef PLAN_A<br>
> > + /* If there is a current program and that<br>
> program has an<br>
> > + * active attribute named piglit_vertex, don't use<br>
> > the fixed<br>
> > + * function inputs.<br>
> > + */<br>
> > + use_fixed_function_attributes = prog == 0<br>
> > + || glGetAttribLocation(prog,<br>
> > "piglit_vertex") == -1;<br>
> > +#elif defined PLAN_B<br>
> > + if (prog != 0) {<br>
> > + GLint num_attribs;<br>
> > + int i;<br>
> > + char name[64];<br>
> > + GLint size;<br>
> > + GLenum type;<br>
> > +<br>
> > + /* Assume that fixed-function attributes<br>
> > won't be used<br>
> > + * until an attribute with the name "gl_*"<br>
> > is found.<br>
> > + */<br>
> > + use_fixed_function_attributes = false;<br>
> > +<br>
> > + glGetProgramiv(prog,<br>
> > + GL_ACTIVE_ATTRIBUTES,<br>
> > + &num_attribs);<br>
> > +<br>
> > + for (i = 0; i < num_attribs; i++) {<br>
> > + glGetActiveAttrib(prog,<br>
> > + i,<br>
> > + sizeof(name),<br>
> > + NULL,<br>
> > + &size,<br>
> > + &type,<br>
> > + name);<br>
> > +<br>
> > + if (strncmp("gl_", name, 3) ==<br>
> 0) {<br>
> > +<br>
> > use_fixed_function_attributes = true;<br>
> > + break;<br>
> > + }<br>
> > + }<br>
> > + }<br>
> > +#endif<br>
> ><br>
> ><br>
> > I have a strong preference for plan A. Here's my reasons:<br>
> ><br>
> > 1. It's simpler.<br>
><br>
> That is its primary advantage. As a disadvantage, it means that we have<br>
> to have a variable named "piglit_vertex". I've noticed that most of the<br>
> existing test that use 'draw arrays' name the vertex input "vertex".<br>
> Plan B would correctly identify those.<br>
><br>
> What I wanted as a query that would tell me what name was bound to<br>
> attribute 0. I believe ARB_program_interface_query gives this ability,<br>
> but alas.<br>
><br>
> > 2. I didn't have to look at the GL spec to reassure myself that it was<br>
> > correct (with plan B, I was briefly worried that glGetActiveAttrib<br>
> would<br>
> > only return information about user-defined vertex inputs).<br>
> ><br>
> > 3. It correctly classifies shaders like this:<br>
> ><br>
> > in vec4 piglit_vertex;<br>
> > out vec4 vertex_id;<br>
> > void main()<br>
> > {<br>
> > gl_Position = piglit_vertex;<br>
> > vertex_id = gl_VertexID;<br>
> > }<br>
><br>
> Are you sure? That seems surprising to me. It's a vertex shader input,<br>
> but it's not really an attribute (you can't source it's value from<br>
> anywhere). I wouldn't have thought that any of the gl_*ID variables<br>
> would be returned by glGetActiveAttrib.<br>
><br>
><br>
> the GL 4.4 core spec says it does. From section 11.1.1 (Vertex<br>
> Attributes), on page 343:<br>
><br>
> For GetActiveAttrib, all active vertex shader input variables are<br>
> enumerated,<br>
> including the special built-in inputs gl_VertexID and gl_InstanceID.<br>
<br>
</div></div>Well... you learn something new every day. That's an argument against<br>
as least the current version of plan B.<br>
<br>
Do we have test cases for this?<br></blockquote><div><br></div><div>None that I can find. I've made a note of it in my to-do list, but I doubt I'll get to it until geometry shaders are a lot further along.<br></div>
</div></div></div>