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