|
44 | 44 | #include "glslang/Public/ResourceLimits.h" |
45 | 45 | #include "Worklist.h" |
46 | 46 | #include "DirStackFileIncluder.h" |
47 | | -#include "./../glslang/Include/ShHandle.h" |
48 | 47 | #include "./../glslang/Public/ShaderLang.h" |
49 | 48 | #include "../glslang/MachineIndependent/localintermediate.h" |
50 | 49 | #include "../SPIRV/GlslangToSpv.h" |
51 | 50 | #include "../SPIRV/GLSL.std.450.h" |
52 | | -#include "../SPIRV/doc.h" |
53 | 51 | #include "../SPIRV/disassemble.h" |
54 | 52 |
|
55 | 53 | #include <array> |
|
58 | 56 | #include <cmath> |
59 | 57 | #include <cstdlib> |
60 | 58 | #include <cstring> |
| 59 | +#include <iterator> |
61 | 60 | #include <map> |
62 | 61 | #include <memory> |
63 | 62 | #include <set> |
64 | 63 | #include <thread> |
| 64 | +#include <type_traits> |
65 | 65 |
|
66 | 66 | #include "../glslang/OSDependent/osinclude.h" |
67 | 67 |
|
@@ -110,6 +110,8 @@ enum TOptions : uint64_t { |
110 | 110 | EOptionInvertY = (1ull << 30), |
111 | 111 | EOptionDumpBareVersion = (1ull << 31), |
112 | 112 | EOptionCompileOnly = (1ull << 32), |
| 113 | + EOptionDisplayErrorColumn = (1ull << 33), |
| 114 | + EOptionLinkTimeOptimization = (1ull << 34), |
113 | 115 | }; |
114 | 116 | bool targetHlslFunctionality1 = false; |
115 | 117 | bool SpvToolsDisassembler = false; |
@@ -842,6 +844,9 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem |
842 | 844 | } else if (strcmp(argv[1], "vulkan1.3") == 0) { |
843 | 845 | setVulkanSpv(); |
844 | 846 | ClientVersion = glslang::EShTargetVulkan_1_3; |
| 847 | + } else if (strcmp(argv[1], "vulkan1.4") == 0) { |
| 848 | + setVulkanSpv(); |
| 849 | + ClientVersion = glslang::EShTargetVulkan_1_4; |
845 | 850 | } else if (strcmp(argv[1], "opengl") == 0) { |
846 | 851 | setOpenGlSpv(); |
847 | 852 | ClientVersion = glslang::EShTargetOpenGL_450; |
@@ -898,6 +903,10 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem |
898 | 903 | Options |= EOptionDumpVersions; |
899 | 904 | } else if (lowerword == "no-link") { |
900 | 905 | Options |= EOptionCompileOnly; |
| 906 | + } else if (lowerword == "error-column") { |
| 907 | + Options |= EOptionDisplayErrorColumn; |
| 908 | + } else if (lowerword == "lto") { |
| 909 | + Options |= EOptionLinkTimeOptimization; |
901 | 910 | } else if (lowerword == "help") { |
902 | 911 | usage(); |
903 | 912 | break; |
@@ -1082,6 +1091,10 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem |
1082 | 1091 | if ((Options & EOptionDumpReflection) && !(Options & EOptionLinkProgram)) |
1083 | 1092 | Error("reflection requires -l for linking"); |
1084 | 1093 |
|
| 1094 | + // link time optimization makes no sense unless linking |
| 1095 | + if ((Options & EOptionLinkTimeOptimization) && !(Options & EOptionLinkProgram)) |
| 1096 | + Error("link time optimization requires -l for linking"); |
| 1097 | + |
1085 | 1098 | // -o or -x makes no sense if there is no target binary |
1086 | 1099 | if (binaryFileName && (Options & EOptionSpv) == 0) |
1087 | 1100 | Error("no binary generation requested (e.g., -V)"); |
@@ -1113,6 +1126,10 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem |
1113 | 1126 | TargetLanguage = glslang::EShTargetSpv; |
1114 | 1127 | TargetVersion = glslang::EShTargetSpv_1_6; |
1115 | 1128 | break; |
| 1129 | + case glslang::EShTargetVulkan_1_4: |
| 1130 | + TargetLanguage = glslang::EShTargetSpv; |
| 1131 | + TargetVersion = glslang::EShTargetSpv_1_6; |
| 1132 | + break; |
1116 | 1133 | case glslang::EShTargetOpenGL_450: |
1117 | 1134 | TargetLanguage = glslang::EShTargetSpv; |
1118 | 1135 | TargetVersion = glslang::EShTargetSpv_1_0; |
@@ -1164,6 +1181,10 @@ void SetMessageOptions(EShMessages& messages) |
1164 | 1181 | messages = (EShMessages)(messages | EShMsgEnhanced); |
1165 | 1182 | if (AbsolutePath) |
1166 | 1183 | messages = (EShMessages)(messages | EShMsgAbsolutePath); |
| 1184 | + if (Options & EOptionDisplayErrorColumn) |
| 1185 | + messages = (EShMessages)(messages | EShMsgDisplayErrorColumn); |
| 1186 | + if (Options & EOptionLinkTimeOptimization) |
| 1187 | + messages = (EShMessages)(messages | EShMsgLinkTimeOptimization); |
1167 | 1188 | } |
1168 | 1189 |
|
1169 | 1190 | // |
@@ -1506,6 +1527,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) |
1506 | 1527 |
|
1507 | 1528 | // Dump SPIR-V |
1508 | 1529 | if (Options & EOptionSpv) { |
| 1530 | +#ifdef ENABLE_SPIRV |
1509 | 1531 | CompileOrLinkFailed.fetch_or(CompileFailed); |
1510 | 1532 | CompileOrLinkFailed.fetch_or(LinkFailed); |
1511 | 1533 | if (static_cast<bool>(CompileOrLinkFailed.load())) |
@@ -1565,6 +1587,9 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) |
1565 | 1587 | } |
1566 | 1588 | } |
1567 | 1589 | } |
| 1590 | +#else |
| 1591 | + Error("This configuration of glslang does not have SPIR-V support"); |
| 1592 | +#endif |
1568 | 1593 | } |
1569 | 1594 |
|
1570 | 1595 | CompileOrLinkFailed.fetch_or(CompileFailed); |
@@ -1664,21 +1689,31 @@ int singleMain() |
1664 | 1689 | } |
1665 | 1690 |
|
1666 | 1691 | if (Options & EOptionDumpBareVersion) { |
1667 | | - printf("%d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR, GLSLANG_VERSION_MINOR, |
| 1692 | + int spirvGeneratorVersion = 0; |
| 1693 | +#ifdef ENABLE_SPIRV |
| 1694 | + spirvGeneratorVersion = glslang::GetSpirvGeneratorVersion(); |
| 1695 | +#endif |
| 1696 | + printf("%d:%d.%d.%d%s\n", spirvGeneratorVersion, GLSLANG_VERSION_MAJOR, GLSLANG_VERSION_MINOR, |
1668 | 1697 | GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR); |
1669 | 1698 | if (workList.empty()) |
1670 | 1699 | return ESuccess; |
1671 | 1700 | } else if (Options & EOptionDumpVersions) { |
1672 | | - printf("Glslang Version: %d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR, |
| 1701 | + int spirvGeneratorVersion = 0; |
| 1702 | +#ifdef ENABLE_SPIRV |
| 1703 | + spirvGeneratorVersion = glslang::GetSpirvGeneratorVersion(); |
| 1704 | +#endif |
| 1705 | + printf("Glslang Version: %d:%d.%d.%d%s\n", spirvGeneratorVersion, GLSLANG_VERSION_MAJOR, |
1673 | 1706 | GLSLANG_VERSION_MINOR, GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR); |
1674 | 1707 | printf("ESSL Version: %s\n", glslang::GetEsslVersionString()); |
1675 | 1708 | printf("GLSL Version: %s\n", glslang::GetGlslVersionString()); |
1676 | 1709 | std::string spirvVersion; |
| 1710 | +#if ENABLE_SPIRV |
1677 | 1711 | glslang::GetSpirvVersion(spirvVersion); |
| 1712 | +#endif |
1678 | 1713 | printf("SPIR-V Version %s\n", spirvVersion.c_str()); |
1679 | 1714 | printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision); |
1680 | 1715 | printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId()); |
1681 | | - printf("SPIR-V Generator Version %d\n", glslang::GetSpirvGeneratorVersion()); |
| 1716 | + printf("SPIR-V Generator Version %d\n", spirvGeneratorVersion); |
1682 | 1717 | printf("GL_KHR_vulkan_glsl version %d\n", 100); |
1683 | 1718 | printf("ARB_GL_gl_spirv version %d\n", 100); |
1684 | 1719 | if (workList.empty()) |
@@ -2024,6 +2059,7 @@ void usage() |
2024 | 2059 | " shaders compatible with DirectX\n" |
2025 | 2060 | " --invert-y | --iy invert position.Y output in vertex shader\n" |
2026 | 2061 | " --enhanced-msgs print more readable error messages (GLSL only)\n" |
| 2062 | + " --error-column display the column of the error along the line\n" |
2027 | 2063 | " --keep-uncalled | --ku don't eliminate uncalled functions\n" |
2028 | 2064 | " --nan-clamp favor non-NaN operand in min, max, and clamp\n" |
2029 | 2065 | " --no-storage-format | --nsf use Unknown image format\n" |
@@ -2117,7 +2153,8 @@ void usage() |
2117 | 2153 | " initialized with the shader binary code\n" |
2118 | 2154 | " --no-link Only compile shader; do not link (GLSL-only)\n" |
2119 | 2155 | " NOTE: this option will set the export linkage\n" |
2120 | | - " attribute on all functions\n"); |
| 2156 | + " attribute on all functions\n" |
| 2157 | + " --lto perform link time optimization\n"); |
2121 | 2158 |
|
2122 | 2159 | exit(EFailUsage); |
2123 | 2160 | } |
|
0 commit comments