From 9a31c67d578416299ab7c9a6f782162fab5f5fd0 Mon Sep 17 00:00:00 2001 From: Cody Northrop Date: Tue, 10 Jun 2014 13:04:47 -0600 Subject: [PATCH] Minimal test case to expose bug with uniform loading, texturing, and discard --- .../rendezvous_by_location.c | 95 +++++++++++++++++++--- 1 file changed, 82 insertions(+), 13 deletions(-) diff --git a/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c b/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c index 4193ea5..011d4db 100644 --- a/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c +++ b/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c @@ -47,6 +47,9 @@ PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 10; config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + config.window_width = 500; + config.window_height = 500; + PIGLIT_GL_TEST_CONFIG_END @@ -60,14 +63,12 @@ static const char *vs_code_template = "\n" "layout(location = 0) in vec4 piglit_vertex;\n" "\n" - "layout(location = 2) out vec3 a;\n" - "layout(location = 3) out vec3 b;\n" + "layout(location = 0) out vec3 a;\n" "\n" "void main()\n" "{\n" " gl_Position = piglit_vertex;\n" - " a = vec3(0, 0, 1);\n" - " b = vec3(1, 0, 0);\n" + " a = gl_Position.xyz;\n" "}\n" ; @@ -82,12 +83,11 @@ static const char *fs_code_same_declaration_order_template = "#define out_color gl_FragColor\n" "#endif\n" "\n" - "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n" - "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n" + "layout(location = 0) in vec3 a; /* should get vec3(1, 0, 0) */\n" "\n" "void main()\n" "{\n" - " out_color = vec4(cross(b, a), 1);\n" + " out_color = vec4(0.1, 0.1, 0.1, 1.0);\n" "}\n" ; @@ -95,6 +95,7 @@ static const char *fs_code_same_location_order_template = "#version %d\n" "#extension GL_ARB_separate_shader_objects: require\n" "#extension GL_ARB_explicit_attrib_location: enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" "\n" "#if __VERSION__ >= 130\n" "layout(location = 0) out vec4 out_color;\n" @@ -102,15 +103,44 @@ static const char *fs_code_same_location_order_template = "#define out_color gl_FragColor\n" "#endif\n" "\n" - "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n" - "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n" - "\n" + + "layout(std140, binding = 0) uniform globals \n" + "{\n" + " vec3 global0; \n" + " vec3 global1; \n" + " vec3 global2; \n" + " float global3; \n" + "}\n;" + + "layout(binding = 0) uniform sampler2D tex2;\n" + "void main()\n" "{\n" - " out_color = vec4(cross(b, a), 1);\n" + " vec3 var7 = texture (tex2, vec2(0.5)).xyz ;\n" + " if ((gl_FragCoord.x - gl_FragCoord.y) < 0.0) \n" + " discard;\n" + " out_color = vec4(var7 * global2 * global3, 1.0 );\n" "}\n" ; +/** + * Create a single-color image. + */ +static GLubyte * +create_image(GLint w, GLint h, const GLubyte color[4]) +{ + GLubyte *buf = (GLubyte *) malloc(w * h * 4); + int i; + for (i = 0; i < w * h; i++) { + buf[i*4+0] = color[0]; + buf[i*4+1] = color[1]; + buf[i*4+2] = color[2]; + buf[i*4+3] = color[3]; + } + return buf; +} + + enum piglit_result piglit_display(void) { @@ -119,14 +149,53 @@ piglit_display(void) }; bool pass; + + // Set up three textures to pull from, just fill them with solid white + + GLubyte colors[4] = {255, 255, 255, 255}; + + GLuint tex1; + GLint width = 128, height = 64, levels = 1; + GLint level = 0; + GLubyte *colorBuf = create_image(width, height, colors); + + glGenTextures(1, &tex1); + glBindTexture(GL_TEXTURE_2D, tex1); + glTexStorage2D(GL_TEXTURE_2D, levels, GL_RGBA8, width, height); + piglit_check_gl_error(GL_NO_ERROR); + glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, colorBuf); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, tex1); + + + // Set up a uniform buffer with semi random data. + // putting in different values can make the corruption hard to see + // note that first three vectors have the same values, so they can + // be interchanged in the shader. + + GLfloat data2[16] = { + 0.2, 0.2, 0.5, 1.0, + 0.2, 0.2, 0.5, 1.0, + 0.2, 0.2, 0.5, 1.0, + 1.0, 0.0, 0.0, 1.0, + }; + + GLuint uBuffer; + glGenBuffers(1, &uBuffer); + glBindBuffer(GL_UNIFORM_BUFFER, uBuffer); + glBufferData(GL_UNIFORM_BUFFER, sizeof(data2), NULL, GL_STATIC_DRAW); + glBindBufferBase(GL_UNIFORM_BUFFER, 0, uBuffer); + glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(data2), data2); + glClearColor(0.1f, 0.1f, 0.1f, 0.1f); glClear(GL_COLOR_BUFFER_BIT); glBindProgramPipeline(pipeline_same_declaration_order); - piglit_draw_rect(-1, -1, 1, 2); + piglit_draw_rect(-1, -1, 2, 2); glBindProgramPipeline(pipeline_same_location_order); - piglit_draw_rect(0, -1, 1, 2); + piglit_draw_rect(-1, -1, 2, 2); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, expected); -- 1.8.3.2