2 * Copyright © 2020 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eleni Maria Stea <estea@igalia.com>
27 #include <piglit-util-gl.h>
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 30;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
36 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const char vs
[] =
42 "in vec4 piglit_vertex;\n"
43 "in vec2 piglit_texcoord;\n"
44 "out vec2 tex_coords;\n"
47 " gl_Position = piglit_vertex;\n"
48 " tex_coords = piglit_texcoord;\n"
51 static const char fs
[] =
53 "in vec2 tex_coords;\n"
54 "uniform sampler2D tex; \n"
58 " color = texture(tex, tex_coords);\n"
68 VkFormat color_format
,
69 VkFormat depth_format
,
70 VkImageTiling color_tiling
,
71 VkImageTiling depth_tiling
,
72 VkImageLayout color_in_layout
,
73 VkImageLayout depth_in_layout
,
74 VkImageLayout color_end_layout
,
75 VkImageLayout depth_end_layout
);
89 static struct vk_ctx vk_core
;
90 static struct vk_image_att vk_color_att
;
91 static struct vk_image_att vk_depth_att
;
92 static struct vk_renderer vk_rnd
;
93 static struct vk_buf vk_bo
;
94 static VkBufferUsageFlagBits vk_bo_usage
= VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
95 VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
96 VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
;
98 static GLuint gl_prog
;
99 static GLuint gl_memobj
;
101 static GLuint gl_tex
;
103 static float vk_fb_color
[4] = { 1.0, 1.0, 1.0, 1.0 };
106 piglit_init(int argc
, char **argv
)
108 piglit_require_extension("GL_EXT_memory_object");
109 piglit_require_extension("GL_EXT_memory_object_fd");
110 piglit_require_extension("GL_ARB_texture_storage");
111 piglit_require_extension("GL_ARB_pixel_buffer_object");
118 if (!vk_init(w
, h
, d
, num_samples
, num_levels
, num_layers
,
119 color_format
, depth_format
,
120 color_tiling
, depth_tiling
,
121 color_in_layout
, depth_in_layout
,
122 color_end_layout
, depth_end_layout
)) {
123 fprintf(stderr
, "Failed to initialize Vulkan, skipping the test.\n");
124 piglit_report_result(PIGLIT_SKIP
);
127 if (!gl_create_mem_obj_from_vk_mem(&vk_core
, &vk_bo
.mobj
, &gl_memobj
)) {
128 fprintf(stderr
, "Failed to create GL memory object from Vulkan memory.\n");
129 piglit_report_result(PIGLIT_FAIL
);
132 if (!gl_gen_buf_from_mem_obj(gl_memobj
, GL_PIXEL_UNPACK_BUFFER
, vk_bo
.mobj
.mem_sz
, 0, &gl_bo
)) {
133 fprintf(stderr
, "Failed to create GL buffer from memory object.\n");
134 piglit_report_result(PIGLIT_FAIL
);
137 vk_draw(&vk_core
, 0, &vk_rnd
, vk_fb_color
, 4, 0,
138 false, false, NULL
, 0, 0, 0, w
, h
);
140 vk_copy_image_to_buffer(&vk_core
, &vk_color_att
, &vk_bo
, w
, h
);
143 fprintf(stderr
, "Failed to initialize OpenGL.\n");
144 piglit_report_result(PIGLIT_FAIL
);
152 float colors
[6][4] = {
153 {1.0, 0.0, 0.0, 1.0},
154 {0.0, 1.0, 0.0, 1.0},
155 {0.0, 0.0, 1.0, 1.0},
156 {1.0, 1.0, 0.0, 1.0},
157 {1.0, 0.0, 1.0, 1.0},
161 glUseProgram(gl_prog
);
162 glBindTexture(GL_TEXTURE_2D
, gl_tex
);
164 piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
166 for (i
= 0; i
< 6; i
++) {
167 float x
= i
* (float)piglit_width
/ 6.0 + (float)piglit_width
/ 12.0;
168 float y
= (float)piglit_height
/ 2.0;
170 if (!piglit_probe_pixel_rgba(x
, y
, colors
[i
])) {
171 piglit_present_results();
176 piglit_present_results();
185 uint32_t num_samples
,
188 VkFormat color_format
,
189 VkFormat depth_format
,
190 VkImageTiling color_tiling
,
191 VkImageTiling depth_tiling
,
192 VkImageLayout color_in_layout
,
193 VkImageLayout depth_in_layout
,
194 VkImageLayout color_end_layout
,
195 VkImageLayout depth_end_layout
)
202 if (!vk_init_ctx_for_rendering(&vk_core
)) {
203 fprintf(stderr
, "Failed to create Vulkan context.\n");
207 if (!vk_check_gl_compatibility(&vk_core
)) {
208 fprintf(stderr
, "Mismatch in driver/device UUID\n");
212 if (!vk_fill_ext_image_props(&vk_core
,
222 &vk_color_att
.props
)) {
223 fprintf(stderr
, "Unsupported color image properties.\n");
226 if (!vk_create_ext_image(&vk_core
, &vk_color_att
.props
, &vk_color_att
.obj
)) {
227 fprintf(stderr
, "Failed to create color image.\n");
231 if (!vk_fill_ext_image_props(&vk_core
,
241 &vk_depth_att
.props
)) {
242 fprintf(stderr
, "Unsupported depth image properties.\n");
246 if (!vk_create_ext_image(&vk_core
, &vk_depth_att
.props
, &vk_depth_att
.obj
)) {
247 fprintf(stderr
, "Failed to create depth image.\n");
251 if (!(vs_src
= load_shader(VK_BANDS_VERT
, &vs_sz
)))
254 if (!(fs_src
= load_shader(VK_BANDS_FRAG
, &fs_sz
)))
257 if (!vk_create_renderer(&vk_core
, vs_src
, vs_sz
, fs_src
, fs_sz
,
259 &vk_color_att
, &vk_depth_att
, 0, &vk_rnd
)) {
260 fprintf(stderr
, "Failed to create Vulkan renderer.\n");
264 if (!vk_create_ext_buffer(&vk_core
, w
* h
* 4 * sizeof(float), vk_bo_usage
, &vk_bo
)) {
265 fprintf(stderr
, "Failed to create Vulkan buffer.\n");
284 gl_prog
= piglit_build_simple_program(vs
, fs
);
286 glClearColor(1.0, 0.0, 0.0, 1.0);
287 glClear(GL_COLOR_BUFFER_BIT
);
289 glGenTextures(1, &gl_tex
);
290 glBindTexture(GL_TEXTURE_2D
, gl_tex
);
291 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
292 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
293 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
294 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
296 glBindBuffer(GL_PIXEL_UNPACK_BUFFER
, gl_bo
);
297 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA32F
, w
, h
, 0, GL_RGBA
, GL_FLOAT
, 0);
298 glBindBuffer(GL_PIXEL_UNPACK_BUFFER
, 0);
300 glBindTexture(GL_TEXTURE_2D
, 0);
301 return glGetError() == GL_NO_ERROR
;
314 vk_destroy_ext_image(&vk_core
, &vk_color_att
.obj
);
315 vk_destroy_ext_image(&vk_core
, &vk_depth_att
.obj
);
316 vk_destroy_renderer(&vk_core
, &vk_rnd
);
317 vk_destroy_buffer(&vk_core
, &vk_bo
);
318 vk_cleanup_ctx(&vk_core
);
324 glDeleteProgram(gl_prog
);
325 glDeleteMemoryObjectsEXT(1, &gl_memobj
);
326 glDeleteBuffers(1, &gl_bo
);