1 // Copyright (c) 2015-2016 The Khronos Group Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a 4 // copy of this software and/or associated documentation files (the 5 // "Materials"), to deal in the Materials without restriction, including 6 // without limitation the rights to use, copy, modify, merge, publish, 7 // distribute, sublicense, and/or sell copies of the Materials, and to 8 // permit persons to whom the Materials are furnished to do so, subject to 9 // 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 Materials. 13 // 14 // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 15 // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS 16 // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT 17 // https://www.khronos.org/registry/ 18 // 19 // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 26 27 #include <cassert> 28 #include <cstring> 29 30 #include "spirv-tools/libspirv.h" 31 #include "spirv_constant.h" 32 33 const char* spvTargetEnvDescription(spv_target_env env) { 34 switch (env) { 35 case SPV_ENV_UNIVERSAL_1_0: 36 return "SPIR-V 1.0"; 37 case SPV_ENV_VULKAN_1_0: 38 return "SPIR-V 1.0 (under Vulkan 1.0 semantics)"; 39 case SPV_ENV_UNIVERSAL_1_1: 40 return "SPIR-V 1.1"; 41 default: 42 break; 43 } 44 assert(0 && "Unhandled SPIR-V target environment"); 45 return ""; 46 } 47 48 uint32_t spvVersionForTargetEnv(spv_target_env env) { 49 switch (env) { 50 case SPV_ENV_UNIVERSAL_1_0: 51 case SPV_ENV_VULKAN_1_0: 52 return SPV_SPIRV_VERSION_WORD(1, 0); 53 case SPV_ENV_UNIVERSAL_1_1: 54 return SPV_SPIRV_VERSION_WORD(1, 1); 55 default: 56 break; 57 } 58 assert(0 && "Unhandled SPIR-V target environment"); 59 return SPV_SPIRV_VERSION_WORD(0, 0); 60 } 61 62 bool spvParseTargetEnv(const char* s, spv_target_env* env) { 63 if (!strncmp(s, "vulkan1.0", strlen("vulkan1.0"))) { 64 if (env) *env = SPV_ENV_VULKAN_1_0; 65 return true; 66 } else if (!strncmp(s, "spv1.0", strlen("spv1.0"))) { 67 if (env) *env = SPV_ENV_UNIVERSAL_1_0; 68 return true; 69 } else if (!strncmp(s, "spv1.1", strlen("spv1.1"))) { 70 if (env) *env = SPV_ENV_UNIVERSAL_1_1; 71 return true; 72 } else { 73 if (env) *env = SPV_ENV_UNIVERSAL_1_0; 74 return false; 75 } 76 } 77