summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2015-10-26 05:48:33 +1000
committerDave Airlie <airlied@redhat.com>2015-10-28 10:27:50 +1000
commitd5633094634081b43fb426949ea4b2e9e9359d49 (patch)
tree8b96fe0d3b98cf3208e1441e2eb60408a2a6e781
parente7f3ae588171ae6163262d58b504caf3513a7028 (diff)
bindless: write test for all the layout options
-rw-r--r--tests/spec/arb_bindless_texture/CMakeLists.gl.txt2
-rw-r--r--tests/spec/arb_bindless_texture/bindless_texture_layout.c166
2 files changed, 167 insertions, 1 deletions
diff --git a/tests/spec/arb_bindless_texture/CMakeLists.gl.txt b/tests/spec/arb_bindless_texture/CMakeLists.gl.txt
index b8544964f..68d3d2055 100644
--- a/tests/spec/arb_bindless_texture/CMakeLists.gl.txt
+++ b/tests/spec/arb_bindless_texture/CMakeLists.gl.txt
@@ -10,5 +10,5 @@ link_libraries (
)
piglit_add_executable (arb_bindless_texture-bindless-texture bindless_texture.c)
-
+piglit_add_executable (arb_bindless_texture-layout bindless_texture_layout.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_bindless_texture/bindless_texture_layout.c b/tests/spec/arb_bindless_texture/bindless_texture_layout.c
new file mode 100644
index 000000000..c53d8087f
--- /dev/null
+++ b/tests/spec/arb_bindless_texture/bindless_texture_layout.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2015 Red Hat
+ *
+ * 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 VMWARE 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.
+ */
+
+/**
+ * Tests GL_ARB_bindless_texture
+ */
+
+#include "piglit-util-gl.h"
+#include "piglit-util.h"
+#include <GL/glx.h>
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_core_version = 32;
+
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint prog;
+GLuint texid;
+GLuint loc;
+GLuint64 texhandle;
+
+#define SAMPLER_TYPE_NONE 0
+#define SAMPLER_TYPE_BOUND 1
+#define SAMPLER_TYPE_BINDLESS 2
+
+void
+compile_shader(int default_sampler_type, int sampler_type)
+{
+ GLuint vs;
+ GLuint fs;
+ GLboolean ok;
+ char buf[255], *str, *default_str;
+ static const char *vert =
+ "#version 130\n"
+ "in vec4 piglit_vertex;\n"
+ "in vec2 tc_in;\n"
+ "out vec2 texCoord;\n"
+ "void main() { gl_Position = piglit_vertex; texCoord = tc_in; }\n";
+
+ static const char *frag =
+ "#version 330\n"
+ "#extension GL_ARB_bindless_texture : enable\n"
+ "%s\n"
+ "%suniform sampler2D mysamp;\n"
+ "in vec2 texCoord;\n"
+ "out vec4 finalColor;"
+ "void main()\n"
+ "{\n"
+ " finalColor = texture(mysamp, texCoord);\n"
+ "}\n";
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
+ if (default_sampler_type == SAMPLER_TYPE_NONE)
+ default_str = "";
+ else if (default_sampler_type == SAMPLER_TYPE_BOUND)
+ default_str = "layout (bound_sampler) uniform;";
+ else if (default_sampler_type == SAMPLER_TYPE_BINDLESS)
+ default_str = "layout (bindless_sampler) uniform;";
+
+ if (sampler_type == SAMPLER_TYPE_NONE)
+ str = "";
+ else if (sampler_type == SAMPLER_TYPE_BOUND)
+ str = "layout (bound_sampler) ";
+ else if (sampler_type == SAMPLER_TYPE_BINDLESS)
+ str = "layout (bindless_sampler) ";
+
+ snprintf(buf, 255, frag, default_str, str);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, buf);
+ prog = piglit_link_simple_program(vs, fs);
+
+ ok = piglit_link_check_status(prog);
+ if (!ok)
+ piglit_report_result(PIGLIT_FAIL);
+ loc = glGetUniformLocation(prog, "mysamp");
+}
+
+typedef GLuint64 (*gth)(GLuint texture);
+typedef void (*guh)(GLuint loc, GLuint64 handle);
+typedef void (*resident)(GLuint64 handle);
+
+gth GetTextureHandle;
+guh UniformHandle;
+resident MakeRes, MakeNonRes;
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_SKIP;
+}
+
+struct {
+ int default_type;
+ int sampler_type;
+ GLenum expected_error;
+} tests[] = {
+ { SAMPLER_TYPE_NONE, SAMPLER_TYPE_NONE, GL_INVALID_OPERATION },
+ { SAMPLER_TYPE_NONE, SAMPLER_TYPE_BOUND, GL_INVALID_OPERATION },
+ { SAMPLER_TYPE_NONE, SAMPLER_TYPE_BINDLESS, GL_NO_ERROR },
+
+ { SAMPLER_TYPE_BOUND, SAMPLER_TYPE_NONE, GL_INVALID_OPERATION },
+ { SAMPLER_TYPE_BOUND, SAMPLER_TYPE_BOUND, GL_INVALID_OPERATION },
+ { SAMPLER_TYPE_BOUND, SAMPLER_TYPE_BINDLESS, GL_NO_ERROR },
+
+ { SAMPLER_TYPE_BINDLESS, SAMPLER_TYPE_NONE, GL_NO_ERROR },
+ { SAMPLER_TYPE_BINDLESS, SAMPLER_TYPE_BOUND, GL_INVALID_OPERATION },
+ { SAMPLER_TYPE_BINDLESS, SAMPLER_TYPE_BINDLESS, GL_NO_ERROR },
+};
+
+static void execute_test(int i)
+{
+ compile_shader(tests[i].default_type,
+ tests[i].sampler_type);
+ glUseProgram(prog);
+ UniformHandle(loc, texhandle);
+ if (!piglit_check_gl_error(tests[i].expected_error)) {
+ fprintf(stderr, "failed test %d\n", i);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ glUseProgram(0);
+ glDeleteProgram(prog);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ int i;
+ piglit_require_extension("GL_ARB_bindless_texture");
+
+ GetTextureHandle = (gth)glXGetProcAddress("glGetTextureHandleARB");
+ UniformHandle = glXGetProcAddress("glUniformHandleui64ARB");
+ MakeRes = (resident)glXGetProcAddress("glMakeTextureHandleResidentARB");
+ MakeNonRes = (resident)glXGetProcAddress("glMakeTextureHandleNonResidentARB");
+ texid = piglit_rgbw_texture(GL_RGBA, 64, 64, GL_FALSE, GL_TRUE, GL_UNSIGNED_NORMALIZED);
+ texhandle = GetTextureHandle(texid);
+
+ if (argc == 2) {
+ execute_test(atoi(argv[1]));
+ piglit_report_result(PIGLIT_PASS);
+ }
+ for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ execute_test(i);
+ }
+ piglit_report_result(PIGLIT_PASS);
+}