aboutsummaryrefslogtreecommitdiff
path: root/glslc/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'glslc/src/main.cc')
-rw-r--r--glslc/src/main.cc75
1 files changed, 72 insertions, 3 deletions
diff --git a/glslc/src/main.cc b/glslc/src/main.cc
index 571e65f..108212d 100644
--- a/glslc/src/main.cc
+++ b/glslc/src/main.cc
@@ -21,12 +21,15 @@
#include <string>
#include <utility>
+#include "libshaderc_util/compiler.h"
+#include "libshaderc_util/io.h"
#include "libshaderc_util/string_piece.h"
#include "shaderc/shaderc.h"
#include "spirv-tools/libspirv.h"
#include "file.h"
#include "file_compiler.h"
+#include "resource_parse.h"
#include "shader_stage.h"
using shaderc_util::string_piece;
@@ -46,13 +49,21 @@ Options:
-Dmacro[=defn] Add an implicit macro definition.
-E Outputs only the results of the preprocessing step.
Output defaults to standard output.
+ -fentry-point=<name>
+ Specify the entry point name for HLSL compilation, for
+ all subsequent source files. Default is "main".
+ -flimit=<settings>
+ Specify resource limits. Each limit is specified by a limit
+ name followed by an integer value. Tokens should be
+ separated by whitespace. If the same limit is specified
+ several times, only the last setting takes effect.
+ --show-limits Display available limit names and their default values.
+ -flimit-file <file>
+ Set limits as specified in the given file.
-fshader-stage=<stage>
Treat subsequent input files as having stage <stage>.
Valid stages are vertex, fragment, tesscontrol, tesseval,
geometry, and compute.
- -fentry-point=<name>
- Specify the entry point name for HLSL compilation, for
- all subsequent source files. Default is "main".
-g Generate source-level debug information.
Currently this option has no effect.
--help Display available options.
@@ -110,6 +121,22 @@ bool GetOptionArgument(int argc, char** argv, int* index,
}
}
+// Sets resource limits according to the given string. The string
+// should be formated as required for ParseResourceSettings.
+// Returns true on success. Otherwise returns false and sets err
+// to a descriptive error message.
+bool SetResourceLimits(const std::string& str, shaderc::CompileOptions* options,
+ std::string* err) {
+ std::vector<glslc::ResourceSetting> settings;
+ if (!ParseResourceSettings(str, &settings, err)) {
+ return false;
+ }
+ for (const auto& setting : settings) {
+ options->SetLimit(setting.limit, setting.value);
+ }
+ return true;
+}
+
const char kBuildVersion[] =
#include "build-version.inc"
;
@@ -131,6 +158,20 @@ int main(int argc, char** argv) {
if (arg == "--help") {
::PrintHelp(&std::cout);
return 0;
+ } else if (arg == "--show-limits") {
+ shaderc_util::Compiler default_compiler;
+// The static cast here depends on us keeping the shaderc_limit enum in
+// lockstep with the shaderc_util::Compiler::Limit enum. The risk of mismatch
+// is low since both are generated from the same resources.inc file.
+#define RESOURCE(NAME, FIELD, ENUM) \
+ std::cout << #NAME << " " \
+ << default_compiler.GetLimit( \
+ static_cast<shaderc_util::Compiler::Limit>( \
+ shaderc_limit_##ENUM)) \
+ << std::endl;
+#include "libshaderc_util/resources.inc"
+#undef RESOURCE
+ return 0;
} else if (arg == "--version") {
std::cout << kBuildVersion << std::endl;
std::cout << "Target: " << spvTargetEnvDescription(SPV_ENV_UNIVERSAL_1_0)
@@ -156,6 +197,34 @@ int main(int argc, char** argv) {
} else if (arg.starts_with("-fentry-point=")) {
current_entry_point_name =
arg.substr(std::strlen("-fentry-point=")).str();
+ } else if (arg.starts_with("-flimit=")) {
+ std::string err;
+ if (!SetResourceLimits(arg.substr(std::strlen("-flimit=")).str(),
+ &compiler.options(), &err)) {
+ std::cerr << "glslc: error: -flimit error: " << err << std::endl;
+ return 1;
+ }
+ } else if (arg.starts_with("-flimit-file")) {
+ std::string err;
+ string_piece limits_file;
+ if (!GetOptionArgument(argc, argv, &i, "-flimit-file", &limits_file)) {
+ std::cerr << "glslc: error: argument to '-flimit-file' is missing"
+ << std::endl;
+ return 1;
+ }
+ std::vector<char> contents;
+ if (!shaderc_util::ReadFile(limits_file.str(), &contents)) {
+ std::cerr << "glslc: cannot read limits file: " << limits_file
+ << std::endl;
+ return 1;
+ }
+ if (!SetResourceLimits(
+ string_piece(contents.data(), contents.data() + contents.size())
+ .str(),
+ &compiler.options(), &err)) {
+ std::cerr << "glslc: error: -flimit-file error: " << err << std::endl;
+ return 1;
+ }
} else if (arg.starts_with("-std=")) {
const string_piece standard = arg.substr(std::strlen("-std="));
int version;