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