blob: 241fc951f59533bb4c1b73505c5ea5424766b3dc [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-
Ian Elliottae0e8242015-08-10 13:20:49 -0600843 // tearing mode. If not, try IMMEDIATE which will usually be available,
844 // and is fastest (though it tears). If not, fall back to FIFO which is
845 // always available.
846 VkPresentModeWSI swapChainPresentMode = VK_PRESENT_MODE_FIFO_WSI;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600847 for (size_t i = 0; i < presentModeCount; i++) {
Ian Elliott8b139792015-08-07 11:51:12 -0600848 if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_WSI) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600849 swapChainPresentMode = VK_PRESENT_MODE_MAILBOX_WSI;
850 break;
851 }
Ian Elliottae0e8242015-08-10 13:20:49 -0600852 if ((swapChainPresentMode != VK_PRESENT_MODE_MAILBOX_WSI) &&
853 (presentModes[i] == VK_PRESENT_MODE_IMMEDIATE_WSI)) {
854 swapChainPresentMode = VK_PRESENT_MODE_IMMEDIATE_WSI;
855 }
Tony Barbour6a3faf02015-07-23 10:36:18 -0600856 }
857
858 // Determine the number of VkImage's to use in the swap chain (we desire to
859 // own only 1 image at a time, besides the images being displayed and
860 // queued for display):
Ian Elliott8b139792015-08-07 11:51:12 -0600861 uint32_t desiredNumberOfSwapChainImages = surfProperties.minImageCount + 1;
862 if ((surfProperties.maxImageCount > 0) &&
863 (desiredNumberOfSwapChainImages > surfProperties.maxImageCount))
Tony Barbour6a3faf02015-07-23 10:36:18 -0600864 {
865 // Application must settle for fewer images than desired:
Ian Elliott8b139792015-08-07 11:51:12 -0600866 desiredNumberOfSwapChainImages = surfProperties.maxImageCount;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600867 }
868
869 VkSurfaceTransformWSI preTransform;
Ian Elliott8b139792015-08-07 11:51:12 -0600870 if (surfProperties.supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_WSI) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600871 preTransform = VK_SURFACE_TRANSFORM_NONE_WSI;
872 } else {
Ian Elliott8b139792015-08-07 11:51:12 -0600873 preTransform = surfProperties.currentTransform;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600874 }
Ian Elliott1a3845b2015-07-06 14:33:04 -0600875
Chia-I Wuf8693382015-04-16 22:02:10 +0800876 VkSwapChainCreateInfoWSI swap_chain = {};
877 swap_chain.sType = VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI;
Ian Elliott1a3845b2015-07-06 14:33:04 -0600878 swap_chain.pNext = NULL;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600879 swap_chain.pSurfaceDescription = (const VkSurfaceDescriptionWSI *)&m_surface_description;
880 swap_chain.minImageCount = desiredNumberOfSwapChainImages;
881 swap_chain.imageFormat = m_format;
Ian Elliott8b139792015-08-07 11:51:12 -0600882 swap_chain.imageColorSpace = m_color_space;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600883 swap_chain.imageExtent.width = swapChainExtent.width;
884 swap_chain.imageExtent.height = swapChainExtent.height;
Cody Northropdf8f42a2015-08-05 15:38:39 -0600885 // Workaround: Some implementations need color attachment for blit targets
886 swap_chain.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT |
887 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600888 swap_chain.preTransform = preTransform;
Chia-I Wuf8693382015-04-16 22:02:10 +0800889 swap_chain.imageArraySize = 1;
Ian Elliott8b139792015-08-07 11:51:12 -0600890 swap_chain.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
891 swap_chain.queueFamilyCount = 0;
892 swap_chain.pQueueFamilyIndices = NULL;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600893 swap_chain.presentMode = swapChainPresentMode;
894 swap_chain.oldSwapChain.handle = 0;
895 swap_chain.clipped = true;
896
897 uint32_t i;
Chia-I Wuf8693382015-04-16 22:02:10 +0800898
Chia-I Wuf368b602015-07-03 10:41:20 +0800899 err = m_fpCreateSwapChainWSI(m_device.handle(), &swap_chain, &m_swap_chain);
Chia-I Wuf8693382015-04-16 22:02:10 +0800900 assert(!err);
901
Ian Elliott8b139792015-08-07 11:51:12 -0600902 err = m_fpGetSwapChainImagesWSI(m_device.handle(), m_swap_chain,
903 &m_swapChainImageCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600904 assert(!err);
905
Ian Elliott8b139792015-08-07 11:51:12 -0600906 VkImage* swapChainImages = (VkImage*)malloc(m_swapChainImageCount * sizeof(VkImage));
Tony Barbour6a3faf02015-07-23 10:36:18 -0600907 assert(swapChainImages);
Ian Elliott8b139792015-08-07 11:51:12 -0600908 err = m_fpGetSwapChainImagesWSI(m_device.handle(), m_swap_chain,
909 &m_swapChainImageCount, swapChainImages);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600910 assert(!err);
911
Tony Barbour6a3faf02015-07-23 10:36:18 -0600912 m_buffers = (SwapChainBuffers*)malloc(sizeof(SwapChainBuffers)*m_swapChainImageCount);
913 assert(m_buffers);
914
915 for (i = 0; i < m_swapChainImageCount; i++) {
916 VkAttachmentViewCreateInfo color_attachment_view = {};
917 color_attachment_view.sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO;
918 color_attachment_view.pNext = NULL;
919 color_attachment_view.format = m_format;
920 color_attachment_view.mipLevel = 0;
921 color_attachment_view.baseArraySlice = 0;
922 color_attachment_view.arraySize = 1;
923
Ian Elliott8b139792015-08-07 11:51:12 -0600924 m_buffers[i].image = swapChainImages[i];
Tony Barbour6a3faf02015-07-23 10:36:18 -0600925
926 color_attachment_view.image = m_buffers[i].image;
927 err = vkCreateAttachmentView(m_device.handle(),
928 &color_attachment_view, &m_buffers[i].view);
929 assert(!err);
930 }
Tony Barbour96db8822015-02-25 12:28:39 -0700931}
932
Jon Ashburn07daee72015-05-21 18:13:33 -0600933void TestFrameworkVkPresent::InitPresentFramework(std::list<VkTestImageRecord> &imagesIn, VkInstance inst)
Tony Barbour96db8822015-02-25 12:28:39 -0700934{
Tony Barbour6a3faf02015-07-23 10:36:18 -0600935 GET_INSTANCE_PROC_ADDR(inst, GetPhysicalDeviceSurfaceSupportWSI);
Ian Elliott8b139792015-08-07 11:51:12 -0600936 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePropertiesWSI);
937 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfaceFormatsWSI);
938 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePresentModesWSI);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600939 GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapChainWSI);
940 GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapChainWSI);
941 GET_DEVICE_PROC_ADDR(m_device.handle(), DestroySwapChainWSI);
Ian Elliott8b139792015-08-07 11:51:12 -0600942 GET_DEVICE_PROC_ADDR(m_device.handle(), GetSwapChainImagesWSI);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600943 GET_DEVICE_PROC_ADDR(m_device.handle(), AcquireNextImageWSI);
944 GET_DEVICE_PROC_ADDR(m_device.handle(), QueuePresentWSI);
Jon Ashburn07daee72015-05-21 18:13:33 -0600945
Tony Barbour96db8822015-02-25 12:28:39 -0700946 m_images = imagesIn;
947}
948
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600949#ifdef _WIN32
950void TestFrameworkVkPresent::CreateMyWindow()
951{
952 WNDCLASSEX win_class;
953 // const ::testing::TestInfo* const test_info =
954 // ::testing::UnitTest::GetInstance()->current_test_info();
955 m_connection = GetModuleHandle(NULL);
956
957 for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin();
958 it != m_images.end(); it++) {
959 if (m_width < it->m_width)
960 m_width = it->m_width;
961 if (m_height < it->m_height)
962 m_height = it->m_height;
963 }
964 // Initialize the window class structure:
965 win_class.cbSize = sizeof(WNDCLASSEX);
966 win_class.style = CS_HREDRAW | CS_VREDRAW;
967 win_class.lpfnWndProc = (WNDPROC) &TestFrameworkVkPresent::WndProc;
968 win_class.cbClsExtra = 0;
969 win_class.cbWndExtra = 0;
970 win_class.hInstance = m_connection; // hInstance
971 win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
972 win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
973 win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
974 win_class.lpszMenuName = NULL;
975 win_class.lpszClassName = "Test";
976 win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
977 // Register window class:
978 if (!RegisterClassEx(&win_class)) {
979 // It didn't work, so try to give a useful error:
980 printf("Unexpected error trying to start the application!\n");
981 fflush(stdout);
982 exit(1);
983 }
984 // Create window with the registered class:
Cody Northrop39582252015-08-05 15:39:31 -0600985 RECT wr = { 0, 0, m_width, m_height };
986 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600987 m_window = CreateWindowEx(0,
988 "Test", // class name
989 "Test", // app name
990 WS_OVERLAPPEDWINDOW | // window style
991 WS_VISIBLE |
992 WS_SYSMENU,
993 100,100, // x/y coords
Cody Northrop39582252015-08-05 15:39:31 -0600994 wr.right - wr.left, // width
995 wr.bottom - wr.top, // height
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600996 NULL, // handle to parent
997 NULL, // handle to menu
998 m_connection, // hInstance
999 NULL); // no extra parameters
1000
1001 if (!m_window) {
1002 // It didn't work, so try to give a useful error:
1003 DWORD error = GetLastError();
1004 char message[120];
1005 sprintf(message, "Cannot create a window in which to draw!\n GetLastError = %d", error);
1006 MessageBox(NULL, message, "Error", MB_OK);
1007 exit(1);
1008 }
Tony-LunarG399dfca2015-05-19 14:08:26 -06001009 // Put our this pointer into the window's user data so our WndProc can use it when it starts.
1010 SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR) this);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001011}
1012#else
Tony Barbour6918cd52015-04-09 12:58:51 -06001013void TestFrameworkVkPresent::CreateMyWindow()
Tony Barbour96db8822015-02-25 12:28:39 -07001014{
Chia-I Wuf8693382015-04-16 22:02:10 +08001015 const xcb_setup_t *setup;
1016 xcb_screen_iterator_t iter;
1017 int scr;
Tony Barbour96db8822015-02-25 12:28:39 -07001018 uint32_t value_mask, value_list[32];
1019
Chia-I Wuf8693382015-04-16 22:02:10 +08001020 m_connection = xcb_connect(NULL, &scr);
1021
1022 setup = xcb_get_setup(m_connection);
1023 iter = xcb_setup_roots_iterator(setup);
1024 while (scr-- > 0)
1025 xcb_screen_next(&iter);
1026
1027 m_screen = iter.data;
1028
1029 for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin();
1030 it != m_images.end(); it++) {
1031 if (m_width < it->m_width)
1032 m_width = it->m_width;
1033 if (m_height < it->m_height)
1034 m_height = it->m_height;
1035 }
1036
1037 m_window = xcb_generate_id(m_connection);
Tony Barbour96db8822015-02-25 12:28:39 -07001038
1039 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
Chia-I Wuf8693382015-04-16 22:02:10 +08001040 value_list[0] = m_screen->black_pixel;
Tony Barbour96db8822015-02-25 12:28:39 -07001041 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE |
1042 XCB_EVENT_MASK_EXPOSURE |
1043 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1044
Chia-I Wuf8693382015-04-16 22:02:10 +08001045 xcb_create_window(m_connection,
Tony Barbour96db8822015-02-25 12:28:39 -07001046 XCB_COPY_FROM_PARENT,
Chia-I Wuf8693382015-04-16 22:02:10 +08001047 m_window, m_screen->root,
Tony Barbour96db8822015-02-25 12:28:39 -07001048 0, 0, m_width, m_height, 0,
1049 XCB_WINDOW_CLASS_INPUT_OUTPUT,
Chia-I Wuf8693382015-04-16 22:02:10 +08001050 m_screen->root_visual,
Tony Barbour96db8822015-02-25 12:28:39 -07001051 value_mask, value_list);
1052
1053 /* Magic code that will send notification when window is destroyed */
Chia-I Wuf8693382015-04-16 22:02:10 +08001054 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 1, 12,
Tony Barbour96db8822015-02-25 12:28:39 -07001055 "WM_PROTOCOLS");
Chia-I Wuf8693382015-04-16 22:02:10 +08001056 xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(m_connection, cookie, 0);
Tony Barbour96db8822015-02-25 12:28:39 -07001057
Chia-I Wuf8693382015-04-16 22:02:10 +08001058 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(m_connection, 0, 16, "WM_DELETE_WINDOW");
1059 m_atom_wm_delete_window = xcb_intern_atom_reply(m_connection, cookie2, 0);
Tony Barbour96db8822015-02-25 12:28:39 -07001060
Chia-I Wuf8693382015-04-16 22:02:10 +08001061 xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE,
Tony Barbour96db8822015-02-25 12:28:39 -07001062 m_window, (*reply).atom, 4, 32, 1,
1063 &(*m_atom_wm_delete_window).atom);
1064 free(reply);
1065
Chia-I Wuf8693382015-04-16 22:02:10 +08001066 xcb_map_window(m_connection, m_window);
Tony Barbour96db8822015-02-25 12:28:39 -07001067}
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001068#endif
Tony Barbour96db8822015-02-25 12:28:39 -07001069
Tony Barbour6918cd52015-04-09 12:58:51 -06001070void TestFrameworkVkPresent::TearDown()
Tony Barbour96db8822015-02-25 12:28:39 -07001071{
Ian Elliott1a3845b2015-07-06 14:33:04 -06001072 m_fpDestroySwapChainWSI(m_device.handle(), m_swap_chain);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001073#ifndef _WIN32
Chia-I Wuf8693382015-04-16 22:02:10 +08001074 xcb_destroy_window(m_connection, m_window);
1075 xcb_disconnect(m_connection);
Tony Barbour3d69c9e2015-05-20 16:53:31 -06001076#endif
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001077}
1078
Tony Barbour6918cd52015-04-09 12:58:51 -06001079void VkTestFramework::Finish()
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001080{
1081 if (m_images.size() == 0) return;
1082
Chia-I Wuf8693382015-04-16 22:02:10 +08001083 vk_testing::Environment env;
1084 env.SetUp();
Tony Barbour96db8822015-02-25 12:28:39 -07001085 {
Chia-I Wuf8693382015-04-16 22:02:10 +08001086 TestFrameworkVkPresent vkPresent(env.default_device());
Tony Barbour96db8822015-02-25 12:28:39 -07001087
Jon Ashburn07daee72015-05-21 18:13:33 -06001088 vkPresent.InitPresentFramework(m_images, env.get_instance());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001089 vkPresent.CreateMyWindow();
Chia-I Wuf8693382015-04-16 22:02:10 +08001090 vkPresent.CreateSwapChain();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001091 vkPresent.Run();
1092 vkPresent.TearDown();
Tony Barbour96db8822015-02-25 12:28:39 -07001093 }
Chia-I Wuf8693382015-04-16 22:02:10 +08001094 env.TearDown();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001095}
1096
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001097//
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001098// These are the default resources for TBuiltInResources, used for both
1099// - parsing this string for the case where the user didn't supply one
1100// - dumping out a template for user construction of a config file
1101//
1102static const char* DefaultConfig =
1103 "MaxLights 32\n"
1104 "MaxClipPlanes 6\n"
1105 "MaxTextureUnits 32\n"
1106 "MaxTextureCoords 32\n"
1107 "MaxVertexAttribs 64\n"
1108 "MaxVertexUniformComponents 4096\n"
1109 "MaxVaryingFloats 64\n"
1110 "MaxVertexTextureImageUnits 32\n"
1111 "MaxCombinedTextureImageUnits 80\n"
1112 "MaxTextureImageUnits 32\n"
1113 "MaxFragmentUniformComponents 4096\n"
1114 "MaxDrawBuffers 32\n"
1115 "MaxVertexUniformVectors 128\n"
1116 "MaxVaryingVectors 8\n"
1117 "MaxFragmentUniformVectors 16\n"
1118 "MaxVertexOutputVectors 16\n"
1119 "MaxFragmentInputVectors 15\n"
1120 "MinProgramTexelOffset -8\n"
1121 "MaxProgramTexelOffset 7\n"
1122 "MaxClipDistances 8\n"
1123 "MaxComputeWorkGroupCountX 65535\n"
1124 "MaxComputeWorkGroupCountY 65535\n"
1125 "MaxComputeWorkGroupCountZ 65535\n"
1126 "MaxComputeWorkGroupSizeX 1024\n"
1127 "MaxComputeWorkGroupSizeY 1024\n"
1128 "MaxComputeWorkGroupSizeZ 64\n"
1129 "MaxComputeUniformComponents 1024\n"
1130 "MaxComputeTextureImageUnits 16\n"
1131 "MaxComputeImageUniforms 8\n"
1132 "MaxComputeAtomicCounters 8\n"
1133 "MaxComputeAtomicCounterBuffers 1\n"
1134 "MaxVaryingComponents 60\n"
1135 "MaxVertexOutputComponents 64\n"
1136 "MaxGeometryInputComponents 64\n"
1137 "MaxGeometryOutputComponents 128\n"
1138 "MaxFragmentInputComponents 128\n"
1139 "MaxImageUnits 8\n"
1140 "MaxCombinedImageUnitsAndFragmentOutputs 8\n"
1141 "MaxCombinedShaderOutputResources 8\n"
1142 "MaxImageSamples 0\n"
1143 "MaxVertexImageUniforms 0\n"
1144 "MaxTessControlImageUniforms 0\n"
1145 "MaxTessEvaluationImageUniforms 0\n"
1146 "MaxGeometryImageUniforms 0\n"
1147 "MaxFragmentImageUniforms 8\n"
1148 "MaxCombinedImageUniforms 8\n"
1149 "MaxGeometryTextureImageUnits 16\n"
1150 "MaxGeometryOutputVertices 256\n"
1151 "MaxGeometryTotalOutputComponents 1024\n"
1152 "MaxGeometryUniformComponents 1024\n"
1153 "MaxGeometryVaryingComponents 64\n"
1154 "MaxTessControlInputComponents 128\n"
1155 "MaxTessControlOutputComponents 128\n"
1156 "MaxTessControlTextureImageUnits 16\n"
1157 "MaxTessControlUniformComponents 1024\n"
1158 "MaxTessControlTotalOutputComponents 4096\n"
1159 "MaxTessEvaluationInputComponents 128\n"
1160 "MaxTessEvaluationOutputComponents 128\n"
1161 "MaxTessEvaluationTextureImageUnits 16\n"
1162 "MaxTessEvaluationUniformComponents 1024\n"
1163 "MaxTessPatchComponents 120\n"
1164 "MaxPatchVertices 32\n"
1165 "MaxTessGenLevel 64\n"
1166 "MaxViewports 16\n"
1167 "MaxVertexAtomicCounters 0\n"
1168 "MaxTessControlAtomicCounters 0\n"
1169 "MaxTessEvaluationAtomicCounters 0\n"
1170 "MaxGeometryAtomicCounters 0\n"
1171 "MaxFragmentAtomicCounters 8\n"
1172 "MaxCombinedAtomicCounters 8\n"
1173 "MaxAtomicCounterBindings 1\n"
1174 "MaxVertexAtomicCounterBuffers 0\n"
1175 "MaxTessControlAtomicCounterBuffers 0\n"
1176 "MaxTessEvaluationAtomicCounterBuffers 0\n"
1177 "MaxGeometryAtomicCounterBuffers 0\n"
1178 "MaxFragmentAtomicCounterBuffers 1\n"
1179 "MaxCombinedAtomicCounterBuffers 1\n"
1180 "MaxAtomicCounterBufferSize 16384\n"
1181 "MaxTransformFeedbackBuffers 4\n"
1182 "MaxTransformFeedbackInterleavedComponents 64\n"
1183 "MaxCullDistances 8\n"
1184 "MaxCombinedClipAndCullDistances 8\n"
1185 "MaxSamples 4\n"
1186
1187 "nonInductiveForLoops 1\n"
1188 "whileLoops 1\n"
1189 "doWhileLoops 1\n"
1190 "generalUniformIndexing 1\n"
1191 "generalAttributeMatrixVectorIndexing 1\n"
1192 "generalVaryingIndexing 1\n"
1193 "generalSamplerIndexing 1\n"
1194 "generalVariableIndexing 1\n"
1195 "generalConstantMatrixVectorIndexing 1\n"
1196 ;
1197
1198//
1199// *.conf => this is a config file that can set limits/resources
1200//
Tony Barbour6918cd52015-04-09 12:58:51 -06001201bool VkTestFramework::SetConfigFile(const std::string& name)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001202{
1203 if (name.size() < 5)
1204 return false;
1205
1206 if (name.compare(name.size() - 5, 5, ".conf") == 0) {
1207 ConfigFile = name;
1208 return true;
1209 }
1210
1211 return false;
1212}
1213
1214//
1215// Parse either a .conf file provided by the user or the default string above.
1216//
Tony Barbour6918cd52015-04-09 12:58:51 -06001217void VkTestFramework::ProcessConfigFile()
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001218{
1219 char** configStrings = 0;
1220 char* config = 0;
1221 if (ConfigFile.size() > 0) {
1222 configStrings = ReadFileData(ConfigFile.c_str());
1223 if (configStrings)
1224 config = *configStrings;
1225 else {
1226 printf("Error opening configuration file; will instead use the default configuration\n");
1227 }
1228 }
1229
1230 if (config == 0) {
1231 config = new char[strlen(DefaultConfig) + 1];
1232 strcpy(config, DefaultConfig);
1233 }
1234
1235 const char* delims = " \t\n\r";
1236 const char* token = strtok(config, delims);
1237 while (token) {
1238 const char* valueStr = strtok(0, delims);
1239 if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) {
1240 printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : "");
1241 return;
1242 }
1243 int value = atoi(valueStr);
1244
1245 if (strcmp(token, "MaxLights") == 0)
1246 Resources.maxLights = value;
1247 else if (strcmp(token, "MaxClipPlanes") == 0)
1248 Resources.maxClipPlanes = value;
1249 else if (strcmp(token, "MaxTextureUnits") == 0)
1250 Resources.maxTextureUnits = value;
1251 else if (strcmp(token, "MaxTextureCoords") == 0)
1252 Resources.maxTextureCoords = value;
1253 else if (strcmp(token, "MaxVertexAttribs") == 0)
1254 Resources.maxVertexAttribs = value;
1255 else if (strcmp(token, "MaxVertexUniformComponents") == 0)
1256 Resources.maxVertexUniformComponents = value;
1257 else if (strcmp(token, "MaxVaryingFloats") == 0)
1258 Resources.maxVaryingFloats = value;
1259 else if (strcmp(token, "MaxVertexTextureImageUnits") == 0)
1260 Resources.maxVertexTextureImageUnits = value;
1261 else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0)
1262 Resources.maxCombinedTextureImageUnits = value;
1263 else if (strcmp(token, "MaxTextureImageUnits") == 0)
1264 Resources.maxTextureImageUnits = value;
1265 else if (strcmp(token, "MaxFragmentUniformComponents") == 0)
1266 Resources.maxFragmentUniformComponents = value;
1267 else if (strcmp(token, "MaxDrawBuffers") == 0)
1268 Resources.maxDrawBuffers = value;
1269 else if (strcmp(token, "MaxVertexUniformVectors") == 0)
1270 Resources.maxVertexUniformVectors = value;
1271 else if (strcmp(token, "MaxVaryingVectors") == 0)
1272 Resources.maxVaryingVectors = value;
1273 else if (strcmp(token, "MaxFragmentUniformVectors") == 0)
1274 Resources.maxFragmentUniformVectors = value;
1275 else if (strcmp(token, "MaxVertexOutputVectors") == 0)
1276 Resources.maxVertexOutputVectors = value;
1277 else if (strcmp(token, "MaxFragmentInputVectors") == 0)
1278 Resources.maxFragmentInputVectors = value;
1279 else if (strcmp(token, "MinProgramTexelOffset") == 0)
1280 Resources.minProgramTexelOffset = value;
1281 else if (strcmp(token, "MaxProgramTexelOffset") == 0)
1282 Resources.maxProgramTexelOffset = value;
1283 else if (strcmp(token, "MaxClipDistances") == 0)
1284 Resources.maxClipDistances = value;
1285 else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0)
1286 Resources.maxComputeWorkGroupCountX = value;
1287 else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0)
1288 Resources.maxComputeWorkGroupCountY = value;
1289 else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0)
1290 Resources.maxComputeWorkGroupCountZ = value;
1291 else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0)
1292 Resources.maxComputeWorkGroupSizeX = value;
1293 else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0)
1294 Resources.maxComputeWorkGroupSizeY = value;
1295 else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0)
1296 Resources.maxComputeWorkGroupSizeZ = value;
1297 else if (strcmp(token, "MaxComputeUniformComponents") == 0)
1298 Resources.maxComputeUniformComponents = value;
1299 else if (strcmp(token, "MaxComputeTextureImageUnits") == 0)
1300 Resources.maxComputeTextureImageUnits = value;
1301 else if (strcmp(token, "MaxComputeImageUniforms") == 0)
1302 Resources.maxComputeImageUniforms = value;
1303 else if (strcmp(token, "MaxComputeAtomicCounters") == 0)
1304 Resources.maxComputeAtomicCounters = value;
1305 else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0)
1306 Resources.maxComputeAtomicCounterBuffers = value;
1307 else if (strcmp(token, "MaxVaryingComponents") == 0)
1308 Resources.maxVaryingComponents = value;
1309 else if (strcmp(token, "MaxVertexOutputComponents") == 0)
1310 Resources.maxVertexOutputComponents = value;
1311 else if (strcmp(token, "MaxGeometryInputComponents") == 0)
1312 Resources.maxGeometryInputComponents = value;
1313 else if (strcmp(token, "MaxGeometryOutputComponents") == 0)
1314 Resources.maxGeometryOutputComponents = value;
1315 else if (strcmp(token, "MaxFragmentInputComponents") == 0)
1316 Resources.maxFragmentInputComponents = value;
1317 else if (strcmp(token, "MaxImageUnits") == 0)
1318 Resources.maxImageUnits = value;
1319 else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0)
1320 Resources.maxCombinedImageUnitsAndFragmentOutputs = value;
1321 else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0)
1322 Resources.maxCombinedShaderOutputResources = value;
1323 else if (strcmp(token, "MaxImageSamples") == 0)
1324 Resources.maxImageSamples = value;
1325 else if (strcmp(token, "MaxVertexImageUniforms") == 0)
1326 Resources.maxVertexImageUniforms = value;
1327 else if (strcmp(token, "MaxTessControlImageUniforms") == 0)
1328 Resources.maxTessControlImageUniforms = value;
1329 else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0)
1330 Resources.maxTessEvaluationImageUniforms = value;
1331 else if (strcmp(token, "MaxGeometryImageUniforms") == 0)
1332 Resources.maxGeometryImageUniforms = value;
1333 else if (strcmp(token, "MaxFragmentImageUniforms") == 0)
1334 Resources.maxFragmentImageUniforms = value;
1335 else if (strcmp(token, "MaxCombinedImageUniforms") == 0)
1336 Resources.maxCombinedImageUniforms = value;
1337 else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0)
1338 Resources.maxGeometryTextureImageUnits = value;
1339 else if (strcmp(token, "MaxGeometryOutputVertices") == 0)
1340 Resources.maxGeometryOutputVertices = value;
1341 else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0)
1342 Resources.maxGeometryTotalOutputComponents = value;
1343 else if (strcmp(token, "MaxGeometryUniformComponents") == 0)
1344 Resources.maxGeometryUniformComponents = value;
1345 else if (strcmp(token, "MaxGeometryVaryingComponents") == 0)
1346 Resources.maxGeometryVaryingComponents = value;
1347 else if (strcmp(token, "MaxTessControlInputComponents") == 0)
1348 Resources.maxTessControlInputComponents = value;
1349 else if (strcmp(token, "MaxTessControlOutputComponents") == 0)
1350 Resources.maxTessControlOutputComponents = value;
1351 else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0)
1352 Resources.maxTessControlTextureImageUnits = value;
1353 else if (strcmp(token, "MaxTessControlUniformComponents") == 0)
1354 Resources.maxTessControlUniformComponents = value;
1355 else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0)
1356 Resources.maxTessControlTotalOutputComponents = value;
1357 else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0)
1358 Resources.maxTessEvaluationInputComponents = value;
1359 else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0)
1360 Resources.maxTessEvaluationOutputComponents = value;
1361 else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0)
1362 Resources.maxTessEvaluationTextureImageUnits = value;
1363 else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0)
1364 Resources.maxTessEvaluationUniformComponents = value;
1365 else if (strcmp(token, "MaxTessPatchComponents") == 0)
1366 Resources.maxTessPatchComponents = value;
1367 else if (strcmp(token, "MaxPatchVertices") == 0)
1368 Resources.maxPatchVertices = value;
1369 else if (strcmp(token, "MaxTessGenLevel") == 0)
1370 Resources.maxTessGenLevel = value;
1371 else if (strcmp(token, "MaxViewports") == 0)
1372 Resources.maxViewports = value;
1373 else if (strcmp(token, "MaxVertexAtomicCounters") == 0)
1374 Resources.maxVertexAtomicCounters = value;
1375 else if (strcmp(token, "MaxTessControlAtomicCounters") == 0)
1376 Resources.maxTessControlAtomicCounters = value;
1377 else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0)
1378 Resources.maxTessEvaluationAtomicCounters = value;
1379 else if (strcmp(token, "MaxGeometryAtomicCounters") == 0)
1380 Resources.maxGeometryAtomicCounters = value;
1381 else if (strcmp(token, "MaxFragmentAtomicCounters") == 0)
1382 Resources.maxFragmentAtomicCounters = value;
1383 else if (strcmp(token, "MaxCombinedAtomicCounters") == 0)
1384 Resources.maxCombinedAtomicCounters = value;
1385 else if (strcmp(token, "MaxAtomicCounterBindings") == 0)
1386 Resources.maxAtomicCounterBindings = value;
1387 else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0)
1388 Resources.maxVertexAtomicCounterBuffers = value;
1389 else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0)
1390 Resources.maxTessControlAtomicCounterBuffers = value;
1391 else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0)
1392 Resources.maxTessEvaluationAtomicCounterBuffers = value;
1393 else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0)
1394 Resources.maxGeometryAtomicCounterBuffers = value;
1395 else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0)
1396 Resources.maxFragmentAtomicCounterBuffers = value;
1397 else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0)
1398 Resources.maxCombinedAtomicCounterBuffers = value;
1399 else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0)
1400 Resources.maxAtomicCounterBufferSize = value;
1401 else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0)
1402 Resources.maxTransformFeedbackBuffers = value;
1403 else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0)
1404 Resources.maxTransformFeedbackInterleavedComponents = value;
1405 else if (strcmp(token, "MaxCullDistances") == 0)
1406 Resources.maxCullDistances = value;
1407 else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0)
1408 Resources.maxCombinedClipAndCullDistances = value;
1409 else if (strcmp(token, "MaxSamples") == 0)
1410 Resources.maxSamples = value;
1411
1412 else if (strcmp(token, "nonInductiveForLoops") == 0)
1413 Resources.limits.nonInductiveForLoops = (value != 0);
1414 else if (strcmp(token, "whileLoops") == 0)
1415 Resources.limits.whileLoops = (value != 0);
1416 else if (strcmp(token, "doWhileLoops") == 0)
1417 Resources.limits.doWhileLoops = (value != 0);
1418 else if (strcmp(token, "generalUniformIndexing") == 0)
1419 Resources.limits.generalUniformIndexing = (value != 0);
1420 else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0)
1421 Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0);
1422 else if (strcmp(token, "generalVaryingIndexing") == 0)
1423 Resources.limits.generalVaryingIndexing = (value != 0);
1424 else if (strcmp(token, "generalSamplerIndexing") == 0)
1425 Resources.limits.generalSamplerIndexing = (value != 0);
1426 else if (strcmp(token, "generalVariableIndexing") == 0)
1427 Resources.limits.generalVariableIndexing = (value != 0);
1428 else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0)
1429 Resources.limits.generalConstantMatrixVectorIndexing = (value != 0);
1430 else
1431 printf("Warning: unrecognized limit (%s) in configuration file.\n", token);
1432
1433 token = strtok(0, delims);
1434 }
1435 if (configStrings)
1436 FreeFileData(configStrings);
1437}
1438
Tony Barbour6918cd52015-04-09 12:58:51 -06001439void VkTestFramework::SetMessageOptions(EShMessages& messages)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001440{
1441 if (m_compile_options & EOptionRelaxedErrors)
1442 messages = (EShMessages)(messages | EShMsgRelaxedErrors);
1443 if (m_compile_options & EOptionIntermediate)
1444 messages = (EShMessages)(messages | EShMsgAST);
1445 if (m_compile_options & EOptionSuppressWarnings)
1446 messages = (EShMessages)(messages | EShMsgSuppressWarnings);
1447}
1448
1449//
1450// Malloc a string of sufficient size and read a string into it.
1451//
Tony Barbour6918cd52015-04-09 12:58:51 -06001452char** VkTestFramework::ReadFileData(const char* fileName)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001453{
1454 FILE *in;
1455 #if defined(_WIN32) && defined(__GNUC__)
1456 in = fopen(fileName, "r");
1457 int errorCode = in ? 0 : 1;
1458 #else
1459 int errorCode = fopen_s(&in, fileName, "r");
1460 #endif
1461
1462 char *fdata;
1463 int count = 0;
1464 const int maxSourceStrings = 5;
1465 char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1));
1466
1467 if (errorCode) {
1468 printf("Error: unable to open input file: %s\n", fileName);
1469 return 0;
1470 }
1471
1472 while (fgetc(in) != EOF)
1473 count++;
1474
1475 fseek(in, 0, SEEK_SET);
1476
1477 if (!(fdata = (char*)malloc(count+2))) {
1478 printf("Error allocating memory\n");
1479 return 0;
1480 }
1481 if (fread(fdata,1,count, in)!=count) {
1482 printf("Error reading input file: %s\n", fileName);
1483 return 0;
1484 }
1485 fdata[count] = '\0';
1486 fclose(in);
1487 if (count == 0) {
1488 return_data[0]=(char*)malloc(count+2);
1489 return_data[0][0]='\0';
1490 m_num_shader_strings = 0;
1491 return return_data;
1492 } else
1493 m_num_shader_strings = 1;
1494
1495 int len = (int)(ceil)((float)count/(float)m_num_shader_strings);
1496 int ptr_len=0,i=0;
1497 while(count>0){
1498 return_data[i]=(char*)malloc(len+2);
1499 memcpy(return_data[i],fdata+ptr_len,len);
1500 return_data[i][len]='\0';
1501 count-=(len);
1502 ptr_len+=(len);
1503 if(count<len){
1504 if(count==0){
1505 m_num_shader_strings=(i+1);
1506 break;
1507 }
1508 len = count;
1509 }
1510 ++i;
1511 }
1512 return return_data;
1513}
1514
Tony Barbour6918cd52015-04-09 12:58:51 -06001515void VkTestFramework::FreeFileData(char** data)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001516{
1517 for(int i=0;i<m_num_shader_strings;i++)
1518 free(data[i]);
1519}
1520
1521//
1522// Deduce the language from the filename. Files must end in one of the
1523// following extensions:
1524//
1525// .vert = vertex
1526// .tesc = tessellation control
1527// .tese = tessellation evaluation
1528// .geom = geometry
1529// .frag = fragment
1530// .comp = compute
1531//
Tony Barbour6918cd52015-04-09 12:58:51 -06001532EShLanguage VkTestFramework::FindLanguage(const std::string& name)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001533{
1534 size_t ext = name.rfind('.');
1535 if (ext == std::string::npos) {
1536 return EShLangVertex;
1537 }
1538
1539 std::string suffix = name.substr(ext + 1, std::string::npos);
1540 if (suffix == "vert")
1541 return EShLangVertex;
1542 else if (suffix == "tesc")
1543 return EShLangTessControl;
1544 else if (suffix == "tese")
1545 return EShLangTessEvaluation;
1546 else if (suffix == "geom")
1547 return EShLangGeometry;
1548 else if (suffix == "frag")
1549 return EShLangFragment;
1550 else if (suffix == "comp")
1551 return EShLangCompute;
1552
1553 return EShLangVertex;
1554}
1555
1556//
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001557// Convert VK shader type to compiler's
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001558//
Tony Barbourd1c35722015-04-16 15:59:00 -06001559EShLanguage VkTestFramework::FindLanguage(const VkShaderStage shader_type)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001560{
1561 switch (shader_type) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001562 case VK_SHADER_STAGE_VERTEX:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001563 return EShLangVertex;
1564
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001565 case VK_SHADER_STAGE_TESS_CONTROL:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001566 return EShLangTessControl;
1567
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001568 case VK_SHADER_STAGE_TESS_EVALUATION:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001569 return EShLangTessEvaluation;
1570
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001571 case VK_SHADER_STAGE_GEOMETRY:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001572 return EShLangGeometry;
1573
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001574 case VK_SHADER_STAGE_FRAGMENT:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001575 return EShLangFragment;
1576
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001577 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001578 return EShLangCompute;
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001579
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001580 default:
1581 return EShLangVertex;
1582 }
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001583}
1584
1585
1586//
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001587// Compile a given string containing GLSL into SPV for use by VK
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001588// Return value of false means an error was encountered.
1589//
Tony Barbourd1c35722015-04-16 15:59:00 -06001590bool VkTestFramework::GLSLtoSPV(const VkShaderStage shader_type,
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001591 const char *pshader,
Cody Northrop5a95b472015-06-03 13:01:54 -06001592 std::vector<unsigned int> &spirv)
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001593{
1594 glslang::TProgram& program = *new glslang::TProgram;
1595 const char *shaderStrings[1];
1596
1597 // TODO: Do we want to load a special config file depending on the
1598 // shader source? Optional name maybe?
1599 // SetConfigFile(fileName);
1600
1601 ProcessConfigFile();
1602
1603 EShMessages messages = EShMsgDefault;
1604 SetMessageOptions(messages);
1605
1606 EShLanguage stage = FindLanguage(shader_type);
1607 glslang::TShader* shader = new glslang::TShader(stage);
1608
1609 shaderStrings[0] = pshader;
1610 shader->setStrings(shaderStrings, 1);
1611
1612 if (! shader->parse(&Resources, (m_compile_options & EOptionDefaultDesktop) ? 110 : 100, false, messages)) {
1613
Cody Northrop195d6622014-11-03 12:54:37 -07001614 if (! (m_compile_options & EOptionSuppressInfolog)) {
1615 puts(shader->getInfoLog());
1616 puts(shader->getInfoDebugLog());
1617 }
1618
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001619 return false; // something didn't work
1620 }
1621
1622 program.addShader(shader);
1623
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001624
1625 //
1626 // Program-level processing...
1627 //
1628
Cody Northrop195d6622014-11-03 12:54:37 -07001629 if (! program.link(messages)) {
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001630
Cody Northrop195d6622014-11-03 12:54:37 -07001631 if (! (m_compile_options & EOptionSuppressInfolog)) {
1632 puts(shader->getInfoLog());
1633 puts(shader->getInfoDebugLog());
1634 }
1635
1636 return false;
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001637 }
1638
1639 if (m_compile_options & EOptionDumpReflection) {
1640 program.buildReflection();
1641 program.dumpReflection();
1642 }
1643
Cody Northrop5a95b472015-06-03 13:01:54 -06001644 glslang::GlslangToSpv(*program.getIntermediate(stage), spirv);
1645
1646 //
1647 // Test the different modes of SPIR-V modification
1648 //
1649 if (this->m_canonicalize_spv) {
1650 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::ALL_BUT_STRIP);
1651 }
1652
1653 if (this->m_strip_spv) {
1654 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::STRIP);
1655 }
1656
1657 if (this->m_do_everything_spv) {
1658 spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::DO_EVERYTHING);
1659 }
1660
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -06001661
1662 return true;
1663}
1664
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001665
1666
Tony Barbour6918cd52015-04-09 12:58:51 -06001667VkTestImageRecord::VkTestImageRecord() : // Constructor
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001668 m_width( 0 ),
1669 m_height( 0 ),
Chia-I Wu837f9952014-12-15 23:29:34 +08001670 m_data( NULL ),
1671 m_data_size( 0 )
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001672{
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001673}
1674
Tony Barbour6918cd52015-04-09 12:58:51 -06001675VkTestImageRecord::~VkTestImageRecord()
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001676{
1677
1678}
1679
Tony Barbour6918cd52015-04-09 12:58:51 -06001680VkTestImageRecord::VkTestImageRecord(const VkTestImageRecord &copyin) // Copy constructor to handle pass by value.
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001681{
1682 m_title = copyin.m_title;
1683 m_width = copyin.m_width;
1684 m_height = copyin.m_height;
1685 m_data_size = copyin.m_data_size;
1686 m_data = copyin.m_data; // TODO: Do we need to copy the data or is pointer okay?
1687}
1688
Tony Barbour6918cd52015-04-09 12:58:51 -06001689ostream &operator<<(ostream &output, const VkTestImageRecord &VkTestImageRecord)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001690{
Tony Barbour6918cd52015-04-09 12:58:51 -06001691 output << VkTestImageRecord.m_title << " (" << VkTestImageRecord.m_width <<
1692 "," << VkTestImageRecord.m_height << ")" << endl;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001693 return output;
1694}
1695
Tony Barbour6918cd52015-04-09 12:58:51 -06001696VkTestImageRecord& VkTestImageRecord::operator=(const VkTestImageRecord &rhs)
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001697{
1698 m_title = rhs.m_title;
1699 m_width = rhs.m_width;
1700 m_height = rhs.m_height;
1701 m_data_size = rhs.m_data_size;
1702 m_data = rhs.m_data;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001703 return *this;
1704}
1705
Tony Barbour6918cd52015-04-09 12:58:51 -06001706int VkTestImageRecord::operator==(const VkTestImageRecord &rhs) const
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001707{
1708 if( this->m_data != rhs.m_data) return 0;
1709 return 1;
1710}
1711
1712// This function is required for built-in STL list functions like sort
Tony Barbour6918cd52015-04-09 12:58:51 -06001713int VkTestImageRecord::operator<(const VkTestImageRecord &rhs) const
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001714{
1715 if( this->m_data_size < rhs.m_data_size ) return 1;
1716 return 0;
1717}
1718