[Piglit] [PATCH 6/6] ext_memory_object: WIP: Test render with vulkan and sample with gl

Topi Pohjolainen topi.pohjolainen at gmail.com
Thu Nov 30 14:52:43 UTC 2017


Currently only the vulkan rendering part is implemented.

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/spec/ext_memory_object/CMakeLists.gl.txt     |  20 +++
 tests/spec/ext_memory_object/vk_fragcoord.fs       |   8 +
 tests/spec/ext_memory_object/vk_fragcoord.vs       |   9 ++
 tests/spec/ext_memory_object/vk_render_gl_sample.c | 173 +++++++++++++++++++++
 4 files changed, 210 insertions(+)
 create mode 100644 tests/spec/ext_memory_object/vk_fragcoord.fs
 create mode 100644 tests/spec/ext_memory_object/vk_fragcoord.vs
 create mode 100644 tests/spec/ext_memory_object/vk_render_gl_sample.c

diff --git a/tests/spec/ext_memory_object/CMakeLists.gl.txt b/tests/spec/ext_memory_object/CMakeLists.gl.txt
index 3a714e6af..44ea66127 100644
--- a/tests/spec/ext_memory_object/CMakeLists.gl.txt
+++ b/tests/spec/ext_memory_object/CMakeLists.gl.txt
@@ -1,3 +1,18 @@
+
+set(GLSLC /home/tpohjola/work/shaderc/src/glslc/glslc)
+set(LIBVULKAN_LIBRARY /usr/lib/x86_64-linux-gnu/libvulkan.so)
+
+add_custom_command (
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_vs.h
+  	COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/compile_and_dump_glsl_as_spirv.py --with-glslc=${GLSLC} --stage=vertex ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord.vs > ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_vs.h
+)
+
+add_custom_command (
+	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_fs.h
+  	COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/compile_and_dump_glsl_as_spirv.py --with-glslc=${GLSLC} --stage=fragment ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord.fs > ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_fs.h
+)
+
+
 include_directories(
 	${GLEXT_INCLUDE_DIR}
 	${OPENGL_INCLUDE_PATH}
@@ -6,9 +21,14 @@ include_directories(
 link_libraries (
 	piglitutil_${piglit_target_api}
 	${OPENGL_gl_LIBRARY}
+	${LIBVULKAN_LIBRARY}
 )
 
 piglit_add_executable (ext_memory_object-api-errors api-errors.c)
 
+piglit_add_executable (ext_memory_object-vulkan_render_gl_sample
+		       vk_render_gl_sample.c vk_fb.c vk_common.c
+		       ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_fs.h
+		       ${CMAKE_CURRENT_SOURCE_DIR}/vk_fragcoord_vs.h)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_memory_object/vk_fragcoord.fs b/tests/spec/ext_memory_object/vk_fragcoord.fs
new file mode 100644
index 000000000..26ab7ed6d
--- /dev/null
+++ b/tests/spec/ext_memory_object/vk_fragcoord.fs
@@ -0,0 +1,8 @@
+layout(origin_upper_left) in vec4 gl_FragCoord;
+layout(location = 0) in vec2 v_attr;
+layout(location = 0) out vec4 f_color;
+void main()
+{
+	f_color.xy = v_attr + gl_FragCoord.xy / 32.0;
+	f_color.zw = gl_FragCoord.zw;
+}
diff --git a/tests/spec/ext_memory_object/vk_fragcoord.vs b/tests/spec/ext_memory_object/vk_fragcoord.vs
new file mode 100644
index 000000000..8c81716c5
--- /dev/null
+++ b/tests/spec/ext_memory_object/vk_fragcoord.vs
@@ -0,0 +1,9 @@
+layout(location = 0) in vec4 a_position;
+layout(location = 0) out vec2 v_attr;
+void main()
+{
+	gl_Position.xy = a_position.xy * 2 - vec2(1.0);
+	gl_Position.zw = a_position.zw;
+	v_attr.x = -a_position.x;
+	v_attr.y = 1.0 - a_position.y;
+}
diff --git a/tests/spec/ext_memory_object/vk_render_gl_sample.c b/tests/spec/ext_memory_object/vk_render_gl_sample.c
new file mode 100644
index 000000000..cef9fb4d4
--- /dev/null
+++ b/tests/spec/ext_memory_object/vk_render_gl_sample.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2017 Intel Corporation
+ *
+ * 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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/**
+ * Test GL sampling memory written by Vulkan.
+ */
+
+#include "piglit-util-gl.h"
+#include "vk_common.h"
+#include "vk_fragcoord_vs.h"
+#include "vk_fragcoord_fs.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+	config.khr_no_error_support = PIGLIT_HAS_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const unsigned w = 64;
+static const unsigned h = 64;
+
+static VkDevice vk_dev = VK_NULL_HANDLE;
+static VkRenderPass vk_render_pass = VK_NULL_HANDLE;
+static VkPipeline vk_pipeline = VK_NULL_HANDLE;
+static VkShaderModule vk_vs = VK_NULL_HANDLE;
+static VkShaderModule vk_fs = VK_NULL_HANDLE;
+
+static struct vk_fb vk_fb = {
+        { { VK_NULL_HANDLE, VK_NULL_HANDLE }, VK_NULL_HANDLE },
+        { { VK_NULL_HANDLE, VK_NULL_HANDLE }, VK_NULL_HANDLE },
+        VK_NULL_HANDLE,
+        VK_NULL_HANDLE };
+
+static void
+pipeline_cleanup(void)
+{
+	if (vk_pipeline != VK_NULL_HANDLE)
+		vkDestroyPipeline(vk_dev, vk_pipeline, NULL);
+
+	if (vk_vs != VK_NULL_HANDLE)
+		vkDestroyShaderModule(vk_dev, vk_vs, NULL);
+
+	if (vk_fs != VK_NULL_HANDLE)
+		vkDestroyShaderModule(vk_dev, vk_fs, NULL);
+
+	if (vk_render_pass != VK_NULL_HANDLE)
+		vkDestroyRenderPass(vk_dev, vk_render_pass, NULL);
+
+        vk_fb_destroy(vk_dev, &vk_fb);
+
+	vk_cleanup();
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* From the EXT_external_objects spec:
+	 *
+	 *   "GL_EXT_memory_object requires ARB_texture_storage or a
+	 *   version of OpenGL or OpenGL ES that incorporates it."
+	 */
+	piglit_require_extension("GL_ARB_texture_storage");
+	piglit_require_extension("GL_EXT_memory_object");
+
+	vk_dev = vk_init();
+
+	vk_render_pass = vk_create_render_pass(VK_FORMAT_R8G8B8A8_UNORM);
+	if (vk_render_pass == VK_NULL_HANDLE)
+		goto fail;
+
+	vk_vs = vk_add_shader(vk_fragcoord_vs_spir_v_src,
+			      sizeof(vk_fragcoord_vs_spir_v_src));
+	if (vk_vs == VK_NULL_HANDLE)
+		goto fail;
+
+	vk_fs = vk_add_shader(vk_fragcoord_fs_spir_v_src,
+			      sizeof(vk_fragcoord_fs_spir_v_src));
+	if (vk_fs == VK_NULL_HANDLE)
+		goto fail;
+
+	vk_pipeline = vk_create_pipeline(w, h, 8, VK_FORMAT_R32G32_SFLOAT,
+					 vk_render_pass, vk_fs, vk_vs);
+	if (vk_pipeline == VK_NULL_HANDLE)
+		goto fail;
+
+        const unsigned num_layers = 1;
+        const unsigned num_samples = 1;
+        vk_setup_fb(vk_dev, w, h, num_samples, num_layers,
+                    VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED, &vk_fb);
+        if (vk_fb.fb != VK_NULL_HANDLE)
+                return;
+
+fail:
+	pipeline_cleanup();
+	piglit_report_result(PIGLIT_FAIL);
+}
+
+static bool
+render_and_wait(void)
+{
+	const uint64_t timeout = UINT64_MAX;
+	const float vertices[] = {
+		0.0, 1.0,
+		1.0, 1.0,
+		0.0, 0.0,
+		1.0, 0.0
+	};
+	struct vk_vertex_buffer vb = { VK_NULL_HANDLE, VK_NULL_HANDLE };
+	VkFence fence = vk_create_fence(vk_dev);
+	bool status = false;
+
+	if (fence == VK_NULL_HANDLE)
+		goto cleanup;
+
+	vk_setup_vertex_buffer(vertices, 4, &vb);
+	if (vb.buf == VK_NULL_HANDLE)
+		goto cleanup;
+
+	vk_begin_render_pass(vk_render_pass, vk_fb.fb, w, h);
+
+	if (!vk_draw(vk_pipeline, vb.buf, fence))
+		goto cleanup;
+
+	status = vkWaitForFences(vk_dev, 1, &fence, true, timeout) ==
+			VK_SUCCESS;
+
+cleanup:
+	if (vb.buf != VK_NULL_HANDLE) {
+		vkFreeMemory(vk_dev, vb.mem, NULL);
+		vkDestroyBuffer(vk_dev, vb.buf, NULL);
+	}
+
+        if (fence != VK_NULL_HANDLE)
+                vkDestroyFence(vk_dev, fence, NULL);
+
+	return status;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool result = render_and_wait();
+
+	/* TODO: Import the memory from the vulkan framebuffer to GL, create a
+	 *       texture against it and sample.
+	 */
+
+	pipeline_cleanup();
+
+	return result ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
2.14.1



More information about the Piglit mailing list