[Mesa-dev] about varying support for i915

Yuanhan Liu yuanhan.liu at linux.intel.com
Wed Mar 7 03:28:58 PST 2012


Hi Eric,

Few days ago, I wrote a patch(058fc6521e3bc483bc948cc90dc5ee3b08d6ec64)
to fix an issue specifying the point size in vertex shader. And I
mentiond it also fixed the point-size.html webglc case. Well, it does fix
the piglit case glsl-vs-point-size, but it doesn't fix the webglc case.
I don't know why I remember that my patch fixed the webglc issue as
well. I guess this is becase it fixed the gl case I wrote for the webglc
case(I wrote a local gl program to do exctally what the case do for
debugging).  Really sorry for the mistake I made first.


Then I continued to figure out why my patches doesn't work. It takes me
quite a while to figure out why my local gl program passed while the
webglc case failed, since I do write my gl program extaclly just like
the webglc case. 

And finally, I found the root cause: chrome(and firefox as well) will
call glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) and
glEnable(GL_POINT_SPRITE_ARB) first when init the GPU process. (well,
this turned out that my former patch does work).

So, here is how the issue triggered. Firstly, the case(I also attached
my another gl testcase for reproducing this issue) using glsl varying
var to assign the glFragColor like the following code:
    varying vec4 color;
    void main()
    {
           gl_FragColor = color;
    }

which translated to: 
   fp:
   # Fragment Program/Shader 3
     0: MOV OUTPUT[2], INPUT[16];
     1: END
   
   # Fragment Program/Shader 3
     0: MOV OUTPUT[2], INPUT[16];
     1: END
   i915:
                   BEGIN
                   DCL T_TEX0
                   oC = MOV T_TEX0
                   END

And I found that i915 varying support is added by you by the commit
f9f31b25740887373806cb489e5480dc9b261805, which you just use the texture
coord.

So, when the POINT_SPRITE_ARB is enabled(always enabled in chrome and
firefox), the texture coord is replaced due to point sprite is enabled.
Thus the varying support isn't work.


Honestly speaking, I don't quite understand how the shader handling
varying inputs works.  Would you mind please educate me a little bit?
(I will try to understand that by reading more, of course).

BTW, any thoughts on handling varying inputs better(I mean, don't use
texture coord)?

You can use the program I attached to reproduce this issue on pineview.

Thanks,
Yuanhan Liu
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <assert.h>

static const char *vs = 
"#version 120\n"
"attribute vec3 pos;\n"
"attribute vec4 colorIn;\n"
"varying vec4 color;\n"
"uniform float pointSize;\n"
"void main()\n"
"{\n"
"	color = colorIn;\n"
"	gl_Position = vec4(pos, 1.0);\n"
"}\n";

static const char *ps =
"#version 120\n"
"varying vec4 color;\n"
"void main()\n"
"{\n"
"	gl_FragColor = color;\n"
"}\n";

static GLuint shader_stuff()
{
	GLuint shaderProgram;
	GLuint vertexShader, fragmentShader;

	vertexShader = glCreateShader(GL_VERTEX_SHADER);
	fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

	glShaderSource(vertexShader, 1, &vs, NULL);
	glShaderSource(fragmentShader, 1, &ps, NULL);
	glCompileShader(vertexShader);
	glCompileShader(fragmentShader);

	shaderProgram = glCreateProgram();
	glAttachShader(shaderProgram, vertexShader);
	glAttachShader(shaderProgram, fragmentShader);

	glBindAttribLocation(shaderProgram, 0, "pos");
	glBindAttribLocation(shaderProgram, 1, "colorIn");

	glLinkProgram(shaderProgram);


	return shaderProgram;
}

void myDisplay(void)
{							
	GLuint program;
	GLuint vbo;
	GLfloat vertices [] = {
		0.0, 0.0, 0.0,
	};
	GLubyte colors [] = {
		255, 0, 0, 255,
	};

	/* A must to reprodue the wrong handling of varying inputs on pineview */
	glEnable(GL_POINT_SPRITE_ARB);

	program = shader_stuff();
	glUseProgram(program);

	glGenBuffers(1, &vbo);

	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(colors), NULL, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
	glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);

	glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, NULL);
	glEnableVertexAttribArray(0);

	glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, 0, 0, sizeof(vertices));
	glEnableVertexAttribArray(1);


	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT);

	glPointSize(100);
	glDrawArrays(GL_POINTS, 0, 1);

	glFlush();
}

int main(int argc,char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(200, 200);
	glutInitWindowPosition(100,100);
	glutCreateWindow("varying-color");
	glutDisplayFunc(myDisplay);

	glutMainLoop();
	return 0;
}


More information about the mesa-dev mailing list