[Piglit] [PATCH] gl-3.2-compat: test gl_ClipVertex built-in with geometry shaders
These tests have been adapted from the glsl-1.20 clipping tests. This tests both setting gl_ClipVertex in the geometry shader and using the gs to passthrough the gl_ClipVertex value from the vertex shader. I tested these on NVIDIA 384.111 binary driver but some of these get a cryptic error message: variable "gl_ClipVertex" domain conflicts with semantics "CLPV" However I believe the tests are correct and this is a driver bug. --- .../gs-clip-vertex-const-accept.shader_test | 68 +++ .../gs-clip-vertex-const-reject.shader_test | 58 ++ ...vertex-different-from-position.shader_test | 79 .../gs-clip-vertex-enables.shader_test| 163 ...-clip-vertex-equal-to-position.shader_test | 73 .../gs-clip-vertex-homogeneity.shader_test| 86 + ...s-clip-vertex-primitives-lines.shader_test | 72 +++ ...-clip-vertex-primitives-points.shader_test | 72 +++ ...rtex-primitives-triangle-strip.shader_test | 72 +++ ...vs-gs-clip-vertex-const-accept.shader_test | 70 +++ ...vs-gs-clip-vertex-const-reject.shader_test | 70 +++ ...vertex-different-from-position.shader_test | 90 + .../vs-gs-clip-vertex-enables.shader_test | 175 ++ ...-clip-vertex-equal-to-position.shader_test | 85 + .../vs-gs-clip-vertex-homogeneity.shader_test | 97 ++ ...rtex-primitives-triangle-strip.shader_test | 83 + 16 files changed, 1413 insertions(+) create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-const-accept.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-const-reject.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-different-from-position.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-enables.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-equal-to-position.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-homogeneity.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-primitives-lines.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-primitives-points.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-primitives-triangle-strip.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-const-accept.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-const-reject.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-different-from-position.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-enables.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-equal-to-position.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-homogeneity.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/clipping/vs-gs-clip-vertex-primitives-triangle-strip.shader_test diff --git a/tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-const-accept.shader_test b/tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-const-accept.shader_test new file mode 100644 index 0..a59fbd98a --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/clipping/gs-clip-vertex-const-accept.shader_test @@ -0,0 +1,68 @@ +# From the GL 2.1 spec, section 2.17 (Clipping): +# +# All points with eye coordinates (x_e y_e z_e w_e)^T that satisfy +# +# (x_e) +# (p_1' p_2' p_3' p_4')(y_e) >= 0 +# (z_e) +# (w_e) +# +# lie in the half-space defined by the plane; points that do not +# satisfy this condition do not lie in the half-space. +# +# This test checks that gl_ClipVertex works properly for the trivial +# case where gl_ClipVertex is a constant value satisfying the above +# inequality. + +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +out gl_PerVertex { + vec4 gl_Position; + vec4 gl_ClipVertex; +}; + +void main(void) +{ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +in gl_PerVertex { + vec4 gl_Position; + vec4 gl_ClipVertex; +} gl_in[]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + gl_ClipVertex = vec4(1.0, 0.0, 0.0, 0.0); + +
[Piglit] [PATCH v2] gl-3.2-compat: test gl_TexCoord[] built-in with geometry shaders
This tests both setting gl_TexCoord[] in the geometry shader and using the gs to passthrough the gl_TexCoord[] values from the vertex shader. --- .../gs-texcoord-array-2.shader_test | 57 .../gs-texcoord-array.shader_test | 51 ++ .../vs-gs-texcoord-array-2.shader_test| 65 ++ .../vs-gs-texcoord-array.shader_test | 66 +++ 4 files changed, 239 insertions(+) create mode 100644 tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array-2.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/vs-gs-texcoord-array-2.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/vs-gs-texcoord-array.shader_test diff --git a/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array-2.shader_test b/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array-2.shader_test new file mode 100644 index 0..852bc10c0 --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array-2.shader_test @@ -0,0 +1,57 @@ +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +out gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +}; + +void main() +{ + gl_Position = gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +out vec4 gl_TexCoord[5]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + + /* 0.05, 0.05, 0.10, 0.15, 0.20 */ + for (int j = 0; j < 5; j++) { + gl_TexCoord[j] = vec4(float(j) * 0.05); + } + + EmitVertex(); + } +} + +[fragment shader] +#version 110 + +varying vec4 gl_TexCoord[5]; +void main() +{ + vec4 result = vec4(0.0); + + for (int i = 0; i < 4; i++) + result += gl_TexCoord[i]; + + /* 0.00 + 0.05 + 0.10 + 0.15 = 0.30 */ + gl_FragColor = result; +} + +[test] +draw rect -1 -1 2 2 +probe rgba 1 1 0.3 0.3 0.3 0.3 diff --git a/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array.shader_test b/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array.shader_test new file mode 100644 index 0..0ee316ef1 --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/gs-texcoord-array.shader_test @@ -0,0 +1,51 @@ +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +void main() +{ + gl_Position = gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +uniform int n; + +out vec4 gl_TexCoord[5]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + + for (int j = 0; j < n; j++) { + gl_TexCoord[j] = vec4(0.5, 0.5, 0.5, 0.5) * float(j); + } + + EmitVertex(); + } +} + +[fragment shader] +#version 150 compatibility + +uniform int index; +in vec4 gl_TexCoord[5]; + +void main() +{ + gl_FragColor = gl_TexCoord[index]; +} + +[test] +uniform int index 1 +uniform int n 4 +draw rect -1 -1 2 2 +probe rgba 1 1 0.5 0.5 0.5 0.5 diff --git a/tests/spec/glsl-1.50/execution/compatibility/vs-gs-texcoord-array-2.shader_test b/tests/spec/glsl-1.50/execution/compatibility/vs-gs-texcoord-array-2.shader_test new file mode 100644 index 0..ec910524c --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/vs-gs-texcoord-array-2.shader_test @@ -0,0 +1,65 @@ +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +out gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +}; + +void main() +{ + /* 0.05, 0.05, 0.10, 0.15, 0.20 */ + for (int i = 0; i < 5; i++) + gl_TexCoord[i] = vec4(float(i) * 0.05); + + gl_Position = gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +in gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +} gl_in[]; + +out vec4 gl_TexCoord[5]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + + for (int j = 0; j < 5; j++) { + gl_TexCoord[j] = gl_in[i].gl_TexCoord[j]; + } + + EmitVertex(); + } +} + +[fragment shader] +#version 110 + +varying vec4 gl_TexCoord[5]; +void main() +{ + vec4 result = vec4(0.0); + + for (int i = 0; i < 4; i++) + result += gl_TexCoord[i]; + + /* 0.00 + 0.05 + 0.10 + 0.15 = 0.30 */ + gl_FragColor = result; +} + +[test] +draw rect -1 -1 2 2 +probe rgba 1 1 0.3 0.3
[Piglit] [PATCH] gl-3.2-compat: test gl_TexCoord[] built-in with geometry shaders
--- .../texcoord-array-2.shader_test | 65 ++ .../compatibility/texcoord-array.shader_test | 66 +++ 2 files changed, 131 insertions(+) create mode 100644 tests/spec/glsl-1.50/execution/compatibility/texcoord-array-2.shader_test create mode 100644 tests/spec/glsl-1.50/execution/compatibility/texcoord-array.shader_test diff --git a/tests/spec/glsl-1.50/execution/compatibility/texcoord-array-2.shader_test b/tests/spec/glsl-1.50/execution/compatibility/texcoord-array-2.shader_test new file mode 100644 index 0..ec910524c --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/texcoord-array-2.shader_test @@ -0,0 +1,65 @@ +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +out gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +}; + +void main() +{ + /* 0.05, 0.05, 0.10, 0.15, 0.20 */ + for (int i = 0; i < 5; i++) + gl_TexCoord[i] = vec4(float(i) * 0.05); + + gl_Position = gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +in gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +} gl_in[]; + +out vec4 gl_TexCoord[5]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + + for (int j = 0; j < 5; j++) { + gl_TexCoord[j] = gl_in[i].gl_TexCoord[j]; + } + + EmitVertex(); + } +} + +[fragment shader] +#version 110 + +varying vec4 gl_TexCoord[5]; +void main() +{ + vec4 result = vec4(0.0); + + for (int i = 0; i < 4; i++) + result += gl_TexCoord[i]; + + /* 0.00 + 0.05 + 0.10 + 0.15 = 0.30 */ + gl_FragColor = result; +} + +[test] +draw rect -1 -1 2 2 +probe rgba 1 1 0.3 0.3 0.3 0.3 diff --git a/tests/spec/glsl-1.50/execution/compatibility/texcoord-array.shader_test b/tests/spec/glsl-1.50/execution/compatibility/texcoord-array.shader_test new file mode 100644 index 0..fae6cff63 --- /dev/null +++ b/tests/spec/glsl-1.50/execution/compatibility/texcoord-array.shader_test @@ -0,0 +1,66 @@ +[require] +GL COMPAT >= 3.2 +GLSL >= 1.50 + +[vertex shader] +#version 150 compatibility + +uniform int n; + +out gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +}; + +void main() +{ + for (int i = 0; i < n; i++) { + gl_TexCoord[i] = vec4(0.5, 0.5, 0.5, 0.5) * float(i); + } + gl_Position = gl_Vertex; +} + +[geometry shader] +#version 150 compatibility + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +uniform int n; + +in gl_PerVertex { + vec4 gl_Position; + vec4 gl_TexCoord[5]; +} gl_in[]; + +out vec4 gl_TexCoord[5]; + +void main() +{ + for (int i = 0; i < 3; i++) { + gl_Position = gl_in[i].gl_Position; + + for (int j = 0; j < n; j++) { + gl_TexCoord[j] = gl_in[i].gl_TexCoord[j]; + } + + EmitVertex(); + } +} + +[fragment shader] +#version 150 compatibility + +uniform int index; +in vec4 gl_TexCoord[5]; + +void main() +{ + gl_FragColor = gl_TexCoord[index]; +} + +[test] +uniform int index 1 +uniform int n 4 +draw rect -1 -1 2 2 +probe rgba 1 1 0.5 0.5 0.5 0.5 -- 2.17.0 ___ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit
Re: [Piglit] [PATCH] cmake: Bump minimum version to 3.2.
Quoting Vinson Lee (2018-05-17 13:28:26) > This build error occurs with cmake 2.8.12. > /bin/sh: BYPRODUCTS: command not found > > BYPRODUCTS is not available until cmake 3.2. > https://cmake.org/cmake/help/v3.2/release/3.2.html > > Fixes: 2f02cf0d4c2d ("Generate xml for builtin profiles") > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106370 > Signed-off-by: Vinson Lee> --- > CMakeLists.txt |2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/CMakeLists.txt b/CMakeLists.txt > index 8c7d162..e56aafb 100644 > --- a/CMakeLists.txt > +++ b/CMakeLists.txt > @@ -1,4 +1,4 @@ > -cmake_minimum_required(VERSION 2.8.5) > +cmake_minimum_required(VERSION 3.2) > > list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") > > -- > 1.7.1 > I could have sworn I replied to this already, sorry about that. This seems reasonable to me, and I was going to propose it myself. 3.2 is from 2015, and 3.11 is current, and requiring software that's ~3 years old seems fine for a test suite. Reviewed-by: Dylan Baker Dylan signature.asc Description: signature ___ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit
Re: [Piglit] [PATCH v2] util: provide way to read a texture in ES compatible way
On 21.05.2018 18:01, Brian Paul wrote: On 05/21/2018 05:53 AM, Tapani Pälli wrote: Implementation supports GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY and affects following functions: - piglit_probe_texel_rect_rgba - piglit_probe_texel_volume_rgba v2: use read_texture only on GL ES fix indentation issues Signed-off-by: Tapani Pälli--- tests/util/piglit-util-gl.c | 121 +--- 1 file changed, 115 insertions(+), 6 deletions(-) diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 2443be03e..271cca4a8 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -1882,6 +1882,99 @@ piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format, return 1; } +static GLuint +create_fbo_from_texture(GLenum target, GLint texture, GLint level, GLint layer) +{ + GLuint fbo; + + glGenFramebuffers(1, ); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + if (layer > 0) { + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + texture, level, layer); + } else { + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + target, texture, level); + } + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == + GL_FRAMEBUFFER_COMPLETE); + return fbo; +} + +static GLenum +binding_from_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_2D: + return GL_TEXTURE_BINDING_2D; + case GL_TEXTURE_2D_ARRAY: + return GL_TEXTURE_BINDING_2D_ARRAY; + default: + fprintf(stderr, "%s: unsupported target 0x%x\n", + __func__, target); + return 0; + } +} + +/** + * Read texels in OpenGL ES compatible way. + * + * Currently bound texture is attached to a framebuffer object and + * contents are read using glReadPixels. Supported targets are + * GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY. + */ +static GLfloat * +read_texture(int target, int level, int x, int y, int layer, int w, int h) Maybe read_texture_es() or read_texture_via_fbo() to be a bit less generic? Yeah, read_texure_via_fbo() sounds fine to me. +{ + GLint width, height, depth; + GLint current_read_fbo, current_draw_fbo, current_texture; + GLenum binding = binding_from_target(target); + unsigned char *buf; + GLfloat *buffer; + unsigned offset; + + assert(binding != 0); + + glGetIntegerv(binding, _texture); + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, _read_fbo); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, _draw_fbo); + + assert(target == GL_TEXTURE_2D || target == GL_TEXTURE_2D_ARRAY); + + glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, ); + + buffer = malloc(width * height * depth * 4 * sizeof(GLfloat)); + buf = malloc(width * height * depth * 4 * sizeof(unsigned char)); Aren't we always returning a 2D image? If so, why 'depth' here? Function supports reading a single layer of 2D array (called from piglit_probe_texel_volume_rgba). This could be refactored a bit cleaner I guess but it fulfills the current requirements of the callers. One option would be to move buffer alloc to the callers and not have any offsets calculated here. + + GLuint fbo = + create_fbo_from_texture(target, current_texture, level, layer); + assert(fbo != 0); + + /* Offset to the layer we are expected to read. */ + offset = layer * (width * height * 4); If we're always returning a 2D image, I don't think we need the offset. + + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, + buf + offset); + + for (unsigned k = offset; k < offset + width * height * 4; k++) + buffer[k] = ((float) buf[k]) / 255.0; Wondering about the offset here too. At the very least, I think more comments are needed to explain what's going on if I'm misunderstanding this. Sure, I can add a bit more comments what is going on. Thanks. -Brian + + free(buf); + + glDeleteFramebuffers(1, ); + + /* Restore FBO state. */ + glBindFramebuffer(GL_READ_FRAMEBUFFER, current_read_fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current_draw_fbo); + + return buffer; +} + + /** * Read a texel rectangle from the given location and compare its RGB value to * the given expected values. @@ -1957,10 +2050,18 @@ int piglit_probe_texel_rect_rgba(int target, int level, int x, int y, glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); - buffer = malloc(width * height * 4 * sizeof(GLfloat)); - - glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer); +#ifndef PIGLIT_USE_OPENGL + if (target == GL_TEXTURE_2D) { + buffer = read_texture(target, level, x, y, 0, w, h); + } else
Re: [Piglit] [PATCH v2] util: provide way to read a texture in ES compatible way
On 05/21/2018 05:53 AM, Tapani Pälli wrote: Implementation supports GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY and affects following functions: - piglit_probe_texel_rect_rgba - piglit_probe_texel_volume_rgba v2: use read_texture only on GL ES fix indentation issues Signed-off-by: Tapani Pälli--- tests/util/piglit-util-gl.c | 121 +--- 1 file changed, 115 insertions(+), 6 deletions(-) diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 2443be03e..271cca4a8 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -1882,6 +1882,99 @@ piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format, return 1; } +static GLuint +create_fbo_from_texture(GLenum target, GLint texture, GLint level, GLint layer) +{ + GLuint fbo; + + glGenFramebuffers(1, ); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + if (layer > 0) { + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + texture, level, layer); + } else { + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + target, texture, level); + } + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == + GL_FRAMEBUFFER_COMPLETE); + return fbo; +} + +static GLenum +binding_from_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_2D: + return GL_TEXTURE_BINDING_2D; + case GL_TEXTURE_2D_ARRAY: + return GL_TEXTURE_BINDING_2D_ARRAY; + default: + fprintf(stderr, "%s: unsupported target 0x%x\n", + __func__, target); + return 0; + } +} + +/** + * Read texels in OpenGL ES compatible way. + * + * Currently bound texture is attached to a framebuffer object and + * contents are read using glReadPixels. Supported targets are + * GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY. + */ +static GLfloat * +read_texture(int target, int level, int x, int y, int layer, int w, int h) Maybe read_texture_es() or read_texture_via_fbo() to be a bit less generic? +{ + GLint width, height, depth; + GLint current_read_fbo, current_draw_fbo, current_texture; + GLenum binding = binding_from_target(target); + unsigned char *buf; + GLfloat *buffer; + unsigned offset; + + assert(binding != 0); + + glGetIntegerv(binding, _texture); + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, _read_fbo); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, _draw_fbo); + + assert(target == GL_TEXTURE_2D || target == GL_TEXTURE_2D_ARRAY); + + glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, ); + + buffer = malloc(width * height * depth * 4 * sizeof(GLfloat)); + buf = malloc(width * height * depth * 4 * sizeof(unsigned char)); Aren't we always returning a 2D image? If so, why 'depth' here? + + GLuint fbo = + create_fbo_from_texture(target, current_texture, level, layer); + assert(fbo != 0); + + /* Offset to the layer we are expected to read. */ + offset = layer * (width * height * 4); If we're always returning a 2D image, I don't think we need the offset. + + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, +buf + offset); + + for (unsigned k = offset; k < offset + width * height * 4; k++) + buffer[k] = ((float) buf[k]) / 255.0; Wondering about the offset here too. At the very least, I think more comments are needed to explain what's going on if I'm misunderstanding this. Thanks. -Brian + + free(buf); + + glDeleteFramebuffers(1, ); + + /* Restore FBO state. */ + glBindFramebuffer(GL_READ_FRAMEBUFFER, current_read_fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current_draw_fbo); + + return buffer; +} + + /** * Read a texel rectangle from the given location and compare its RGB value to * the given expected values. @@ -1957,10 +2050,18 @@ int piglit_probe_texel_rect_rgba(int target, int level, int x, int y, glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); - buffer = malloc(width * height * 4 * sizeof(GLfloat)); - - glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer); +#ifndef PIGLIT_USE_OPENGL + if (target == GL_TEXTURE_2D) { + buffer = read_texture(target, level, x, y, 0, w, h); + } else { +#else + buffer = malloc(width * height * 4 * sizeof(GLfloat)); + glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer); +#endif +#ifndef PIGLIT_USE_OPENGL + } +#endif
[Piglit] [PATCH v2] util: provide way to read a texture in ES compatible way
Implementation supports GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY and affects following functions: - piglit_probe_texel_rect_rgba - piglit_probe_texel_volume_rgba v2: use read_texture only on GL ES fix indentation issues Signed-off-by: Tapani Pälli--- tests/util/piglit-util-gl.c | 121 +--- 1 file changed, 115 insertions(+), 6 deletions(-) diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 2443be03e..271cca4a8 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -1882,6 +1882,99 @@ piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format, return 1; } +static GLuint +create_fbo_from_texture(GLenum target, GLint texture, GLint level, GLint layer) +{ + GLuint fbo; + + glGenFramebuffers(1, ); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + if (layer > 0) { + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + texture, level, layer); + } else { + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + target, texture, level); + } + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == + GL_FRAMEBUFFER_COMPLETE); + return fbo; +} + +static GLenum +binding_from_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_2D: + return GL_TEXTURE_BINDING_2D; + case GL_TEXTURE_2D_ARRAY: + return GL_TEXTURE_BINDING_2D_ARRAY; + default: + fprintf(stderr, "%s: unsupported target 0x%x\n", + __func__, target); + return 0; + } +} + +/** + * Read texels in OpenGL ES compatible way. + * + * Currently bound texture is attached to a framebuffer object and + * contents are read using glReadPixels. Supported targets are + * GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY. + */ +static GLfloat * +read_texture(int target, int level, int x, int y, int layer, int w, int h) +{ + GLint width, height, depth; + GLint current_read_fbo, current_draw_fbo, current_texture; + GLenum binding = binding_from_target(target); + unsigned char *buf; + GLfloat *buffer; + unsigned offset; + + assert(binding != 0); + + glGetIntegerv(binding, _texture); + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, _read_fbo); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, _draw_fbo); + + assert(target == GL_TEXTURE_2D || target == GL_TEXTURE_2D_ARRAY); + + glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); + glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, ); + + buffer = malloc(width * height * depth * 4 * sizeof(GLfloat)); + buf = malloc(width * height * depth * 4 * sizeof(unsigned char)); + + GLuint fbo = + create_fbo_from_texture(target, current_texture, level, layer); + assert(fbo != 0); + + /* Offset to the layer we are expected to read. */ + offset = layer * (width * height * 4); + + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, +buf + offset); + + for (unsigned k = offset; k < offset + width * height * 4; k++) + buffer[k] = ((float) buf[k]) / 255.0; + + free(buf); + + glDeleteFramebuffers(1, ); + + /* Restore FBO state. */ + glBindFramebuffer(GL_READ_FRAMEBUFFER, current_read_fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current_draw_fbo); + + return buffer; +} + + /** * Read a texel rectangle from the given location and compare its RGB value to * the given expected values. @@ -1957,10 +2050,18 @@ int piglit_probe_texel_rect_rgba(int target, int level, int x, int y, glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); - buffer = malloc(width * height * 4 * sizeof(GLfloat)); - - glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer); +#ifndef PIGLIT_USE_OPENGL + if (target == GL_TEXTURE_2D) { + buffer = read_texture(target, level, x, y, 0, w, h); + } else { +#else + buffer = malloc(width * height * 4 * sizeof(GLfloat)); + glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer); +#endif +#ifndef PIGLIT_USE_OPENGL + } +#endif assert(x >= 0); assert(y >= 0); assert(x+w <= width); @@ -2021,10 +2122,18 @@ int piglit_probe_texel_volume_rgba(int target, int level, int x, int y, int z, glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, ); glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, ); glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, ); - buffer = malloc(width * height * depth * 4 *
[Piglit] [PATCH] gl-3.2-compat: test gl_*Color built-ins with geometry shaders
This updates the existing vertex shader test and makes it more flexable. --- tests/spec/gl-2.0/vertex-program-two-side.c | 195 +++- 1 file changed, 145 insertions(+), 50 deletions(-) diff --git a/tests/spec/gl-2.0/vertex-program-two-side.c b/tests/spec/gl-2.0/vertex-program-two-side.c index 81cf11d9d..c53668124 100644 --- a/tests/spec/gl-2.0/vertex-program-two-side.c +++ b/tests/spec/gl-2.0/vertex-program-two-side.c @@ -66,6 +66,16 @@ static float secondary_frontcolor[4] = {0.0, 0.25, 0.0, 0.0}; static float secondary_backcolor[4] = {0.0, 0.0, 0.25, 0.0}; static int draw_secondary_loc; +char *vs_outputs[4] = {"", "", "", ""}; +char *gs_outputs[4] = {"", "", "", ""}; +char *gs_inputs_outputs[4] = {"", "", "", ""}; + +static const char *dummy_vs_source = + "void main()\n" + "{\n" + " gl_Position = gl_Vertex;\n" + "}\n"; + static const char *fs_source = "uniform bool draw_secondary;\n" "void main()\n" @@ -76,24 +86,13 @@ static const char *fs_source = " gl_FragColor = gl_Color;\n" "}\n"; -enum piglit_result -piglit_display(void) +static bool +probe_colors() { + bool pass = true; int x1 = 0, y1 = 0; int w = piglit_width / 2, h = piglit_height / 2; int x2 = piglit_width - w, y2 = piglit_height - h; - bool pass = true; - - glClearColor(0.5, 0.5, 0.5, 0.5); - glClear(GL_COLOR_BUFFER_BIT); - - glUniform1i(draw_secondary_loc, false); - piglit_draw_rect(-1, 0, 1, 1); /* top left */ - piglit_draw_rect( 1, 0, -1, 1); /* top right */ - - glUniform1i(draw_secondary_loc, true); - piglit_draw_rect(-1, -1, 1, 1); /* bot left */ - piglit_draw_rect( 1, -1, -1, 1); /* bot right */ if (front) { pass = pass && piglit_probe_rect_rgba(x1, y2, w, h, @@ -127,13 +126,41 @@ piglit_display(void) } } - piglit_present_results(); + return pass; +} - return pass ? PIGLIT_PASS : PIGLIT_FAIL; +static bool +test_prog(unsigned prog, const char *test_name) +{ + glUseProgram(prog); + draw_secondary_loc = glGetUniformLocation(prog, "draw_secondary"); + assert(draw_secondary_loc != -1); + + if (enabled) + glEnable(GL_VERTEX_PROGRAM_TWO_SIDE); + + /* Draw */ + glClearColor(0.5, 0.5, 0.5, 0.5); + glClear(GL_COLOR_BUFFER_BIT); + + glUniform1i(draw_secondary_loc, false); + piglit_draw_rect(-1, 0, 1, 1); /* top left */ + piglit_draw_rect( 1, 0, -1, 1); /* top right */ + + glUniform1i(draw_secondary_loc, true); + piglit_draw_rect(-1, -1, 1, 1); /* bot left */ + piglit_draw_rect( 1, -1, -1, 1); /* bot right */ + + /* probe and report result */ + bool pass = probe_colors(); + piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "%s", +test_name); + + return pass; } static void -setup_output(char **out, const char *name, float *values) +setup_vs_output(char **out, const char *name, float *values) { (void)!asprintf(out, " %s = vec4(%f, %f, %f, %f);\n", @@ -144,15 +171,94 @@ setup_output(char **out, const char *name, float *values) values[3]); } -void -piglit_init(int argc, char **argv) +static void +setup_gs_vars(char **in_out, char **out, const char *name, float *values) +{ + (void)!asprintf(in_out, " %s = gl_in[i].%s;\n", name, name); + (void)!asprintf(out, " %s = vec4(%f, %f, %f, %f);\n", + name, + values[0], + values[1], + values[2], + values[3]); +} + +static void +create_gs_source(char **gs_source, char **builtins) +{ + (void)!asprintf(gs_source, + "#version 150 compatibility\n" + "layout(triangles) in;\n" + "layout(triangle_strip, max_vertices = 3) out;\n" + "\n" + "void main()\n" + "{\n" + " for (int i = 0; i < 3; i++) {\n" + " gl_Position = gl_in[i].gl_Position;\n" + " %s%s%s%s\n" + " EmitVertex();\n" + " }\n" + "}\n", + builtins[0], + builtins[1], + builtins[2], + builtins[3]); +} + +enum piglit_result +piglit_display(void) { - char *vs_outputs[4] = {"", "", "", ""}; char *vs_source; - int i; + char *gs_source; + char *gs_source2; + bool pass; - piglit_require_GLSL(); + (void)!asprintf(_source, +"void main()\n" +"{\n" +" gl_Position = gl_Vertex;\n" +"%s%s%s%s" +"}\n", +vs_outputs[0], +