[Piglit] [PATCH] tests: add nvidia conservative rasterization tests

Rhys Perry pendingchaos02 at gmail.com
Thu Mar 22 13:43:25 UTC 2018


Adds tests for GL_NV_conservative_raster, GL_NV_conservative_raster_dilate
and GL_NV_conservative_raster_pre_snap_triangles.
---
 tests/all.py                                       |  20 ++
 tests/spec/CMakeLists.txt                          |   3 +
 .../spec/nv_conservative_raster/CMakeLists.gl.txt  |  13 +
 .../nv_conservative_raster/CMakeLists.gles2.txt    |   3 +
 tests/spec/nv_conservative_raster/CMakeLists.txt   |   1 +
 tests/spec/nv_conservative_raster/attrib.c         |  69 +++++
 tests/spec/nv_conservative_raster/dlist.c          |  75 ++++++
 tests/spec/nv_conservative_raster/draw.c           | 288 +++++++++++++++++++++
 .../CMakeLists.gl.txt                              |  11 +
 .../CMakeLists.gles2.txt                           |   3 +
 .../nv_conservative_raster_dilate/CMakeLists.txt   |   1 +
 tests/spec/nv_conservative_raster_dilate/draw.c    | 128 +++++++++
 .../CMakeLists.gl.txt                              |  11 +
 .../CMakeLists.gles2.txt                           |   3 +
 .../CMakeLists.txt                                 |   1 +
 .../draw.c                                         | 117 +++++++++
 16 files changed, 747 insertions(+)
 create mode 100644 tests/spec/nv_conservative_raster/CMakeLists.gl.txt
 create mode 100644 tests/spec/nv_conservative_raster/CMakeLists.gles2.txt
 create mode 100644 tests/spec/nv_conservative_raster/CMakeLists.txt
 create mode 100644 tests/spec/nv_conservative_raster/attrib.c
 create mode 100644 tests/spec/nv_conservative_raster/dlist.c
 create mode 100644 tests/spec/nv_conservative_raster/draw.c
 create mode 100644 tests/spec/nv_conservative_raster_dilate/CMakeLists.gl.txt
 create mode 100644 tests/spec/nv_conservative_raster_dilate/CMakeLists.gles2.txt
 create mode 100644 tests/spec/nv_conservative_raster_dilate/CMakeLists.txt
 create mode 100644 tests/spec/nv_conservative_raster_dilate/draw.c
 create mode 100644 tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gl.txt
 create mode 100644 tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gles2.txt
 create mode 100644 tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.txt
 create mode 100644 tests/spec/nv_conservative_raster_pre_snap_triangles/draw.c

diff --git a/tests/all.py b/tests/all.py
index 4cd911fab..a5da80f14 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4984,5 +4984,25 @@ with profile.test_list.group_manager(
     g(['arb_bindless_texture-uint64_attribs'], 'uint64_attribs')
     g(['arb_bindless_texture-uniform'], 'uniform')
 
+# Group NV_conservative_raster
+with profile.test_list.group_manager(
+	PiglitGLTest,
+	grouptools.join('spec', 'NV_conservative_raster')) as g:
+    g(['nv_conservative_raster-draw'], 'draw')
+    g(['nv_conservative_raster-dlist'], 'dlist')
+    g(['nv_conservative_raster-attrib'], 'attrib')
+
+# Group NV_conservative_raster_dilate
+with profile.test_list.group_manager(
+	PiglitGLTest,
+	grouptools.join('spec', 'NV_conservative_raster_dilate')) as g:
+    g(['nv_conservative_raster_dilate-draw'], 'draw')
+
+# Group NV_conservative_raster_pre_snap_triangles
+with profile.test_list.group_manager(
+	PiglitGLTest,
+	grouptools.join('spec', 'NV_conservative_raster_pre_snap_triangles')) as g:
+    g(['nv_conservative_raster_pre_snap_triangles-draw'], 'draw')
+
 if platform.system() is 'Windows':
     profile.filters.append(lambda p, _: not p.startswith('glx'))
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index e57e8d703..d7ed033c4 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -101,6 +101,9 @@ add_subdirectory (ext_texture_swizzle)
 add_subdirectory (ext_timer_query)
 add_subdirectory (ext_transform_feedback)
 add_subdirectory (nv_conditional_render)
+add_subdirectory (nv_conservative_raster)
+add_subdirectory (nv_conservative_raster_dilate)
+add_subdirectory (nv_conservative_raster_pre_snap_triangles)
 add_subdirectory (nv_fill_rectangle)
 add_subdirectory (nv_image_formats)
 add_subdirectory (nv_texture_barrier)
diff --git a/tests/spec/nv_conservative_raster/CMakeLists.gl.txt b/tests/spec/nv_conservative_raster/CMakeLists.gl.txt
new file mode 100644
index 000000000..5f632c864
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/CMakeLists.gl.txt
@@ -0,0 +1,13 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (nv_conservative_raster-draw draw.c)
+piglit_add_executable (nv_conservative_raster-dlist dlist.c)
+piglit_add_executable (nv_conservative_raster-attrib attrib.c)
diff --git a/tests/spec/nv_conservative_raster/CMakeLists.gles2.txt b/tests/spec/nv_conservative_raster/CMakeLists.gles2.txt
new file mode 100644
index 000000000..b33576074
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/CMakeLists.gles2.txt
@@ -0,0 +1,3 @@
+link_libraries(piglitutil_${piglit_target_api})
+
+piglit_add_executable (nv_conservative_raster-draw_gles2 draw.c)
diff --git a/tests/spec/nv_conservative_raster/CMakeLists.txt b/tests/spec/nv_conservative_raster/CMakeLists.txt
new file mode 100644
index 000000000..144a306f4
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/nv_conservative_raster/attrib.c b/tests/spec/nv_conservative_raster/attrib.c
new file mode 100644
index 000000000..3c135f1ce
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/attrib.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018 Rhys Perry
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#if PIGLIT_USE_OPENGL
+	config.supports_gl_compat_version = 10;
+#endif
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void piglit_init(int argc, char **argv)
+{
+	GLint max_subpixel_bits_bias;
+
+	piglit_require_extension("GL_NV_conservative_raster");
+
+	glGetIntegerv(GL_MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV, &max_subpixel_bits_bias);
+	if (max_subpixel_bits_bias<3)
+		piglit_report_result(PIGLIT_SKIP);
+}
+
+enum piglit_result piglit_display(void)
+{
+	bool enable_pass, viewport_pass;
+	GLint biasx, biasy;
+	glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glPushAttrib(GL_ENABLE_BIT);
+	glDisable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glPopAttrib();
+
+	enable_pass = glIsEnabled(GL_CONSERVATIVE_RASTERIZATION_NV);
+	piglit_report_subtest_result(enable_pass ? PIGLIT_PASS : PIGLIT_FAIL, "enable attributes");
+
+	glSubpixelPrecisionBiasNV(0, 1);
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glSubpixelPrecisionBiasNV(2, 3);
+	glPopAttrib(GL_VIEWPORT_BIT);
+
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_X_BITS_NV, &biasx);
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_Y_BITS_NV, &biasy);
+	viewport_pass = biasx==0 && biasy==1;
+	piglit_report_subtest_result(viewport_pass ? PIGLIT_PASS : PIGLIT_FAIL, "viewport attributes");
+
+	return (enable_pass && viewport_pass) ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/nv_conservative_raster/dlist.c b/tests/spec/nv_conservative_raster/dlist.c
new file mode 100644
index 000000000..be94a88c4
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/dlist.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Rhys Perry
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#if PIGLIT_USE_OPENGL
+	config.supports_gl_compat_version = 10;
+#endif
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint list;
+
+void piglit_init(int argc, char **argv)
+{
+	GLint max_subpixel_bits_bias;
+
+	piglit_require_extension("GL_NV_conservative_raster");
+
+	glGetIntegerv(GL_MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV, &max_subpixel_bits_bias);
+	if (max_subpixel_bits_bias<3)
+		piglit_report_result(PIGLIT_SKIP);
+
+	list = glGenLists(1);
+	glNewList(list, GL_COMPILE);
+	glSubpixelPrecisionBiasNV(0, 1);
+	glEndList();
+}
+
+enum piglit_result piglit_display(void)
+{
+	bool dlist_pass[2];
+	GLint biasx, biasy;
+
+	glCallList(list);
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_X_BITS_NV, &biasx);
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_Y_BITS_NV, &biasy);
+
+	dlist_pass[0] = biasx==0 && biasy==1;
+	piglit_report_subtest_result(dlist_pass[0] ? PIGLIT_PASS : PIGLIT_FAIL, "compiled display list");
+
+	glNewList(list, GL_COMPILE_AND_EXECUTE);
+	glSubpixelPrecisionBiasNV(2, 3);
+	glEndList();
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_X_BITS_NV, &biasx);
+	glGetIntegerv(GL_SUBPIXEL_PRECISION_BIAS_Y_BITS_NV, &biasy);
+
+	dlist_pass[1] = biasx==2 && biasy==3;
+	piglit_report_subtest_result(dlist_pass[1] ? PIGLIT_PASS : PIGLIT_FAIL, "compile/execute display list");
+
+	return (dlist_pass[0] && dlist_pass[1]) ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/nv_conservative_raster/draw.c b/tests/spec/nv_conservative_raster/draw.c
new file mode 100644
index 000000000..fe40deb1f
--- /dev/null
+++ b/tests/spec/nv_conservative_raster/draw.c
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2018 Rhys Perry
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#if PIGLIT_USE_OPENGL
+	config.supports_gl_compat_version = 21;
+#else
+	config.supports_gl_es_version = 20;
+#endif
+
+	config.window_width = 250;
+	config.window_height = 250;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint program, buf_triangle, buf_lines, buf_point, buf_degenerate;
+
+static const float verts_triangle[6] = {
+	-0.799998779, -0.799998779,
+	 0.799998779,  0.799998779,
+	 0.799998779, -0.799998779};
+
+static const float verts_lines[6] = {
+	 0.799998779,  0.799998779,
+	 0.799998779, -0.799998779,
+	-0.799998779, -0.799998779};
+
+static const float verts_point[2] = {
+	 0.001601953, 0.001601953};
+
+static const float verts_degenerate[6] = {
+	 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+
+static const float white[3] = {1.0f, 1.0f, 1.0f};
+static const float black[3] = {0.0f, 0.0f, 0.0f};
+
+void piglit_init(int argc, char **argv)
+{
+	GLint max_subpixel_bits_bias;
+
+	piglit_require_extension("GL_NV_conservative_raster");
+
+	glGetIntegerv(GL_MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV, &max_subpixel_bits_bias);
+	if (max_subpixel_bits_bias<8)
+		piglit_report_result(PIGLIT_SKIP);
+
+	program = piglit_build_simple_program(
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"attribute vec2 piglit_vertex;"
+			"void main() { gl_Position = vec4(piglit_vertex, 0.0, 1.0); }\n",
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"void main() { gl_FragColor = vec4(1.0); }\n");
+
+	glGenBuffers(1, &buf_triangle);
+	glGenBuffers(1, &buf_lines);
+	glGenBuffers(1, &buf_point);
+	glGenBuffers(1, &buf_degenerate);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_triangle);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_triangle), verts_triangle, GL_STATIC_DRAW);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_lines);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_lines), verts_lines, GL_STATIC_DRAW);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_point);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_point), verts_point, GL_STATIC_DRAW);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_degenerate);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_degenerate), verts_degenerate, GL_STATIC_DRAW);
+}
+
+static void draw(GLenum prim)
+{
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	switch (prim) {
+	case GL_TRIANGLES:
+		glBindBuffer(GL_ARRAY_BUFFER, buf_triangle);
+	break;
+	case GL_LINE_STRIP:
+		glBindBuffer(GL_ARRAY_BUFFER, buf_lines);
+	break;
+	case GL_POINTS:
+		glBindBuffer(GL_ARRAY_BUFFER, buf_point);
+	break;
+	}
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)0);
+
+	glUseProgram(program);
+	glDrawArrays(prim, 0, prim==GL_POINTS?1:3);
+}
+
+static bool test_triangle(bool smooth, bool conservative, bool xbias, bool ybias) {
+	bool c1 = conservative ? 1 : 0;
+	if (smooth) {
+		glEnable(GL_BLEND);
+		glEnable(GL_POLYGON_SMOOTH);
+	}
+	if (conservative)
+		glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glSubpixelPrecisionBiasNV(xbias?8:0, ybias?8:0);
+	draw(GL_TRIANGLES);
+	int c = 0;
+	if (ybias) {
+		c += piglit_probe_pixel_rgb(58, 25, white);
+		c += piglit_probe_pixel_rgb(58, 24, black);
+	} else {
+		c += piglit_probe_pixel_rgb(58, 25-c1, white);
+		c += piglit_probe_pixel_rgb(58, 24-c1, black);
+	}
+	c += piglit_probe_pixel_rgb(180, 180+c1, white);
+	c += piglit_probe_pixel_rgb(180, 181+c1, black);
+	if (xbias) {
+		c += piglit_probe_pixel_rgb(224, 189, white);
+		c += piglit_probe_pixel_rgb(225, 189, black);
+	} else {
+		c += piglit_probe_pixel_rgb(224+c1, 189, white);
+		c += piglit_probe_pixel_rgb(225+c1, 189, black);
+	}
+	if (xbias && ybias)
+		c += piglit_probe_pixel_rgb(224, 24, black);
+	else if (xbias)
+		c += piglit_probe_pixel_rgb(224, 225, white);
+	else if (ybias)
+		c += piglit_probe_pixel_rgb(225, 225, black);
+	else
+		c += piglit_probe_pixel_rgb(225, 225, conservative?white:black);
+	return c == 7;
+}
+
+static bool test_lines(bool smooth, bool conservative, bool xbias, bool ybias) {
+	int c1 = conservative ? 1 : 0;
+	if (smooth) {
+		glEnable(GL_BLEND);
+		glEnable(GL_LINE_SMOOTH);
+	}
+	if (conservative)
+		glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glSubpixelPrecisionBiasNV(xbias?8:0, ybias?8:0);
+	draw(GL_LINE_STRIP);
+	int c = piglit_probe_pixel_rgb(224+c1, 149, white);
+	c += piglit_probe_pixel_rgb(225+c1, 149, black);
+	c += piglit_probe_pixel_rgb(100, 25-c1, white);
+	c += piglit_probe_pixel_rgb(100, 24-c1, black);
+	if (conservative) {
+		c += piglit_probe_pixel_rgb(24, 24, xbias?black:white);
+		c += piglit_probe_pixel_rgb(225, 225, ybias?black:white);
+		c += piglit_probe_pixel_rgb(225, 24, (xbias&&ybias)?black:white);
+	} else {
+		c += 3;
+	}
+	return c == 7;
+}
+
+static bool test_line_stipple(bool _0, bool _1, bool _2, bool _3) {
+	glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glEnable(GL_LINE_STIPPLE);
+	glLineStipple(3, 0xaaaa);
+	draw(GL_LINE_STRIP);
+	return piglit_probe_pixel_rgb(26, 25, white);
+}
+
+static bool test_point(bool smooth, bool conservative, bool _0, bool _1) {
+	if (smooth) {
+		glEnable(GL_BLEND);
+		glEnable(GL_POINT_SMOOTH);
+	}
+	if (conservative)
+		glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	draw(GL_POINTS);
+	int c = 0;
+	if (conservative) {
+		c += piglit_probe_pixel_rgb(124, 128, white);
+		c += piglit_probe_pixel_rgb(124, 129, black);
+		c += piglit_probe_pixel_rgb(128, 124, white);
+		c += piglit_probe_pixel_rgb(129, 124, black);
+	} else {
+		c += piglit_probe_pixel_rgb(123, 123, white);
+		c += piglit_probe_pixel_rgb(122, 123, black);
+		c += piglit_probe_pixel_rgb(125, 127, white);
+		c += piglit_probe_pixel_rgb(125, 128, black);
+	}
+	return c == 4;
+}
+
+static bool run_test(bool (*func)(bool, bool, bool, bool), const char* name,
+					 bool smooth, bool conservative, bool xbias, bool ybias) {
+	glDisable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glDisable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#if PIGLIT_USE_OPENGL
+	glDisable(GL_POLYGON_SMOOTH);
+	glDisable(GL_LINE_SMOOTH);
+	glDisable(GL_LINE_STIPPLE);
+	glPointSize(5.0);
+#endif
+	glSubpixelPrecisionBiasNV(0, 0);
+	
+	bool pass = func(smooth, conservative, xbias, ybias);
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, name);
+	
+	return pass;
+}
+
+static bool degenerate_test() {
+	glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glBindBuffer(GL_ARRAY_BUFFER, buf_degenerate);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)0);
+
+	glUseProgram(program);
+	glDrawArrays(GL_TRIANGLES, 0, 3);
+
+	bool pass = piglit_probe_pixel_rgb(125, 125, black);
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "degenerate triangle");
+
+	return pass;
+}
+
+enum piglit_result piglit_display(void)
+{
+	bool pass[17];
+	for (int i = 0; i < 17; i++) pass[i] = true;
+
+	pass[0] = run_test(&test_triangle, "normal triangle", false, false, false, false);
+	pass[1] = run_test(&test_triangle, "bias 0 0 triangle", false, true, false, false);
+	pass[2] = run_test(&test_triangle, "bias 0 8 triangle", false, true, false, true);
+	pass[3] = run_test(&test_triangle, "bias 8 0 triangle", false, true, true, false);
+	pass[4] = run_test(&test_triangle, "bias 8 8 triangle", false, true, true, true);
+#if PIGLIT_USE_OPENGL
+	pass[5] = run_test(&test_triangle, "smooth triangle", true, true, false, false);
+#endif
+	pass[6] = run_test(&test_lines, "normal line", false, false, false, false);
+	pass[7] = run_test(&test_lines, "bias 0 0 line", false, true, false, false);
+	pass[8] = run_test(&test_lines, "bias 0 8 line", false, true, false, true);
+	pass[9] = run_test(&test_lines, "bias 8 0 line", false, true, true, false);
+	pass[10] = run_test(&test_lines, "bias 8 8 line", false, true, true, true);
+#if PIGLIT_USE_OPENGL
+	pass[11] = run_test(&test_lines, "smooth line", true, true, false, false);
+	pass[12] = run_test(&test_line_stipple, "line stipple", false, false, false, false);
+	pass[13] = run_test(&test_point, "normal point", false, false, false, false);
+	pass[14] = run_test(&test_point, "bias 0 0 point", false, true, false, false);
+	pass[15] = run_test(&test_point, "smooth point", true, true, false, false);
+#endif
+	pass[16] = degenerate_test();
+	piglit_present_results();
+
+	for (int i = 0; i < 17; i++) {
+		if (!pass[i]) return PIGLIT_FAIL;
+	}
+	return PIGLIT_PASS;
+}
diff --git a/tests/spec/nv_conservative_raster_dilate/CMakeLists.gl.txt b/tests/spec/nv_conservative_raster_dilate/CMakeLists.gl.txt
new file mode 100644
index 000000000..5485eb1a6
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_dilate/CMakeLists.gl.txt
@@ -0,0 +1,11 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (nv_conservative_raster_dilate-draw draw.c)
diff --git a/tests/spec/nv_conservative_raster_dilate/CMakeLists.gles2.txt b/tests/spec/nv_conservative_raster_dilate/CMakeLists.gles2.txt
new file mode 100644
index 000000000..dbafd55aa
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_dilate/CMakeLists.gles2.txt
@@ -0,0 +1,3 @@
+link_libraries(piglitutil_${piglit_target_api})
+
+piglit_add_executable (nv_conservative_raster_dilate-draw_gles2 draw.c)
diff --git a/tests/spec/nv_conservative_raster_dilate/CMakeLists.txt b/tests/spec/nv_conservative_raster_dilate/CMakeLists.txt
new file mode 100644
index 000000000..144a306f4
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_dilate/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/nv_conservative_raster_dilate/draw.c b/tests/spec/nv_conservative_raster_dilate/draw.c
new file mode 100644
index 000000000..fda7e17ea
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_dilate/draw.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2018 Rhys Perry
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#if PIGLIT_USE_OPENGL
+	config.supports_gl_compat_version = 21;
+#else
+	config.supports_gl_es_version = 20;
+#endif
+
+	config.window_width = 250;
+	config.window_height = 250;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint program, buf_triangle;
+
+static const float verts_triangle[6] = {
+	-0.799998779, -0.799998779,
+	 0.799998779,  0.799998779,
+	 0.799998779, -0.799998779};
+
+static const float white[3] = {1.0f, 1.0f, 1.0f};
+static const float black[3] = {0.0f, 0.0f, 0.0f};
+
+void piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_NV_conservative_raster_dilate");
+
+	program = piglit_build_simple_program(
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"attribute vec2 piglit_vertex;"
+			"void main() { gl_Position = vec4(piglit_vertex, 0.0, 1.0); }\n",
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"void main() { gl_FragColor = vec4(1.0); }\n");
+
+	glGenBuffers(1, &buf_triangle);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_triangle);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_triangle), verts_triangle, GL_STATIC_DRAW);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)0);
+}
+
+static void draw(GLenum prim)
+{
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glUseProgram(program);
+	glDrawArrays(GL_TRIANGLES, 0, 3);
+}
+
+static bool test_triangle(const char* name, bool dilate) {
+	int d1 = dilate ? 1 : 0;
+	glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glConservativeRasterParameterfNV(GL_CONSERVATIVE_RASTER_DILATE_NV, dilate?0.75:0.0);
+	draw(GL_TRIANGLES);
+	int c = 0;
+
+	c += piglit_probe_pixel_rgb(90-d1, 92, black);
+	c += piglit_probe_pixel_rgb(90-d1, 91, white);
+
+	c += piglit_probe_pixel_rgb(179, 181+d1, black);
+	c += piglit_probe_pixel_rgb(180, 181+d1, white);
+
+	c += piglit_probe_pixel_rgb(226, 119, black);
+	c += piglit_probe_pixel_rgb(225, 119, white);
+
+	c += piglit_probe_pixel_rgb(130, 23, black);
+	c += piglit_probe_pixel_rgb(130, 24, white);
+
+	bool pass = c == 8;
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, name);
+	return pass;
+}
+
+enum piglit_result piglit_display(void)
+{
+	bool pass[2];
+	pass[0] = test_triangle("dilate 0", false);
+	pass[1] = test_triangle("dilate 3/4", true);
+	pass[0] = test_triangle("dilate 0", false);
+	pass[1] = test_triangle("dilate 3/4", true);
+	pass[0] = test_triangle("dilate 0", false);
+	pass[1] = test_triangle("dilate 3/4", true);
+	piglit_present_results();
+
+	for (int i = 0; i < 2; i++) {
+		if (!pass[i])
+			return PIGLIT_FAIL;
+	}
+	return PIGLIT_PASS;
+}
diff --git a/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gl.txt b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gl.txt
new file mode 100644
index 000000000..8fe798531
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gl.txt
@@ -0,0 +1,11 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (nv_conservative_raster_pre_snap_triangles-draw draw.c)
diff --git a/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gles2.txt b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gles2.txt
new file mode 100644
index 000000000..9e663ce72
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.gles2.txt
@@ -0,0 +1,3 @@
+link_libraries(piglitutil_${piglit_target_api})
+
+piglit_add_executable (nv_conservative_raster_pre_snap_triangles-draw_gles2 draw.c)
diff --git a/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.txt b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.txt
new file mode 100644
index 000000000..144a306f4
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_pre_snap_triangles/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/nv_conservative_raster_pre_snap_triangles/draw.c b/tests/spec/nv_conservative_raster_pre_snap_triangles/draw.c
new file mode 100644
index 000000000..ae1df47d4
--- /dev/null
+++ b/tests/spec/nv_conservative_raster_pre_snap_triangles/draw.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2018 Rhys Perry
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#if PIGLIT_USE_OPENGL
+	config.supports_gl_compat_version = 21;
+#else
+	config.supports_gl_es_version = 20;
+#endif
+
+	config.window_width = 250;
+	config.window_height = 250;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint program, buf_triangle, buf_zero;
+
+static const float verts_triangle[6] = {
+	-0.399991212, -0.799982424,
+	 0.799982424,  0.399991212,
+	 0.399991212, -0.799982424};
+
+static const float verts_zero[6] = {
+	0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+
+static const float white[3] = {1.0f, 1.0f, 1.0f};
+static const float black[3] = {0.0f, 0.0f, 0.0f};
+
+void piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_NV_conservative_raster_pre_snap_triangles");
+
+	program = piglit_build_simple_program(
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"attribute vec2 piglit_vertex;"
+			"void main() { gl_Position = vec4(piglit_vertex, 0.0, 1.0); }\n",
+#ifdef PIGLIT_USE_OPENGL
+			"#version 120\n"
+#else
+			"#version 100\n"
+			"precision highp float;\n"
+#endif
+			"void main() { gl_FragColor = vec4(1.0); }\n");
+
+	glGenBuffers(1, &buf_triangle);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_triangle);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_triangle), verts_triangle, GL_STATIC_DRAW);
+	glGenBuffers(1, &buf_zero);
+	glBindBuffer(GL_ARRAY_BUFFER, buf_zero);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts_zero), verts_zero, GL_STATIC_DRAW);
+}
+
+static void draw(bool zero)
+{
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glBindBuffer(GL_ARRAY_BUFFER, zero?buf_zero:buf_triangle);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)0);
+
+	glUseProgram(program);
+	glDrawArrays(GL_TRIANGLES, 0, 3);
+}
+
+enum piglit_result piglit_display(void)
+{
+	bool pass[2];
+
+	glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
+	glConservativeRasterParameteriNV(GL_CONSERVATIVE_RASTER_MODE_NV, GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV);
+
+	draw(true);
+	pass[0] = piglit_probe_pixel_rgb(125, 125, white);
+	piglit_report_subtest_result(pass[0] ? PIGLIT_PASS : PIGLIT_FAIL, "Degenerate triangle");
+
+	draw(false);
+	pass[1] = piglit_probe_pixel_rgb(177, 30, white);
+	pass[1] = pass[1] && piglit_probe_pixel_rgb(177, 29, black);
+	piglit_report_subtest_result(pass[1] ? PIGLIT_PASS : PIGLIT_FAIL, "Normal");
+
+	piglit_present_results();
+
+	if (!pass[0]) return PIGLIT_FAIL;
+	if (!pass[1]) return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
-- 
2.14.3



More information about the Piglit mailing list