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