Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 19 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 20 | * Author: Tony Barbour <tony@LunarG.com> |
| 21 | */ |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 22 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 23 | #include "vktestframework.h" |
| 24 | #include "vkrenderframework.h" |
Karl Schultz | 80b8aca | 2017-01-24 14:44:26 -0800 | [diff] [blame] | 25 | |
| 26 | // For versions prior to VS 2015, suppress the warning |
| 27 | // caused by the inconsistent redefinition of snprintf |
| 28 | // between a vulkan header and a glslang header. |
| 29 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) |
| 30 | #pragma warning(push) |
| 31 | #pragma warning(disable : 4005) |
| 32 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 33 | // TODO FIXME remove this once glslang doesn't define this |
Jon Ashburn | 94207e9 | 2015-12-04 17:03:59 -0700 | [diff] [blame] | 34 | #undef BadValue |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 35 | #include "SPIRV/GlslangToSpv.h" |
| 36 | #include "SPIRV/SPVRemapper.h" |
Karl Schultz | 80b8aca | 2017-01-24 14:44:26 -0800 | [diff] [blame] | 37 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) |
| 38 | #pragma warning(pop) |
| 39 | #endif |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 40 | #include <limits.h> |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 41 | #include <math.h> |
Jon Ashburn | 94207e9 | 2015-12-04 17:03:59 -0700 | [diff] [blame] | 42 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 43 | #if defined(PATH_MAX) && !defined(MAX_PATH) |
| 44 | #define MAX_PATH PATH_MAX |
| 45 | #endif |
| 46 | |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 47 | #ifdef _WIN32 |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 48 | #define ERR_EXIT(err_msg, err_class) \ |
| 49 | do { \ |
| 50 | MessageBox(NULL, err_msg, err_class, MB_OK); \ |
| 51 | exit(1); \ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 52 | } while (0) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 53 | #else // _WIN32 |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 54 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 55 | #define ERR_EXIT(err_msg, err_class) \ |
| 56 | do { \ |
| 57 | printf(err_msg); \ |
| 58 | fflush(stdout); \ |
| 59 | exit(1); \ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 60 | } while (0) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 61 | #endif // _WIN32 |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 62 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 63 | #define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \ |
| 64 | { \ |
| 65 | m_fp##entrypoint = (PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \ |
| 66 | if (m_fp##entrypoint == NULL) { \ |
| 67 | ERR_EXIT("vkGetInstanceProcAddr failed to find vk" #entrypoint, "vkGetInstanceProcAddr Failure"); \ |
| 68 | } \ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 69 | } |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 70 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 71 | #define GET_DEVICE_PROC_ADDR(dev, entrypoint) \ |
| 72 | { \ |
| 73 | m_fp##entrypoint = (PFN_vk##entrypoint)vkGetDeviceProcAddr(dev, "vk" #entrypoint); \ |
| 74 | if (m_fp##entrypoint == NULL) { \ |
| 75 | ERR_EXIT("vkGetDeviceProcAddr failed to find vk" #entrypoint, "vkGetDeviceProcAddr Failure"); \ |
| 76 | } \ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 77 | } |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 78 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 79 | // Command-line options |
| 80 | enum TOptions { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 81 | EOptionNone = 0x000, |
| 82 | EOptionIntermediate = 0x001, |
| 83 | EOptionSuppressInfolog = 0x002, |
| 84 | EOptionMemoryLeakMode = 0x004, |
| 85 | EOptionRelaxedErrors = 0x008, |
| 86 | EOptionGiveWarnings = 0x010, |
| 87 | EOptionLinkProgram = 0x020, |
| 88 | EOptionMultiThreaded = 0x040, |
| 89 | EOptionDumpConfig = 0x080, |
| 90 | EOptionDumpReflection = 0x100, |
| 91 | EOptionSuppressWarnings = 0x200, |
| 92 | EOptionDumpVersions = 0x400, |
| 93 | EOptionSpv = 0x800, |
| 94 | EOptionDefaultDesktop = 0x1000, |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 95 | }; |
| 96 | |
Mark Lobodzinski | b5ccf3f | 2016-05-19 17:26:51 -0600 | [diff] [blame] | 97 | struct SwapchainBuffers { |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 98 | VkImage image; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 99 | VkCommandBuffer cmd; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 100 | VkImageView view; |
Mark Lobodzinski | b5ccf3f | 2016-05-19 17:26:51 -0600 | [diff] [blame] | 101 | }; |
Tony Barbour | 6a3faf0 | 2015-07-23 10:36:18 -0600 | [diff] [blame] | 102 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 103 | #ifndef _WIN32 |
| 104 | |
| 105 | #include <errno.h> |
| 106 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 107 | int fopen_s(FILE **pFile, const char *filename, const char *mode) { |
| 108 | if (!pFile || !filename || !mode) { |
| 109 | return EINVAL; |
| 110 | } |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 111 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 112 | FILE *f = fopen(filename, mode); |
| 113 | if (!f) { |
| 114 | if (errno != 0) { |
| 115 | return errno; |
| 116 | } else { |
| 117 | return ENOENT; |
| 118 | } |
| 119 | } |
| 120 | *pFile = f; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 121 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 122 | return 0; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | #endif |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 126 | |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 127 | // Set up environment for GLSL compiler |
| 128 | // Must be done once per process |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 129 | void TestEnvironment::SetUp() { |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 130 | // Initialize GLSL to SPV compiler utility |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 131 | glslang::InitializeProcess(); |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 132 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 133 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 136 | void TestEnvironment::TearDown() { glslang::FinalizeProcess(); } |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 137 | |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 138 | VkTestFramework::VkTestFramework() : m_compile_options(0), m_num_shader_strings(0) {} |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 139 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 140 | VkTestFramework::~VkTestFramework() {} |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 141 | |
| 142 | // Define all the static elements |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 143 | bool VkTestFramework::m_canonicalize_spv = false; |
| 144 | bool VkTestFramework::m_strip_spv = false; |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 145 | bool VkTestFramework::m_do_everything_spv = false; |
Tobin Ehlis | 7288864 | 2017-11-15 09:43:56 -0700 | [diff] [blame] | 146 | bool VkTestFramework::m_devsim_layer = false; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 147 | int VkTestFramework::m_width = 0; |
| 148 | int VkTestFramework::m_height = 0; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 149 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 150 | bool VkTestFramework::optionMatch(const char *option, char *optionLine) { |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 151 | if (strncmp(option, optionLine, strlen(option)) == 0) |
| 152 | return true; |
| 153 | else |
| 154 | return false; |
| 155 | } |
| 156 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 157 | void VkTestFramework::InitArgs(int *argc, char *argv[]) { |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 158 | int i, n; |
| 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | for (i = 1, n = 1; i < *argc; i++) { |
Chris Forbes | b5e2225 | 2017-04-04 15:51:36 -0700 | [diff] [blame] | 161 | if (optionMatch("--strip-SPV", argv[i])) |
Tony Barbour | 7b60e49 | 2016-02-02 14:43:55 -0700 | [diff] [blame] | 162 | m_strip_spv = true; |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 163 | else if (optionMatch("--canonicalize-SPV", argv[i])) |
| 164 | m_canonicalize_spv = true; |
Tobin Ehlis | 7288864 | 2017-11-15 09:43:56 -0700 | [diff] [blame] | 165 | else if (optionMatch("--devsim", argv[i])) |
| 166 | m_devsim_layer = true; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 167 | else if (optionMatch("--help", argv[i]) || optionMatch("-h", argv[i])) { |
Courtney Goeltzenleuchter | 31144b7 | 2014-12-02 13:13:10 -0700 | [diff] [blame] | 168 | printf("\nOther options:\n"); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 169 | printf( |
| 170 | "\t--show-images\n" |
| 171 | "\t\tDisplay test images in viewer after tests complete.\n"); |
| 172 | printf( |
| 173 | "\t--save-images\n" |
| 174 | "\t\tSave tests images as ppm files in current working " |
| 175 | "directory.\n" |
| 176 | "\t\tUsed to generate golden images for compare-images.\n"); |
| 177 | printf( |
| 178 | "\t--compare-images\n" |
| 179 | "\t\tCompare test images to 'golden' image in golden folder.\n" |
| 180 | "\t\tAlso saves the generated test image in current working\n" |
| 181 | "\t\t\tdirectory but only if the image is different from the " |
| 182 | "golden\n" |
| 183 | "\t\tSetting RENDERTEST_GOLDEN_DIR environment variable can " |
| 184 | "specify\n" |
| 185 | "\t\t\tdifferent directory for golden images\n" |
| 186 | "\t\tSignal test failure if different.\n"); |
| 187 | printf( |
| 188 | "\t--no-SPV\n" |
| 189 | "\t\tUse built-in GLSL compiler rather than SPV code path.\n"); |
| 190 | printf( |
| 191 | "\t--strip-SPV\n" |
| 192 | "\t\tStrip SPIR-V debug information (line numbers, names, " |
| 193 | "etc).\n"); |
| 194 | printf( |
| 195 | "\t--canonicalize-SPV\n" |
| 196 | "\t\tRemap SPIR-V ids before submission to aid compression.\n"); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 197 | exit(0); |
| 198 | } else { |
| 199 | printf("\nUnrecognized option: %s\n", argv[i]); |
| 200 | printf("\nUse --help or -h for option list.\n"); |
Tony Barbour | 4ab4542 | 2014-12-10 17:00:20 -0700 | [diff] [blame] | 201 | exit(0); |
Courtney Goeltzenleuchter | 31144b7 | 2014-12-02 13:13:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 204 | /* |
| 205 | * Since the above "consume" inputs, update argv |
| 206 | * so that it contains the trimmed list of args for glutInit |
| 207 | */ |
| 208 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 209 | argv[n] = argv[i]; |
| 210 | n++; |
| 211 | } |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 212 | } |
| 213 | |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 214 | VkFormat VkTestFramework::GetFormat(VkInstance instance, vk_testing::Device *device) { |
Tony Barbour | 2d6d54e | 2015-12-03 16:05:11 -0700 | [diff] [blame] | 215 | VkFormatProperties format_props; |
Tony Barbour | 7b60e49 | 2016-02-02 14:43:55 -0700 | [diff] [blame] | 216 | |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 217 | vkGetPhysicalDeviceFormatProperties(device->phy().handle(), VK_FORMAT_B8G8R8A8_UNORM, &format_props); |
| 218 | if (format_props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT || |
| 219 | format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
Tony Barbour | 7b60e49 | 2016-02-02 14:43:55 -0700 | [diff] [blame] | 220 | return VK_FORMAT_B8G8R8A8_UNORM; |
Tony Barbour | 2d6d54e | 2015-12-03 16:05:11 -0700 | [diff] [blame] | 221 | } |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 222 | vkGetPhysicalDeviceFormatProperties(device->phy().handle(), VK_FORMAT_R8G8B8A8_UNORM, &format_props); |
| 223 | if (format_props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT || |
| 224 | format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
Tony Barbour | 7b60e49 | 2016-02-02 14:43:55 -0700 | [diff] [blame] | 225 | return VK_FORMAT_R8G8B8A8_UNORM; |
Tony Barbour | 2d6d54e | 2015-12-03 16:05:11 -0700 | [diff] [blame] | 226 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 227 | printf( |
| 228 | "Error - device does not support VK_FORMAT_B8G8R8A8_UNORM nor " |
| 229 | "VK_FORMAT_R8G8B8A8_UNORM - exiting\n"); |
Tobin Ehlis | e37e973 | 2016-07-11 12:57:29 -0600 | [diff] [blame] | 230 | exit(1); |
Tony Barbour | 2d6d54e | 2015-12-03 16:05:11 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 233 | void VkTestFramework::Finish() {} |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 234 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 235 | // |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 236 | // These are the default resources for TBuiltInResources, used for both |
| 237 | // - parsing this string for the case where the user didn't supply one |
| 238 | // - dumping out a template for user construction of a config file |
| 239 | // |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 240 | static const char *DefaultConfig = |
| 241 | "MaxLights 32\n" |
| 242 | "MaxClipPlanes 6\n" |
| 243 | "MaxTextureUnits 32\n" |
| 244 | "MaxTextureCoords 32\n" |
| 245 | "MaxVertexAttribs 64\n" |
| 246 | "MaxVertexUniformComponents 4096\n" |
| 247 | "MaxVaryingFloats 64\n" |
| 248 | "MaxVertexTextureImageUnits 32\n" |
| 249 | "MaxCombinedTextureImageUnits 80\n" |
| 250 | "MaxTextureImageUnits 32\n" |
| 251 | "MaxFragmentUniformComponents 4096\n" |
| 252 | "MaxDrawBuffers 32\n" |
| 253 | "MaxVertexUniformVectors 128\n" |
| 254 | "MaxVaryingVectors 8\n" |
| 255 | "MaxFragmentUniformVectors 16\n" |
| 256 | "MaxVertexOutputVectors 16\n" |
| 257 | "MaxFragmentInputVectors 15\n" |
| 258 | "MinProgramTexelOffset -8\n" |
| 259 | "MaxProgramTexelOffset 7\n" |
| 260 | "MaxClipDistances 8\n" |
| 261 | "MaxComputeWorkGroupCountX 65535\n" |
| 262 | "MaxComputeWorkGroupCountY 65535\n" |
| 263 | "MaxComputeWorkGroupCountZ 65535\n" |
| 264 | "MaxComputeWorkGroupSizeX 1024\n" |
| 265 | "MaxComputeWorkGroupSizeY 1024\n" |
| 266 | "MaxComputeWorkGroupSizeZ 64\n" |
| 267 | "MaxComputeUniformComponents 1024\n" |
| 268 | "MaxComputeTextureImageUnits 16\n" |
| 269 | "MaxComputeImageUniforms 8\n" |
| 270 | "MaxComputeAtomicCounters 8\n" |
| 271 | "MaxComputeAtomicCounterBuffers 1\n" |
| 272 | "MaxVaryingComponents 60\n" |
| 273 | "MaxVertexOutputComponents 64\n" |
| 274 | "MaxGeometryInputComponents 64\n" |
| 275 | "MaxGeometryOutputComponents 128\n" |
| 276 | "MaxFragmentInputComponents 128\n" |
| 277 | "MaxImageUnits 8\n" |
| 278 | "MaxCombinedImageUnitsAndFragmentOutputs 8\n" |
| 279 | "MaxCombinedShaderOutputResources 8\n" |
| 280 | "MaxImageSamples 0\n" |
| 281 | "MaxVertexImageUniforms 0\n" |
| 282 | "MaxTessControlImageUniforms 0\n" |
| 283 | "MaxTessEvaluationImageUniforms 0\n" |
| 284 | "MaxGeometryImageUniforms 0\n" |
| 285 | "MaxFragmentImageUniforms 8\n" |
| 286 | "MaxCombinedImageUniforms 8\n" |
| 287 | "MaxGeometryTextureImageUnits 16\n" |
| 288 | "MaxGeometryOutputVertices 256\n" |
| 289 | "MaxGeometryTotalOutputComponents 1024\n" |
| 290 | "MaxGeometryUniformComponents 1024\n" |
| 291 | "MaxGeometryVaryingComponents 64\n" |
| 292 | "MaxTessControlInputComponents 128\n" |
| 293 | "MaxTessControlOutputComponents 128\n" |
| 294 | "MaxTessControlTextureImageUnits 16\n" |
| 295 | "MaxTessControlUniformComponents 1024\n" |
| 296 | "MaxTessControlTotalOutputComponents 4096\n" |
| 297 | "MaxTessEvaluationInputComponents 128\n" |
| 298 | "MaxTessEvaluationOutputComponents 128\n" |
| 299 | "MaxTessEvaluationTextureImageUnits 16\n" |
| 300 | "MaxTessEvaluationUniformComponents 1024\n" |
| 301 | "MaxTessPatchComponents 120\n" |
| 302 | "MaxPatchVertices 32\n" |
| 303 | "MaxTessGenLevel 64\n" |
| 304 | "MaxViewports 16\n" |
| 305 | "MaxVertexAtomicCounters 0\n" |
| 306 | "MaxTessControlAtomicCounters 0\n" |
| 307 | "MaxTessEvaluationAtomicCounters 0\n" |
| 308 | "MaxGeometryAtomicCounters 0\n" |
| 309 | "MaxFragmentAtomicCounters 8\n" |
| 310 | "MaxCombinedAtomicCounters 8\n" |
| 311 | "MaxAtomicCounterBindings 1\n" |
| 312 | "MaxVertexAtomicCounterBuffers 0\n" |
| 313 | "MaxTessControlAtomicCounterBuffers 0\n" |
| 314 | "MaxTessEvaluationAtomicCounterBuffers 0\n" |
| 315 | "MaxGeometryAtomicCounterBuffers 0\n" |
| 316 | "MaxFragmentAtomicCounterBuffers 1\n" |
| 317 | "MaxCombinedAtomicCounterBuffers 1\n" |
| 318 | "MaxAtomicCounterBufferSize 16384\n" |
| 319 | "MaxTransformFeedbackBuffers 4\n" |
| 320 | "MaxTransformFeedbackInterleavedComponents 64\n" |
| 321 | "MaxCullDistances 8\n" |
| 322 | "MaxCombinedClipAndCullDistances 8\n" |
| 323 | "MaxSamples 4\n" |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 324 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 325 | "nonInductiveForLoops 1\n" |
| 326 | "whileLoops 1\n" |
| 327 | "doWhileLoops 1\n" |
| 328 | "generalUniformIndexing 1\n" |
| 329 | "generalAttributeMatrixVectorIndexing 1\n" |
| 330 | "generalVaryingIndexing 1\n" |
| 331 | "generalSamplerIndexing 1\n" |
| 332 | "generalVariableIndexing 1\n" |
| 333 | "generalConstantMatrixVectorIndexing 1\n"; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 334 | |
| 335 | // |
| 336 | // *.conf => this is a config file that can set limits/resources |
| 337 | // |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 338 | bool VkTestFramework::SetConfigFile(const std::string &name) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 339 | if (name.size() < 5) return false; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 340 | |
| 341 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
| 342 | ConfigFile = name; |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | // |
| 350 | // Parse either a .conf file provided by the user or the default string above. |
| 351 | // |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 352 | void VkTestFramework::ProcessConfigFile() { |
| 353 | char **configStrings = 0; |
| 354 | char *config = 0; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 355 | if (ConfigFile.size() > 0) { |
| 356 | configStrings = ReadFileData(ConfigFile.c_str()); |
| 357 | if (configStrings) |
| 358 | config = *configStrings; |
| 359 | else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 360 | printf( |
| 361 | "Error opening configuration file; will instead use the " |
| 362 | "default configuration\n"); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | if (config == 0) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 367 | config = (char *)alloca(strlen(DefaultConfig) + 1); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 368 | strcpy(config, DefaultConfig); |
| 369 | } |
| 370 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 371 | const char *delims = " \t\n\r"; |
| 372 | const char *token = strtok(config, delims); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 373 | while (token) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 374 | const char *valueStr = strtok(0, delims); |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 375 | if (valueStr == 0 || !(valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 376 | printf( |
| 377 | "Error: '%s' bad .conf file. Each name must be followed by " |
| 378 | "one number.\n", |
| 379 | valueStr ? valueStr : ""); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | int value = atoi(valueStr); |
| 383 | |
| 384 | if (strcmp(token, "MaxLights") == 0) |
| 385 | Resources.maxLights = value; |
| 386 | else if (strcmp(token, "MaxClipPlanes") == 0) |
| 387 | Resources.maxClipPlanes = value; |
| 388 | else if (strcmp(token, "MaxTextureUnits") == 0) |
| 389 | Resources.maxTextureUnits = value; |
| 390 | else if (strcmp(token, "MaxTextureCoords") == 0) |
| 391 | Resources.maxTextureCoords = value; |
| 392 | else if (strcmp(token, "MaxVertexAttribs") == 0) |
| 393 | Resources.maxVertexAttribs = value; |
| 394 | else if (strcmp(token, "MaxVertexUniformComponents") == 0) |
| 395 | Resources.maxVertexUniformComponents = value; |
| 396 | else if (strcmp(token, "MaxVaryingFloats") == 0) |
| 397 | Resources.maxVaryingFloats = value; |
| 398 | else if (strcmp(token, "MaxVertexTextureImageUnits") == 0) |
| 399 | Resources.maxVertexTextureImageUnits = value; |
| 400 | else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0) |
| 401 | Resources.maxCombinedTextureImageUnits = value; |
| 402 | else if (strcmp(token, "MaxTextureImageUnits") == 0) |
| 403 | Resources.maxTextureImageUnits = value; |
| 404 | else if (strcmp(token, "MaxFragmentUniformComponents") == 0) |
| 405 | Resources.maxFragmentUniformComponents = value; |
| 406 | else if (strcmp(token, "MaxDrawBuffers") == 0) |
| 407 | Resources.maxDrawBuffers = value; |
| 408 | else if (strcmp(token, "MaxVertexUniformVectors") == 0) |
| 409 | Resources.maxVertexUniformVectors = value; |
| 410 | else if (strcmp(token, "MaxVaryingVectors") == 0) |
| 411 | Resources.maxVaryingVectors = value; |
| 412 | else if (strcmp(token, "MaxFragmentUniformVectors") == 0) |
| 413 | Resources.maxFragmentUniformVectors = value; |
| 414 | else if (strcmp(token, "MaxVertexOutputVectors") == 0) |
| 415 | Resources.maxVertexOutputVectors = value; |
| 416 | else if (strcmp(token, "MaxFragmentInputVectors") == 0) |
| 417 | Resources.maxFragmentInputVectors = value; |
| 418 | else if (strcmp(token, "MinProgramTexelOffset") == 0) |
| 419 | Resources.minProgramTexelOffset = value; |
| 420 | else if (strcmp(token, "MaxProgramTexelOffset") == 0) |
| 421 | Resources.maxProgramTexelOffset = value; |
| 422 | else if (strcmp(token, "MaxClipDistances") == 0) |
| 423 | Resources.maxClipDistances = value; |
| 424 | else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0) |
| 425 | Resources.maxComputeWorkGroupCountX = value; |
| 426 | else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0) |
| 427 | Resources.maxComputeWorkGroupCountY = value; |
| 428 | else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0) |
| 429 | Resources.maxComputeWorkGroupCountZ = value; |
| 430 | else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0) |
| 431 | Resources.maxComputeWorkGroupSizeX = value; |
| 432 | else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0) |
| 433 | Resources.maxComputeWorkGroupSizeY = value; |
| 434 | else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0) |
| 435 | Resources.maxComputeWorkGroupSizeZ = value; |
| 436 | else if (strcmp(token, "MaxComputeUniformComponents") == 0) |
| 437 | Resources.maxComputeUniformComponents = value; |
| 438 | else if (strcmp(token, "MaxComputeTextureImageUnits") == 0) |
| 439 | Resources.maxComputeTextureImageUnits = value; |
| 440 | else if (strcmp(token, "MaxComputeImageUniforms") == 0) |
| 441 | Resources.maxComputeImageUniforms = value; |
| 442 | else if (strcmp(token, "MaxComputeAtomicCounters") == 0) |
| 443 | Resources.maxComputeAtomicCounters = value; |
| 444 | else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0) |
| 445 | Resources.maxComputeAtomicCounterBuffers = value; |
| 446 | else if (strcmp(token, "MaxVaryingComponents") == 0) |
| 447 | Resources.maxVaryingComponents = value; |
| 448 | else if (strcmp(token, "MaxVertexOutputComponents") == 0) |
| 449 | Resources.maxVertexOutputComponents = value; |
| 450 | else if (strcmp(token, "MaxGeometryInputComponents") == 0) |
| 451 | Resources.maxGeometryInputComponents = value; |
| 452 | else if (strcmp(token, "MaxGeometryOutputComponents") == 0) |
| 453 | Resources.maxGeometryOutputComponents = value; |
| 454 | else if (strcmp(token, "MaxFragmentInputComponents") == 0) |
| 455 | Resources.maxFragmentInputComponents = value; |
| 456 | else if (strcmp(token, "MaxImageUnits") == 0) |
| 457 | Resources.maxImageUnits = value; |
| 458 | else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0) |
| 459 | Resources.maxCombinedImageUnitsAndFragmentOutputs = value; |
| 460 | else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0) |
| 461 | Resources.maxCombinedShaderOutputResources = value; |
| 462 | else if (strcmp(token, "MaxImageSamples") == 0) |
| 463 | Resources.maxImageSamples = value; |
| 464 | else if (strcmp(token, "MaxVertexImageUniforms") == 0) |
| 465 | Resources.maxVertexImageUniforms = value; |
| 466 | else if (strcmp(token, "MaxTessControlImageUniforms") == 0) |
| 467 | Resources.maxTessControlImageUniforms = value; |
| 468 | else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0) |
| 469 | Resources.maxTessEvaluationImageUniforms = value; |
| 470 | else if (strcmp(token, "MaxGeometryImageUniforms") == 0) |
| 471 | Resources.maxGeometryImageUniforms = value; |
| 472 | else if (strcmp(token, "MaxFragmentImageUniforms") == 0) |
| 473 | Resources.maxFragmentImageUniforms = value; |
| 474 | else if (strcmp(token, "MaxCombinedImageUniforms") == 0) |
| 475 | Resources.maxCombinedImageUniforms = value; |
| 476 | else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0) |
| 477 | Resources.maxGeometryTextureImageUnits = value; |
| 478 | else if (strcmp(token, "MaxGeometryOutputVertices") == 0) |
| 479 | Resources.maxGeometryOutputVertices = value; |
| 480 | else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0) |
| 481 | Resources.maxGeometryTotalOutputComponents = value; |
| 482 | else if (strcmp(token, "MaxGeometryUniformComponents") == 0) |
| 483 | Resources.maxGeometryUniformComponents = value; |
| 484 | else if (strcmp(token, "MaxGeometryVaryingComponents") == 0) |
| 485 | Resources.maxGeometryVaryingComponents = value; |
| 486 | else if (strcmp(token, "MaxTessControlInputComponents") == 0) |
| 487 | Resources.maxTessControlInputComponents = value; |
| 488 | else if (strcmp(token, "MaxTessControlOutputComponents") == 0) |
| 489 | Resources.maxTessControlOutputComponents = value; |
| 490 | else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0) |
| 491 | Resources.maxTessControlTextureImageUnits = value; |
| 492 | else if (strcmp(token, "MaxTessControlUniformComponents") == 0) |
| 493 | Resources.maxTessControlUniformComponents = value; |
| 494 | else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0) |
| 495 | Resources.maxTessControlTotalOutputComponents = value; |
| 496 | else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0) |
| 497 | Resources.maxTessEvaluationInputComponents = value; |
| 498 | else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0) |
| 499 | Resources.maxTessEvaluationOutputComponents = value; |
| 500 | else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0) |
| 501 | Resources.maxTessEvaluationTextureImageUnits = value; |
| 502 | else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0) |
| 503 | Resources.maxTessEvaluationUniformComponents = value; |
| 504 | else if (strcmp(token, "MaxTessPatchComponents") == 0) |
| 505 | Resources.maxTessPatchComponents = value; |
| 506 | else if (strcmp(token, "MaxPatchVertices") == 0) |
| 507 | Resources.maxPatchVertices = value; |
| 508 | else if (strcmp(token, "MaxTessGenLevel") == 0) |
| 509 | Resources.maxTessGenLevel = value; |
| 510 | else if (strcmp(token, "MaxViewports") == 0) |
| 511 | Resources.maxViewports = value; |
| 512 | else if (strcmp(token, "MaxVertexAtomicCounters") == 0) |
| 513 | Resources.maxVertexAtomicCounters = value; |
| 514 | else if (strcmp(token, "MaxTessControlAtomicCounters") == 0) |
| 515 | Resources.maxTessControlAtomicCounters = value; |
| 516 | else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0) |
| 517 | Resources.maxTessEvaluationAtomicCounters = value; |
| 518 | else if (strcmp(token, "MaxGeometryAtomicCounters") == 0) |
| 519 | Resources.maxGeometryAtomicCounters = value; |
| 520 | else if (strcmp(token, "MaxFragmentAtomicCounters") == 0) |
| 521 | Resources.maxFragmentAtomicCounters = value; |
| 522 | else if (strcmp(token, "MaxCombinedAtomicCounters") == 0) |
| 523 | Resources.maxCombinedAtomicCounters = value; |
| 524 | else if (strcmp(token, "MaxAtomicCounterBindings") == 0) |
| 525 | Resources.maxAtomicCounterBindings = value; |
| 526 | else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0) |
| 527 | Resources.maxVertexAtomicCounterBuffers = value; |
| 528 | else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0) |
| 529 | Resources.maxTessControlAtomicCounterBuffers = value; |
| 530 | else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0) |
| 531 | Resources.maxTessEvaluationAtomicCounterBuffers = value; |
| 532 | else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0) |
| 533 | Resources.maxGeometryAtomicCounterBuffers = value; |
| 534 | else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0) |
| 535 | Resources.maxFragmentAtomicCounterBuffers = value; |
| 536 | else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0) |
| 537 | Resources.maxCombinedAtomicCounterBuffers = value; |
| 538 | else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0) |
| 539 | Resources.maxAtomicCounterBufferSize = value; |
| 540 | else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0) |
| 541 | Resources.maxTransformFeedbackBuffers = value; |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 542 | else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0) |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 543 | Resources.maxTransformFeedbackInterleavedComponents = value; |
| 544 | else if (strcmp(token, "MaxCullDistances") == 0) |
| 545 | Resources.maxCullDistances = value; |
| 546 | else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0) |
| 547 | Resources.maxCombinedClipAndCullDistances = value; |
| 548 | else if (strcmp(token, "MaxSamples") == 0) |
| 549 | Resources.maxSamples = value; |
| 550 | |
| 551 | else if (strcmp(token, "nonInductiveForLoops") == 0) |
| 552 | Resources.limits.nonInductiveForLoops = (value != 0); |
| 553 | else if (strcmp(token, "whileLoops") == 0) |
| 554 | Resources.limits.whileLoops = (value != 0); |
| 555 | else if (strcmp(token, "doWhileLoops") == 0) |
| 556 | Resources.limits.doWhileLoops = (value != 0); |
| 557 | else if (strcmp(token, "generalUniformIndexing") == 0) |
| 558 | Resources.limits.generalUniformIndexing = (value != 0); |
| 559 | else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0) |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 560 | Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 561 | else if (strcmp(token, "generalVaryingIndexing") == 0) |
| 562 | Resources.limits.generalVaryingIndexing = (value != 0); |
| 563 | else if (strcmp(token, "generalSamplerIndexing") == 0) |
| 564 | Resources.limits.generalSamplerIndexing = (value != 0); |
| 565 | else if (strcmp(token, "generalVariableIndexing") == 0) |
| 566 | Resources.limits.generalVariableIndexing = (value != 0); |
| 567 | else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0) |
| 568 | Resources.limits.generalConstantMatrixVectorIndexing = (value != 0); |
| 569 | else |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 570 | printf("Warning: unrecognized limit (%s) in configuration file.\n", token); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 571 | |
| 572 | token = strtok(0, delims); |
| 573 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 574 | if (configStrings) FreeFileData(configStrings); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 575 | } |
| 576 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 577 | void VkTestFramework::SetMessageOptions(EShMessages &messages) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 578 | if (m_compile_options & EOptionRelaxedErrors) messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 579 | if (m_compile_options & EOptionIntermediate) messages = (EShMessages)(messages | EShMsgAST); |
| 580 | if (m_compile_options & EOptionSuppressWarnings) messages = (EShMessages)(messages | EShMsgSuppressWarnings); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | // |
| 584 | // Malloc a string of sufficient size and read a string into it. |
| 585 | // |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 586 | char **VkTestFramework::ReadFileData(const char *fileName) { |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 587 | FILE *in; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 588 | #if defined(_WIN32) && defined(__GNUC__) |
| 589 | in = fopen(fileName, "r"); |
| 590 | int errorCode = in ? 0 : 1; |
| 591 | #else |
| 592 | int errorCode = fopen_s(&in, fileName, "r"); |
| 593 | #endif |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 594 | |
| 595 | char *fdata; |
Jeremy Hayes | 3b2a3a3 | 2016-06-21 11:05:08 -0600 | [diff] [blame] | 596 | size_t count = 0; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 597 | const int maxSourceStrings = 5; |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 598 | char **return_data = (char **)malloc(sizeof(char *) * (maxSourceStrings + 1)); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 599 | |
| 600 | if (errorCode) { |
| 601 | printf("Error: unable to open input file: %s\n", fileName); |
| 602 | return 0; |
| 603 | } |
| 604 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 605 | while (fgetc(in) != EOF) count++; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 606 | |
| 607 | fseek(in, 0, SEEK_SET); |
| 608 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 609 | if (!(fdata = (char *)malloc(count + 2))) { |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 610 | printf("Error allocating memory\n"); |
| 611 | return 0; |
| 612 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 613 | if (fread(fdata, 1, count, in) != count) { |
| 614 | printf("Error reading input file: %s\n", fileName); |
| 615 | return 0; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 616 | } |
| 617 | fdata[count] = '\0'; |
| 618 | fclose(in); |
| 619 | if (count == 0) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 620 | return_data[0] = (char *)malloc(count + 2); |
| 621 | return_data[0][0] = '\0'; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 622 | m_num_shader_strings = 0; |
| 623 | return return_data; |
| 624 | } else |
| 625 | m_num_shader_strings = 1; |
| 626 | |
Jeremy Hayes | 3b2a3a3 | 2016-06-21 11:05:08 -0600 | [diff] [blame] | 627 | size_t len = (int)(ceil)((float)count / (float)m_num_shader_strings); |
| 628 | size_t ptr_len = 0, i = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 629 | while (count > 0) { |
| 630 | return_data[i] = (char *)malloc(len + 2); |
| 631 | memcpy(return_data[i], fdata + ptr_len, len); |
| 632 | return_data[i][len] = '\0'; |
| 633 | count -= (len); |
| 634 | ptr_len += (len); |
| 635 | if (count < len) { |
| 636 | if (count == 0) { |
| 637 | m_num_shader_strings = (i + 1); |
| 638 | break; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 639 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 640 | len = count; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 641 | } |
| 642 | ++i; |
| 643 | } |
| 644 | return return_data; |
| 645 | } |
| 646 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 647 | void VkTestFramework::FreeFileData(char **data) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 648 | for (int i = 0; i < m_num_shader_strings; i++) free(data[i]); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // |
| 652 | // Deduce the language from the filename. Files must end in one of the |
| 653 | // following extensions: |
| 654 | // |
| 655 | // .vert = vertex |
| 656 | // .tesc = tessellation control |
| 657 | // .tese = tessellation evaluation |
| 658 | // .geom = geometry |
| 659 | // .frag = fragment |
| 660 | // .comp = compute |
| 661 | // |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 662 | EShLanguage VkTestFramework::FindLanguage(const std::string &name) { |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 663 | size_t ext = name.rfind('.'); |
| 664 | if (ext == std::string::npos) { |
| 665 | return EShLangVertex; |
| 666 | } |
| 667 | |
| 668 | std::string suffix = name.substr(ext + 1, std::string::npos); |
| 669 | if (suffix == "vert") |
| 670 | return EShLangVertex; |
| 671 | else if (suffix == "tesc") |
| 672 | return EShLangTessControl; |
| 673 | else if (suffix == "tese") |
| 674 | return EShLangTessEvaluation; |
| 675 | else if (suffix == "geom") |
| 676 | return EShLangGeometry; |
| 677 | else if (suffix == "frag") |
| 678 | return EShLangFragment; |
| 679 | else if (suffix == "comp") |
| 680 | return EShLangCompute; |
| 681 | |
| 682 | return EShLangVertex; |
| 683 | } |
| 684 | |
| 685 | // |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 686 | // Convert VK shader type to compiler's |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 687 | // |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 688 | EShLanguage VkTestFramework::FindLanguage(const VkShaderStageFlagBits shader_type) { |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 689 | switch (shader_type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 690 | case VK_SHADER_STAGE_VERTEX_BIT: |
| 691 | return EShLangVertex; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 692 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 693 | case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: |
| 694 | return EShLangTessControl; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 695 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 696 | case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: |
| 697 | return EShLangTessEvaluation; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 698 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 699 | case VK_SHADER_STAGE_GEOMETRY_BIT: |
| 700 | return EShLangGeometry; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 701 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 702 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
| 703 | return EShLangFragment; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 704 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 705 | case VK_SHADER_STAGE_COMPUTE_BIT: |
| 706 | return EShLangCompute; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 707 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 708 | default: |
| 709 | return EShLangVertex; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 710 | } |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 711 | } |
| 712 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 713 | // |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 714 | // Compile a given string containing GLSL into SPV for use by VK |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 715 | // Return value of false means an error was encountered. |
| 716 | // |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 717 | bool VkTestFramework::GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spirv) { |
Courtney Goeltzenleuchter | c7def92 | 2015-09-24 17:05:05 -0600 | [diff] [blame] | 718 | glslang::TProgram program; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 719 | const char *shaderStrings[1]; |
| 720 | |
| 721 | // TODO: Do we want to load a special config file depending on the |
| 722 | // shader source? Optional name maybe? |
| 723 | // SetConfigFile(fileName); |
| 724 | |
| 725 | ProcessConfigFile(); |
| 726 | |
| 727 | EShMessages messages = EShMsgDefault; |
| 728 | SetMessageOptions(messages); |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 729 | messages = static_cast<EShMessages>(messages | EShMsgSpvRules | EShMsgVulkanRules); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 730 | |
| 731 | EShLanguage stage = FindLanguage(shader_type); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 732 | glslang::TShader *shader = new glslang::TShader(stage); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 733 | |
| 734 | shaderStrings[0] = pshader; |
| 735 | shader->setStrings(shaderStrings, 1); |
| 736 | |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 737 | if (!shader->parse(&Resources, (m_compile_options & EOptionDefaultDesktop) ? 110 : 100, false, messages)) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 738 | if (!(m_compile_options & EOptionSuppressInfolog)) { |
Cody Northrop | 195d662 | 2014-11-03 12:54:37 -0700 | [diff] [blame] | 739 | puts(shader->getInfoLog()); |
| 740 | puts(shader->getInfoDebugLog()); |
| 741 | } |
| 742 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 743 | return false; // something didn't work |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | program.addShader(shader); |
| 747 | |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 748 | // |
| 749 | // Program-level processing... |
| 750 | // |
| 751 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 752 | if (!program.link(messages)) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 753 | if (!(m_compile_options & EOptionSuppressInfolog)) { |
Cody Northrop | 195d662 | 2014-11-03 12:54:37 -0700 | [diff] [blame] | 754 | puts(shader->getInfoLog()); |
| 755 | puts(shader->getInfoDebugLog()); |
| 756 | } |
| 757 | |
| 758 | return false; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | if (m_compile_options & EOptionDumpReflection) { |
| 762 | program.buildReflection(); |
| 763 | program.dumpReflection(); |
| 764 | } |
| 765 | |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 766 | glslang::GlslangToSpv(*program.getIntermediate(stage), spirv); |
| 767 | |
| 768 | // |
| 769 | // Test the different modes of SPIR-V modification |
| 770 | // |
| 771 | if (this->m_canonicalize_spv) { |
| 772 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::ALL_BUT_STRIP); |
| 773 | } |
| 774 | |
| 775 | if (this->m_strip_spv) { |
| 776 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::STRIP); |
| 777 | } |
| 778 | |
| 779 | if (this->m_do_everything_spv) { |
| 780 | spv::spirvbin_t(0).remap(spirv, spv::spirvbin_t::DO_EVERYTHING); |
| 781 | } |
| 782 | |
Courtney Goeltzenleuchter | c7def92 | 2015-09-24 17:05:05 -0600 | [diff] [blame] | 783 | delete shader; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 784 | |
| 785 | return true; |
| 786 | } |