summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Panteleev <apanteleev87@gmail.com>2022-03-08 12:16:32 -0800
committerGitHub <noreply@github.com>2022-03-08 15:16:32 -0500
commit2a80bcfa96089967b299eea0454d9debe52fa0f6 (patch)
treec8e841e358e970f40c4f2d07409c7c6d7ae4c566
parent11da2fb2051894b3cc873748cfc8f47588d8af93 (diff)
Slangc improvements: help message, downstream error passthrough (#2152)
* Pass through the downstream compiler error messages if they are not recognized. * Added a help message that is printed on -h, -help, --help. Added -version as an alias for -v. * Fixed the bug in -lang option processing.
-rw-r--r--source/compiler-core/slang-downstream-compiler.cpp2
-rw-r--r--source/slang/slang-options.cpp221
2 files changed, 220 insertions, 3 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.cpp b/source/compiler-core/slang-downstream-compiler.cpp
index daf31c9eb..1dfaea0a4 100644
--- a/source/compiler-core/slang-downstream-compiler.cpp
+++ b/source/compiler-core/slang-downstream-compiler.cpp
@@ -221,7 +221,7 @@ void DownstreamDiagnostics::requireErrorDiagnostic()
DownstreamDiagnostic diagnostic;
diagnostic.reset();
diagnostic.severity = DownstreamDiagnostic::Severity::Error;
- diagnostic.text = "Generic error during compilation";
+ diagnostic.text = rawDiagnostics;
// Add the diagnostic
diagnostics.add(diagnostic);
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 07f474c78..5d8d52a09 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -487,6 +487,218 @@ struct OptionsParser
return SLANG_OK;
}
+ static char const* getHelpText()
+ {
+#ifdef _WIN32
+#define EXECUTABLE_EXTENSION ".exe"
+#else
+#define EXECUTABLE_EXTENSION ""
+#endif
+
+ return
+ "Usage: slangc" EXECUTABLE_EXTENSION " [options...] [--] <input files>\n"
+ "\n"
+ "General options:\n"
+ "\n"
+ " -D<name>[=<value>], -D <name>[=<value>]: Insert a preprocessor macro.\n"
+ " -entry <name>: Specify the name of an entry-point function.\n"
+ " Multiple -entry options may be used in a single invocation.\n"
+ " If no -entry options are given, compiler will use [shader(...)]\n"
+ " attributes to detect entry points.\n"
+ " -h, -help, --help: Print this message.\n"
+ " -I<path>, -I <path>: Add a path to be used in resolving '#include'\n"
+ " and 'import' operations.\n"
+ " -lang <language>: Set the language for the following input files.\n"
+ " Accepted languages are:\n"
+ " c, cpp, c++, cxx, slang, glsl, hlsl, cu, cuda\n"
+ " -matrix-layout-column-major: Set the default matrix layout to column-major.\n"
+ " -matrix-layout-row-major: Set the default matrix layout to row-major.\n"
+ " -module-name <name>: Set the module name to use when compiling multiple\n"
+ " .slang source files into a single module.\n"
+ " -o <path>: Specify a path where generated output should be written.\n"
+ " If no -target or -stage is specified, one may be inferred\n"
+ " from file extension (see File Extensions).\n"
+ " If multiple -target options and a single -entry are present, each -o\n"
+ " associates with the first -target to its left.\n"
+ " Otherwise, if multiple -entry options are present, each -o associates\n"
+ " with the first -entry to its left, and with the -target that matches\n"
+ " the one inferred from <path>.\n"
+ " -profile <profile>[+<capability>...]: Specify the shader profile for code\n"
+ " generation.\n"
+ " Accepted profiles are:\n"
+ " sm_{4_0,4_1,5_0,5_1,6_0,6_1,6_2,6_3,6_4,6_5,6_6}\n"
+ " glsl_{110,120,130,140,150,330,400,410,420,430,440,450,460}\n"
+ " Additional profiles that include -stage information:\n"
+ " {vs,hs,ds,gs,ps}_<version>\n"
+ " See -capability for information on <capability>\n"
+ " When multiple -target options are present, each -profile associates\n"
+ " with the first -target to its left.\n"
+ " -stage <name>: Specify the stage of an entry-point function.\n"
+ " Accepted stages are:\n"
+ " vertex, hull, domain, geometry, fragment, compute,\n"
+ " raygeneration, intersection, anyhit, closesthit, miss, callable\n"
+ " When multiple -entry options are present, each -stage associated with\n"
+ " the first -entry to its left.\n"
+ " May be omitted if entry-point function has a [shader(...)] attribute;\n"
+ " otherwise required for each -entry option.\n"
+ " -target <format>: Specifies the format in which code should be generated.\n"
+ " Accepted formats are:\n"
+ " glsl, hlsl, spirv, spirv-assembly, dxbc,\n"
+ " dxbc-assembly, dxil, dxil-assembly\n"
+ " -v, -version: Display the build version.\n"
+ " --: Treat the rest of the command line as input files.\n"
+ "\n"
+ "Target code generation options:\n"
+ "\n"
+ " -capability <capability>[+<capability>...]: Add optional capabilities\n"
+ " to a code generation target. See Capabilities below.\n"
+ " -default-image-format-unknown: Set the format of R/W images with unspecified\n"
+ " format to 'unknown'. Otherwise try to guess the format.\n"
+ " -disable-dynamic-dispatch: Disables generating dynamic dispatch code.\n"
+ " -disable-specialization: Disables generics and specialization pass.\n"
+ " -fp-mode <mode>, -floating-point-mode <mode>: Set the floating point mode.\n"
+ " Accepted modes are:\n"
+ " precise : Disable optimization that could change the output of floating-\n"
+ " point computations, including around infinities, NaNs, denormalized\n"
+ " values, and negative zero. Prefer the most precise versions of special\n"
+ " functions supported by the target.\n"
+ " fast : Allow optimizations that may change results of floating-point\n"
+ " computations. Prefer the fastest version of special functions supported\n"
+ " by the target.\n"
+ " -g, -g<N>: Include debug information in the generated code, where possible.\n"
+ " N is the amount of information, 0..3, unspecified means 2\n"
+ " -line-directive-mode <mode>: Sets how the `#line` directives should be\n"
+ " produced. Available options are:\n"
+ " none : Don't emit `#line` directives at all\n"
+ " If not specified, default behavior is to use C-style `#line` directives\n"
+ " for HLSL and C/C++ output, and traditional GLSL-style `#line` directives\n"
+ " for GLSL output.\n"
+ " -O<N>: Set the optimization level.\n"
+ " N is the amount of optimization, 0..3, default is 1\n"
+ " -obfuscate: Remove all source file information from outputs.\n"
+ "\n"
+ "Downstream compiler options:\n"
+ "\n"
+ " -<compiler>-path: Specify path to a downstream <compiler>\n"
+ " executable or library. Accepted compilers are:\n"
+ " fxc (d3dcompiler_47.dll)\n"
+ " dxc (dxcompiler.*)\n"
+ " glslang (slang-glslang.*)\n"
+ " vs = visualstudio (cl.exe)\n"
+ " clang\n"
+ " gcc (g++)\n"
+ " c = cpp = genericcpp\n"
+ " nvrtc\n"
+ " llvm\n"
+ " -default-downstream-compiler <language> <compiler>: Set a default compiler\n"
+ " for the given language. See -lang for the list of languages.\n"
+ " -X<compiler> <option>: Pass arguments to downstream <compiler>.\n"
+ "\n"
+ "Compiler debugging/instrumentation options:\n"
+ "\n"
+ " -dump-ast: Dump the AST to a .slang-ast file next to the input.\n"
+ " -dump-intermediate-prefix <prefix>: File name prefix for -dump-intermediates \n"
+ " outputs, default is 'slang-dump-'\n"
+ " -dump-intermediates: Dump intermediate outputs for debugging.\n"
+ " -dump-ir: Dump the IR for debugging.\n"
+ " -dump-ir-ids: Dump the IDs with -dump-ir (debug builds only)\n"
+ " -dump-repro: Dump a `.slang-repro` file that can be used to reproduce\n"
+ " a compilation on another machine.\n"
+ " -dump-repro-on-error: Dump `.slang-repro` file on any compilation error.\n"
+ " -E, -output-preprocessor: Output the preprocessing result and exit.\n"
+ " -extract-repro <name>: Extract the repro files into a folder.\n"
+ " -load-repro <name>\n"
+ " -load-repro-directory <path>\n"
+ " -no-codegen: Skip the code generation step, just check the code and\n"
+ " generate layout.\n"
+ " -output-includes: Print the hierarchy of the processed source files.\n"
+ " -pass-through <name>: Pass the input through mostly unmodified to the \n"
+ " existing compiler <name>. Accepted compilers are:\n"
+ " fxc, glslang, dxc\n"
+ " -repro-file-system <name>\n"
+ " -serial-ir: Serialize the IR between front-end and back-end.\n"
+ " -skip-codegen: Skip the code generation phase.\n"
+ " -validate-ir: Validate the IR between the phases.\n"
+ " -verbose-paths: Display more detailed paths in diagnostic output.\n"
+ " -verify-debug-serial-ir: Verify IR in the front-end.\n"
+ "\n"
+ "Experimental options (use at your own risk):\n"
+ "\n"
+ " -emit-spirv-directly: Generate SPIR-V output directly (otherwise through \n"
+ " GLSL and using the glslang compiler)\n"
+ " -file-system <fs>: Set the filesystem hook to use for a compile request.\n"
+ " Accepted file systems:\n"
+ " default, load-file, os\n"
+ " -heterogeneous: Output heterogeneity-related code.\n"
+ " -no-mangle: Do as little mangling of names as possible.\n"
+ "\n"
+ "Internal-use options (use at your own risk):\n"
+ "\n"
+ " -archive-type <type>: Set the archive type for -save-stdlib. Default is zip.\n"
+ " Accepted archive types:\n"
+ " zip, riff, riff-deflate, riff-lz4\n"
+ " -compile-stdlib: Compile the StdLib from embedded sources.\n"
+ " Will return a failure if there is already a StdLib available.\n"
+ " -doc: Write documentation for -compile-stdlib\n"
+ " -ir-compression <type>: Set compression for IR and AST outputs.\n"
+ " Accepted compression types:\n"
+ " none, lite\n"
+ " -load-stdlib <filename>: Load the StdLib from file.\n"
+ " -r <name>: reference module <name>\n"
+ " -save-stdlib <filename>: Save the StdLib modules to an archive file.\n"
+ " -save-stdlib-bin-source <filename>: Same as -save-stdlib but output\n"
+ " the data as a C array.\n"
+ "\n"
+ "Deprecated options (allowed but ignored; may be removed in future):\n"
+ "\n"
+ " -parameter-blocks-use-register-spaces\n"
+ "\n"
+ "File Extensions:\n"
+ "\n"
+ " A <language>, <format>, and/or <stage> may be inferred from the\n"
+ " extension of an input or -o path:\n"
+ "\n"
+ " extension | language/format | stage\n"
+ " ====================|=================|======\n"
+ " .hlsl, .fx -> hlsl\n"
+ " .dxbc -> dxbc\n"
+ " .dxbc.asm -> dxbc-assembly\n"
+ " .dxil -> dxil\n"
+ " .dxil.asm -> dxil-assembly\n"
+ " .glsl -> glsl\n"
+ " .vert -> glsl vertex\n"
+ " .frag -> glsl fragment\n"
+ " .geom -> glsl geoemtry\n"
+ " .tesc -> glsl hull\n"
+ " .tese -> glsl domain\n"
+ " .comp -> glsl compute\n"
+ " .slang -> slang\n"
+ " .spv -> spirv\n"
+ " .spv.asm -> spirv-assembly\n"
+ " .c -> c\n"
+ " .cpp, .c++, .cxx -> c++\n"
+ " .exe -> executable\n"
+ " .dll, .so -> sharedlibrary\n"
+ " .cu -> cuda\n"
+ " .ptx -> ptx\n"
+ " .obj, .o -> object-code\n"
+ "\n"
+ "Capabilities:\n"
+ "\n"
+ " A capability describes an optional feature that a target may or\n"
+ " may not support. When a -capability is specified, the compiler\n"
+ " may assume that the target supports that capability, and generate\n"
+ " code accordingly.\n"
+ " Currently defined capabilities are:\n"
+ "\n"
+ " spriv_1_{0,1,2,3,4,5} - minimum supported SPIR-V version\n"
+ " GL_NV_ray_tracing - enables the GL_NV_ray_tracing extension\n"
+ " GL_EXT_ray_tracing - enables the GL_EXT_ray_tracing extension\n"
+ "\n";
+
+#undef EXECUTABLE_EXTENSION
+ }
+
SlangResult parse(
int argc,
char const* const* argv)
@@ -966,7 +1178,7 @@ struct OptionsParser
}
else
{
- while (reader.hasArg() && reader.peekValue().startsWith("-"))
+ while (reader.hasArg() && !reader.peekValue().startsWith("-"))
{
SLANG_RETURN_ON_FAIL(addInputPath(reader.getValueAndAdvance().getBuffer(), sourceLanguage));
}
@@ -1184,10 +1396,15 @@ struct OptionsParser
_addLibraryReference(requestImpl, &fileStream);
}
- else if (argValue == "-v")
+ else if (argValue == "-v" || argValue == "-version")
{
sink->diagnoseRaw(Severity::Note, session->getBuildTagString());
}
+ else if (argValue == "-h" || argValue == "-help" || argValue == "--help")
+ {
+ sink->diagnoseRaw(Severity::Note, getHelpText());
+ return SLANG_FAIL;
+ }
else if( argValue == "-emit-spirv-directly" )
{
getCurrentTarget()->targetFlags |= SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY;