Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // VK tests |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 2 | // |
| 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 23 | #include "vktestframework.h" |
| 24 | #include "vkrenderframework.h" |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 25 | #include "SPIRV/GlslangToSpv.h" |
| 26 | #include "SPIRV/SPVRemapper.h" |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 27 | #include <limits.h> |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 28 | #include <math.h> |
Chia-I Wu | ec664fa | 2014-12-02 11:54:24 +0800 | [diff] [blame] | 29 | #include <wand/MagickWand.h> |
Tony Barbour | feb6196 | 2015-09-21 15:17:33 -0600 | [diff] [blame] | 30 | #ifndef _WIN32 |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 31 | #include <xcb/xcb.h> |
Tony Barbour | feb6196 | 2015-09-21 15:17:33 -0600 | [diff] [blame] | 32 | #endif |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 33 | #include "vk_ext_khr_swapchain.h" |
| 34 | #include "vk_ext_khr_device_swapchain.h" |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 35 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 36 | #if defined(PATH_MAX) && !defined(MAX_PATH) |
| 37 | #define MAX_PATH PATH_MAX |
| 38 | #endif |
| 39 | |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 40 | #ifdef _WIN32 |
| 41 | #define ERR_EXIT(err_msg, err_class) \ |
| 42 | do { \ |
| 43 | MessageBox(NULL, err_msg, err_class, MB_OK); \ |
| 44 | exit(1); \ |
| 45 | } while (0) |
| 46 | #else // _WIN32 |
| 47 | |
| 48 | #define ERR_EXIT(err_msg, err_class) \ |
| 49 | do { \ |
| 50 | printf(err_msg); \ |
| 51 | fflush(stdout); \ |
| 52 | exit(1); \ |
| 53 | } while (0) |
| 54 | #endif // _WIN32 |
| 55 | |
| 56 | #define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \ |
| 57 | { \ |
| 58 | m_fp##entrypoint = (PFN_vk##entrypoint) vkGetInstanceProcAddr(inst, "vk"#entrypoint); \ |
| 59 | if (m_fp##entrypoint == NULL) { \ |
| 60 | ERR_EXIT("vkGetInstanceProcAddr failed to find vk"#entrypoint, \ |
| 61 | "vkGetInstanceProcAddr Failure"); \ |
| 62 | } \ |
| 63 | } |
| 64 | |
| 65 | #define GET_DEVICE_PROC_ADDR(dev, entrypoint) \ |
| 66 | { \ |
| 67 | m_fp##entrypoint = (PFN_vk##entrypoint) vkGetDeviceProcAddr(dev, "vk"#entrypoint); \ |
| 68 | if (m_fp##entrypoint == NULL) { \ |
| 69 | ERR_EXIT("vkGetDeviceProcAddr failed to find vk"#entrypoint, \ |
| 70 | "vkGetDeviceProcAddr Failure"); \ |
| 71 | } \ |
| 72 | } |
| 73 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 74 | // Command-line options |
| 75 | enum TOptions { |
| 76 | EOptionNone = 0x000, |
| 77 | EOptionIntermediate = 0x001, |
| 78 | EOptionSuppressInfolog = 0x002, |
| 79 | EOptionMemoryLeakMode = 0x004, |
| 80 | EOptionRelaxedErrors = 0x008, |
| 81 | EOptionGiveWarnings = 0x010, |
| 82 | EOptionLinkProgram = 0x020, |
| 83 | EOptionMultiThreaded = 0x040, |
| 84 | EOptionDumpConfig = 0x080, |
| 85 | EOptionDumpReflection = 0x100, |
| 86 | EOptionSuppressWarnings = 0x200, |
| 87 | EOptionDumpVersions = 0x400, |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 88 | EOptionSpv = 0x800, |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 89 | EOptionDefaultDesktop = 0x1000, |
| 90 | }; |
| 91 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 92 | typedef struct _SwapchainBuffers { |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 93 | VkImage image; |
| 94 | VkCmdBuffer cmd; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 95 | VkImageView view; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 96 | } SwapchainBuffers; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 97 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 98 | class TestFrameworkVkPresent |
| 99 | { |
| 100 | public: |
| 101 | TestFrameworkVkPresent(vk_testing::Device &device); |
| 102 | |
| 103 | void Run(); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 104 | void InitPresentFramework(std::list<VkTestImageRecord> &imagesIn, VkInstance inst); |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 105 | void CreateMyWindow(); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 106 | void CreateSwapchain(); |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 107 | void TearDown(); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 108 | #ifdef _WIN32 |
| 109 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
| 110 | #endif |
| 111 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 112 | |
| 113 | protected: |
| 114 | vk_testing::Device &m_device; |
| 115 | vk_testing::Queue &m_queue; |
Dana Jansens | 233a0ea | 2015-07-30 13:04:16 -0700 | [diff] [blame] | 116 | vk_testing::CmdPool m_cmdpool; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 117 | vk_testing::CmdBuffer m_cmdbuf; |
| 118 | |
| 119 | private: |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 120 | #ifdef _WIN32 |
| 121 | HINSTANCE m_connection; // hInstance - Windows Instance |
| 122 | HWND m_window; // hWnd - window handle |
| 123 | |
| 124 | #else |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 125 | xcb_connection_t *m_connection; |
| 126 | xcb_screen_t *m_screen; |
| 127 | xcb_window_t m_window; |
| 128 | xcb_intern_atom_reply_t *m_atom_wm_delete_window; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 129 | VkPlatformHandleXcbKHR m_platform_handle_xcb; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 130 | #endif |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 131 | std::list<VkTestImageRecord> m_images; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 132 | uint32_t m_present_queue_node_index; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 133 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 134 | PFN_vkGetPhysicalDeviceSurfaceSupportKHR m_fpGetPhysicalDeviceSurfaceSupportKHR; |
| 135 | PFN_vkGetSurfacePropertiesKHR m_fpGetSurfacePropertiesKHR; |
| 136 | PFN_vkGetSurfaceFormatsKHR m_fpGetSurfaceFormatsKHR; |
| 137 | PFN_vkGetSurfacePresentModesKHR m_fpGetSurfacePresentModesKHR; |
| 138 | PFN_vkCreateSwapchainKHR m_fpCreateSwapchainKHR; |
| 139 | PFN_vkDestroySwapchainKHR m_fpDestroySwapchainKHR; |
| 140 | PFN_vkGetSwapchainImagesKHR m_fpGetSwapchainImagesKHR; |
| 141 | PFN_vkAcquireNextImageKHR m_fpAcquireNextImageKHR; |
| 142 | PFN_vkQueuePresentKHR m_fpQueuePresentKHR; |
| 143 | VkSurfaceDescriptionWindowKHR m_surface_description; |
| 144 | uint32_t m_swapchainImageCount; |
| 145 | VkSwapchainKHR m_swap_chain; |
| 146 | SwapchainBuffers *m_buffers; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 147 | VkFormat m_format; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 148 | VkColorSpaceKHR m_color_space; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 149 | |
| 150 | uint32_t m_current_buffer; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 151 | |
| 152 | bool m_quit; |
| 153 | bool m_pause; |
| 154 | |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 155 | int m_width; |
| 156 | int m_height; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 157 | |
| 158 | std::list<VkTestImageRecord>::iterator m_display_image; |
| 159 | |
| 160 | void Display(); |
Tony Barbour | feb6196 | 2015-09-21 15:17:33 -0600 | [diff] [blame] | 161 | #ifndef _WIN32 |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 162 | void HandleEvent(xcb_generic_event_t *event); |
Tony Barbour | feb6196 | 2015-09-21 15:17:33 -0600 | [diff] [blame] | 163 | #endif |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 164 | }; |
| 165 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 166 | #ifndef _WIN32 |
| 167 | |
| 168 | #include <errno.h> |
| 169 | |
| 170 | int fopen_s( |
| 171 | FILE** pFile, |
| 172 | const char* filename, |
| 173 | const char* mode |
| 174 | ) |
| 175 | { |
| 176 | if (!pFile || !filename || !mode) { |
| 177 | return EINVAL; |
| 178 | } |
| 179 | |
| 180 | FILE* f = fopen(filename, mode); |
| 181 | if (! f) { |
| 182 | if (errno != 0) { |
| 183 | return errno; |
| 184 | } else { |
| 185 | return ENOENT; |
| 186 | } |
| 187 | } |
| 188 | *pFile = f; |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | #endif |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 194 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 195 | |
| 196 | |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 197 | // Set up environment for GLSL compiler |
| 198 | // Must be done once per process |
| 199 | void TestEnvironment::SetUp() |
| 200 | { |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 201 | // Initialize GLSL to SPV compiler utility |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 202 | glslang::InitializeProcess(); |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 203 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 204 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void TestEnvironment::TearDown() |
| 208 | { |
| 209 | glslang::FinalizeProcess(); |
| 210 | } |
| 211 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 212 | VkTestFramework::VkTestFramework() : |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 213 | m_compile_options( 0 ), |
| 214 | m_num_shader_strings( 0 ) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 215 | { |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 216 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 217 | } |
| 218 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 219 | VkTestFramework::~VkTestFramework() |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 220 | { |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 221 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | // Define all the static elements |
Cody Northrop | a3673cf | 2015-06-09 13:00:45 -0600 | [diff] [blame] | 225 | bool VkTestFramework::m_show_images = false; |
| 226 | bool VkTestFramework::m_save_images = false; |
| 227 | bool VkTestFramework::m_compare_images = false; |
| 228 | bool VkTestFramework::m_use_glsl = false; |
| 229 | bool VkTestFramework::m_canonicalize_spv = false; |
| 230 | bool VkTestFramework::m_strip_spv = false; |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 231 | bool VkTestFramework::m_do_everything_spv = false; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 232 | int VkTestFramework::m_width = 0; |
| 233 | int VkTestFramework::m_height = 0; |
| 234 | std::list<VkTestImageRecord> VkTestFramework::m_images; |
| 235 | std::list<VkTestImageRecord>::iterator VkTestFramework::m_display_image; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 236 | int m_display_image_idx = 0; |
| 237 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 238 | bool VkTestFramework::optionMatch(const char* option, char* optionLine) |
| 239 | { |
| 240 | if (strncmp(option, optionLine, strlen(option)) == 0) |
| 241 | return true; |
| 242 | else |
| 243 | return false; |
| 244 | } |
| 245 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 246 | void VkTestFramework::InitArgs(int *argc, char *argv[]) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 247 | { |
| 248 | int i, n; |
| 249 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 250 | for (i=1, n=1; i< *argc; i++) { |
| 251 | if (optionMatch("--show-images", argv[i])) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 252 | m_show_images = true; |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 253 | else if (optionMatch("--save-images", argv[i])) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 254 | m_save_images = true; |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 255 | else if (optionMatch("--no-SPV", argv[i])) |
| 256 | m_use_glsl = true; |
| 257 | else if (optionMatch("--strip-SPV", argv[i])) |
| 258 | m_strip_spv = true; |
| 259 | else if (optionMatch("--canonicalize-SPV", argv[i])) |
| 260 | m_canonicalize_spv = true; |
| 261 | else if (optionMatch("--compare-images", argv[i])) |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 262 | m_compare_images = true; |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 263 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 264 | else if (optionMatch("--help", argv[i]) || |
| 265 | optionMatch("-h", argv[i])) { |
Courtney Goeltzenleuchter | 31144b7 | 2014-12-02 13:13:10 -0700 | [diff] [blame] | 266 | printf("\nOther options:\n"); |
| 267 | printf("\t--show-images\n" |
| 268 | "\t\tDisplay test images in viewer after tests complete.\n"); |
| 269 | printf("\t--save-images\n" |
| 270 | "\t\tSave tests images as ppm files in current working directory.\n" |
| 271 | "\t\tUsed to generate golden images for compare-images.\n"); |
| 272 | printf("\t--compare-images\n" |
| 273 | "\t\tCompare test images to 'golden' image in golden folder.\n" |
Tony Barbour | a98d393 | 2014-12-11 09:52:49 -0700 | [diff] [blame] | 274 | "\t\tAlso saves the generated test image in current working\n" |
| 275 | "\t\t\tdirectory but only if the image is different from the golden\n" |
| 276 | "\t\tSetting RENDERTEST_GOLDEN_DIR environment variable can specify\n" |
| 277 | "\t\t\tdifferent directory for golden images\n" |
Courtney Goeltzenleuchter | 31144b7 | 2014-12-02 13:13:10 -0700 | [diff] [blame] | 278 | "\t\tSignal test failure if different.\n"); |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 279 | printf("\t--no-SPV\n" |
| 280 | "\t\tUse built-in GLSL compiler rather than SPV code path.\n"); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 281 | printf("\t--strip-SPV\n" |
Cody Northrop | a9bad9c | 2015-07-13 12:48:41 -0600 | [diff] [blame] | 282 | "\t\tStrip SPIR-V debug information (line numbers, names, etc).\n"); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 283 | printf("\t--canonicalize-SPV\n" |
Cody Northrop | a9bad9c | 2015-07-13 12:48:41 -0600 | [diff] [blame] | 284 | "\t\tRemap SPIR-V ids before submission to aid compression.\n"); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 285 | exit(0); |
| 286 | } else { |
| 287 | printf("\nUnrecognized option: %s\n", argv[i]); |
| 288 | printf("\nUse --help or -h for option list.\n"); |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 289 | exit(0); |
Courtney Goeltzenleuchter | 31144b7 | 2014-12-02 13:13:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 292 | /* |
| 293 | * Since the above "consume" inputs, update argv |
| 294 | * so that it contains the trimmed list of args for glutInit |
| 295 | */ |
| 296 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 297 | argv[n] = argv[i]; |
| 298 | n++; |
| 299 | } |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 300 | } |
| 301 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 302 | void VkTestFramework::WritePPM( const char *basename, VkImageObj *image ) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 303 | { |
| 304 | string filename; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | VkResult err; |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 306 | uint32_t x, y; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 307 | VkImageObj displayImage(image->device()); |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 308 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 309 | |
Tony Barbour | e65788f | 2015-07-21 17:01:42 -0600 | [diff] [blame] | 310 | displayImage.init(image->extent().width, image->extent().height, image->format(), VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, VK_IMAGE_TILING_LINEAR, reqs); |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 311 | displayImage.CopyImage(*image); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 312 | |
| 313 | filename.append(basename); |
| 314 | filename.append(".ppm"); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 315 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 316 | const VkImageSubresource sr = { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 317 | VK_IMAGE_ASPECT_COLOR, 0, 0 |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 318 | }; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 319 | VkSubresourceLayout sr_layout; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 320 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 321 | err = vkGetImageSubresourceLayout(image->device()->device(), displayImage.image(), &sr, &sr_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 322 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 323 | |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 324 | char *ptr; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 325 | ptr = (char *) displayImage.MapMemory(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 326 | ptr += sr_layout.offset; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 327 | ofstream file (filename.c_str(), ios::binary); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 328 | ASSERT_TRUE(file.is_open()) << "Unable to open file: " << filename; |
| 329 | |
| 330 | file << "P6\n"; |
Tony Barbour | feb6196 | 2015-09-21 15:17:33 -0600 | [diff] [blame] | 331 | file << displayImage.width() << " "; |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 332 | file << displayImage.height() << "\n"; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 333 | file << 255 << "\n"; |
| 334 | |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 335 | for (y = 0; y < displayImage.height(); y++) { |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 336 | const int *row = (const int *) ptr; |
| 337 | int swapped; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 338 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 339 | if (displayImage.format() == VK_FORMAT_B8G8R8A8_UNORM) |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 340 | { |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 341 | for (x = 0; x < displayImage.width(); x++) { |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 342 | swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16; |
| 343 | file.write((char *) &swapped, 3); |
| 344 | row++; |
| 345 | } |
| 346 | } |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 347 | else if (displayImage.format() == VK_FORMAT_R8G8B8A8_UNORM) |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 348 | { |
Tony Barbour | 84d448c | 2015-04-02 14:02:33 -0600 | [diff] [blame] | 349 | for (x = 0; x < displayImage.width(); x++) { |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 350 | file.write((char *) row, 3); |
| 351 | row++; |
| 352 | } |
| 353 | } |
| 354 | else { |
| 355 | printf("Unrecognized image format - will not write image files"); |
| 356 | break; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | ptr += sr_layout.rowPitch; |
| 360 | } |
| 361 | |
| 362 | file.close(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 363 | displayImage.UnmapMemory(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 364 | } |
| 365 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 366 | void VkTestFramework::Compare(const char *basename, VkImageObj *image ) |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 367 | { |
| 368 | |
| 369 | MagickWand *magick_wand_1; |
| 370 | MagickWand *magick_wand_2; |
| 371 | MagickWand *compare_wand; |
| 372 | MagickBooleanType status; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 373 | char testimage[256],golden[MAX_PATH+256],golddir[MAX_PATH] = "./golden"; |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 374 | double differenz; |
| 375 | |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 376 | if (getenv("RENDERTEST_GOLDEN_DIR")) |
| 377 | { |
| 378 | strcpy(golddir,getenv("RENDERTEST_GOLDEN_DIR")); |
| 379 | } |
| 380 | |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 381 | MagickWandGenesis(); |
| 382 | magick_wand_1=NewMagickWand(); |
| 383 | sprintf(testimage,"%s.ppm",basename); |
| 384 | status=MagickReadImage(magick_wand_1,testimage); |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 385 | ASSERT_EQ(status, MagickTrue) << "Unable to open file: " << testimage; |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 386 | |
| 387 | |
| 388 | MagickWandGenesis(); |
| 389 | magick_wand_2=NewMagickWand(); |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 390 | sprintf(golden,"%s/%s.ppm",golddir,basename); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 391 | status=MagickReadImage(magick_wand_2,golden); |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 392 | ASSERT_EQ(status, MagickTrue) << "Unable to open file: " << golden; |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 393 | |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 394 | compare_wand=MagickCompareImages(magick_wand_1,magick_wand_2, MeanAbsoluteErrorMetric, &differenz); |
| 395 | if (differenz != 0.0) |
| 396 | { |
| 397 | char difference[256]; |
| 398 | |
| 399 | sprintf(difference,"%s-diff.ppm",basename); |
| 400 | status = MagickWriteImage(compare_wand, difference); |
| 401 | ASSERT_TRUE(differenz == 0.0) << "Image comparison failed - diff file written"; |
| 402 | } |
| 403 | DestroyMagickWand(compare_wand); |
| 404 | |
| 405 | DestroyMagickWand(magick_wand_1); |
| 406 | DestroyMagickWand(magick_wand_2); |
| 407 | MagickWandTerminus(); |
Courtney Goeltzenleuchter | fcda72d | 2014-12-05 15:41:02 -0700 | [diff] [blame] | 408 | |
| 409 | if (differenz == 0.0) |
| 410 | { |
| 411 | /* |
| 412 | * If test image and golden image match, we do not need to |
| 413 | * keep around the test image. |
| 414 | */ |
| 415 | remove(testimage); |
| 416 | } |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 417 | } |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 418 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 419 | void VkTestFramework::Show(const char *comment, VkImageObj *image) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 420 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 421 | VkResult err; |
Courtney Goeltzenleuchter | fcf43ab | 2015-04-29 10:53:31 -0600 | [diff] [blame] | 422 | VkSubresourceLayout sr_layout; |
| 423 | char *ptr; |
| 424 | VkTestImageRecord record; |
Courtney Goeltzenleuchter | fcf43ab | 2015-04-29 10:53:31 -0600 | [diff] [blame] | 425 | VkImageObj displayImage(image->device()); |
| 426 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 427 | |
Cody Northrop | c9a6991 | 2015-06-18 17:05:15 -0600 | [diff] [blame] | 428 | displayImage.init(image->extent().width, image->extent().height, image->format(), VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, VK_IMAGE_TILING_LINEAR, reqs); |
| 429 | |
Courtney Goeltzenleuchter | fcf43ab | 2015-04-29 10:53:31 -0600 | [diff] [blame] | 430 | displayImage.CopyImage(*image); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 431 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 432 | const VkImageSubresource sr = { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 433 | VK_IMAGE_ASPECT_COLOR, 0, 0 |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 434 | }; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 435 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 436 | err = vkGetImageSubresourceLayout(displayImage.device()->device(), displayImage.image(), &sr, &sr_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 437 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 438 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 439 | ptr = (char *) displayImage.MapMemory(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 440 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 441 | |
| 442 | ptr += sr_layout.offset; |
| 443 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 444 | record.m_title.append(comment); |
Courtney Goeltzenleuchter | fcf43ab | 2015-04-29 10:53:31 -0600 | [diff] [blame] | 445 | record.m_width = displayImage.width(); |
| 446 | record.m_height = displayImage.height(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 447 | // TODO: Need to make this more robust to handle different image formats |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 448 | record.m_data_size = displayImage.width() * displayImage.height() * 4; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 449 | record.m_data = malloc(record.m_data_size); |
| 450 | memcpy(record.m_data, ptr, record.m_data_size); |
| 451 | m_images.push_back(record); |
| 452 | m_display_image = --m_images.end(); |
| 453 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 454 | displayImage.UnmapMemory(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 455 | } |
| 456 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 457 | void VkTestFramework::RecordImages(vector<VkImageObj *> images) |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 458 | { |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 459 | for (int32_t i = 0; i < images.size(); i++) { |
| 460 | RecordImage(images[i]); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 464 | void VkTestFramework::RecordImage(VkImageObj * image) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 465 | { |
| 466 | const ::testing::TestInfo* const test_info = |
| 467 | ::testing::UnitTest::GetInstance()->current_test_info(); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 468 | ostringstream filestream; |
| 469 | string filename; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 470 | |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 471 | m_width = 40; |
| 472 | |
| 473 | if (strcmp(test_info->name(), m_testName.c_str())) { |
| 474 | filestream << test_info->name(); |
| 475 | m_testName.assign(test_info->name()); |
Tony Barbour | a0e2ee8 | 2014-11-18 17:02:36 -0700 | [diff] [blame] | 476 | m_frameNum = 2; |
| 477 | filename = filestream.str(); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 478 | } |
| 479 | else { |
| 480 | filestream << test_info->name() << "-" << m_frameNum; |
| 481 | m_frameNum++; |
Tony Barbour | a0e2ee8 | 2014-11-18 17:02:36 -0700 | [diff] [blame] | 482 | filename = filestream.str(); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 483 | } |
| 484 | |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 485 | // ToDo - scrub string for bad characters |
| 486 | |
| 487 | if (m_save_images || m_compare_images) { |
| 488 | WritePPM(filename.c_str(), image); |
| 489 | if (m_compare_images) { |
| 490 | Compare(filename.c_str(), image); |
| 491 | } |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (m_show_images) { |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 495 | Show(test_info->name(), image); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 499 | TestFrameworkVkPresent::TestFrameworkVkPresent(vk_testing::Device &device) : |
| 500 | m_device(device), |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 501 | m_queue(*m_device.graphics_queues()[0]), |
Dana Jansens | 233a0ea | 2015-07-30 13:04:16 -0700 | [diff] [blame] | 502 | m_cmdpool(m_device, vk_testing::CmdPool::create_info(m_device.graphics_queue_node_index_)), |
| 503 | m_cmdbuf(m_device, vk_testing::CmdBuffer::create_info(m_cmdpool.handle())) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 504 | { |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 505 | m_quit = false; |
| 506 | m_pause = false; |
| 507 | m_width = 0; |
| 508 | m_height = 0; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 509 | } |
| 510 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 511 | void TestFrameworkVkPresent::Display() |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 512 | { |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 513 | VkResult U_ASSERT_ONLY err; |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 514 | vk_testing::Buffer buf; |
| 515 | void *dest_ptr; |
| 516 | |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 517 | VkSemaphore presentCompleteSemaphore; |
| 518 | VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {}; |
| 519 | presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 520 | presentCompleteSemaphoreCreateInfo.pNext = NULL; |
| 521 | presentCompleteSemaphoreCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
| 522 | |
| 523 | |
| 524 | err = vkCreateSemaphore(m_device.handle(), |
| 525 | &presentCompleteSemaphoreCreateInfo, |
| 526 | &presentCompleteSemaphore); |
| 527 | assert(!err); |
| 528 | |
| 529 | // Get the index of the next available swapchain image: |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 530 | err = m_fpAcquireNextImageKHR(m_device.handle(), m_swap_chain, |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 531 | UINT64_MAX, |
| 532 | presentCompleteSemaphore, |
| 533 | &m_current_buffer); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 534 | // TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 535 | // return codes |
| 536 | assert(!err); |
| 537 | |
| 538 | // Wait for the present complete semaphore to be signaled to ensure |
| 539 | // that the image won't be rendered to until the presentation |
| 540 | // engine has fully released ownership to the application, and it is |
| 541 | // okay to render to the image. |
| 542 | vkQueueWaitSemaphore(m_queue.handle(), presentCompleteSemaphore); |
Tony Barbour | 9226a82 | 2015-10-23 10:58:56 -0600 | [diff] [blame^] | 543 | vkDestroySemaphore(m_device.handle(), presentCompleteSemaphore); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 544 | |
| 545 | VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Cody Northrop | 7fb4386 | 2015-06-22 14:56:14 -0600 | [diff] [blame] | 546 | buf.init_as_src(m_device, (VkDeviceSize)m_display_image->m_data_size, flags); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 547 | dest_ptr = buf.memory().map(); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 548 | memcpy(dest_ptr, m_display_image->m_data, m_display_image->m_data_size); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 549 | buf.memory().unmap(); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 550 | |
| 551 | m_cmdbuf.begin(); |
| 552 | |
| 553 | VkBufferImageCopy region = {}; |
| 554 | region.imageExtent.height = m_display_image->m_height; |
| 555 | region.imageExtent.width = m_display_image->m_width; |
| 556 | region.imageExtent.depth = 1; |
| 557 | |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 558 | vkCmdCopyBufferToImage(m_cmdbuf.handle(), |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 559 | buf.handle(), |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 560 | m_buffers[m_current_buffer].image, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL, |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 561 | 1, ®ion); |
| 562 | m_cmdbuf.end(); |
| 563 | |
| 564 | VkCmdBuffer cmdBufs[1]; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 565 | cmdBufs[0] = m_cmdbuf.handle(); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 566 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 567 | VkFence nullFence = { VK_NULL_HANDLE }; |
| 568 | vkQueueSubmit(m_queue.handle(), 1, cmdBufs, nullFence); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 569 | m_queue.wait(); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 570 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 571 | VkPresentInfoKHR present = {}; |
| 572 | present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 573 | present.pNext = NULL; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 574 | present.swapchainCount = 1; |
| 575 | present.swapchains = & m_swap_chain; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 576 | present.imageIndices = &m_current_buffer; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 577 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 578 | #ifndef _WIN32 |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 579 | xcb_change_property (m_connection, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 580 | XCB_PROP_MODE_REPLACE, |
| 581 | m_window, |
| 582 | XCB_ATOM_WM_NAME, |
| 583 | XCB_ATOM_STRING, |
| 584 | 8, |
| 585 | m_display_image->m_title.size(), |
| 586 | m_display_image->m_title.c_str()); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 587 | #endif |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 588 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 589 | err = m_fpQueuePresentKHR(m_queue.handle(), &present); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 590 | assert(!err); |
| 591 | |
| 592 | m_queue.wait(); |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 593 | m_current_buffer = (m_current_buffer + 1) % 2; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 594 | } |
| 595 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 596 | #ifdef _WIN32 |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 597 | # define PREVIOUSLY_DOWN 1<<29 |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 598 | // MS-Windows event handling function: |
| 599 | LRESULT CALLBACK TestFrameworkVkPresent::WndProc(HWND hWnd, |
| 600 | UINT uMsg, |
| 601 | WPARAM wParam, |
| 602 | LPARAM lParam) |
| 603 | { |
| 604 | |
| 605 | switch(uMsg) |
| 606 | { |
| 607 | case WM_CLOSE: |
| 608 | PostQuitMessage(0); |
| 609 | break; |
| 610 | |
| 611 | case WM_PAINT: |
| 612 | { |
| 613 | TestFrameworkVkPresent* me = reinterpret_cast<TestFrameworkVkPresent*>(GetWindowLongPtr(hWnd, GWLP_USERDATA)); |
| 614 | if (me) { |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 615 | SetWindowText(hWnd, me->m_display_image->m_title.c_str()); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 616 | me->Display(); |
| 617 | } |
| 618 | } |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case WM_KEYDOWN: |
| 622 | { |
| 623 | if (lParam & (PREVIOUSLY_DOWN)){ |
| 624 | break; |
| 625 | } |
| 626 | // To be able to be a CALLBACK, WndProc had to be static, so it doesn't get a this pointer. When we created |
| 627 | // the window, we put the this pointer into the window's user data so we could get it back now |
| 628 | TestFrameworkVkPresent* me = reinterpret_cast<TestFrameworkVkPresent*>(GetWindowLongPtr(hWnd, GWLP_USERDATA)); |
| 629 | switch (wParam) |
| 630 | { |
| 631 | case VK_ESCAPE: me->m_quit = true; |
| 632 | break; |
| 633 | |
| 634 | case VK_LEFT: // left arrow key |
| 635 | if (me->m_display_image == me->m_images.begin()) { |
| 636 | me->m_display_image = --me->m_images.end(); |
| 637 | } |
| 638 | else { |
| 639 | --me->m_display_image; |
| 640 | } |
| 641 | break; |
| 642 | |
| 643 | case VK_RIGHT: // right arrow key |
| 644 | ++me->m_display_image; |
| 645 | if (me->m_display_image == me->m_images.end()) { |
| 646 | me->m_display_image = me->m_images.begin(); |
| 647 | } |
| 648 | break; |
| 649 | |
| 650 | default: |
| 651 | break; |
| 652 | } |
| 653 | SetWindowText(hWnd, me->m_display_image->m_title.c_str()); |
| 654 | me->Display(); |
| 655 | } |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 656 | } |
| 657 | return (DefWindowProc(hWnd, uMsg, wParam, lParam)); |
| 658 | } |
| 659 | |
| 660 | void TestFrameworkVkPresent::Run() |
| 661 | { |
| 662 | MSG msg; // message |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 663 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 664 | /* main message loop*/ |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 665 | while(! m_quit) { |
| 666 | GetMessage(&msg, m_window, 0, 0); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 667 | if (msg.message == WM_QUIT) { |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 668 | m_quit = true; //if found, quit app |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 669 | } else { |
| 670 | /* Translate and dispatch to event queue*/ |
| 671 | TranslateMessage(&msg); |
| 672 | DispatchMessage(&msg); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | #else |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 678 | void TestFrameworkVkPresent::HandleEvent(xcb_generic_event_t *event) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 679 | { |
Tony Barbour | 0dd968a | 2015-04-02 15:48:24 -0600 | [diff] [blame] | 680 | uint8_t event_code = event->response_type & 0x7f; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 681 | switch (event_code) { |
| 682 | case XCB_EXPOSE: |
| 683 | Display(); // TODO: handle resize |
| 684 | break; |
| 685 | case XCB_CLIENT_MESSAGE: |
| 686 | if((*(xcb_client_message_event_t*)event).data.data32[0] == |
| 687 | (m_atom_wm_delete_window)->atom) { |
| 688 | m_quit = true; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 689 | } |
| 690 | break; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 691 | case XCB_KEY_RELEASE: |
| 692 | { |
| 693 | const xcb_key_release_event_t *key = |
| 694 | (const xcb_key_release_event_t *) event; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 695 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 696 | switch (key->detail) { |
| 697 | case 0x9: // Escape |
| 698 | m_quit = true; |
| 699 | break; |
| 700 | case 0x71: // left arrow key |
| 701 | if (m_display_image == m_images.begin()) { |
| 702 | m_display_image = --m_images.end(); |
| 703 | } else { |
| 704 | --m_display_image; |
| 705 | } |
| 706 | break; |
| 707 | case 0x72: // right arrow key |
| 708 | ++m_display_image; |
| 709 | if (m_display_image == m_images.end()) { |
| 710 | m_display_image = m_images.begin(); |
| 711 | } |
| 712 | break; |
| 713 | case 0x41: |
| 714 | m_pause = !m_pause; |
| 715 | break; |
| 716 | } |
| 717 | Display(); |
| 718 | } |
| 719 | break; |
| 720 | default: |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 721 | break; |
| 722 | } |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 725 | void TestFrameworkVkPresent::Run() |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 726 | { |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 727 | xcb_flush(m_connection); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 728 | |
| 729 | while (! m_quit) { |
| 730 | xcb_generic_event_t *event; |
| 731 | |
| 732 | if (m_pause) { |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 733 | event = xcb_wait_for_event(m_connection); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 734 | } else { |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 735 | event = xcb_poll_for_event(m_connection); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 736 | } |
| 737 | if (event) { |
| 738 | HandleEvent(event); |
| 739 | free(event); |
| 740 | } |
| 741 | } |
| 742 | } |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 743 | #endif // _WIN32 |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 744 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 745 | void TestFrameworkVkPresent::CreateSwapchain() |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 746 | { |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 747 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 748 | |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 749 | m_display_image = m_images.begin(); |
| 750 | m_current_buffer = 0; |
| 751 | |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 752 | // Construct the WSI surface description: |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 753 | m_surface_description.sType = VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 754 | m_surface_description.pNext = NULL; |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 755 | #ifdef _WIN32 |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 756 | m_surface_description.platform = VK_PLATFORM_WIN32_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 757 | m_surface_description.pPlatformHandle = m_connection; |
| 758 | m_surface_description.pPlatformWindow = m_window; |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 759 | #else // _WIN32 |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 760 | m_platform_handle_xcb.connection = m_connection; |
| 761 | m_platform_handle_xcb.root = m_screen->root; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 762 | m_surface_description.platform = VK_PLATFORM_XCB_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 763 | m_surface_description.pPlatformHandle = &m_platform_handle_xcb; |
| 764 | m_surface_description.pPlatformWindow = &m_window; |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 765 | #endif // _WIN32 |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 766 | |
| 767 | // Iterate over each queue to learn whether it supports presenting to WSI: |
| 768 | VkBool32 supportsPresent; |
| 769 | m_present_queue_node_index = UINT32_MAX; |
| 770 | std::vector<vk_testing::Queue *> queues = m_device.graphics_queues(); |
| 771 | for (int i=0; i < queues.size(); i++) |
| 772 | { |
| 773 | int family_index = queues[i]->get_family_index(); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 774 | m_fpGetPhysicalDeviceSurfaceSupportKHR(m_device.phy().handle(), |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 775 | family_index, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 776 | (VkSurfaceDescriptionKHR *) &m_surface_description, |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 777 | &supportsPresent); |
| 778 | if (supportsPresent) { |
| 779 | m_present_queue_node_index = family_index; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | assert(m_present_queue_node_index != UINT32_MAX); |
| 784 | |
| 785 | |
| 786 | // Get the list of VkFormat's that are supported: |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 787 | uint32_t formatCount; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 788 | err = m_fpGetSurfaceFormatsKHR(m_device.handle(), |
| 789 | (VkSurfaceDescriptionKHR *) &m_surface_description, |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 790 | &formatCount, NULL); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 791 | assert(!err); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 792 | VkSurfaceFormatKHR *surfFormats = |
| 793 | (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR)); |
| 794 | err = m_fpGetSurfaceFormatsKHR(m_device.handle(), |
| 795 | (VkSurfaceDescriptionKHR *) &m_surface_description, |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 796 | &formatCount, surfFormats); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 797 | assert(!err); |
| 798 | // If the format list includes just one entry of VK_FORMAT_UNDEFINED, |
| 799 | // the surface has no preferred format. Otherwise, at least one |
| 800 | // supported format will be returned. |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 801 | if (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED) |
| 802 | { |
| 803 | m_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 804 | } |
| 805 | else |
| 806 | { |
| 807 | assert(formatCount >= 1); |
| 808 | m_format = surfFormats[0].format; |
| 809 | } |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 810 | m_color_space = surfFormats[0].colorSpace; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 811 | |
| 812 | // Check the surface proprties and formats |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 813 | VkSurfacePropertiesKHR surfProperties; |
| 814 | err = m_fpGetSurfacePropertiesKHR(m_device.handle(), |
| 815 | (const VkSurfaceDescriptionKHR *)&m_surface_description, |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 816 | &surfProperties); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 817 | assert(!err); |
| 818 | |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 819 | uint32_t presentModeCount; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 820 | err = m_fpGetSurfacePresentModesKHR(m_device.handle(), |
| 821 | (const VkSurfaceDescriptionKHR *)&m_surface_description, |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 822 | &presentModeCount, NULL); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 823 | assert(!err); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 824 | VkPresentModeKHR *presentModes = |
| 825 | (VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR)); |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 826 | assert(presentModes); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 827 | err = m_fpGetSurfacePresentModesKHR(m_device.handle(), |
| 828 | (const VkSurfaceDescriptionKHR *)&m_surface_description, |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 829 | &presentModeCount, presentModes); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 830 | assert(!err); |
| 831 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 832 | VkExtent2D swapchainExtent; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 833 | // width and height are either both -1, or both not -1. |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 834 | if (surfProperties.currentExtent.width == -1) |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 835 | { |
| 836 | // If the surface size is undefined, the size is set to |
| 837 | // the size of the images requested. |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 838 | swapchainExtent.width = m_width; |
| 839 | swapchainExtent.height = m_height; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 840 | } |
| 841 | else |
| 842 | { |
| 843 | // If the surface size is defined, the swap chain size must match |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 844 | swapchainExtent = surfProperties.currentExtent; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | // If mailbox mode is available, use it, as is the lowest-latency non- |
Ian Elliott | ae0e824 | 2015-08-10 13:20:49 -0600 | [diff] [blame] | 848 | // tearing mode. If not, try IMMEDIATE which will usually be available, |
| 849 | // and is fastest (though it tears). If not, fall back to FIFO which is |
| 850 | // always available. |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 851 | VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 852 | for (size_t i = 0; i < presentModeCount; i++) { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 853 | if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR) { |
| 854 | swapchainPresentMode = VK_PRESENT_MODE_MAILBOX_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 855 | break; |
| 856 | } |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 857 | if ((swapchainPresentMode != VK_PRESENT_MODE_MAILBOX_KHR) && |
| 858 | (presentModes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR)) { |
| 859 | swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; |
Ian Elliott | ae0e824 | 2015-08-10 13:20:49 -0600 | [diff] [blame] | 860 | } |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | // Determine the number of VkImage's to use in the swap chain (we desire to |
| 864 | // own only 1 image at a time, besides the images being displayed and |
| 865 | // queued for display): |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 866 | uint32_t desiredNumberOfSwapchainImages = surfProperties.minImageCount + 1; |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 867 | if ((surfProperties.maxImageCount > 0) && |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 868 | (desiredNumberOfSwapchainImages > surfProperties.maxImageCount)) |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 869 | { |
| 870 | // Application must settle for fewer images than desired: |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 871 | desiredNumberOfSwapchainImages = surfProperties.maxImageCount; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 872 | } |
| 873 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 874 | VkSurfaceTransformKHR preTransform; |
| 875 | if (surfProperties.supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_KHR) { |
| 876 | preTransform = VK_SURFACE_TRANSFORM_NONE_KHR; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 877 | } else { |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 878 | preTransform = surfProperties.currentTransform; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 879 | } |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 880 | |
Cody Northrop | df5b092 | 2015-08-28 16:22:48 -0600 | [diff] [blame] | 881 | // We want to blit to the swap chain, ensure the driver supports it. Color is always supported, per WSI spec. |
| 882 | assert((surfProperties.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT) != 0); |
| 883 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 884 | VkSwapchainCreateInfoKHR swap_chain = {}; |
Ian Elliott | a257eea | 2015-09-22 10:20:23 -0600 | [diff] [blame] | 885 | swap_chain.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
Ian Elliott | 1a3845b | 2015-07-06 14:33:04 -0600 | [diff] [blame] | 886 | swap_chain.pNext = NULL; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 887 | swap_chain.pSurfaceDescription = (const VkSurfaceDescriptionKHR *)&m_surface_description; |
| 888 | swap_chain.minImageCount = desiredNumberOfSwapchainImages; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 889 | swap_chain.imageFormat = m_format; |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 890 | swap_chain.imageColorSpace = m_color_space; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 891 | swap_chain.imageExtent.width = swapchainExtent.width; |
| 892 | swap_chain.imageExtent.height = swapchainExtent.height; |
Cody Northrop | df8f42a | 2015-08-05 15:38:39 -0600 | [diff] [blame] | 893 | swap_chain.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT | |
| 894 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 895 | swap_chain.preTransform = preTransform; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 896 | swap_chain.imageArraySize = 1; |
Ian Elliott | 8b13979 | 2015-08-07 11:51:12 -0600 | [diff] [blame] | 897 | swap_chain.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 898 | swap_chain.queueFamilyCount = 0; |
| 899 | swap_chain.pQueueFamilyIndices = NULL; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 900 | swap_chain.presentMode = swapchainPresentMode; |
| 901 | swap_chain.oldSwapchain.handle = 0; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 902 | swap_chain.clipped = true; |
| 903 | |
| 904 | uint32_t i; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 905 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 906 | err = m_fpCreateSwapchainKHR(m_device.handle(), &swap_chain, &m_swap_chain); |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 907 | assert(!err); |
| 908 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 909 | err = m_fpGetSwapchainImagesKHR(m_device.handle(), m_swap_chain, |
| 910 | &m_swapchainImageCount, NULL); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 911 | assert(!err); |
| 912 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 913 | VkImage* swapchainImages = (VkImage*)malloc(m_swapchainImageCount * sizeof(VkImage)); |
| 914 | assert(swapchainImages); |
| 915 | err = m_fpGetSwapchainImagesKHR(m_device.handle(), m_swap_chain, |
| 916 | &m_swapchainImageCount, swapchainImages); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 917 | assert(!err); |
| 918 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 919 | m_buffers = (SwapchainBuffers*)malloc(sizeof(SwapchainBuffers)*m_swapchainImageCount); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 920 | assert(m_buffers); |
| 921 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 922 | for (i = 0; i < m_swapchainImageCount; i++) { |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 923 | VkImageViewCreateInfo color_image_view = {}; |
| 924 | color_image_view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 925 | color_image_view.pNext = NULL; |
Courtney Goeltzenleuchter | 00265c8 | 2015-09-11 15:22:06 -0600 | [diff] [blame] | 926 | color_image_view.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 927 | color_image_view.format = m_format; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 928 | color_image_view.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 929 | color_image_view.subresourceRange.baseMipLevel = 0; |
| 930 | color_image_view.subresourceRange.mipLevels = 1; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 931 | color_image_view.subresourceRange.baseArrayLayer = 0; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 932 | color_image_view.subresourceRange.arraySize = 1; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 933 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 934 | m_buffers[i].image = swapchainImages[i]; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 935 | |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 936 | color_image_view.image = m_buffers[i].image; |
| 937 | err = vkCreateImageView(m_device.handle(), |
| 938 | &color_image_view, &m_buffers[i].view); |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 939 | assert(!err); |
| 940 | } |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 943 | void TestFrameworkVkPresent::InitPresentFramework(std::list<VkTestImageRecord> &imagesIn, VkInstance inst) |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 944 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 945 | GET_INSTANCE_PROC_ADDR(inst, GetPhysicalDeviceSurfaceSupportKHR); |
| 946 | GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePropertiesKHR); |
| 947 | GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfaceFormatsKHR); |
| 948 | GET_DEVICE_PROC_ADDR(m_device.handle(), GetSurfacePresentModesKHR); |
| 949 | GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapchainKHR); |
| 950 | GET_DEVICE_PROC_ADDR(m_device.handle(), CreateSwapchainKHR); |
| 951 | GET_DEVICE_PROC_ADDR(m_device.handle(), DestroySwapchainKHR); |
| 952 | GET_DEVICE_PROC_ADDR(m_device.handle(), GetSwapchainImagesKHR); |
| 953 | GET_DEVICE_PROC_ADDR(m_device.handle(), AcquireNextImageKHR); |
| 954 | GET_DEVICE_PROC_ADDR(m_device.handle(), QueuePresentKHR); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 955 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 956 | m_images = imagesIn; |
| 957 | } |
| 958 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 959 | #ifdef _WIN32 |
| 960 | void TestFrameworkVkPresent::CreateMyWindow() |
| 961 | { |
| 962 | WNDCLASSEX win_class; |
| 963 | // const ::testing::TestInfo* const test_info = |
| 964 | // ::testing::UnitTest::GetInstance()->current_test_info(); |
| 965 | m_connection = GetModuleHandle(NULL); |
| 966 | |
| 967 | for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin(); |
| 968 | it != m_images.end(); it++) { |
| 969 | if (m_width < it->m_width) |
| 970 | m_width = it->m_width; |
| 971 | if (m_height < it->m_height) |
| 972 | m_height = it->m_height; |
| 973 | } |
| 974 | // Initialize the window class structure: |
| 975 | win_class.cbSize = sizeof(WNDCLASSEX); |
| 976 | win_class.style = CS_HREDRAW | CS_VREDRAW; |
| 977 | win_class.lpfnWndProc = (WNDPROC) &TestFrameworkVkPresent::WndProc; |
| 978 | win_class.cbClsExtra = 0; |
| 979 | win_class.cbWndExtra = 0; |
| 980 | win_class.hInstance = m_connection; // hInstance |
| 981 | win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); |
| 982 | win_class.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 983 | win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); |
| 984 | win_class.lpszMenuName = NULL; |
| 985 | win_class.lpszClassName = "Test"; |
| 986 | win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO); |
| 987 | // Register window class: |
| 988 | if (!RegisterClassEx(&win_class)) { |
| 989 | // It didn't work, so try to give a useful error: |
| 990 | printf("Unexpected error trying to start the application!\n"); |
| 991 | fflush(stdout); |
| 992 | exit(1); |
| 993 | } |
| 994 | // Create window with the registered class: |
Cody Northrop | 3958225 | 2015-08-05 15:39:31 -0600 | [diff] [blame] | 995 | RECT wr = { 0, 0, m_width, m_height }; |
| 996 | AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 997 | m_window = CreateWindowEx(0, |
| 998 | "Test", // class name |
| 999 | "Test", // app name |
| 1000 | WS_OVERLAPPEDWINDOW | // window style |
| 1001 | WS_VISIBLE | |
| 1002 | WS_SYSMENU, |
| 1003 | 100,100, // x/y coords |
Cody Northrop | 3958225 | 2015-08-05 15:39:31 -0600 | [diff] [blame] | 1004 | wr.right - wr.left, // width |
| 1005 | wr.bottom - wr.top, // height |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 1006 | NULL, // handle to parent |
| 1007 | NULL, // handle to menu |
| 1008 | m_connection, // hInstance |
| 1009 | NULL); // no extra parameters |
| 1010 | |
| 1011 | if (!m_window) { |
| 1012 | // It didn't work, so try to give a useful error: |
| 1013 | DWORD error = GetLastError(); |
| 1014 | char message[120]; |
| 1015 | sprintf(message, "Cannot create a window in which to draw!\n GetLastError = %d", error); |
| 1016 | MessageBox(NULL, message, "Error", MB_OK); |
| 1017 | exit(1); |
| 1018 | } |
Tony-LunarG | 399dfca | 2015-05-19 14:08:26 -0600 | [diff] [blame] | 1019 | // Put our this pointer into the window's user data so our WndProc can use it when it starts. |
| 1020 | SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR) this); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 1021 | } |
| 1022 | #else |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1023 | void TestFrameworkVkPresent::CreateMyWindow() |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1024 | { |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1025 | const xcb_setup_t *setup; |
| 1026 | xcb_screen_iterator_t iter; |
| 1027 | int scr; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1028 | uint32_t value_mask, value_list[32]; |
| 1029 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1030 | m_connection = xcb_connect(NULL, &scr); |
| 1031 | |
| 1032 | setup = xcb_get_setup(m_connection); |
| 1033 | iter = xcb_setup_roots_iterator(setup); |
| 1034 | while (scr-- > 0) |
| 1035 | xcb_screen_next(&iter); |
| 1036 | |
| 1037 | m_screen = iter.data; |
| 1038 | |
| 1039 | for (std::list<VkTestImageRecord>::const_iterator it = m_images.begin(); |
| 1040 | it != m_images.end(); it++) { |
| 1041 | if (m_width < it->m_width) |
| 1042 | m_width = it->m_width; |
| 1043 | if (m_height < it->m_height) |
| 1044 | m_height = it->m_height; |
| 1045 | } |
| 1046 | |
| 1047 | m_window = xcb_generate_id(m_connection); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1048 | |
| 1049 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1050 | value_list[0] = m_screen->black_pixel; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1051 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | |
| 1052 | XCB_EVENT_MASK_EXPOSURE | |
| 1053 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1054 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1055 | xcb_create_window(m_connection, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1056 | XCB_COPY_FROM_PARENT, |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1057 | m_window, m_screen->root, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1058 | 0, 0, m_width, m_height, 0, |
| 1059 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1060 | m_screen->root_visual, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1061 | value_mask, value_list); |
| 1062 | |
| 1063 | /* Magic code that will send notification when window is destroyed */ |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1064 | xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 1, 12, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1065 | "WM_PROTOCOLS"); |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1066 | xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(m_connection, cookie, 0); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1067 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1068 | xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(m_connection, 0, 16, "WM_DELETE_WINDOW"); |
| 1069 | m_atom_wm_delete_window = xcb_intern_atom_reply(m_connection, cookie2, 0); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1070 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1071 | xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1072 | m_window, (*reply).atom, 4, 32, 1, |
| 1073 | &(*m_atom_wm_delete_window).atom); |
| 1074 | free(reply); |
| 1075 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1076 | xcb_map_window(m_connection, m_window); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1077 | } |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 1078 | #endif |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1079 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1080 | void TestFrameworkVkPresent::TearDown() |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1081 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1082 | m_fpDestroySwapchainKHR(m_device.handle(), m_swap_chain); |
Tony Barbour | 9226a82 | 2015-10-23 10:58:56 -0600 | [diff] [blame^] | 1083 | |
| 1084 | for (uint32_t i = 0; i < m_swapchainImageCount; i++) { |
| 1085 | vkDestroyImageView(m_device.handle(), m_buffers[i].view); |
| 1086 | } |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 1087 | #ifndef _WIN32 |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1088 | xcb_destroy_window(m_connection, m_window); |
| 1089 | xcb_disconnect(m_connection); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 1090 | #endif |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1091 | } |
| 1092 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1093 | void VkTestFramework::Finish() |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1094 | { |
| 1095 | if (m_images.size() == 0) return; |
| 1096 | |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1097 | vk_testing::Environment env; |
| 1098 | env.SetUp(); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1099 | { |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1100 | TestFrameworkVkPresent vkPresent(env.default_device()); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1101 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1102 | vkPresent.InitPresentFramework(m_images, env.get_instance()); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1103 | vkPresent.CreateMyWindow(); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1104 | vkPresent.CreateSwapchain(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1105 | vkPresent.Run(); |
| 1106 | vkPresent.TearDown(); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 1107 | } |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1108 | env.TearDown(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1109 | } |
| 1110 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1111 | // |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1112 | // These are the default resources for TBuiltInResources, used for both |
| 1113 | // - parsing this string for the case where the user didn't supply one |
| 1114 | // - dumping out a template for user construction of a config file |
| 1115 | // |
| 1116 | static const char* DefaultConfig = |
| 1117 | "MaxLights 32\n" |
| 1118 | "MaxClipPlanes 6\n" |
| 1119 | "MaxTextureUnits 32\n" |
| 1120 | "MaxTextureCoords 32\n" |
| 1121 | "MaxVertexAttribs 64\n" |
| 1122 | "MaxVertexUniformComponents 4096\n" |
| 1123 | "MaxVaryingFloats 64\n" |
| 1124 | "MaxVertexTextureImageUnits 32\n" |
| 1125 | "MaxCombinedTextureImageUnits 80\n" |
| 1126 | "MaxTextureImageUnits 32\n" |
| 1127 | "MaxFragmentUniformComponents 4096\n" |
| 1128 | "MaxDrawBuffers 32\n" |
| 1129 | "MaxVertexUniformVectors 128\n" |
| 1130 | "MaxVaryingVectors 8\n" |
| 1131 | "MaxFragmentUniformVectors 16\n" |
| 1132 | "MaxVertexOutputVectors 16\n" |
| 1133 | "MaxFragmentInputVectors 15\n" |
| 1134 | "MinProgramTexelOffset -8\n" |
| 1135 | "MaxProgramTexelOffset 7\n" |
| 1136 | "MaxClipDistances 8\n" |
| 1137 | "MaxComputeWorkGroupCountX 65535\n" |
| 1138 | "MaxComputeWorkGroupCountY 65535\n" |
| 1139 | "MaxComputeWorkGroupCountZ 65535\n" |
| 1140 | "MaxComputeWorkGroupSizeX 1024\n" |
| 1141 | "MaxComputeWorkGroupSizeY 1024\n" |
| 1142 | "MaxComputeWorkGroupSizeZ 64\n" |
| 1143 | "MaxComputeUniformComponents 1024\n" |
| 1144 | "MaxComputeTextureImageUnits 16\n" |
| 1145 | "MaxComputeImageUniforms 8\n" |
| 1146 | "MaxComputeAtomicCounters 8\n" |
| 1147 | "MaxComputeAtomicCounterBuffers 1\n" |
| 1148 | "MaxVaryingComponents 60\n" |
| 1149 | "MaxVertexOutputComponents 64\n" |
| 1150 | "MaxGeometryInputComponents 64\n" |
| 1151 | "MaxGeometryOutputComponents 128\n" |
| 1152 | "MaxFragmentInputComponents 128\n" |
| 1153 | "MaxImageUnits 8\n" |
| 1154 | "MaxCombinedImageUnitsAndFragmentOutputs 8\n" |
| 1155 | "MaxCombinedShaderOutputResources 8\n" |
| 1156 | "MaxImageSamples 0\n" |
| 1157 | "MaxVertexImageUniforms 0\n" |
| 1158 | "MaxTessControlImageUniforms 0\n" |
| 1159 | "MaxTessEvaluationImageUniforms 0\n" |
| 1160 | "MaxGeometryImageUniforms 0\n" |
| 1161 | "MaxFragmentImageUniforms 8\n" |
| 1162 | "MaxCombinedImageUniforms 8\n" |
| 1163 | "MaxGeometryTextureImageUnits 16\n" |
| 1164 | "MaxGeometryOutputVertices 256\n" |
| 1165 | "MaxGeometryTotalOutputComponents 1024\n" |
| 1166 | "MaxGeometryUniformComponents 1024\n" |
| 1167 | "MaxGeometryVaryingComponents 64\n" |
| 1168 | "MaxTessControlInputComponents 128\n" |
| 1169 | "MaxTessControlOutputComponents 128\n" |
| 1170 | "MaxTessControlTextureImageUnits 16\n" |
| 1171 | "MaxTessControlUniformComponents 1024\n" |
| 1172 | "MaxTessControlTotalOutputComponents 4096\n" |
| 1173 | "MaxTessEvaluationInputComponents 128\n" |
| 1174 | "MaxTessEvaluationOutputComponents 128\n" |
| 1175 | "MaxTessEvaluationTextureImageUnits 16\n" |
| 1176 | "MaxTessEvaluationUniformComponents 1024\n" |
| 1177 | "MaxTessPatchComponents 120\n" |
| 1178 | "MaxPatchVertices 32\n" |
| 1179 | "MaxTessGenLevel 64\n" |
| 1180 | "MaxViewports 16\n" |
| 1181 | "MaxVertexAtomicCounters 0\n" |
| 1182 | "MaxTessControlAtomicCounters 0\n" |
| 1183 | "MaxTessEvaluationAtomicCounters 0\n" |
| 1184 | "MaxGeometryAtomicCounters 0\n" |
| 1185 | "MaxFragmentAtomicCounters 8\n" |
| 1186 | "MaxCombinedAtomicCounters 8\n" |
| 1187 | "MaxAtomicCounterBindings 1\n" |
| 1188 | "MaxVertexAtomicCounterBuffers 0\n" |
| 1189 | "MaxTessControlAtomicCounterBuffers 0\n" |
| 1190 | "MaxTessEvaluationAtomicCounterBuffers 0\n" |
| 1191 | "MaxGeometryAtomicCounterBuffers 0\n" |
| 1192 | "MaxFragmentAtomicCounterBuffers 1\n" |
| 1193 | "MaxCombinedAtomicCounterBuffers 1\n" |
| 1194 | "MaxAtomicCounterBufferSize 16384\n" |
| 1195 | "MaxTransformFeedbackBuffers 4\n" |
| 1196 | "MaxTransformFeedbackInterleavedComponents 64\n" |
| 1197 | "MaxCullDistances 8\n" |
| 1198 | "MaxCombinedClipAndCullDistances 8\n" |
| 1199 | "MaxSamples 4\n" |
| 1200 | |
| 1201 | "nonInductiveForLoops 1\n" |
| 1202 | "whileLoops 1\n" |
| 1203 | "doWhileLoops 1\n" |
| 1204 | "generalUniformIndexing 1\n" |
| 1205 | "generalAttributeMatrixVectorIndexing 1\n" |
| 1206 | "generalVaryingIndexing 1\n" |
| 1207 | "generalSamplerIndexing 1\n" |
| 1208 | "generalVariableIndexing 1\n" |
| 1209 | "generalConstantMatrixVectorIndexing 1\n" |
| 1210 | ; |
| 1211 | |
| 1212 | // |
| 1213 | // *.conf => this is a config file that can set limits/resources |
| 1214 | // |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1215 | bool VkTestFramework::SetConfigFile(const std::string& name) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1216 | { |
| 1217 | if (name.size() < 5) |
| 1218 | return false; |
| 1219 | |
| 1220 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
| 1221 | ConfigFile = name; |
| 1222 | return true; |
| 1223 | } |
| 1224 | |
| 1225 | return false; |
| 1226 | } |
| 1227 | |
| 1228 | // |
| 1229 | // Parse either a .conf file provided by the user or the default string above. |
| 1230 | // |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1231 | void VkTestFramework::ProcessConfigFile() |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1232 | { |
| 1233 | char** configStrings = 0; |
| 1234 | char* config = 0; |
| 1235 | if (ConfigFile.size() > 0) { |
| 1236 | configStrings = ReadFileData(ConfigFile.c_str()); |
| 1237 | if (configStrings) |
| 1238 | config = *configStrings; |
| 1239 | else { |
| 1240 | printf("Error opening configuration file; will instead use the default configuration\n"); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if (config == 0) { |
Courtney Goeltzenleuchter | c7def92 | 2015-09-24 17:05:05 -0600 | [diff] [blame] | 1245 | config = (char *) alloca(strlen(DefaultConfig) + 1); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1246 | strcpy(config, DefaultConfig); |
| 1247 | } |
| 1248 | |
| 1249 | const char* delims = " \t\n\r"; |
| 1250 | const char* token = strtok(config, delims); |
| 1251 | while (token) { |
| 1252 | const char* valueStr = strtok(0, delims); |
| 1253 | if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) { |
| 1254 | printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : ""); |
| 1255 | return; |
| 1256 | } |
| 1257 | int value = atoi(valueStr); |
| 1258 | |
| 1259 | if (strcmp(token, "MaxLights") == 0) |
| 1260 | Resources.maxLights = value; |
| 1261 | else if (strcmp(token, "MaxClipPlanes") == 0) |
| 1262 | Resources.maxClipPlanes = value; |
| 1263 | else if (strcmp(token, "MaxTextureUnits") == 0) |
| 1264 | Resources.maxTextureUnits = value; |
| 1265 | else if (strcmp(token, "MaxTextureCoords") == 0) |
| 1266 | Resources.maxTextureCoords = value; |
| 1267 | else if (strcmp(token, "MaxVertexAttribs") == 0) |
| 1268 | Resources.maxVertexAttribs = value; |
| 1269 | else if (strcmp(token, "MaxVertexUniformComponents") == 0) |
| 1270 | Resources.maxVertexUniformComponents = value; |
| 1271 | else if (strcmp(token, "MaxVaryingFloats") == 0) |
| 1272 | Resources.maxVaryingFloats = value; |
| 1273 | else if (strcmp(token, "MaxVertexTextureImageUnits") == 0) |
| 1274 | Resources.maxVertexTextureImageUnits = value; |
| 1275 | else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0) |
| 1276 | Resources.maxCombinedTextureImageUnits = value; |
| 1277 | else if (strcmp(token, "MaxTextureImageUnits") == 0) |
| 1278 | Resources.maxTextureImageUnits = value; |
| 1279 | else if (strcmp(token, "MaxFragmentUniformComponents") == 0) |
| 1280 | Resources.maxFragmentUniformComponents = value; |
| 1281 | else if (strcmp(token, "MaxDrawBuffers") == 0) |
| 1282 | Resources.maxDrawBuffers = value; |
| 1283 | else if (strcmp(token, "MaxVertexUniformVectors") == 0) |
| 1284 | Resources.maxVertexUniformVectors = value; |
| 1285 | else if (strcmp(token, "MaxVaryingVectors") == 0) |
| 1286 | Resources.maxVaryingVectors = value; |
| 1287 | else if (strcmp(token, "MaxFragmentUniformVectors") == 0) |
| 1288 | Resources.maxFragmentUniformVectors = value; |
| 1289 | else if (strcmp(token, "MaxVertexOutputVectors") == 0) |
| 1290 | Resources.maxVertexOutputVectors = value; |
| 1291 | else if (strcmp(token, "MaxFragmentInputVectors") == 0) |
| 1292 | Resources.maxFragmentInputVectors = value; |
| 1293 | else if (strcmp(token, "MinProgramTexelOffset") == 0) |
| 1294 | Resources.minProgramTexelOffset = value; |
| 1295 | else if (strcmp(token, "MaxProgramTexelOffset") == 0) |
| 1296 | Resources.maxProgramTexelOffset = value; |
| 1297 | else if (strcmp(token, "MaxClipDistances") == 0) |
| 1298 | Resources.maxClipDistances = value; |
| 1299 | else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0) |
| 1300 | Resources.maxComputeWorkGroupCountX = value; |
| 1301 | else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0) |
| 1302 | Resources.maxComputeWorkGroupCountY = value; |
| 1303 | else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0) |
| 1304 | Resources.maxComputeWorkGroupCountZ = value; |
| 1305 | else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0) |
| 1306 | Resources.maxComputeWorkGroupSizeX = value; |
| 1307 | else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0) |
| 1308 | Resources.maxComputeWorkGroupSizeY = value; |
| 1309 | else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0) |
| 1310 | Resources.maxComputeWorkGroupSizeZ = value; |
| 1311 | else if (strcmp(token, "MaxComputeUniformComponents") == 0) |
| 1312 | Resources.maxComputeUniformComponents = value; |
| 1313 | else if (strcmp(token, "MaxComputeTextureImageUnits") == 0) |
| 1314 | Resources.maxComputeTextureImageUnits = value; |
| 1315 | else if (strcmp(token, "MaxComputeImageUniforms") == 0) |
| 1316 | Resources.maxComputeImageUniforms = value; |
| 1317 | else if (strcmp(token, "MaxComputeAtomicCounters") == 0) |
| 1318 | Resources.maxComputeAtomicCounters = value; |
| 1319 | else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0) |
| 1320 | Resources.maxComputeAtomicCounterBuffers = value; |
| 1321 | else if (strcmp(token, "MaxVaryingComponents") == 0) |
| 1322 | Resources.maxVaryingComponents = value; |
| 1323 | else if (strcmp(token, "MaxVertexOutputComponents") == 0) |
| 1324 | Resources.maxVertexOutputComponents = value; |
| 1325 | else if (strcmp(token, "MaxGeometryInputComponents") == 0) |
| 1326 | Resources.maxGeometryInputComponents = value; |
| 1327 | else if (strcmp(token, "MaxGeometryOutputComponents") == 0) |
| 1328 | Resources.maxGeometryOutputComponents = value; |
| 1329 | else if (strcmp(token, "MaxFragmentInputComponents") == 0) |
| 1330 | Resources.maxFragmentInputComponents = value; |
| 1331 | else if (strcmp(token, "MaxImageUnits") == 0) |
| 1332 | Resources.maxImageUnits = value; |
| 1333 | else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0) |
| 1334 | Resources.maxCombinedImageUnitsAndFragmentOutputs = value; |
| 1335 | else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0) |
| 1336 | Resources.maxCombinedShaderOutputResources = value; |
| 1337 | else if (strcmp(token, "MaxImageSamples") == 0) |
| 1338 | Resources.maxImageSamples = value; |
| 1339 | else if (strcmp(token, "MaxVertexImageUniforms") == 0) |
| 1340 | Resources.maxVertexImageUniforms = value; |
| 1341 | else if (strcmp(token, "MaxTessControlImageUniforms") == 0) |
| 1342 | Resources.maxTessControlImageUniforms = value; |
| 1343 | else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0) |
| 1344 | Resources.maxTessEvaluationImageUniforms = value; |
| 1345 | else if (strcmp(token, "MaxGeometryImageUniforms") == 0) |
| 1346 | Resources.maxGeometryImageUniforms = value; |
| 1347 | else if (strcmp(token, "MaxFragmentImageUniforms") == 0) |
| 1348 | Resources.maxFragmentImageUniforms = value; |
| 1349 | else if (strcmp(token, "MaxCombinedImageUniforms") == 0) |
| 1350 | Resources.maxCombinedImageUniforms = value; |
| 1351 | else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0) |
| 1352 | Resources.maxGeometryTextureImageUnits = value; |
| 1353 | else if (strcmp(token, "MaxGeometryOutputVertices") == 0) |
| 1354 | Resources.maxGeometryOutputVertices = value; |
| 1355 | else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0) |
| 1356 | Resources.maxGeometryTotalOutputComponents = value; |
| 1357 | else if (strcmp(token, "MaxGeometryUniformComponents") == 0) |
| 1358 | Resources.maxGeometryUniformComponents = value; |
| 1359 | else if (strcmp(token, "MaxGeometryVaryingComponents") == 0) |
| 1360 | Resources.maxGeometryVaryingComponents = value; |
| 1361 | else if (strcmp(token, "MaxTessControlInputComponents") == 0) |
| 1362 | Resources.maxTessControlInputComponents = value; |
| 1363 | else if (strcmp(token, "MaxTessControlOutputComponents") == 0) |
| 1364 | Resources.maxTessControlOutputComponents = value; |
| 1365 | else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0) |
| 1366 | Resources.maxTessControlTextureImageUnits = value; |
| 1367 | else if (strcmp(token, "MaxTessControlUniformComponents") == 0) |
| 1368 | Resources.maxTessControlUniformComponents = value; |
| 1369 | else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0) |
| 1370 | Resources.maxTessControlTotalOutputComponents = value; |
| 1371 | else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0) |
| 1372 | Resources.maxTessEvaluationInputComponents = value; |
| 1373 | else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0) |
| 1374 | Resources.maxTessEvaluationOutputComponents = value; |
| 1375 | else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0) |
| 1376 | Resources.maxTessEvaluationTextureImageUnits = value; |
| 1377 | else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0) |
| 1378 | Resources.maxTessEvaluationUniformComponents = value; |
| 1379 | else if (strcmp(token, "MaxTessPatchComponents") == 0) |
| 1380 | Resources.maxTessPatchComponents = value; |
| 1381 | else if (strcmp(token, "MaxPatchVertices") == 0) |
| 1382 | Resources.maxPatchVertices = value; |
| 1383 | else if (strcmp(token, "MaxTessGenLevel") == 0) |
| 1384 | Resources.maxTessGenLevel = value; |
| 1385 | else if (strcmp(token, "MaxViewports") == 0) |
| 1386 | Resources.maxViewports = value; |
| 1387 | else if (strcmp(token, "MaxVertexAtomicCounters") == 0) |
| 1388 | Resources.maxVertexAtomicCounters = value; |
| 1389 | else if (strcmp(token, "MaxTessControlAtomicCounters") == 0) |
| 1390 | Resources.maxTessControlAtomicCounters = value; |
| 1391 | else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0) |
| 1392 | Resources.maxTessEvaluationAtomicCounters = value; |
| 1393 | else if (strcmp(token, "MaxGeometryAtomicCounters") == 0) |
| 1394 | Resources.maxGeometryAtomicCounters = value; |
| 1395 | else if (strcmp(token, "MaxFragmentAtomicCounters") == 0) |
| 1396 | Resources.maxFragmentAtomicCounters = value; |
| 1397 | else if (strcmp(token, "MaxCombinedAtomicCounters") == 0) |
| 1398 | Resources.maxCombinedAtomicCounters = value; |
| 1399 | else if (strcmp(token, "MaxAtomicCounterBindings") == 0) |
| 1400 | Resources.maxAtomicCounterBindings = value; |
| 1401 | else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0) |
| 1402 | Resources.maxVertexAtomicCounterBuffers = value; |
| 1403 | else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0) |
| 1404 | Resources.maxTessControlAtomicCounterBuffers = value; |
| 1405 | else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0) |
| 1406 | Resources.maxTessEvaluationAtomicCounterBuffers = value; |
| 1407 | else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0) |
| 1408 | Resources.maxGeometryAtomicCounterBuffers = value; |
| 1409 | else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0) |
| 1410 | Resources.maxFragmentAtomicCounterBuffers = value; |
| 1411 | else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0) |
| 1412 | Resources.maxCombinedAtomicCounterBuffers = value; |
| 1413 | else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0) |
| 1414 | Resources.maxAtomicCounterBufferSize = value; |
| 1415 | else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0) |
| 1416 | Resources.maxTransformFeedbackBuffers = value; |
| 1417 | else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0) |
| 1418 | Resources.maxTransformFeedbackInterleavedComponents = value; |
| 1419 | else if (strcmp(token, "MaxCullDistances") == 0) |
| 1420 | Resources.maxCullDistances = value; |
| 1421 | else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0) |
| 1422 | Resources.maxCombinedClipAndCullDistances = value; |
| 1423 | else if (strcmp(token, "MaxSamples") == 0) |
| 1424 | Resources.maxSamples = value; |
| 1425 | |
| 1426 | else if (strcmp(token, "nonInductiveForLoops") == 0) |
| 1427 | Resources.limits.nonInductiveForLoops = (value != 0); |
| 1428 | else if (strcmp(token, "whileLoops") == 0) |
| 1429 | Resources.limits.whileLoops = (value != 0); |
| 1430 | else if (strcmp(token, "doWhileLoops") == 0) |
| 1431 | Resources.limits.doWhileLoops = (value != 0); |
| 1432 | else if (strcmp(token, "generalUniformIndexing") == 0) |
| 1433 | Resources.limits.generalUniformIndexing = (value != 0); |
| 1434 | else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0) |
| 1435 | Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0); |
| 1436 | else if (strcmp(token, "generalVaryingIndexing") == 0) |
| 1437 | Resources.limits.generalVaryingIndexing = (value != 0); |
| 1438 | else if (strcmp(token, "generalSamplerIndexing") == 0) |
| 1439 | Resources.limits.generalSamplerIndexing = (value != 0); |
| 1440 | else if (strcmp(token, "generalVariableIndexing") == 0) |
| 1441 | Resources.limits.generalVariableIndexing = (value != 0); |
| 1442 | else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0) |
| 1443 | Resources.limits.generalConstantMatrixVectorIndexing = (value != 0); |
| 1444 | else |
| 1445 | printf("Warning: unrecognized limit (%s) in configuration file.\n", token); |
| 1446 | |
| 1447 | token = strtok(0, delims); |
| 1448 | } |
| 1449 | if (configStrings) |
| 1450 | FreeFileData(configStrings); |
| 1451 | } |
| 1452 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1453 | void VkTestFramework::SetMessageOptions(EShMessages& messages) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1454 | { |
| 1455 | if (m_compile_options & EOptionRelaxedErrors) |
| 1456 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 1457 | if (m_compile_options & EOptionIntermediate) |
| 1458 | messages = (EShMessages)(messages | EShMsgAST); |
| 1459 | if (m_compile_options & EOptionSuppressWarnings) |
| 1460 | messages = (EShMessages)(messages | EShMsgSuppressWarnings); |
| 1461 | } |
| 1462 | |
| 1463 | // |
| 1464 | // Malloc a string of sufficient size and read a string into it. |
| 1465 | // |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1466 | char** VkTestFramework::ReadFileData(const char* fileName) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1467 | { |
| 1468 | FILE *in; |
| 1469 | #if defined(_WIN32) && defined(__GNUC__) |
| 1470 | in = fopen(fileName, "r"); |
| 1471 | int errorCode = in ? 0 : 1; |
| 1472 | #else |
| 1473 | int errorCode = fopen_s(&in, fileName, "r"); |
| 1474 | #endif |
| 1475 | |
| 1476 | char *fdata; |
| 1477 | int count = 0; |
| 1478 | const int maxSourceStrings = 5; |
| 1479 | char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); |
| 1480 | |
| 1481 | if (errorCode) { |
| 1482 | printf("Error: unable to open input file: %s\n", fileName); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | while (fgetc(in) != EOF) |
| 1487 | count++; |
| 1488 | |
| 1489 | fseek(in, 0, SEEK_SET); |
| 1490 | |
| 1491 | if (!(fdata = (char*)malloc(count+2))) { |
| 1492 | printf("Error allocating memory\n"); |
| 1493 | return 0; |
| 1494 | } |
| 1495 | if (fread(fdata,1,count, in)!=count) { |
| 1496 | printf("Error reading input file: %s\n", fileName); |
| 1497 | return 0; |
| 1498 | } |
| 1499 | fdata[count] = '\0'; |
| 1500 | fclose(in); |
| 1501 | if (count == 0) { |
| 1502 | return_data[0]=(char*)malloc(count+2); |
| 1503 | return_data[0][0]='\0'; |
| 1504 | m_num_shader_strings = 0; |
| 1505 | return return_data; |
| 1506 | } else |
| 1507 | m_num_shader_strings = 1; |
| 1508 | |
| 1509 | int len = (int)(ceil)((float)count/(float)m_num_shader_strings); |
| 1510 | int ptr_len=0,i=0; |
| 1511 | while(count>0){ |
| 1512 | return_data[i]=(char*)malloc(len+2); |
| 1513 | memcpy(return_data[i],fdata+ptr_len,len); |
| 1514 | return_data[i][len]='\0'; |
| 1515 | count-=(len); |
| 1516 | ptr_len+=(len); |
| 1517 | if(count<len){ |
| 1518 | if(count==0){ |
| 1519 | m_num_shader_strings=(i+1); |
| 1520 | break; |
| 1521 | } |
| 1522 | len = count; |
| 1523 | } |
| 1524 | ++i; |
| 1525 | } |
| 1526 | return return_data; |
| 1527 | } |
| 1528 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1529 | void VkTestFramework::FreeFileData(char** data) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1530 | { |
| 1531 | for(int i=0;i<m_num_shader_strings;i++) |
| 1532 | free(data[i]); |
| 1533 | } |
| 1534 | |
| 1535 | // |
| 1536 | // Deduce the language from the filename. Files must end in one of the |
| 1537 | // following extensions: |
| 1538 | // |
| 1539 | // .vert = vertex |
| 1540 | // .tesc = tessellation control |
| 1541 | // .tese = tessellation evaluation |
| 1542 | // .geom = geometry |
| 1543 | // .frag = fragment |
| 1544 | // .comp = compute |
| 1545 | // |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1546 | EShLanguage VkTestFramework::FindLanguage(const std::string& name) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1547 | { |
| 1548 | size_t ext = name.rfind('.'); |
| 1549 | if (ext == std::string::npos) { |
| 1550 | return EShLangVertex; |
| 1551 | } |
| 1552 | |
| 1553 | std::string suffix = name.substr(ext + 1, std::string::npos); |
| 1554 | if (suffix == "vert") |
| 1555 | return EShLangVertex; |
| 1556 | else if (suffix == "tesc") |
| 1557 | return EShLangTessControl; |
| 1558 | else if (suffix == "tese") |
| 1559 | return EShLangTessEvaluation; |
| 1560 | else if (suffix == "geom") |
| 1561 | return EShLangGeometry; |
| 1562 | else if (suffix == "frag") |
| 1563 | return EShLangFragment; |
| 1564 | else if (suffix == "comp") |
| 1565 | return EShLangCompute; |
| 1566 | |
| 1567 | return EShLangVertex; |
| 1568 | } |
| 1569 | |
| 1570 | // |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1571 | // Convert VK shader type to compiler's |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1572 | // |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1573 | EShLanguage VkTestFramework::FindLanguage(const VkShaderStage shader_type) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1574 | { |
| 1575 | switch (shader_type) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1576 | case VK_SHADER_STAGE_VERTEX: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1577 | return EShLangVertex; |
| 1578 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1579 | case VK_SHADER_STAGE_TESS_CONTROL: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1580 | return EShLangTessControl; |
| 1581 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1582 | case VK_SHADER_STAGE_TESS_EVALUATION: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1583 | return EShLangTessEvaluation; |
| 1584 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1585 | case VK_SHADER_STAGE_GEOMETRY: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1586 | return EShLangGeometry; |
| 1587 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1588 | case VK_SHADER_STAGE_FRAGMENT: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1589 | return EShLangFragment; |
| 1590 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1591 | case VK_SHADER_STAGE_COMPUTE: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1592 | return EShLangCompute; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1593 | |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 1594 | default: |
| 1595 | return EShLangVertex; |
| 1596 | } |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | |
| 1600 | // |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1601 | // Compile a given string containing GLSL into SPV for use by VK |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1602 | // Return value of false means an error was encountered. |
| 1603 | // |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1604 | bool VkTestFramework::GLSLtoSPV(const VkShaderStage shader_type, |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1605 | const char *pshader, |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 1606 | std::vector<unsigned int> &spirv) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1607 | { |
Courtney Goeltzenleuchter | c7def92 | 2015-09-24 17:05:05 -0600 | [diff] [blame] | 1608 | glslang::TProgram program; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1609 | const char *shaderStrings[1]; |
| 1610 | |
| 1611 | // TODO: Do we want to load a special config file depending on the |
| 1612 | // shader source? Optional name maybe? |
| 1613 | // SetConfigFile(fileName); |
| 1614 | |
| 1615 | ProcessConfigFile(); |
| 1616 | |
| 1617 | EShMessages messages = EShMsgDefault; |
| 1618 | SetMessageOptions(messages); |
| 1619 | |
| 1620 | EShLanguage stage = FindLanguage(shader_type); |
| 1621 | glslang::TShader* shader = new glslang::TShader(stage); |
| 1622 | |
| 1623 | shaderStrings[0] = pshader; |
| 1624 | shader->setStrings(shaderStrings, 1); |
| 1625 | |
| 1626 | if (! shader->parse(&Resources, (m_compile_options & EOptionDefaultDesktop) ? 110 : 100, false, messages)) { |
| 1627 | |
Cody Northrop | 195d662 | 2014-11-03 12:54:37 -0700 | [diff] [blame] | 1628 | if (! (m_compile_options & EOptionSuppressInfolog)) { |
| 1629 | puts(shader->getInfoLog()); |
| 1630 | puts(shader->getInfoDebugLog()); |
| 1631 | } |
| 1632 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1633 | return false; // something didn't work |
| 1634 | } |
| 1635 | |
| 1636 | program.addShader(shader); |
| 1637 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1638 | |
| 1639 | // |
| 1640 | // Program-level processing... |
| 1641 | // |
| 1642 | |
Cody Northrop | 195d662 | 2014-11-03 12:54:37 -0700 | [diff] [blame] | 1643 | if (! program.link(messages)) { |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1644 | |
Cody Northrop | 195d662 | 2014-11-03 12:54:37 -0700 | [diff] [blame] | 1645 | if (! (m_compile_options & EOptionSuppressInfolog)) { |
| 1646 | puts(shader->getInfoLog()); |
| 1647 | puts(shader->getInfoDebugLog()); |
| 1648 | } |
| 1649 | |
| 1650 | return false; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | if (m_compile_options & EOptionDumpReflection) { |
| 1654 | program.buildReflection(); |
| 1655 | program.dumpReflection(); |
| 1656 | } |
| 1657 | |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 1658 | glslang::GlslangToSpv(*program.getIntermediate(stage), spirv); |
| 1659 | |
| 1660 | // |
| 1661 | // Test the different modes of SPIR-V modification |
| 1662 | // |
| 1663 | if (this->m_canonicalize_spv) { |
| 1664 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::ALL_BUT_STRIP); |
| 1665 | } |
| 1666 | |
| 1667 | if (this->m_strip_spv) { |
| 1668 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::STRIP); |
| 1669 | } |
| 1670 | |
| 1671 | if (this->m_do_everything_spv) { |
| 1672 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::DO_EVERYTHING); |
| 1673 | } |
| 1674 | |
Courtney Goeltzenleuchter | c7def92 | 2015-09-24 17:05:05 -0600 | [diff] [blame] | 1675 | delete shader; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 1676 | |
| 1677 | return true; |
| 1678 | } |
| 1679 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1680 | |
| 1681 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1682 | VkTestImageRecord::VkTestImageRecord() : // Constructor |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1683 | m_width( 0 ), |
| 1684 | m_height( 0 ), |
Chia-I Wu | 837f995 | 2014-12-15 23:29:34 +0800 | [diff] [blame] | 1685 | m_data( NULL ), |
| 1686 | m_data_size( 0 ) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1687 | { |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1688 | } |
| 1689 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1690 | VkTestImageRecord::~VkTestImageRecord() |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1691 | { |
| 1692 | |
| 1693 | } |
| 1694 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1695 | VkTestImageRecord::VkTestImageRecord(const VkTestImageRecord ©in) // Copy constructor to handle pass by value. |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1696 | { |
| 1697 | m_title = copyin.m_title; |
| 1698 | m_width = copyin.m_width; |
| 1699 | m_height = copyin.m_height; |
| 1700 | m_data_size = copyin.m_data_size; |
| 1701 | m_data = copyin.m_data; // TODO: Do we need to copy the data or is pointer okay? |
| 1702 | } |
| 1703 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1704 | ostream &operator<<(ostream &output, const VkTestImageRecord &VkTestImageRecord) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1705 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1706 | output << VkTestImageRecord.m_title << " (" << VkTestImageRecord.m_width << |
| 1707 | "," << VkTestImageRecord.m_height << ")" << endl; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1708 | return output; |
| 1709 | } |
| 1710 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1711 | VkTestImageRecord& VkTestImageRecord::operator=(const VkTestImageRecord &rhs) |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1712 | { |
| 1713 | m_title = rhs.m_title; |
| 1714 | m_width = rhs.m_width; |
| 1715 | m_height = rhs.m_height; |
| 1716 | m_data_size = rhs.m_data_size; |
| 1717 | m_data = rhs.m_data; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1718 | return *this; |
| 1719 | } |
| 1720 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1721 | int VkTestImageRecord::operator==(const VkTestImageRecord &rhs) const |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1722 | { |
| 1723 | if( this->m_data != rhs.m_data) return 0; |
| 1724 | return 1; |
| 1725 | } |
| 1726 | |
| 1727 | // This function is required for built-in STL list functions like sort |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1728 | int VkTestImageRecord::operator<(const VkTestImageRecord &rhs) const |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1729 | { |
| 1730 | if( this->m_data_size < rhs.m_data_size ) return 1; |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |