2 * Copyright © 2021 Eleni Maria Stea
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 <elene.mst@gmail.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
;
94 static GLenum gl_target
= GL_TEXTURE_2D
;
95 static GLenum gl_tex_storage_format
= GL_RGBA32F
;
98 static GLuint gl_textures
[NUM_TEX
];
99 static GLuint gl_combined_tex
;
101 static GLint gl_prog
;
102 static GLuint gl_mem_obj
;
104 static float vk_fb_color
[4] = { 1.0, 1.0, 1.0, 1.0 };
106 void piglit_init(int argc
, char **argv
)
110 piglit_require_extension("GL_ARB_texture_storage");
111 piglit_require_extension("GL_EXT_memory_object");
112 piglit_require_extension("GL_EXT_memory_object_fd");
113 piglit_require_extension("GL_EXT_semaphore");
114 piglit_require_extension("GL_EXT_semaphore_fd");
118 if (!vk_init(piglit_width
, piglit_height
, 1, 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 /* create memory object and gl texture */
128 if (!gl_create_mem_obj_from_vk_mem(&vk_core
, &vk_color_att
.obj
.mobj
,
130 fprintf(stderr
, "Failed to create GL memory object from Vulkan memory.\n");
131 piglit_report_result(PIGLIT_FAIL
);
134 struct vk_image_att images
[] = { vk_color_att
, vk_depth_att
};
135 vk_draw(&vk_core
, 0, &vk_rnd
, vk_fb_color
, 4, 0,
136 false, false, images
, ARRAY_SIZE(images
), 0, 0, piglit_width
, piglit_height
);
138 /* generate NUM_TEX textures */
139 for (i
= 0; i
< NUM_TEX
; i
++) {
140 if (!gl_gen_tex_from_mem_obj(&vk_color_att
.props
,
141 gl_tex_storage_format
,
142 gl_mem_obj
, 0, &gl_textures
[i
])) {
143 fprintf(stderr
, "Failed to create texture gl_textures[%d] from GL memory object.\n", i
);
144 piglit_report_result(PIGLIT_FAIL
);
149 fprintf(stderr
, "Failed to initialize structs for GL rendering.\n");
150 piglit_report_result(PIGLIT_FAIL
);
157 enum piglit_result res
= PIGLIT_PASS
;
159 float colors
[6][4] = {
160 {1.0, 0.0, 0.0, 1.0},
161 {0.0, 1.0, 0.0, 1.0},
162 {0.0, 0.0, 1.0, 1.0},
163 {1.0, 1.0, 0.0, 1.0},
164 {1.0, 0.0, 1.0, 1.0},
168 /* bind all textures */
169 for (i
= 0; i
< NUM_TEX
; i
++) {
170 glBindTexture(gl_target
, gl_textures
[i
]);
173 piglit_draw_rect_tex(-1, -1, 1, 1, 0, 0, 1, 1);
176 piglit_draw_rect_tex(-1, 0, 1, 1, 0, 0, 1, 1);
179 piglit_draw_rect_tex(0, 0, 1, 1, 0, 0, 1, 1);
182 piglit_draw_rect_tex(0, -1, 1, 1, 0, 0, 1, 1);
190 for (i
= 0; i
< 6; i
++) {
191 float x
= i
* (float)piglit_width
/ 12.0 + (float)piglit_width
/ 24.0;
192 float y
= (float)piglit_height
/ 4.0;
194 if (!piglit_probe_pixel_rgba(x
, y
, colors
[i
])) {
200 piglit_present_results();
208 uint32_t num_samples
,
211 VkFormat color_format
,
212 VkFormat depth_format
,
213 VkImageTiling color_tiling
,
214 VkImageTiling depth_tiling
,
215 VkImageLayout color_in_layout
,
216 VkImageLayout depth_in_layout
,
217 VkImageLayout color_end_layout
,
218 VkImageLayout depth_end_layout
)
225 if (!vk_init_ctx_for_rendering(&vk_core
)) {
226 fprintf(stderr
, "Failed to create Vulkan context.\n");
230 if (!vk_check_gl_compatibility(&vk_core
)) {
231 fprintf(stderr
, "Mismatch in driver/device UUID\n");
235 /* creating external images */
237 if (!vk_fill_ext_image_props(&vk_core
,
247 &vk_color_att
.props
)) {
248 fprintf(stderr
, "Unsupported color image properties.\n");
251 if (!vk_create_ext_image(&vk_core
, &vk_color_att
.props
, &vk_color_att
.obj
)) {
252 fprintf(stderr
, "Failed to create color image.\n");
257 if (!vk_fill_ext_image_props(&vk_core
,
267 &vk_depth_att
.props
)) {
268 fprintf(stderr
, "Unsupported depth image properties.\n");
272 if (!vk_create_ext_image(&vk_core
, &vk_depth_att
.props
, &vk_depth_att
.obj
)) {
273 fprintf(stderr
, "Failed to create depth image.\n");
278 if (!(vs_src
= load_shader(VK_BANDS_VERT
, &vs_sz
)))
281 if (!(fs_src
= load_shader(VK_BANDS_FRAG
, &fs_sz
)))
284 /* create Vulkan renderer */
285 if (!vk_create_renderer(&vk_core
, vs_src
, vs_sz
, fs_src
, fs_sz
,
287 &vk_color_att
, &vk_depth_att
, 0, &vk_rnd
)) {
288 fprintf(stderr
, "Failed to create Vulkan renderer.\n");
307 vk_destroy_ext_image(&vk_core
, &vk_color_att
.obj
);
308 vk_destroy_ext_image(&vk_core
, &vk_depth_att
.obj
);
310 vk_destroy_renderer(&vk_core
, &vk_rnd
);
312 vk_cleanup_ctx(&vk_core
);
325 gl_prog
= piglit_build_simple_program(vs
, fs
);
326 glUseProgram(gl_prog
);
327 glGenTextures(1, &gl_combined_tex
);
329 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
330 return glGetError() == GL_NO_ERROR
;
336 glBindTexture(gl_target
, 0);
338 glDeleteTextures(NUM_TEX
, gl_textures
);
339 glDeleteProgram(gl_prog
);
341 glDeleteMemoryObjectsEXT(1, &gl_mem_obj
);