blob: 90c692b9c49b572e4c2ba6d403ddd2495c410797 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001// VK tests
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06002//
3// Copyright (C) 2014 LunarG, Inc.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
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.
22
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060023#include "vktestframework.h"
24#include "vkrenderframework.h"
Cody Northrop5a95b472015-06-03 13:01:54 -060025#include "SPIRV/GlslangToSpv.h"
26#include "SPIRV/SPVRemapper.h"
Tony Barbour4ab45422014-12-10 17:00:20 -070027#include <limits.h>
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060028#include <math.h>
Chia-I Wuec664fa2014-12-02 11:54:24 +080029#include <wand/MagickWand.h>
Chia-I Wuf8693382015-04-16 22:02:10 +080030#include <xcb/xcb.h>
Ian Elliott1a3845b2015-07-06 14:33:04 -060031#include "vk_wsi_swapchain.h"
32#include "vk_wsi_device_swapchain.h"
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060033
Tony Barbour3d69c9e2015-05-20 16:53:31 -060034#if defined(PATH_MAX) && !defined(MAX_PATH)
35#define MAX_PATH PATH_MAX
36#endif
37
Tony Barbour6a3faf02015-07-23 10:36:18 -060038#ifdef _WIN32
39#define ERR_EXIT(err_msg, err_class) \
40 do { \
41 MessageBox(NULL, err_msg, err_class, MB_OK); \
42 exit(1); \
43 } while (0)
44#else // _WIN32
45
46#define ERR_EXIT(err_msg, err_class) \
47 do { \
48 printf(err_msg); \
49 fflush(stdout); \
50 exit(1); \
51 } while (0)
52#endif // _WIN32
53
54#define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \
55{ \
56 m_fp##entrypoint = (PFN_vk##entrypoint) vkGetInstanceProcAddr(inst, "vk"#entrypoint); \
57 if (m_fp##entrypoint == NULL) { \
58 ERR_EXIT("vkGetInstanceProcAddr failed to find vk"#entrypoint, \
59 "vkGetInstanceProcAddr Failure"); \
60 } \
61}
62
63#define GET_DEVICE_PROC_ADDR(dev, entrypoint) \
64{ \
65 m_fp##entrypoint = (PFN_vk##entrypoint) vkGetDeviceProcAddr(dev, "vk"#entrypoint); \
66 if (m_fp##entrypoint == NULL) { \
67 ERR_EXIT("vkGetDeviceProcAddr failed to find vk"#entrypoint, \
68 "vkGetDeviceProcAddr Failure"); \
69 } \
70}
71
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060072// Command-line options
73enum TOptions {
74 EOptionNone = 0x000,
75 EOptionIntermediate = 0x001,
76 EOptionSuppressInfolog = 0x002,
77 EOptionMemoryLeakMode = 0x004,
78 EOptionRelaxedErrors = 0x008,
79 EOptionGiveWarnings = 0x010,
80 EOptionLinkProgram = 0x020,
81 EOptionMultiThreaded = 0x040,
82 EOptionDumpConfig = 0x080,
83 EOptionDumpReflection = 0x100,
84 EOptionSuppressWarnings = 0x200,
85 EOptionDumpVersions = 0x400,
Cody Northrop3bfd27c2015-03-17 15:55:58 -060086 EOptionSpv = 0x800,
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060087 EOptionDefaultDesktop = 0x1000,
88};
89
Tony Barbour6a3faf02015-07-23 10:36:18 -060090typedef struct _SwapChainBuffers {
91 VkImage image;
92 VkCmdBuffer cmd;
93 VkAttachmentView view;
94} SwapChainBuffers;
95
Chia-I Wuf8693382015-04-16 22:02:10 +080096class TestFrameworkVkPresent
97{
98public:
99 TestFrameworkVkPresent(vk_testing::Device &device);
100
101 void Run();
Jon Ashburn07daee72015-05-21 18:13:33 -0600102 void InitPresentFramework(std::list<VkTestImageRecord> &imagesIn, VkInstance inst);
Chia-I Wuf8693382015-04-16 22:02:10 +0800103 void CreateMyWindow();
104 void CreateSwapChain();
105 void TearDown();
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600106#ifdef _WIN32
107 static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
108#endif
109
Chia-I Wuf8693382015-04-16 22:02:10 +0800110
111protected:
112 vk_testing::Device &m_device;
113 vk_testing::Queue &m_queue;
Dana Jansens233a0ea2015-07-30 13:04:16 -0700114 vk_testing::CmdPool m_cmdpool;
Chia-I Wuf8693382015-04-16 22:02:10 +0800115 vk_testing::CmdBuffer m_cmdbuf;
116
117private:
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600118#ifdef _WIN32
119 HINSTANCE m_connection; // hInstance - Windows Instance
120 HWND m_window; // hWnd - window handle
121
122#else
Chia-I Wuf8693382015-04-16 22:02:10 +0800123 xcb_connection_t *m_connection;
124 xcb_screen_t *m_screen;
125 xcb_window_t m_window;
126 xcb_intern_atom_reply_t *m_atom_wm_delete_window;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600127 VkPlatformHandleXcbWSI m_platform_handle_xcb;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600128#endif
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600129 std::list<VkTestImageRecord> m_images;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600130 uint32_t m_present_queue_node_index;
Chia-I Wuf8693382015-04-16 22:02:10 +0800131
Tony Barbour6a3faf02015-07-23 10:36:18 -0600132 PFN_vkGetPhysicalDeviceSurfaceSupportWSI m_fpGetPhysicalDeviceSurfaceSupportWSI;
Ian Elliott8b139792015-08-07 11:51:12 -0600133 PFN_vkGetSurfacePropertiesWSI m_fpGetSurfacePropertiesWSI;
134 PFN_vkGetSurfaceFormatsWSI m_fpGetSurfaceFormatsWSI;
135 PFN_vkGetSurfacePresentModesWSI m_fpGetSurfacePresentModesWSI;
Jon Ashburn07daee72015-05-21 18:13:33 -0600136 PFN_vkCreateSwapChainWSI m_fpCreateSwapChainWSI;
137 PFN_vkDestroySwapChainWSI m_fpDestroySwapChainWSI;
Ian Elliott8b139792015-08-07 11:51:12 -0600138 PFN_vkGetSwapChainImagesWSI m_fpGetSwapChainImagesWSI;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600139 PFN_vkAcquireNextImageWSI m_fpAcquireNextImageWSI;
Jon Ashburn07daee72015-05-21 18:13:33 -0600140 PFN_vkQueuePresentWSI m_fpQueuePresentWSI;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600141 VkSurfaceDescriptionWindowWSI m_surface_description;
Ian Elliott8b139792015-08-07 11:51:12 -0600142 uint32_t m_swapChainImageCount;
Chia-I Wuf8693382015-04-16 22:02:10 +0800143 VkSwapChainWSI m_swap_chain;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600144 SwapChainBuffers *m_buffers;
145 VkFormat m_format;
Ian Elliott8b139792015-08-07 11:51:12 -0600146 VkColorSpaceWSI m_color_space;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600147
148 uint32_t m_current_buffer;
Chia-I Wuf8693382015-04-16 22:02:10 +0800149
150 bool m_quit;
151 bool m_pause;
152
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600153 int m_width;
154 int m_height;
Chia-I Wuf8693382015-04-16 22:02:10 +0800155
156 std::list<VkTestImageRecord>::iterator m_display_image;
157
158 void Display();
159 void HandleEvent(xcb_generic_event_t *event);
160};
161
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600162#ifndef _WIN32
163
164#include <errno.h>
165
166int fopen_s(
167 FILE** pFile,
168 const char* filename,
169 const char* mode
170)
171{
172 if (!pFile || !filename || !mode) {
173 return EINVAL;
174 }
175
176 FILE* f = fopen(filename, mode);
177 if (! f) {
178 if (errno != 0) {
179 return errno;
180 } else {
181 return ENOENT;
182 }
183 }
184 *pFile = f;
185
186 return 0;
187}
188
189#endif
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600190
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600191
192
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600193// Set up environment for GLSL compiler
194// Must be done once per process
195void TestEnvironment::SetUp()
196{
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600197 // Initialize GLSL to SPV compiler utility
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600198 glslang::InitializeProcess();
Chia-I Wub76e0fa2014-12-28 14:27:28 +0800199
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600200 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600201}
202
203void TestEnvironment::TearDown()
204{
205 glslang::FinalizeProcess();
206}
207
Tony Barbour6918cd52015-04-09 12:58:51 -0600208VkTestFramework::VkTestFramework() :
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600209 m_compile_options( 0 ),
210 m_num_shader_strings( 0 )
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600211{
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600212
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600213}
214
Tony Barbour6918cd52015-04-09 12:58:51 -0600215VkTestFramework::~VkTestFramework()
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600216{
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600217
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600218}
219
220// Define all the static elements
Cody Northropa3673cf2015-06-09 13:00:45 -0600221bool VkTestFramework::m_show_images = false;
222bool VkTestFramework::m_save_images = false;
223bool VkTestFramework::m_compare_images = false;
224bool VkTestFramework::m_use_glsl = false;
225bool VkTestFramework::m_canonicalize_spv = false;
226bool VkTestFramework::m_strip_spv = false;
Cody Northrop5a95b472015-06-03 13:01:54 -0600227bool VkTestFramework::m_do_everything_spv = false;
Tony Barbour6918cd52015-04-09 12:58:51 -0600228int VkTestFramework::m_width = 0;
229int VkTestFramework::m_height = 0;
230std::list<VkTestImageRecord> VkTestFramework::m_images;
231std::list<VkTestImageRecord>::iterator VkTestFramework::m_display_image;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600232int m_display_image_idx = 0;
233
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600234bool VkTestFramework::optionMatch(const char* option, char* optionLine)
235{
236 if (strncmp(option, optionLine, strlen(option)) == 0)
237 return true;
238 else
239 return false;
240}
241
Tony Barbour6918cd52015-04-09 12:58:51 -0600242void VkTestFramework::InitArgs(int *argc, char *argv[])
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600243{
244 int i, n;
245
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600246 for (i=1, n=1; i< *argc; i++) {
247 if (optionMatch("--show-images", argv[i]))
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600248 m_show_images = true;
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600249 else if (optionMatch("--save-images", argv[i]))
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600250 m_save_images = true;
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600251 else if (optionMatch("--no-SPV", argv[i]))
252 m_use_glsl = true;
253 else if (optionMatch("--strip-SPV", argv[i]))
254 m_strip_spv = true;
255 else if (optionMatch("--canonicalize-SPV", argv[i]))
256 m_canonicalize_spv = true;
257 else if (optionMatch("--compare-images", argv[i]))
Tony Barbour247bf372014-10-30 14:29:04 -0600258 m_compare_images = true;
Tony Barbour247bf372014-10-30 14:29:04 -0600259
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600260 else if (optionMatch("--help", argv[i]) ||
261 optionMatch("-h", argv[i])) {
Courtney Goeltzenleuchter31144b72014-12-02 13:13:10 -0700262 printf("\nOther options:\n");
263 printf("\t--show-images\n"
264 "\t\tDisplay test images in viewer after tests complete.\n");
265 printf("\t--save-images\n"
266 "\t\tSave tests images as ppm files in current working directory.\n"
267 "\t\tUsed to generate golden images for compare-images.\n");
268 printf("\t--compare-images\n"
269 "\t\tCompare test images to 'golden' image in golden folder.\n"
Tony Barboura98d3932014-12-11 09:52:49 -0700270 "\t\tAlso saves the generated test image in current working\n"
271 "\t\t\tdirectory but only if the image is different from the golden\n"
272 "\t\tSetting RENDERTEST_GOLDEN_DIR environment variable can specify\n"
273 "\t\t\tdifferent directory for golden images\n"
Courtney Goeltzenleuchter31144b72014-12-02 13:13:10 -0700274 "\t\tSignal test failure if different.\n");
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600275 printf("\t--no-SPV\n"
276 "\t\tUse built-in GLSL compiler rather than SPV code path.\n");
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600277 printf("\t--strip-SPV\n"
Cody Northropa9bad9c2015-07-13 12:48:41 -0600278 "\t\tStrip SPIR-V debug information (line numbers, names, etc).\n");
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600279 printf("\t--canonicalize-SPV\n"
Cody Northropa9bad9c2015-07-13 12:48:41 -0600280 "\t\tRemap SPIR-V ids before submission to aid compression.\n");
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600281 exit(0);
282 } else {
283 printf("\nUnrecognized option: %s\n", argv[i]);
284 printf("\nUse --help or -h for option list.\n");
Tony Barbour4ab45422014-12-10 17:00:20 -0700285 exit(0);
Courtney Goeltzenleuchter31144b72014-12-02 13:13:10 -0700286 }
287
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600288 /*
289 * Since the above "consume" inputs, update argv
290 * so that it contains the trimmed list of args for glutInit
291 */
292
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600293 argv[n] = argv[i];
294 n++;
295 }
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600296}
297
Tony Barbour6918cd52015-04-09 12:58:51 -0600298void VkTestFramework::WritePPM( const char *basename, VkImageObj *image )
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600299{
300 string filename;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600301 VkResult err;
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600302 uint32_t x, y;
Tony Barbour6918cd52015-04-09 12:58:51 -0600303 VkImageObj displayImage(image->device());
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600304 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbour84d448c2015-04-02 14:02:33 -0600305
Tony Barboure65788f2015-07-21 17:01:42 -0600306 displayImage.init(image->extent().width, image->extent().height, image->format(), VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, VK_IMAGE_TILING_LINEAR, reqs);
Tony Barbour84d448c2015-04-02 14:02:33 -0600307 displayImage.CopyImage(*image);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600308
309 filename.append(basename);
310 filename.append(".ppm");
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600311
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600312 const VkImageSubresource sr = {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313 VK_IMAGE_ASPECT_COLOR, 0, 0
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600314 };
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600315 VkSubresourceLayout sr_layout;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600316
Tony Barbour59a47322015-06-24 16:06:58 -0600317 err = vkGetImageSubresourceLayout(image->device()->device(), displayImage.image(), &sr, &sr_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600318 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600319
Tony Barbour84d448c2015-04-02 14:02:33 -0600320 char *ptr;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800321 ptr = (char *) displayImage.MapMemory();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600322 ptr += sr_layout.offset;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600323 ofstream file (filename.c_str(), ios::binary);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600324 ASSERT_TRUE(file.is_open()) << "Unable to open file: " << filename;
325
326 file << "P6\n";
Tony Barbour84d448c2015-04-02 14:02:33 -0600327 file << displayImage.width() << "\n";
328 file << displayImage.height() << "\n";
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600329 file << 255 << "\n";
330
Tony Barbour84d448c2015-04-02 14:02:33 -0600331 for (y = 0; y < displayImage.height(); y++) {
Tony Barboura53a6942015-02-25 11:25:11 -0700332 const int *row = (const int *) ptr;
333 int swapped;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600334
Tony Barbourd1c35722015-04-16 15:59:00 -0600335 if (displayImage.format() == VK_FORMAT_B8G8R8A8_UNORM)
Tony Barboura53a6942015-02-25 11:25:11 -0700336 {
Tony Barbour84d448c2015-04-02 14:02:33 -0600337 for (x = 0; x < displayImage.width(); x++) {
Tony Barboura53a6942015-02-25 11:25:11 -0700338 swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16;
339 file.write((char *) &swapped, 3);
340 row++;
341 }
342 }
Tony Barbourd1c35722015-04-16 15:59:00 -0600343 else if (displayImage.format() == VK_FORMAT_R8G8B8A8_UNORM)
Tony Barboura53a6942015-02-25 11:25:11 -0700344 {
Tony Barbour84d448c2015-04-02 14:02:33 -0600345 for (x = 0; x < displayImage.width(); x++) {
Tony Barboura53a6942015-02-25 11:25:11 -0700346 file.write((char *) row, 3);
347 row++;
348 }
349 }
350 else {
351 printf("Unrecognized image format - will not write image files");
352 break;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600353 }
354
355 ptr += sr_layout.rowPitch;
356 }
357
358 file.close();
Chia-I Wu681d7a02015-07-03 13:44:34 +0800359 displayImage.UnmapMemory();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600360}
361
Tony Barbour6918cd52015-04-09 12:58:51 -0600362void VkTestFramework::Compare(const char *basename, VkImageObj *image )
Tony Barbour247bf372014-10-30 14:29:04 -0600363{
364
365 MagickWand *magick_wand_1;
366 MagickWand *magick_wand_2;
367 MagickWand *compare_wand;
368 MagickBooleanType status;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600369 char testimage[256],golden[MAX_PATH+256],golddir[MAX_PATH] = "./golden";
Tony Barbour247bf372014-10-30 14:29:04 -0600370 double differenz;
371
Tony Barbour4ab45422014-12-10 17:00:20 -0700372 if (getenv("RENDERTEST_GOLDEN_DIR"))
373 {
374 strcpy(golddir,getenv("RENDERTEST_GOLDEN_DIR"));
375 }
376
Tony Barbour247bf372014-10-30 14:29:04 -0600377 MagickWandGenesis();
378 magick_wand_1=NewMagickWand();
379 sprintf(testimage,"%s.ppm",basename);
380 status=MagickReadImage(magick_wand_1,testimage);
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600381 ASSERT_EQ(status, MagickTrue) << "Unable to open file: " << testimage;
Tony Barbour247bf372014-10-30 14:29:04 -0600382
383
384 MagickWandGenesis();
385 magick_wand_2=NewMagickWand();
Tony Barbour4ab45422014-12-10 17:00:20 -0700386 sprintf(golden,"%s/%s.ppm",golddir,basename);
Tony Barbour247bf372014-10-30 14:29:04 -0600387 status=MagickReadImage(magick_wand_2,golden);
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600388 ASSERT_EQ(status, MagickTrue) << "Unable to open file: " << golden;
Tony Barbour247bf372014-10-30 14:29:04 -0600389
Tony Barbour247bf372014-10-30 14:29:04 -0600390 compare_wand=MagickCompareImages(magick_wand_1,magick_wand_2, MeanAbsoluteErrorMetric, &differenz);
391 if (differenz != 0.0)
392 {
393 char difference[256];
394
395 sprintf(difference,"%s-diff.ppm",basename);
396 status = MagickWriteImage(compare_wand, difference);
397 ASSERT_TRUE(differenz == 0.0) << "Image comparison failed - diff file written";
398 }
399 DestroyMagickWand(compare_wand);
400
401 DestroyMagickWand(magick_wand_1);
402 DestroyMagickWand(magick_wand_2);
403 MagickWandTerminus();
Courtney Goeltzenleuchterfcda72d2014-12-05 15:41:02 -0700404
405 if (differenz == 0.0)
406 {
407 /*
408 * If test image and golden image match, we do not need to
409 * keep around the test image.
410 */
411 remove(testimage);
412 }
Tony Barbour247bf372014-10-30 14:29:04 -0600413}
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600414
Tony Barbour6918cd52015-04-09 12:58:51 -0600415void VkTestFramework::Show(const char *comment, VkImageObj *image)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600416{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600417 VkResult err;
Courtney Goeltzenleuchterfcf43ab2015-04-29 10:53:31 -0600418 VkSubresourceLayout sr_layout;
419 char *ptr;
420 VkTestImageRecord record;
Courtney Goeltzenleuchterfcf43ab2015-04-29 10:53:31 -0600421 VkImageObj displayImage(image->device());
422 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
423
Cody Northropc9a69912015-06-18 17:05:15 -0600424 displayImage.init(image->extent().width, image->extent().height, image->format(), VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, VK_IMAGE_TILING_LINEAR, reqs);
425
Courtney Goeltzenleuchterfcf43ab2015-04-29 10:53:31 -0600426 displayImage.CopyImage(*image);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600427
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600428 const VkImageSubresource sr = {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600429 VK_IMAGE_ASPECT_COLOR, 0, 0
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600430 };
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600431
Tony Barbour59a47322015-06-24 16:06:58 -0600432 err = vkGetImageSubresourceLayout(displayImage.device()->device(), displayImage.image(), &sr, &sr_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600433 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600434
Chia-I Wu681d7a02015-07-03 13:44:34 +0800435 ptr = (char *) displayImage.MapMemory();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600436 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600437
438 ptr += sr_layout.offset;
439
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600440 record.m_title.append(comment);
Courtney Goeltzenleuchterfcf43ab2015-04-29 10:53:31 -0600441 record.m_width = displayImage.width();
442 record.m_height = displayImage.height();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600443 // TODO: Need to make this more robust to handle different image formats
Tony-LunarG399dfca2015-05-19 14:08:26 -0600444 record.m_data_size = displayImage.width() * displayImage.height() * 4;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600445 record.m_data = malloc(record.m_data_size);
446 memcpy(record.m_data, ptr, record.m_data_size);
447 m_images.push_back(record);
448 m_display_image = --m_images.end();
449
Chia-I Wu681d7a02015-07-03 13:44:34 +0800450 displayImage.UnmapMemory();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600451}
452
Tony Barbour6918cd52015-04-09 12:58:51 -0600453void VkTestFramework::RecordImages(vector<VkImageObj *> images)
Tony Barbour247bf372014-10-30 14:29:04 -0600454{
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600455 for (int32_t i = 0; i < images.size(); i++) {
456 RecordImage(images[i]);
Tony Barbour247bf372014-10-30 14:29:04 -0600457 }
458}
459
Tony Barbour6918cd52015-04-09 12:58:51 -0600460void VkTestFramework::RecordImage(VkImageObj * image)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600461{
462 const ::testing::TestInfo* const test_info =
463 ::testing::UnitTest::GetInstance()->current_test_info();
Tony Barbour247bf372014-10-30 14:29:04 -0600464 ostringstream filestream;
465 string filename;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600466
Tony Barbour247bf372014-10-30 14:29:04 -0600467 m_width = 40;
468
469 if (strcmp(test_info->name(), m_testName.c_str())) {
470 filestream << test_info->name();
471 m_testName.assign(test_info->name());
Tony Barboura0e2ee82014-11-18 17:02:36 -0700472 m_frameNum = 2;
473 filename = filestream.str();
Tony Barbour247bf372014-10-30 14:29:04 -0600474 }
475 else {
476 filestream << test_info->name() << "-" << m_frameNum;
477 m_frameNum++;
Tony Barboura0e2ee82014-11-18 17:02:36 -0700478 filename = filestream.str();
Tony Barbour247bf372014-10-30 14:29:04 -0600479 }
480
Tony Barbour247bf372014-10-30 14:29:04 -0600481 // ToDo - scrub string for bad characters
482
483 if (m_save_images || m_compare_images) {
484 WritePPM(filename.c_str(), image);
485 if (m_compare_images) {
486 Compare(filename.c_str(), image);
487 }
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600488 }
489
490 if (m_show_images) {
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600491 Show(test_info->name(), image);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600492 }
493}
494
Chia-I Wuf8693382015-04-16 22:02:10 +0800495TestFrameworkVkPresent::TestFrameworkVkPresent(vk_testing::Device &device) :
496 m_device(device),
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700497 m_queue(*m_device.graphics_queues()[0]),
Dana Jansens233a0ea2015-07-30 13:04:16 -0700498 m_cmdpool(m_device, vk_testing::CmdPool::create_info(m_device.graphics_queue_node_index_)),
499 m_cmdbuf(m_device, vk_testing::CmdBuffer::create_info(m_cmdpool.handle()))
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600500{
Tony Barbour96db8822015-02-25 12:28:39 -0700501 m_quit = false;
502 m_pause = false;
503 m_width = 0;
504 m_height = 0;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600505}
506
Tony Barbour6918cd52015-04-09 12:58:51 -0600507void TestFrameworkVkPresent::Display()
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600508{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600509 VkResult U_ASSERT_ONLY err;
Tony-LunarG399dfca2015-05-19 14:08:26 -0600510 vk_testing::Buffer buf;
511 void *dest_ptr;
512
Tony Barbour6a3faf02015-07-23 10:36:18 -0600513 VkSemaphore presentCompleteSemaphore;
514 VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {};
515 presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
516 presentCompleteSemaphoreCreateInfo.pNext = NULL;
517 presentCompleteSemaphoreCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
518
519
520 err = vkCreateSemaphore(m_device.handle(),
521 &presentCompleteSemaphoreCreateInfo,
522 &presentCompleteSemaphore);
523 assert(!err);
524
525 // Get the index of the next available swapchain image:
526 err = m_fpAcquireNextImageWSI(m_device.handle(), m_swap_chain,
527 UINT64_MAX,
528 presentCompleteSemaphore,
529 &m_current_buffer);
530 // TODO: Deal with the VK_SUBOPTIMAL_WSI and VK_ERROR_OUT_OF_DATE_WSI
531 // return codes
532 assert(!err);
533
534 // Wait for the present complete semaphore to be signaled to ensure
535 // that the image won't be rendered to until the presentation
536 // engine has fully released ownership to the application, and it is
537 // okay to render to the image.
538 vkQueueWaitSemaphore(m_queue.handle(), presentCompleteSemaphore);
Tony-LunarG399dfca2015-05-19 14:08:26 -0600539
540 VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -0600541 buf.init_as_src(m_device, (VkDeviceSize)m_display_image->m_data_size, flags);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800542 dest_ptr = buf.memory().map();
Tony-LunarG399dfca2015-05-19 14:08:26 -0600543 memcpy(dest_ptr, m_display_image->m_data, m_display_image->m_data_size);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800544 buf.memory().unmap();
Tony-LunarG399dfca2015-05-19 14:08:26 -0600545
546 m_cmdbuf.begin();
547
548 VkBufferImageCopy region = {};
549 region.imageExtent.height = m_display_image->m_height;
550 region.imageExtent.width = m_display_image->m_width;
551 region.imageExtent.depth = 1;
552
Chia-I Wube2b9172015-07-03 11:49:42 +0800553 vkCmdCopyBufferToImage(m_cmdbuf.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800554 buf.handle(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600555 m_buffers[m_current_buffer].image, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL,
Tony-LunarG399dfca2015-05-19 14:08:26 -0600556 1, &region);
557 m_cmdbuf.end();
558
559 VkCmdBuffer cmdBufs[1];
Chia-I Wube2b9172015-07-03 11:49:42 +0800560 cmdBufs[0] = m_cmdbuf.handle();
Tony-LunarG399dfca2015-05-19 14:08:26 -0600561
Tony Barbour67e99152015-07-10 14:10:27 -0600562 VkFence nullFence = { VK_NULL_HANDLE };
563 vkQueueSubmit(m_queue.handle(), 1, cmdBufs, nullFence);
Tony-LunarG399dfca2015-05-19 14:08:26 -0600564 m_queue.wait();
Tony Barbour96db8822015-02-25 12:28:39 -0700565
Chia-I Wuf8693382015-04-16 22:02:10 +0800566 VkPresentInfoWSI present = {};
Ian Elliott8b139792015-08-07 11:51:12 -0600567 present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_WSI;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600568 present.pNext = NULL;
569 present.swapChainCount = 1;
570 present.swapChains = & m_swap_chain;
571 present.imageIndices = &m_current_buffer;
Tony Barbour96db8822015-02-25 12:28:39 -0700572
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600573#ifndef _WIN32
Chia-I Wuf8693382015-04-16 22:02:10 +0800574 xcb_change_property (m_connection,
Tony Barbour96db8822015-02-25 12:28:39 -0700575 XCB_PROP_MODE_REPLACE,
576 m_window,
577 XCB_ATOM_WM_NAME,
578 XCB_ATOM_STRING,
579 8,
580 m_display_image->m_title.size(),
581 m_display_image->m_title.c_str());
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600582#endif
Jon Ashburn07daee72015-05-21 18:13:33 -0600583
Chia-I Wudf12ffd2015-07-03 10:53:18 +0800584 err = m_fpQueuePresentWSI(m_queue.handle(), &present);
Tony Barbour96db8822015-02-25 12:28:39 -0700585 assert(!err);
586
587 m_queue.wait();
Tony-LunarG399dfca2015-05-19 14:08:26 -0600588 m_current_buffer = (m_current_buffer + 1) % 2;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600589}
590
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600591#ifdef _WIN32
Tony-LunarG399dfca2015-05-19 14:08:26 -0600592# define PREVIOUSLY_DOWN 1<<29
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600593// MS-Windows event handling function:
594LRESULT CALLBACK TestFrameworkVkPresent::WndProc(HWND hWnd,
595 UINT uMsg,
596 WPARAM wParam,
597 LPARAM lParam)
598{
599
600 switch(uMsg)
601 {
602 case WM_CLOSE:
603 PostQuitMessage(0);
604 break;
605
606 case WM_PAINT:
607 {
608 TestFrameworkVkPresent* me = reinterpret_cast<TestFrameworkVkPresent*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
609 if (me) {
Tony-LunarG399dfca2015-05-19 14:08:26 -0600610 SetWindowText(hWnd, me->m_display_image->m_title.c_str());
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600611 me->Display();
612 }
613 }
Tony-LunarG399dfca2015-05-19 14:08:26 -0600614 break;
615
616 case WM_KEYDOWN:
617 {
618 if (lParam & (PREVIOUSLY_DOWN)){
619 break;
620 }
621 // To be able to be a CALLBACK, WndProc had to be static, so it doesn't get a this pointer. When we created
622 // the window, we put the this pointer into the window's user data so we could get it back now
623 TestFrameworkVkPresent* me = reinterpret_cast<TestFrameworkVkPresent*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
624 switch (wParam)
625 {
626 case VK_ESCAPE: me->m_quit = true;
627 break;
628
629 case VK_LEFT: // left arrow key
630 if (me->m_display_image == me->m_images.begin()) {
631 me->m_display_image = --me->m_images.end();
632 }
633 else {
634 --me->m_display_image;
635 }
636 break;
637
638 case VK_RIGHT: // right arrow key
639 ++me->m_display_image;
640 if (me->m_display_image == me->m_images.end()) {
641 me->m_display_image = me->m_images.begin();
642 }
643 break;
644
645 default:
646 break;
647 }
648 SetWindowText(hWnd, me->m_display_image->m_title.c_str());
649 me->Display();
650 }
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600651 }
652 return (DefWindowProc(hWnd, uMsg, wParam, lParam));
653}
654
655void TestFrameworkVkPresent::Run()
656{
657 MSG msg; // message
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600658
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600659 /* main message loop*/
Tony-LunarG399dfca2015-05-19 14:08:26 -0600660 while(! m_quit) {
661 GetMessage(&msg, m_window, 0, 0);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600662 if (msg.message == WM_QUIT) {
Tony-LunarG399dfca2015-05-19 14:08:26 -0600663 m_quit = true; //if found, quit app
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600664 } else {
665 /* Translate and dispatch to event queue*/
666 TranslateMessage(&msg);
667 DispatchMessage(&msg);
668 }
669 }
670}
671
672#else
Tony Barbour6918cd52015-04-09 12:58:51 -0600673void TestFrameworkVkPresent::HandleEvent(xcb_generic_event_t *event)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600674{
Tony Barbour0dd968a2015-04-02 15:48:24 -0600675 uint8_t event_code = event->response_type & 0x7f;
Tony Barbour96db8822015-02-25 12:28:39 -0700676 switch (event_code) {
677 case XCB_EXPOSE:
678 Display(); // TODO: handle resize
679 break;
680 case XCB_CLIENT_MESSAGE:
681 if((*(xcb_client_message_event_t*)event).data.data32[0] ==
682 (m_atom_wm_delete_window)->atom) {
683 m_quit = true;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600684 }
685 break;
Tony Barbour96db8822015-02-25 12:28:39 -0700686 case XCB_KEY_RELEASE:
687 {
688 const xcb_key_release_event_t *key =
689 (const xcb_key_release_event_t *) event;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600690
Tony Barbour96db8822015-02-25 12:28:39 -0700691 switch (key->detail) {
692 case 0x9: // Escape
693 m_quit = true;
694 break;
695 case 0x71: // left arrow key
696 if (m_display_image == m_images.begin()) {
697 m_display_image = --m_images.end();
698 } else {
699 --m_display_image;
700 }
701 break;
702 case 0x72: // right arrow key
703 ++m_display_image;
704 if (m_display_image == m_images.end()) {
705 m_display_image = m_images.begin();
706 }
707 break;
708 case 0x41:
709 m_pause = !m_pause;
710 break;
711 }
712 Display();
713 }
714 break;
715 default:
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600716 break;
717 }
Tony Barbour96db8822015-02-25 12:28:39 -0700718}
719
Tony Barbour6918cd52015-04-09 12:58:51 -0600720void TestFrameworkVkPresent::Run()
Tony Barbour96db8822015-02-25 12:28:39 -0700721{
Chia-I Wuf8693382015-04-16 22:02:10 +0800722 xcb_flush(m_connection);
Tony Barbour96db8822015-02-25 12:28:39 -0700723
724 while (! m_quit) {
725 xcb_generic_event_t *event;
726
727 if (m_pause) {
Chia-I Wuf8693382015-04-16 22:02:10 +0800728 event = xcb_wait_for_event(m_connection);
Tony Barbour96db8822015-02-25 12:28:39 -0700729 } else {
Chia-I Wuf8693382015-04-16 22:02:10 +0800730 event = xcb_poll_for_event(m_connection);
Tony Barbour96db8822015-02-25 12:28:39 -0700731 }
732 if (event) {
733 HandleEvent(event);
734 free(event);
735 }
736 }
737}
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600738#endif // _WIN32
Tony Barbour96db8822015-02-25 12:28:39 -0700739
Chia-I Wuf8693382015-04-16 22:02:10 +0800740void TestFrameworkVkPresent::CreateSwapChain()
Tony Barbour96db8822015-02-25 12:28:39 -0700741{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600742 VkResult U_ASSERT_ONLY err;
Tony Barbour96db8822015-02-25 12:28:39 -0700743
Tony-LunarG399dfca2015-05-19 14:08:26 -0600744 m_display_image = m_images.begin();
745 m_current_buffer = 0;
746
Tony Barbour6a3faf02015-07-23 10:36:18 -0600747 // Construct the WSI surface description:
748 m_surface_description.sType = VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI;
749 m_surface_description.pNext = NULL;
Ian Elliott1a3845b2015-07-06 14:33:04 -0600750#ifdef _WIN32
Tony Barbour6a3faf02015-07-23 10:36:18 -0600751 m_surface_description.platform = VK_PLATFORM_WIN32_WSI;
752 m_surface_description.pPlatformHandle = m_connection;
753 m_surface_description.pPlatformWindow = m_window;
Ian Elliott1a3845b2015-07-06 14:33:04 -0600754#else // _WIN32
Tony Barbour6a3faf02015-07-23 10:36:18 -0600755 m_platform_handle_xcb.connection = m_connection;
756 m_platform_handle_xcb.root = m_screen->root;
757 m_surface_description.platform = VK_PLATFORM_XCB_WSI;
758 m_surface_description.pPlatformHandle = &m_platform_handle_xcb;
759 m_surface_description.pPlatformWindow = &m_window;
Ian Elliott1a3845b2015-07-06 14:33:04 -0600760#endif // _WIN32
Tony Barbour6a3faf02015-07-23 10:36:18 -0600761
762 // Iterate over each queue to learn whether it supports presenting to WSI:
763 VkBool32 supportsPresent;
764 m_present_queue_node_index = UINT32_MAX;
765 std::vector<vk_testing::Queue *> queues = m_device.graphics_queues();
766 for (int i=0; i < queues.size(); i++)
767 {
768 int family_index = queues[i]->get_family_index();
769 m_fpGetPhysicalDeviceSurfaceSupportWSI(m_device.phy().handle(),
770 family_index,
771 (VkSurfaceDescriptionWSI *) &m_surface_description,
772 &supportsPresent);
773 if (supportsPresent) {
774 m_present_queue_node_index = family_index;
775 }
776 }
777
778 assert(m_present_queue_node_index != UINT32_MAX);
779
780
781 // Get the list of VkFormat's that are supported:
Ian Elliott8b139792015-08-07 11:51:12 -0600782 uint32_t formatCount;
783 err = m_fpGetSurfaceFormatsWSI(m_device.handle(),
784 (VkSurfaceDescriptionWSI *) &m_surface_description,
785 &formatCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600786 assert(!err);
Ian Elliott8b139792015-08-07 11:51:12 -0600787 VkSurfaceFormatWSI *surfFormats =
788 (VkSurfaceFormatWSI *)malloc(formatCount * sizeof(VkSurfaceFormatWSI));
789 err = m_fpGetSurfaceFormatsWSI(m_device.handle(),
790 (VkSurfaceDescriptionWSI *) &m_surface_description,
791 &formatCount, surfFormats);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600792 assert(!err);
793 // If the format list includes just one entry of VK_FORMAT_UNDEFINED,
794 // the surface has no preferred format. Otherwise, at least one
795 // supported format will be returned.
Tony Barbour6a3faf02015-07-23 10:36:18 -0600796 if (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED)
797 {
798 m_format = VK_FORMAT_B8G8R8A8_UNORM;
799 }
800 else
801 {
802 assert(formatCount >= 1);
803 m_format = surfFormats[0].format;
804 }
Ian Elliott8b139792015-08-07 11:51:12 -0600805 m_color_space = surfFormats[0].colorSpace;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600806
807 // Check the surface proprties and formats
Ian Elliott8b139792015-08-07 11:51:12 -0600808 VkSurfacePropertiesWSI surfProperties;
809 err = m_fpGetSurfacePropertiesWSI(m_device.handle(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600810 (const VkSurfaceDescriptionWSI *)&m_surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600811 &surfProperties);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600812 assert(!err);
813
Ian Elliott8b139792015-08-07 11:51:12 -0600814 uint32_t presentModeCount;
815 err = m_fpGetSurfacePresentModesWSI(m_device.handle(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600816 (const VkSurfaceDescriptionWSI *)&m_surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600817 &presentModeCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600818 assert(!err);
Ian Elliott8b139792015-08-07 11:51:12 -0600819 VkPresentModeWSI *presentModes =
820 (VkPresentModeWSI *)malloc(presentModeCount * sizeof(VkPresentModeWSI));
821 assert(presentModes);
822 err = m_fpGetSurfacePresentModesWSI(m_device.handle(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600823 (const VkSurfaceDescriptionWSI *)&m_surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600824 &presentModeCount, presentModes);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600825 assert(!err);
826
827 VkExtent2D swapChainExtent;
828 // width and height are either both -1, or both not -1.
Ian Elliott8b139792015-08-07 11:51:12 -0600829 if (surfProperties.currentExtent.width == -1)
Tony Barbour6a3faf02015-07-23 10:36:18 -0600830 {
831 // If the surface size is undefined, the size is set to
832 // the size of the images requested.
833 swapChainExtent.width = m_width;
834 swapChainExtent.height = m_height;
835 }
836 else
837 {
838 // If the surface size is defined, the swap chain size must match
Ian Elliott8b139792015-08-07 11:51:12 -0600839 swapChainExtent = surfProperties.currentExtent;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600840 }
841
842 // If mailbox mode is available, use it, as is the lowest-latency non-
843 // tearing mode. If not, fall back to IMMEDIATE which should always be
844 // available.
845 VkPresentModeWSI swapChainPresentMode = VK_PRESENT_MODE_IMMEDIATE_WSI;
Ian Elliott8b139792015-08-07 11:51:12 -0600846#ifdef OLD_CODE
Tony Barbour6a3faf02015-07-23 10:36:18 -0600847 size_t presentModeCount = presentModesSize / sizeof(VkSurfacePresentModePropertiesWSI);
Ian Elliott8b139792015-08-07 11:51:12 -0600848#else // OLD_CODE
849#endif // OLD_CODE
Tony Barbour6a3faf02015-07-23 10:36:18 -0600850 for (size_t i = 0; i < presentModeCount; i++) {
Ian Elliott8b139792015-08-07 11:51:12 -0600851 if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_WSI) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600852 swapChainPresentMode = VK_PRESENT_MODE_MAILBOX_WSI;
853 break;
854 }
855 }
856
857 // Determine the number of VkImage's to use in the swap chain (we desire to
858 // own only 1 image at a time, besides the images being displayed and
859 // queued for display):
Ian Elliott8b139792015-08-07 11:51:12 -0600860 uint32_t desiredNumberOfSwapChainImages = surfProperties.minImageCount + 1;
861 if ((surfProperties.maxImageCount > 0) &&
862 (desiredNumberOfSwapChainImages > surfProperties.maxImageCount))
Tony Barbour6a3faf02015-07-23 10:36:18 -0600863 {
864 // Application must settle for fewer images than desired:
Ian Elliott8b139792015-08-07 11:51:12 -0600865 desiredNumberOfSwapChainImages = surfProperties.maxImageCount;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600866 }
867
868 VkSurfaceTransformWSI preTransform;
Ian Elliott8b139792015-08-07 11:51:12 -0600869 if (surfProperties.supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_WSI) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600870 preTransform = VK_SURFACE_TRANSFORM_NONE_WSI;
871 } else {
Ian Elliott8b139792015-08-07 11:51:12 -0600872 preTransform = surfProperties.currentTransform;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600873 }
Ian Elliott1a3845b2015-07-06 14:33:04 -0600874
Chia-I Wuf8693382015-04-16 22:02:10 +0800875 VkSwapChainCreateInfoWSI swap_chain = {};
876 swap_chain.sType = VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI;
Ian Elliott1a3845b2015-07-06 14:33:04 -0600877 swap_chain.pNext = NULL;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600878 swap_chain.pSurfaceDescription = (const VkSurfaceDescriptionWSI *)&m_surface_description;
879 swap_chain.minImageCount = desiredNumberOfSwapChainImages;
880 swap_chain.imageFormat = m_format;
Ian Elliott8b139792015-08-07 11:51:12 -0600881 swap_chain.imageColorSpace = m_color_space;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600882 swap_chain.imageExtent.width = swapChainExtent.width;
883 swap_chain.imageExtent.height = swapChainExtent.height;
Cody Northropdf8f42a2015-08-05 15:38:39 -0600884 // Workaround: Some implementations need color attachment for blit targets
885 swap_chain.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT |
886 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600887 swap_chain.preTransform = preTransform;
Chia-I Wuf8693382015-04-16 22:02:10 +0800888 swap_chain.imageArraySize = 1;
Ian Elliott8b139792015-08-07 11:51:12 -0600889 swap_chain.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
890 swap_chain.queueFamilyCount = 0;
891 swap_chain.pQueueFamilyIndices = NULL;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600892 swap_chain.presentMode = swapChainPresentMode;
893 swap_chain.oldSwapChain.handle = 0;
894 swap_chain.clipped = true;
895
896 uint32_t i;
Chia-I Wuf8693382015-04-16 22:02:10 +0800897
Chia-I Wuf368b602015-07-03 10:41:20 +0800898 err = m_fpCreateSwapChainWSI(m_device.handle(), &swap_chain, &m_swap_chain);
Chia-I Wuf8693382015-04-16 22:02:10 +0800899 assert(!err);
900
Ian Elliott8b139792015-08-07 11:51:12 -0600901 err = m_fpGetSwapChainImagesWSI(m_device.handle(), m_swap_chain,
902 &m_swapChainImageCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600903 assert(!err);
904
Ian Elliott8b139792015-08-07 11:51:12 -0600905 VkImage* swapChainImages = (VkImage*)malloc(m_swapChainImageCount * sizeof(VkImage));
Tony Barbour6a3faf02015-07-23 10:36:18 -0600906 assert(swapChainImages);
Ian Elliott8b139792015-08-07 11:51:12 -0600907 err = m_fpGetSwapChainImagesWSI(m_device.handle(), m_swap_chain,
908 &m_swapChainImageCount, swapChainImages);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600909 assert(!err);
910
Tony Barbour6a3faf02015-07-23 10:36:18 -0600911 m_buffers = (SwapChainBuffers*)malloc(sizeof(SwapChainBuffers)*m_swapChainImageCount);
912 assert(m_buffers);
913
914 for (i = 0; i < m_swapChainImageCount; i++) {
915 VkAttachmentViewCreateInfo color_attachment_view = {};
916 color_attachment_view.sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO;
917 color_attachment_view.pNext = NULL;
918 color_attachment_view.format = m_format;
919 color_attachment_view.mipLevel = 0;
920 color_attachment_view.baseArraySlice = 0;
921 color_attachment_view.arraySize = 1;
922
Ian Elliott8b139792015-08-07 11:51:12 -0600923 m_buffers[i].image = swapChainImages[i];
Tony Barbour6a3faf02015-07-23 10:36:18 -0600924
925 color_attachment_view.image = m_buffers[i].image;
926 err = vkCreateAttachmentView(m_device.handle(),
927 &color_attachment_view, &m_buffers[i].view);
928 assert(!err);
929 }
Tony Barbour96db8822015-02-25 12:28:39 -0700930}
931
Jon Ashburn07daee72015-05-21 18:13:33 -0600932void TestFrameworkVkPresent::InitPresentFramework(std::list<VkTestImageRecord> &imagesIn, VkInstance inst)
Tony Barbour96db8822015-02-25 12:28:39 -0700933{
Tony Barbour6a3faf02015-07-23 10:36:18 -0600934 GET_INSTANCE_PROC_ADDR(inst, GetPhysicalDeviceSurfaceSupportWSI);
Ian Elliott8b139792015-08-07 11:51:12 -0600935 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePropertiesWSI);
936 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfaceFormatsWSI);
937 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePresentModesWSI);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600938 GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapChainWSI);
939 GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapChainWSI);
940 GET_DEVICE_PROC_ADDR(m_device.handle(), DestroySwapChainWSI);
Ian Elliott8b139792015-08-07 11:51:12 -0600941 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSwapChainImagesWSI);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600942 GET_DEVICE_PROC_ADDR(m_device.handle(), AcquireNextImageWSI);
943 GET_DEVICE_PROC_ADDR(m_device.handle(), QueuePresentWSI);
Jon Ashburn07daee72015-05-21 18:13:33 -0600944
Tony Barbour96db8822015-02-25 12:28:39 -0700945 m_images = imagesIn;
946}
947
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600948#ifdef _WIN32
949void TestFrameworkVkPresent::CreateMyWindow()
950{
951 WNDCLASSEX win_class;
952 // const ::testing::TestInfo* const test_info =
953 // ::testing::UnitTest::GetInstance()->current_test_info();
954 m_connection = GetModuleHandle(NULL);
955
956 for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin();
957 it != m_images.end(); it++) {
958 if (m_width < it->m_width)
959 m_width = it->m_width;
960 if (m_height < it->m_height)
961 m_height = it->m_height;
962 }
963 // Initialize the window class structure:
964 win_class.cbSize = sizeof(WNDCLASSEX);
965 win_class.style = CS_HREDRAW | CS_VREDRAW;
966 win_class.lpfnWndProc = (WNDPROC) &TestFrameworkVkPresent::WndProc;
967 win_class.cbClsExtra = 0;
968 win_class.cbWndExtra = 0;
969 win_class.hInstance = m_connection; // hInstance
970 win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
971 win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
972 win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
973 win_class.lpszMenuName = NULL;
974 win_class.lpszClassName = "Test";
975 win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
976 // Register window class:
977 if (!RegisterClassEx(&win_class)) {
978 // It didn't work, so try to give a useful error:
979 printf("Unexpected error trying to start the application!\n");
980 fflush(stdout);
981 exit(1);
982 }
983 // Create window with the registered class:
Cody Northrop39582252015-08-05 15:39:31 -0600984 RECT wr = { 0, 0, m_width, m_height };
985 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600986 m_window = CreateWindowEx(0,
987 "Test", // class name
988 "Test", // app name
989 WS_OVERLAPPEDWINDOW | // window style
990 WS_VISIBLE |
991 WS_SYSMENU,
992 100,100, // x/y coords
Cody Northrop39582252015-08-05 15:39:31 -0600993 wr.right - wr.left, // width
994 wr.bottom - wr.top, // height
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600995 NULL, // handle to parent
996 NULL, // handle to menu
997 m_connection, // hInstance
998 NULL); // no extra parameters
999
1000 if (!m_window) {
1001 // It didn't work, so try to give a useful error:
1002 DWORD error = GetLastError();
1003 char message[120];
1004 sprintf(message, "Cannot create a window in which to draw!\n GetLastError = %d", error);
1005 MessageBox(NULL, message, "Error", MB_OK);
1006 exit(1);
1007 }
Tony-LunarG399dfca2015-05-19 14:08:26 -06001008 // Put our this pointer into the window's user data so our WndProc can use it when it starts.
1009 SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR) this);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001010}
1011#else
Tony Barbour6918cd52015-04-09 12:58:51 -06001012void TestFrameworkVkPresent::CreateMyWindow()
Tony Barbour96db8822015-02-25 12:28:39 -07001013{
Chia-I Wuf8693382015-04-16 22:02:10 +08001014 const xcb_setup_t *setup;
1015 xcb_screen_iterator_t iter;
1016 int scr;
Tony Barbour96db8822015-02-25 12:28:39 -07001017 uint32_t value_mask, value_list[32];
1018
Chia-I Wuf8693382015-04-16 22:02:10 +08001019 m_connection = xcb_connect(NULL, &scr);
1020
1021 setup = xcb_get_setup(m_connection);
1022 iter = xcb_setup_roots_iterator(setup);
1023 while (scr-- > 0)
1024 xcb_screen_next(&iter);
1025
1026 m_screen = iter.data;
1027
1028 for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin();
1029 it != m_images.end(); it++) {
1030 if (m_width < it->m_width)
1031 m_width = it->m_width;
1032 if (m_height < it->m_height)
1033 m_height = it->m_height;
1034 }
1035
1036 m_window = xcb_generate_id(m_connection);
Tony Barbour96db8822015-02-25 12:28:39 -07001037
1038 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
Chia-I Wuf8693382015-04-16 22:02:10 +08001039 value_list[0] = m_screen->black_pixel;
Tony Barbour96db8822015-02-25 12:28:39 -07001040 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE |
1041 XCB_EVENT_MASK_EXPOSURE |
1042 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1043
Chia-I Wuf8693382015-04-16 22:02:10 +08001044 xcb_create_window(m_connection,
Tony Barbour96db8822015-02-25 12:28:39 -07001045 XCB_COPY_FROM_PARENT,
Chia-I Wuf8693382015-04-16 22:02:10 +08001046 m_window, m_screen->root,
Tony Barbour96db8822015-02-25 12:28:39 -07001047 0, 0, m_width, m_height, 0,
1048 XCB_WINDOW_CLASS_INPUT_OUTPUT,
Chia-I Wuf8693382015-04-16 22:02:10 +08001049 m_screen->root_visual,
Tony Barbour96db8822015-02-25 12:28:39 -07001050 value_mask, value_list);
1051
1052 /* Magic code that will send notification when window is destroyed */
Chia-I Wuf8693382015-04-16 22:02:10 +08001053 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 1, 12,
Tony Barbour96db8822015-02-25 12:28:39 -07001054 "WM_PROTOCOLS");
Chia-I Wuf8693382015-04-16 22:02:10 +08001055 xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(m_connection, cookie, 0);
Tony Barbour96db8822015-02-25 12:28:39 -07001056
Chia-I Wuf8693382015-04-16 22:02:10 +08001057 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(m_connection, 0, 16, "WM_DELETE_WINDOW");
1058 m_atom_wm_delete_window = xcb_intern_atom_reply(m_connection, cookie2, 0);
Tony Barbour96db8822015-02-25 12:28:39 -07001059
Chia-I Wuf8693382015-04-16 22:02:10 +08001060 xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE,
Tony Barbour96db8822015-02-25 12:28:39 -07001061 m_window, (*reply).atom, 4, 32, 1,
1062 &(*m_atom_wm_delete_window).atom);
1063 free(reply);
1064
Chia-I Wuf8693382015-04-16 22:02:10 +08001065 xcb_map_window(m_connection, m_window);
Tony Barbour96db8822015-02-25 12:28:39 -07001066}
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001067#endif
Tony Barbour96db8822015-02-25 12:28:39 -07001068
Tony Barbour6918cd52015-04-09 12:58:51 -06001069void TestFrameworkVkPresent::TearDown()
Tony Barbour96db8822015-02-25 12:28:39 -07001070{
Ian Elliott1a3845b2015-07-06 14:33:04 -06001071 m_fpDestroySwapChainWSI(m_device.handle(), m_swap_chain);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001072#ifndef _WIN32
Chia-I Wuf8693382015-04-16 22:02:10 +08001073 xcb_destroy_window(m_connection, m_window);
1074 xcb_disconnect(m_connection);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001075#endif
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001076}
1077
Tony Barbour6918cd52015-04-09 12:58:51 -06001078void VkTestFramework::Finish()
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001079{
1080 if (m_images.size() == 0) return;
1081
Chia-I Wuf8693382015-04-16 22:02:10 +08001082 vk_testing::Environment env;
1083 env.SetUp();
Tony Barbour96db8822015-02-25 12:28:39 -07001084 {
Chia-I Wuf8693382015-04-16 22:02:10 +08001085 TestFrameworkVkPresent vkPresent(env.default_device());
Tony Barbour96db8822015-02-25 12:28:39 -07001086
Jon Ashburn07daee72015-05-21 18:13:33 -06001087 vkPresent.InitPresentFramework(m_images, env.get_instance());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001088 vkPresent.CreateMyWindow();
Chia-I Wuf8693382015-04-16 22:02:10 +08001089 vkPresent.CreateSwapChain();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001090 vkPresent.Run();
1091 vkPresent.TearDown();
Tony Barbour96db8822015-02-25 12:28:39 -07001092 }
Chia-I Wuf8693382015-04-16 22:02:10 +08001093 env.TearDown();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001094}
1095
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001096//
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001097// These are the default resources for TBuiltInResources, used for both
1098// - parsing this string for the case where the user didn't supply one
1099// - dumping out a template for user construction of a config file
1100//
1101static const char* DefaultConfig =
1102 "MaxLights 32\n"
1103 "MaxClipPlanes 6\n"
1104 "MaxTextureUnits 32\n"
1105 "MaxTextureCoords 32\n"
1106 "MaxVertexAttribs 64\n"
1107 "MaxVertexUniformComponents 4096\n"
1108 "MaxVaryingFloats 64\n"
1109 "MaxVertexTextureImageUnits 32\n"
1110 "MaxCombinedTextureImageUnits 80\n"
1111 "MaxTextureImageUnits 32\n"
1112 "MaxFragmentUniformComponents 4096\n"
1113 "MaxDrawBuffers 32\n"
1114 "MaxVertexUniformVectors 128\n"
1115 "MaxVaryingVectors 8\n"
1116 "MaxFragmentUniformVectors 16\n"
1117 "MaxVertexOutputVectors 16\n"
1118 "MaxFragmentInputVectors 15\n"
1119 "MinProgramTexelOffset -8\n"
1120 "MaxProgramTexelOffset 7\n"
1121 "MaxClipDistances 8\n"
1122 "MaxComputeWorkGroupCountX 65535\n"
1123 "MaxComputeWorkGroupCountY 65535\n"
1124 "MaxComputeWorkGroupCountZ 65535\n"
1125 "MaxComputeWorkGroupSizeX 1024\n"
1126 "MaxComputeWorkGroupSizeY 1024\n"
1127 "MaxComputeWorkGroupSizeZ 64\n"
1128 "MaxComputeUniformComponents 1024\n"
1129 "MaxComputeTextureImageUnits 16\n"
1130 "MaxComputeImageUniforms 8\n"
1131 "MaxComputeAtomicCounters 8\n"
1132 "MaxComputeAtomicCounterBuffers 1\n"
1133 "MaxVaryingComponents 60\n"
1134 "MaxVertexOutputComponents 64\n"
1135 "MaxGeometryInputComponents 64\n"
1136 "MaxGeometryOutputComponents 128\n"
1137 "MaxFragmentInputComponents 128\n"
1138 "MaxImageUnits 8\n"
1139 "MaxCombinedImageUnitsAndFragmentOutputs 8\n"
1140 "MaxCombinedShaderOutputResources 8\n"
1141 "MaxImageSamples 0\n"
1142 "MaxVertexImageUniforms 0\n"
1143 "MaxTessControlImageUniforms 0\n"
1144 "MaxTessEvaluationImageUniforms 0\n"
1145 "MaxGeometryImageUniforms 0\n"
1146 "MaxFragmentImageUniforms 8\n"
1147 "MaxCombinedImageUniforms 8\n"
1148 "MaxGeometryTextureImageUnits 16\n"
1149 "MaxGeometryOutputVertices 256\n"
1150 "MaxGeometryTotalOutputComponents 1024\n"
1151 "MaxGeometryUniformComponents 1024\n"
1152 "MaxGeometryVaryingComponents 64\n"
1153 "MaxTessControlInputComponents 128\n"
1154 "MaxTessControlOutputComponents 128\n"
1155 "MaxTessControlTextureImageUnits 16\n"
1156 "MaxTessControlUniformComponents 1024\n"
1157 "MaxTessControlTotalOutputComponents 4096\n"
1158 "MaxTessEvaluationInputComponents 128\n"
1159 "MaxTessEvaluationOutputComponents 128\n"
1160 "MaxTessEvaluationTextureImageUnits 16\n"
1161 "MaxTessEvaluationUniformComponents 1024\n"
1162 "MaxTessPatchComponents 120\n"
1163 "MaxPatchVertices 32\n"
1164 "MaxTessGenLevel 64\n"
1165 "MaxViewports 16\n"
1166 "MaxVertexAtomicCounters 0\n"
1167 "MaxTessControlAtomicCounters 0\n"
1168 "MaxTessEvaluationAtomicCounters 0\n"
1169 "MaxGeometryAtomicCounters 0\n"
1170 "MaxFragmentAtomicCounters 8\n"
1171 "MaxCombinedAtomicCounters 8\n"
1172 "MaxAtomicCounterBindings 1\n"
1173 "MaxVertexAtomicCounterBuffers 0\n"
1174 "MaxTessControlAtomicCounterBuffers 0\n"
1175 "MaxTessEvaluationAtomicCounterBuffers 0\n"
1176 "MaxGeometryAtomicCounterBuffers 0\n"
1177 "MaxFragmentAtomicCounterBuffers 1\n"
1178 "MaxCombinedAtomicCounterBuffers 1\n"
1179 "MaxAtomicCounterBufferSize 16384\n"
1180 "MaxTransformFeedbackBuffers 4\n"
1181 "MaxTransformFeedbackInterleavedComponents 64\n"
1182 "MaxCullDistances 8\n"
1183 "MaxCombinedClipAndCullDistances 8\n"
1184 "MaxSamples 4\n"
1185
1186 "nonInductiveForLoops 1\n"
1187 "whileLoops 1\n"
1188 "doWhileLoops 1\n"
1189 "generalUniformIndexing 1\n"
1190 "generalAttributeMatrixVectorIndexing 1\n"
1191 "generalVaryingIndexing 1\n"
1192 "generalSamplerIndexing 1\n"
1193 "generalVariableIndexing 1\n"
1194 "generalConstantMatrixVectorIndexing 1\n"
1195 ;
1196
1197//
1198// *.conf => this is a config file that can set limits/resources
1199//
Tony Barbour6918cd52015-04-09 12:58:51 -06001200bool VkTestFramework::SetConfigFile(const std::string& name)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001201{
1202 if (name.size() < 5)
1203 return false;
1204
1205 if (name.compare(name.size() - 5, 5, ".conf") == 0) {
1206 ConfigFile = name;
1207 return true;
1208 }
1209
1210 return false;
1211}
1212
1213//
1214// Parse either a .conf file provided by the user or the default string above.
1215//
Tony Barbour6918cd52015-04-09 12:58:51 -06001216void VkTestFramework::ProcessConfigFile()
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001217{
1218 char** configStrings = 0;
1219 char* config = 0;
1220 if (ConfigFile.size() > 0) {
1221 configStrings = ReadFileData(ConfigFile.c_str());
1222 if (configStrings)
1223 config = *configStrings;
1224 else {
1225 printf("Error opening configuration file; will instead use the default configuration\n");
1226 }
1227 }
1228
1229 if (config == 0) {
1230 config = new char[strlen(DefaultConfig) + 1];
1231 strcpy(config, DefaultConfig);
1232 }
1233
1234 const char* delims = " \t\n\r";
1235 const char* token = strtok(config, delims);
1236 while (token) {
1237 const char* valueStr = strtok(0, delims);
1238 if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) {
1239 printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : "");
1240 return;
1241 }
1242 int value = atoi(valueStr);
1243
1244 if (strcmp(token, "MaxLights") == 0)
1245 Resources.maxLights = value;
1246 else if (strcmp(token, "MaxClipPlanes") == 0)
1247 Resources.maxClipPlanes = value;
1248 else if (strcmp(token, "MaxTextureUnits") == 0)
1249 Resources.maxTextureUnits = value;
1250 else if (strcmp(token, "MaxTextureCoords") == 0)
1251 Resources.maxTextureCoords = value;
1252 else if (strcmp(token, "MaxVertexAttribs") == 0)
1253 Resources.maxVertexAttribs = value;
1254 else if (strcmp(token, "MaxVertexUniformComponents") == 0)
1255 Resources.maxVertexUniformComponents = value;
1256 else if (strcmp(token, "MaxVaryingFloats") == 0)
1257 Resources.maxVaryingFloats = value;
1258 else if (strcmp(token, "MaxVertexTextureImageUnits") == 0)
1259 Resources.maxVertexTextureImageUnits = value;
1260 else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0)
1261 Resources.maxCombinedTextureImageUnits = value;
1262 else if (strcmp(token, "MaxTextureImageUnits") == 0)
1263 Resources.maxTextureImageUnits = value;
1264 else if (strcmp(token, "MaxFragmentUniformComponents") == 0)
1265 Resources.maxFragmentUniformComponents = value;
1266 else if (strcmp(token, "MaxDrawBuffers") == 0)
1267 Resources.maxDrawBuffers = value;
1268 else if (strcmp(token, "MaxVertexUniformVectors") == 0)
1269 Resources.maxVertexUniformVectors = value;
1270 else if (strcmp(token, "MaxVaryingVectors") == 0)
1271 Resources.maxVaryingVectors = value;
1272 else if (strcmp(token, "MaxFragmentUniformVectors") == 0)
1273 Resources.maxFragmentUniformVectors = value;
1274 else if (strcmp(token, "MaxVertexOutputVectors") == 0)
1275 Resources.maxVertexOutputVectors = value;
1276 else if (strcmp(token, "MaxFragmentInputVectors") == 0)
1277 Resources.maxFragmentInputVectors = value;
1278 else if (strcmp(token, "MinProgramTexelOffset") == 0)
1279 Resources.minProgramTexelOffset = value;
1280 else if (strcmp(token, "MaxProgramTexelOffset") == 0)
1281 Resources.maxProgramTexelOffset = value;
1282 else if (strcmp(token, "MaxClipDistances") == 0)
1283 Resources.maxClipDistances = value;
1284 else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0)
1285 Resources.maxComputeWorkGroupCountX = value;
1286 else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0)
1287 Resources.maxComputeWorkGroupCountY = value;
1288 else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0)
1289 Resources.maxComputeWorkGroupCountZ = value;
1290 else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0)
1291 Resources.maxComputeWorkGroupSizeX = value;
1292 else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0)
1293 Resources.maxComputeWorkGroupSizeY = value;
1294 else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0)
1295 Resources.maxComputeWorkGroupSizeZ = value;
1296 else if (strcmp(token, "MaxComputeUniformComponents") == 0)
1297 Resources.maxComputeUniformComponents = value;
1298 else if (strcmp(token, "MaxComputeTextureImageUnits") == 0)
1299 Resources.maxComputeTextureImageUnits = value;
1300 else if (strcmp(token, "MaxComputeImageUniforms") == 0)
1301 Resources.maxComputeImageUniforms = value;
1302 else if (strcmp(token, "MaxComputeAtomicCounters") == 0)
1303 Resources.maxComputeAtomicCounters = value;
1304 else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0)
1305 Resources.maxComputeAtomicCounterBuffers = value;
1306 else if (strcmp(token, "MaxVaryingComponents") == 0)
1307 Resources.maxVaryingComponents = value;
1308 else if (strcmp(token, "MaxVertexOutputComponents") == 0)
1309 Resources.maxVertexOutputComponents = value;
1310 else if (strcmp(token, "MaxGeometryInputComponents") == 0)
1311 Resources.maxGeometryInputComponents = value;
1312 else if (strcmp(token, "MaxGeometryOutputComponents") == 0)
1313 Resources.maxGeometryOutputComponents = value;
1314 else if (strcmp(token, "MaxFragmentInputComponents") == 0)
1315 Resources.maxFragmentInputComponents = value;
1316 else if (strcmp(token, "MaxImageUnits") == 0)
1317 Resources.maxImageUnits = value;
1318 else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0)
1319 Resources.maxCombinedImageUnitsAndFragmentOutputs = value;
1320 else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0)
1321 Resources.maxCombinedShaderOutputResources = value;
1322 else if (strcmp(token, "MaxImageSamples") == 0)
1323 Resources.maxImageSamples = value;
1324 else if (strcmp(token, "MaxVertexImageUniforms") == 0)
1325 Resources.maxVertexImageUniforms = value;
1326 else if (strcmp(token, "MaxTessControlImageUniforms") == 0)
1327 Resources.maxTessControlImageUniforms = value;
1328 else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0)
1329 Resources.maxTessEvaluationImageUniforms = value;
1330 else if (strcmp(token, "MaxGeometryImageUniforms") == 0)
1331 Resources.maxGeometryImageUniforms = value;
1332 else if (strcmp(token, "MaxFragmentImageUniforms") == 0)
1333 Resources.maxFragmentImageUniforms = value;
1334 else if (strcmp(token, "MaxCombinedImageUniforms") == 0)
1335 Resources.maxCombinedImageUniforms = value;
1336 else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0)
1337 Resources.maxGeometryTextureImageUnits = value;
1338 else if (strcmp(token, "MaxGeometryOutputVertices") == 0)
1339 Resources.maxGeometryOutputVertices = value;
1340 else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0)
1341 Resources.maxGeometryTotalOutputComponents = value;
1342 else if (strcmp(token, "MaxGeometryUniformComponents") == 0)
1343 Resources.maxGeometryUniformComponents = value;
1344 else if (strcmp(token, "MaxGeometryVaryingComponents") == 0)
1345 Resources.maxGeometryVaryingComponents = value;
1346 else if (strcmp(token, "MaxTessControlInputComponents") == 0)
1347 Resources.maxTessControlInputComponents = value;
1348 else if (strcmp(token, "MaxTessControlOutputComponents") == 0)
1349 Resources.maxTessControlOutputComponents = value;
1350 else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0)
1351 Resources.maxTessControlTextureImageUnits = value;
1352 else if (strcmp(token, "MaxTessControlUniformComponents") == 0)
1353 Resources.maxTessControlUniformComponents = value;
1354 else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0)
1355 Resources.maxTessControlTotalOutputComponents = value;
1356 else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0)
1357 Resources.maxTessEvaluationInputComponents = value;
1358 else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0)
1359 Resources.maxTessEvaluationOutputComponents = value;
1360 else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0)
1361 Resources.maxTessEvaluationTextureImageUnits = value;
1362 else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0)
1363 Resources.maxTessEvaluationUniformComponents = value;
1364 else if (strcmp(token, "MaxTessPatchComponents") == 0)
1365 Resources.maxTessPatchComponents = value;
1366 else if (strcmp(token, "MaxPatchVertices") == 0)
1367 Resources.maxPatchVertices = value;
1368 else if (strcmp(token, "MaxTessGenLevel") == 0)
1369 Resources.maxTessGenLevel = value;
1370 else if (strcmp(token, "MaxViewports") == 0)
1371 Resources.maxViewports = value;
1372 else if (strcmp(token, "MaxVertexAtomicCounters") == 0)
1373 Resources.maxVertexAtomicCounters = value;
1374 else if (strcmp(token, "MaxTessControlAtomicCounters") == 0)
1375 Resources.maxTessControlAtomicCounters = value;
1376 else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0)
1377 Resources.maxTessEvaluationAtomicCounters = value;
1378 else if (strcmp(token, "MaxGeometryAtomicCounters") == 0)
1379 Resources.maxGeometryAtomicCounters = value;
1380 else if (strcmp(token, "MaxFragmentAtomicCounters") == 0)
1381 Resources.maxFragmentAtomicCounters = value;
1382 else if (strcmp(token, "MaxCombinedAtomicCounters") == 0)
1383 Resources.maxCombinedAtomicCounters = value;
1384 else if (strcmp(token, "MaxAtomicCounterBindings") == 0)
1385 Resources.maxAtomicCounterBindings = value;
1386 else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0)
1387 Resources.maxVertexAtomicCounterBuffers = value;
1388 else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0)
1389 Resources.maxTessControlAtomicCounterBuffers = value;
1390 else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0)
1391 Resources.maxTessEvaluationAtomicCounterBuffers = value;
1392 else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0)
1393 Resources.maxGeometryAtomicCounterBuffers = value;
1394 else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0)
1395 Resources.maxFragmentAtomicCounterBuffers = value;
1396 else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0)
1397 Resources.maxCombinedAtomicCounterBuffers = value;
1398 else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0)
1399 Resources.maxAtomicCounterBufferSize = value;
1400 else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0)
1401 Resources.maxTransformFeedbackBuffers = value;
1402 else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0)
1403 Resources.maxTransformFeedbackInterleavedComponents = value;
1404 else if (strcmp(token, "MaxCullDistances") == 0)
1405 Resources.maxCullDistances = value;
1406 else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0)
1407 Resources.maxCombinedClipAndCullDistances = value;
1408 else if (strcmp(token, "MaxSamples") == 0)
1409 Resources.maxSamples = value;
1410
1411 else if (strcmp(token, "nonInductiveForLoops") == 0)
1412 Resources.limits.nonInductiveForLoops = (value != 0);
1413 else if (strcmp(token, "whileLoops") == 0)
1414 Resources.limits.whileLoops = (value != 0);
1415 else if (strcmp(token, "doWhileLoops") == 0)
1416 Resources.limits.doWhileLoops = (value != 0);
1417 else if (strcmp(token, "generalUniformIndexing") == 0)
1418 Resources.limits.generalUniformIndexing = (value != 0);
1419 else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0)
1420 Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0);
1421 else if (strcmp(token, "generalVaryingIndexing") == 0)
1422 Resources.limits.generalVaryingIndexing = (value != 0);
1423 else if (strcmp(token, "generalSamplerIndexing") == 0)
1424 Resources.limits.generalSamplerIndexing = (value != 0);
1425 else if (strcmp(token, "generalVariableIndexing") == 0)
1426 Resources.limits.generalVariableIndexing = (value != 0);
1427 else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0)
1428 Resources.limits.generalConstantMatrixVectorIndexing = (value != 0);
1429 else
1430 printf("Warning: unrecognized limit (%s) in configuration file.\n", token);
1431
1432 token = strtok(0, delims);
1433 }
1434 if (configStrings)
1435 FreeFileData(configStrings);
1436}
1437
Tony Barbour6918cd52015-04-09 12:58:51 -06001438void VkTestFramework::SetMessageOptions(EShMessages& messages)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001439{
1440 if (m_compile_options & EOptionRelaxedErrors)
1441 messages = (EShMessages)(messages | EShMsgRelaxedErrors);
1442 if (m_compile_options & EOptionIntermediate)
1443 messages = (EShMessages)(messages | EShMsgAST);
1444 if (m_compile_options & EOptionSuppressWarnings)
1445 messages = (EShMessages)(messages | EShMsgSuppressWarnings);
1446}
1447
1448//
1449// Malloc a string of sufficient size and read a string into it.
1450//
Tony Barbour6918cd52015-04-09 12:58:51 -06001451char** VkTestFramework::ReadFileData(const char* fileName)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001452{
1453 FILE *in;
1454 #if defined(_WIN32) && defined(__GNUC__)
1455 in = fopen(fileName, "r");
1456 int errorCode = in ? 0 : 1;
1457 #else
1458 int errorCode = fopen_s(&in, fileName, "r");
1459 #endif
1460
1461 char *fdata;
1462 int count = 0;
1463 const int maxSourceStrings = 5;
1464 char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1));
1465
1466 if (errorCode) {
1467 printf("Error: unable to open input file: %s\n", fileName);
1468 return 0;
1469 }
1470
1471 while (fgetc(in) != EOF)
1472 count++;
1473
1474 fseek(in, 0, SEEK_SET);
1475
1476 if (!(fdata = (char*)malloc(count+2))) {
1477 printf("Error allocating memory\n");
1478 return 0;
1479 }
1480 if (fread(fdata,1,count, in)!=count) {
1481 printf("Error reading input file: %s\n", fileName);
1482 return 0;
1483 }
1484 fdata[count] = '\0';
1485 fclose(in);
1486 if (count == 0) {
1487 return_data[0]=(char*)malloc(count+2);
1488 return_data[0][0]='\0';
1489 m_num_shader_strings = 0;
1490 return return_data;
1491 } else
1492 m_num_shader_strings = 1;
1493
1494 int len = (int)(ceil)((float)count/(float)m_num_shader_strings);
1495 int ptr_len=0,i=0;
1496 while(count>0){
1497 return_data[i]=(char*)malloc(len+2);
1498 memcpy(return_data[i],fdata+ptr_len,len);
1499 return_data[i][len]='\0';
1500 count-=(len);
1501 ptr_len+=(len);
1502 if(count<len){
1503 if(count==0){
1504 m_num_shader_strings=(i+1);
1505 break;
1506 }
1507 len = count;
1508 }
1509 ++i;
1510 }
1511 return return_data;
1512}
1513
Tony Barbour6918cd52015-04-09 12:58:51 -06001514void VkTestFramework::FreeFileData(char** data)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001515{
1516 for(int i=0;i<m_num_shader_strings;i++)
1517 free(data[i]);
1518}
1519
1520//
1521// Deduce the language from the filename. Files must end in one of the
1522// following extensions:
1523//
1524// .vert = vertex
1525// .tesc = tessellation control
1526// .tese = tessellation evaluation
1527// .geom = geometry
1528// .frag = fragment
1529// .comp = compute
1530//
Tony Barbour6918cd52015-04-09 12:58:51 -06001531EShLanguage VkTestFramework::FindLanguage(const std::string& name)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001532{
1533 size_t ext = name.rfind('.');
1534 if (ext == std::string::npos) {
1535 return EShLangVertex;
1536 }
1537
1538 std::string suffix = name.substr(ext + 1, std::string::npos);
1539 if (suffix == "vert")
1540 return EShLangVertex;
1541 else if (suffix == "tesc")
1542 return EShLangTessControl;
1543 else if (suffix == "tese")
1544 return EShLangTessEvaluation;
1545 else if (suffix == "geom")
1546 return EShLangGeometry;
1547 else if (suffix == "frag")
1548 return EShLangFragment;
1549 else if (suffix == "comp")
1550 return EShLangCompute;
1551
1552 return EShLangVertex;
1553}
1554
1555//
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001556// Convert VK shader type to compiler's
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001557//
Tony Barbourd1c35722015-04-16 15:59:00 -06001558EShLanguage VkTestFramework::FindLanguage(const VkShaderStage shader_type)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001559{
1560 switch (shader_type) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001561 case VK_SHADER_STAGE_VERTEX:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001562 return EShLangVertex;
1563
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001564 case VK_SHADER_STAGE_TESS_CONTROL:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001565 return EShLangTessControl;
1566
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001567 case VK_SHADER_STAGE_TESS_EVALUATION:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001568 return EShLangTessEvaluation;
1569
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001570 case VK_SHADER_STAGE_GEOMETRY:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001571 return EShLangGeometry;
1572
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001573 case VK_SHADER_STAGE_FRAGMENT:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001574 return EShLangFragment;
1575
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001576 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001577 return EShLangCompute;
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001578
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001579 default:
1580 return EShLangVertex;
1581 }
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001582}
1583
1584
1585//
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001586// Compile a given string containing GLSL into SPV for use by VK
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001587// Return value of false means an error was encountered.
1588//
Tony Barbourd1c35722015-04-16 15:59:00 -06001589bool VkTestFramework::GLSLtoSPV(const VkShaderStage shader_type,
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001590 const char *pshader,
Cody Northrop5a95b472015-06-03 13:01:54 -06001591 std::vector<unsigned int> &spirv)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001592{
1593 glslang::TProgram& program = *new glslang::TProgram;
1594 const char *shaderStrings[1];
1595
1596 // TODO: Do we want to load a special config file depending on the
1597 // shader source? Optional name maybe?
1598 // SetConfigFile(fileName);
1599
1600 ProcessConfigFile();
1601
1602 EShMessages messages = EShMsgDefault;
1603 SetMessageOptions(messages);
1604
1605 EShLanguage stage = FindLanguage(shader_type);
1606 glslang::TShader* shader = new glslang::TShader(stage);
1607
1608 shaderStrings[0] = pshader;
1609 shader->setStrings(shaderStrings, 1);
1610
1611 if (! shader->parse(&Resources, (m_compile_options & EOptionDefaultDesktop) ? 110 : 100, false, messages)) {
1612
Cody Northrop195d6622014-11-03 12:54:37 -07001613 if (! (m_compile_options & EOptionSuppressInfolog)) {
1614 puts(shader->getInfoLog());
1615 puts(shader->getInfoDebugLog());
1616 }
1617
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001618 return false; // something didn't work
1619 }
1620
1621 program.addShader(shader);
1622
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001623
1624 //
1625 // Program-level processing...
1626 //
1627
Cody Northrop195d6622014-11-03 12:54:37 -07001628 if (! program.link(messages)) {
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001629
Cody Northrop195d6622014-11-03 12:54:37 -07001630 if (! (m_compile_options & EOptionSuppressInfolog)) {
1631 puts(shader->getInfoLog());
1632 puts(shader->getInfoDebugLog());
1633 }
1634
1635 return false;
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001636 }
1637
1638 if (m_compile_options & EOptionDumpReflection) {
1639 program.buildReflection();
1640 program.dumpReflection();
1641 }
1642
Cody Northrop5a95b472015-06-03 13:01:54 -06001643 glslang::GlslangToSpv(*program.getIntermediate(stage), spirv);
1644
1645 //
1646 // Test the different modes of SPIR-V modification
1647 //
1648 if (this->m_canonicalize_spv) {
1649 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::ALL_BUT_STRIP);
1650 }
1651
1652 if (this->m_strip_spv) {
1653 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::STRIP);
1654 }
1655
1656 if (this->m_do_everything_spv) {
1657 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::DO_EVERYTHING);
1658 }
1659
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001660
1661 return true;
1662}
1663
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001664
1665
Tony Barbour6918cd52015-04-09 12:58:51 -06001666VkTestImageRecord::VkTestImageRecord() : // Constructor
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001667 m_width( 0 ),
1668 m_height( 0 ),
Chia-I Wu837f9952014-12-15 23:29:34 +08001669 m_data( NULL ),
1670 m_data_size( 0 )
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001671{
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001672}
1673
Tony Barbour6918cd52015-04-09 12:58:51 -06001674VkTestImageRecord::~VkTestImageRecord()
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001675{
1676
1677}
1678
Tony Barbour6918cd52015-04-09 12:58:51 -06001679VkTestImageRecord::VkTestImageRecord(const VkTestImageRecord &copyin) // Copy constructor to handle pass by value.
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001680{
1681 m_title = copyin.m_title;
1682 m_width = copyin.m_width;
1683 m_height = copyin.m_height;
1684 m_data_size = copyin.m_data_size;
1685 m_data = copyin.m_data; // TODO: Do we need to copy the data or is pointer okay?
1686}
1687
Tony Barbour6918cd52015-04-09 12:58:51 -06001688ostream &operator<<(ostream &output, const VkTestImageRecord &VkTestImageRecord)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001689{
Tony Barbour6918cd52015-04-09 12:58:51 -06001690 output << VkTestImageRecord.m_title << " (" << VkTestImageRecord.m_width <<
1691 "," << VkTestImageRecord.m_height << ")" << endl;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001692 return output;
1693}
1694
Tony Barbour6918cd52015-04-09 12:58:51 -06001695VkTestImageRecord& VkTestImageRecord::operator=(const VkTestImageRecord &rhs)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001696{
1697 m_title = rhs.m_title;
1698 m_width = rhs.m_width;
1699 m_height = rhs.m_height;
1700 m_data_size = rhs.m_data_size;
1701 m_data = rhs.m_data;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001702 return *this;
1703}
1704
Tony Barbour6918cd52015-04-09 12:58:51 -06001705int VkTestImageRecord::operator==(const VkTestImageRecord &rhs) const
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001706{
1707 if( this->m_data != rhs.m_data) return 0;
1708 return 1;
1709}
1710
1711// This function is required for built-in STL list functions like sort
Tony Barbour6918cd52015-04-09 12:58:51 -06001712int VkTestImageRecord::operator<(const VkTestImageRecord &rhs) const
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001713{
1714 if( this->m_data_size < rhs.m_data_size ) return 1;
1715 return 0;
1716}
1717