[Piglit] [PATCH] arb_fragment_shader_interlock: Fix image load/store test.
Plamena Manolova
plamena.manolova at intel.com
Wed May 2 16:27:50 UTC 2018
This test is meant to check whether ARB_fragment_shader_interlock
functions as expected by simulating blending behaviour via image
load/stores. The formula used is meant to be used per-pixel not
per-sample. With multisampling disabled the tests works as expected.
Signed-off-by: Plamena Manolova <plamena.manolova at intel.com>
---
.../image-load-store.c | 207 ++++++++++-----------
1 file changed, 94 insertions(+), 113 deletions(-)
diff --git a/tests/spec/arb_fragment_shader_interlock/image-load-store.c b/tests/spec/arb_fragment_shader_interlock/image-load-store.c
index 597bcf7d5..b9054abfa 100644
--- a/tests/spec/arb_fragment_shader_interlock/image-load-store.c
+++ b/tests/spec/arb_fragment_shader_interlock/image-load-store.c
@@ -48,9 +48,9 @@ make_fbo(void)
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo );
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex_frame);
+ glBindTexture(GL_TEXTURE_2D, tex_frame);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D_MULTISAMPLE, tex_frame, 0);
+ GL_TEXTURE_2D, tex_frame, 0);
return fbo;
}
@@ -73,29 +73,17 @@ make_shader_program(void)
"#version 430\n"
"#extension GL_ARB_fragment_shader_interlock: require\n"
"layout(pixel_interlock_ordered) in;\n"
- "layout(rgba32f, binding = 0) uniform image3D img_output;\n"
+ "layout(rgba32f, binding = 0) uniform image2D img_output;\n"
"layout(location = 1) uniform int sample_rate;\n"
"smooth in vec4 col_vary;\n"
"out vec4 col_out;\n"
"void main()\n"
"{\n"
" vec4 result = vec4(0.0, 0.0, 0.0, 1.0);\n"
- " ivec3 current_sample_coord = ivec3(gl_FragCoord.x, gl_FragCoord.y, gl_SampleID);\n"
- " ivec3 result_coord = ivec3(gl_FragCoord.x, gl_FragCoord.y, sample_rate);\n"
- " int i;\n"
+ " ivec2 result_coord = ivec2(gl_FragCoord.x, gl_FragCoord.y);\n"
" beginInvocationInterlockARB();\n"
- " vec4 current_sample_color = imageLoad(img_output, current_sample_coord);\n"
- " result.rgb += col_vary.a * col_vary.rgb + (1 - col_vary.a) * current_sample_color.rgb;\n"
- " imageStore(img_output, current_sample_coord, result);\n"
- "\n"
- " for (i = 0; i < sample_rate; i++) {\n"
- " if (i != gl_SampleID) {\n"
- " ivec3 sample_coord = ivec3(gl_FragCoord.x, gl_FragCoord.y, i);\n"
- " vec4 sample_color = imageLoad(img_output, sample_coord);\n"
- " result.rgb += sample_color.rgb;\n"
- " }\n"
- " }\n"
- " result.rgb /= sample_rate;\n"
+ " vec4 prev_frag_color = imageLoad(img_output, result_coord);\n"
+ " result.rgb += col_vary.a * col_vary.rgb + (1 - col_vary.a) * prev_frag_color.rgb;\n"
" imageStore(img_output, result_coord, result);\n"
" endInvocationInterlockARB();\n"
" col_out = result;\n"
@@ -124,10 +112,10 @@ make_texture_buffer(void)
GLuint tex;
glGenTextures(1, &tex);
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
- glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 2,
- GL_RGBA32F, piglit_width, piglit_height, false);
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, piglit_width, piglit_height, 0,
+ GL_RGBA, GL_FLOAT, NULL);
+ glBindTexture(GL_TEXTURE_2D, tex);
return tex;
}
@@ -139,11 +127,11 @@ make_texture_blend(void)
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_3D, tex);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindImageTexture(0, tex, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);
return tex;
@@ -152,25 +140,25 @@ make_texture_blend(void)
static GLuint
make_vao(void)
{
- static const float pos_col[18][6] = {
- { -1.0, -1.0, 0.0, 1.0, 0.0, 0.25 },
- { 0.0, -1.0, 0.0, 1.0, 0.0, 0.25 },
- { 0.0, 1.0, 0.0, 1.0, 0.0, 0.25 },
- { 0.0, 1.0, 0.0, 1.0, 0.0, 0.25 },
- { -1.0, 1.0, 0.0, 1.0, 0.0, 0.25 },
- { -1.0, -1.0, 0.0, 1.0, 0.0, 0.25 },
- { -1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },
- { 1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },
- { 1.0, 1.0, 1.0, 0.0, 0.0, 0.25 },
- { 1.0, 1.0, 1.0, 0.0, 0.0, 0.25 },
- { -1.0, 1.0, 1.0, 0.0, 0.0, 0.25 },
- { -1.0, -1.0, 1.0, 0.0, 0.0, 0.25 },
- { -1.0, -1.0, 0.0, 0.0, 1.0, 0.25 },
- { 1.0, -1.0, 0.0, 0.0, 1.0, 0.25 },
- { 1.0, 1.0, 0.0, 0.0, 1.0, 0.25 },
- { 1.0, 1.0, 0.0, 0.0, 1.0, 0.25 },
- { -1.0, 1.0, 0.0, 0.0, 1.0, 0.25 },
- { -1.0, -1.0, 0.0, 0.0, 1.0, 0.25 }
+ static const float pos_col[18][7] = {
+ { -1.0, -1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { 0.0, -1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { 0.0, 1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { 0.0, 1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { -1.0, 1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { -1.0, -1.0, -0.2, 0.0, 1.0, 0.0, 0.25 },
+ { -1.0, -1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { 1.0, -1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { 1.0, 1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { 1.0, 1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { -1.0, 1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { -1.0, -1.0, -0.1, 1.0, 0.0, 0.0, 0.25 },
+ { -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.25 },
+ { 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.25 },
+ { 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.25 },
+ { 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.25 },
+ { -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.25 },
+ { -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.25 }
};
const int stride = sizeof(pos_col[0]);
@@ -183,9 +171,9 @@ make_vao(void)
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(pos_col), pos_col, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, (void *) 0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void *) 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, stride,
- (void *)(sizeof(float) * 2));
+ (void *)(sizeof(float) * 3));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
@@ -202,9 +190,9 @@ piglit_init(int argc, char **argv)
{
piglit_require_extension("GL_ARB_fragment_shader_interlock");
- glEnable(GL_MULTISAMPLE);
+ glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
- glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClearColor(0.0, 0.0, 0.0, 0.0);
prog = make_shader_program();
vao = make_vao();
@@ -216,82 +204,75 @@ piglit_init(int argc, char **argv)
enum piglit_result
piglit_display(void)
{
- int samples[4] = { 2, 4, 8, 16 };
bool pass = true;
- unsigned i, j, k;
+ unsigned i, j;
const unsigned result1[4] = { 47, 35, 63, 255 };
const unsigned result2[4] = { 47, 0, 63, 255 };
- int max_samples;
+ GLfloat *tex_data = calloc(piglit_width * piglit_height * 16,
+ sizeof(GLfloat));
glViewport(0, 0, piglit_width, piglit_height);
- glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
-
- for (i = 0; i < 4 && samples[i] <= max_samples; i++) {
- GLfloat *tex_data = calloc(piglit_width * piglit_height *
- (samples[i] + 1) * 4, sizeof(GLfloat));
-
- glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, piglit_width, piglit_height,
- samples[i] + 1, 0, GL_RGBA, GL_FLOAT, tex_data);
-
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex_frame);
- glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples[i],
- GL_RGBA8, piglit_width, piglit_height, false);
- glUniform1i(1, samples[i]);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
- GL_STENCIL_BUFFER_BIT);
-
- glUseProgram(prog);
- glDrawArrays(GL_TRIANGLES, 0, 18);
-
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
- glDrawBuffer(GL_BACK);
- glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width,
- piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
- pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
- piglit_present_results();
-
- glGetTexImage(GL_TEXTURE_3D, 0, GL_RGBA, GL_FLOAT, tex_data);
- for (j = 0; j < piglit_height; j++) {
- for (k = 0; k < piglit_width; k++) {
- unsigned l = ((piglit_width * piglit_height * samples[i]) +
- (j * piglit_width) + k) * 4;
- unsigned r = fabs(tex_data[l]) * 255;
- unsigned g = fabs(tex_data[l + 1]) * 255;
- unsigned b = fabs(tex_data[l + 2]) * 255;
- unsigned a = fabs(tex_data[l + 3]) * 255;
-
- if ((k < piglit_width / 2) && (r != result1[0] ||
- g != result1[1] || b != result1[2] || a != result1[3])) {
- printf("observed %u %u %u %u %u %u\n", j, k, r,
- g, b, a);
- printf("expected %u %u %u %u %u %u\n", j, k,
- result1[0], result1[1], result1[2], result1[3]);
- pass = false;
- break;
- }
-
- if ((k > piglit_width / 2) && (r != result2[0] ||
- g != result2[1] || b != result2[2] || a != result2[3])) {
- printf("observed %u %u %u %u %u %u\n", j, k, r,
- g, b, a);
- printf("expected %u %u %u %u %u %u\n", j, k,
- result1[0], result1[1], result1[2], result1[3]);
- pass = false;
- break;
- }
+
+ glBindTexture(GL_TEXTURE_2D, tex_blend);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, piglit_width, piglit_height, 0,
+ GL_RGBA, GL_FLOAT, tex_data);
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+ glBindTexture(GL_TEXTURE_2D, tex_frame);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, piglit_width, piglit_height, 0,
+ GL_RGBA, GL_FLOAT, NULL);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
+ GL_STENCIL_BUFFER_BIT);
+
+ glUseProgram(prog);
+ glDrawArrays(GL_TRIANGLES, 0, 18);
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+ glDrawBuffer(GL_BACK);
+ glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width,
+ piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ piglit_present_results();
+
+ glBindTexture(GL_TEXTURE_2D, tex_blend);
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tex_data);
+
+ for (i = 0; i < piglit_height; i++) {
+ for (j = 0; j < piglit_width; j++) {
+ unsigned k = (piglit_width * i + j) * 4;
+ unsigned r = fabs(tex_data[k]) * 255;
+ unsigned g = fabs(tex_data[k + 1]) * 255;
+ unsigned b = fabs(tex_data[k + 2]) * 255;
+ unsigned a = fabs(tex_data[k + 3]) * 255;
+
+ if ((j < piglit_width / 2) && (r != result1[0] ||
+ g != result1[1] || b != result1[2] || a != result1[3])) {
+ printf("observed %u %u %u %u %u %u\n", i, j, r, g, b, a);
+ printf("expected %u %u %u %u %u %u\n", i, j, result1[0],
+ result1[1], result1[2], result1[3]);
+ pass = false;
}
+
+ if ((j > piglit_width / 2) && (r != result2[0] ||
+ g != result2[1] || b != result2[2] || a != result2[3])) {
+ printf("observed %u %u %u %u %u %u\n", i, j,
+ r, g, b, a);
+ printf("expected %u %u %u %u %u %u\n", i, j, result1[0],
+ result1[1], result1[2], result1[3]);
+ pass = false;
+ }
+
if (!pass)
break;
}
- free(tex_data);
- pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
if (!pass)
break;
}
+ free(tex_data);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
--
2.11.0
More information about the Piglit
mailing list