| 1 |
= glslc Manual |
| 2 |
:toc: |
| 3 |
:toclevels: 3 |
| 4 |
:numbered: |
| 5 |
:source-highlighter: pygments |
| 6 |
|
| 7 |
== Name |
| 8 |
|
| 9 |
`glslc` - A command-line GLSL/HLSL to SPIR-V compiler with |
| 10 |
Clang-compatible arguments. |
| 11 |
|
| 12 |
== Synopsis |
| 13 |
|
| 14 |
---- |
| 15 |
glslc [--help] |
| 16 |
glslc [-h] |
| 17 |
|
| 18 |
glslc [--show-limits] |
| 19 |
|
| 20 |
glslc [-c|-S|-E] |
| 21 |
[-x ...] [-std=standard] |
| 22 |
[ ... options for resource bindings ... ] |
| 23 |
[-fhlsl-16bit-types] |
| 24 |
[-fhlsl-offsets] |
| 25 |
[-fhlsl-functionality1] |
| 26 |
[-fentry-point=<name>] |
| 27 |
[-fauto-map-locations] |
| 28 |
[-finvert-y] |
| 29 |
[-flimit=...] |
| 30 |
[-flimit-file <resource-limits-file>] |
| 31 |
[-fshader-stage=...] |
| 32 |
[--target-env=...] |
| 33 |
[--target-spv=...] |
| 34 |
[-g] |
| 35 |
[-O0|-Os] |
| 36 |
[-Idirectory...] |
| 37 |
[-Dmacroname[=value]...] |
| 38 |
[-w] [-Werror] |
| 39 |
[-o outfile] |
| 40 |
shader... |
| 41 |
---- |
| 42 |
|
| 43 |
== Description |
| 44 |
|
| 45 |
=== Input file languages |
| 46 |
|
| 47 |
glslc accepts both GLSL/HLSL source and SPIR-V assembly files as inputs. |
| 48 |
|
| 49 |
==== Shader stage specification |
| 50 |
|
| 51 |
glslc provides three ways to specify the shader stage of a GLSL source file: |
| 52 |
`-fshader-stage=<stage>`, `#pragma shader_stage(<stage>)`, and file extension. |
| 53 |
The `-fshader-stage=` option overrides `#pragma shader_stage()`, which overrides |
| 54 |
the file extension. |
| 55 |
|
| 56 |
Shader stages can be specified by naming a file with an appropriate extension |
| 57 |
as shown in the following table. `-fshader-stage=` and `#pragma shader_stage()`, |
| 58 |
on the other hand, enable you to specify shader stages from the command line |
| 59 |
and within the source file. Possible ``stage``s for them are also listed in |
| 60 |
the following table. Details about `-fshader-stage=` can be found in |
| 61 |
<<option-fshader-stage,its own section>>. |
| 62 |
|
| 63 |
[[shader-stage-selection]] |
| 64 |
.Shader Stage Selection |
| 65 |
|=== |
| 66 |
|Shader Stage |Shader File Extension |`<stage>` |
| 67 |
|
| 68 |
|vertex |`.vert` |`vertex` |
| 69 |
|fragment |`.frag` |`fragment` |
| 70 |
|tesselation control |`.tesc` |`tesscontrol` |
| 71 |
|tesselation evaluation |`.tese` |`tesseval` |
| 72 |
|geometry |`.geom` |`geometry` |
| 73 |
|compute |`.comp` |`compute` |
| 74 |
|=== |
| 75 |
|
| 76 |
`#pragma shader_stage()` relies on the `#pragma` preprocessor directive; thus, |
| 77 |
the token inside `shader_stage()` is not subject to preprocessor macro |
| 78 |
expansion. It must be exactly one of the ``stage``s in the above table. |
| 79 |
|
| 80 |
`#pragma shader_stage()` behaves as follows: |
| 81 |
|
| 82 |
* The first `#pragma shader_stage()` directive in a translation unit must |
| 83 |
precede any non-preprocessor tokens. |
| 84 |
* If there is more than one `#pragma shader_stage()` directive in the same |
| 85 |
translation unit, all the ``stage``s specified must be the same. Otherwise, |
| 86 |
glslc will issue an error. |
| 87 |
|
| 88 |
==== SPIR-V assembly files |
| 89 |
|
| 90 |
SPIR-V assembly input files should follow the |
| 91 |
https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md[syntax] |
| 92 |
defined in the https://github.com/KhronosGroup/SPIRV-Tools[SPIRV-Tools] |
| 93 |
project and have the `.spvasm` extension. Command line options treat SPIR-V |
| 94 |
assembly files differently; some may ignore them, e.g., `<<option-cap-e,-E>>`, |
| 95 |
`<<option-cap-s,-S>>`, and some may even treat them not as SPIR-V assembly |
| 96 |
files, e.g., `<<shader-stage-with-spirv-assembly,-fshader-stage\=>>`. |
| 97 |
|
| 98 |
[[output-file-naming]] |
| 99 |
=== Output file naming |
| 100 |
|
| 101 |
If a name is specified via `-o`, the output file will be given that name. |
| 102 |
Otherwise, |
| 103 |
|
| 104 |
* If a compilation stage selection option is given (`-S` or `-c`), there will |
| 105 |
be one output file generated per input shader file. The generated output file |
| 106 |
will end with a file extension that matches the compilation stage, which is |
| 107 |
`.spvasm` for `-S` and `.spv` for `-c`. The name will depend on the original |
| 108 |
file's name and extension. |
| 109 |
** If the input file has a <<shader-stage-selection,shader stage selection |
| 110 |
extension>>, the output file will be named as by appending the file extension |
| 111 |
for the compilation stage to the input file's name. E.g., `glslc -c foo.vert` |
| 112 |
will generate `foo.vert.spv`, and `glslc -S bar.frag` will generate |
| 113 |
`bar.frag.spvasm`. |
| 114 |
** Otherwise, the output file will be named as by replacing the input file's |
| 115 |
file extension, if any, with the file extension for the compilation stage. |
| 116 |
E.g., `glslc -c foo` will generate `foo.spv`, and `glslc -S bar.glsl` will |
| 117 |
generate `bar.spvasm`. |
| 118 |
* If no compilation stage is selected, the output file will be named `a.spv`. |
| 119 |
|
| 120 |
== Command Line Options |
| 121 |
|
| 122 |
=== Overall Options |
| 123 |
|
| 124 |
==== `--help`, `-h` |
| 125 |
|
| 126 |
Option `--help` or `-h` tells the glslc compiler to display all available options and exit. |
| 127 |
|
| 128 |
==== `--show-limits` |
| 129 |
|
| 130 |
`--show-limits` shows default resource limits for shader compilation. The syntax |
| 131 |
is the same as accepted by `-flimit=` and for the contents of the file specified |
| 132 |
by `-flimit-file`. |
| 133 |
|
| 134 |
==== `-o` |
| 135 |
|
| 136 |
`-o` lets you specify the output file's name. It cannot be used when there are |
| 137 |
multiple files generated. A filename of `-` represents standard output. |
| 138 |
|
| 139 |
=== Language and Mode Selection Options |
| 140 |
|
| 141 |
[[option-finvert-y]] |
| 142 |
==== `-finvert-y` |
| 143 |
|
| 144 |
Inverts position.Y output in a vertex shader. |
| 145 |
|
| 146 |
[[option-flimit]] |
| 147 |
==== `-flimit=` |
| 148 |
|
| 149 |
`-flimit=<resource-limits>` lets you specify resource limits. |
| 150 |
The argument should be a sequence of limit name, integer value pairs. Tokens |
| 151 |
should be separated by whitespace. If the same limit is specified several |
| 152 |
times, only the last setting takes effect. |
| 153 |
|
| 154 |
Use `--show-limits` to show the default values, and example syntax. |
| 155 |
|
| 156 |
This option affects all compiled shaders. |
| 157 |
|
| 158 |
[[option-flimit-file]] |
| 159 |
==== `-flimit-file` |
| 160 |
|
| 161 |
`-flimit-file <resource-limits-file>` lets you specify resource limits in a file. |
| 162 |
The syntax of the file contents is the same as the argument to `-flimit=` and |
| 163 |
the output of `--show-limits`. This option accepts Glslang resource configuration |
| 164 |
files, e.g. as emitted by `glslangValidator -c`. |
| 165 |
|
| 166 |
This option affects all compiled shaders. |
| 167 |
|
| 168 |
[[option-fshader-stage]] |
| 169 |
==== `-fshader-stage=` |
| 170 |
|
| 171 |
`-fshader-stage=<stage>` lets you specify the shader stage for one or more |
| 172 |
inputs from the command line. |
| 173 |
|
| 174 |
Possible values for ``<stage>`` are listed in the <<shader-stage-selection, |
| 175 |
Shader Stage Selection>> table. |
| 176 |
|
| 177 |
`-fshader-stage=` behaves as follows: |
| 178 |
|
| 179 |
* `-fshader-stage=` sets the shader stage for subsequent input files. It does |
| 180 |
not affect the stages of any preceding inputs on the command line. |
| 181 |
* When supplying more than one `-fshader-stage=` argument, the most recent |
| 182 |
argument preceding an input file applies. |
| 183 |
* A shader file not ending with <<shader-stage-selection,known shader file |
| 184 |
extensions>> must have a `-fshader-stage=` argument ahead of it to specify |
| 185 |
its stage. |
| 186 |
* If there is a `-fshader-stage=` before a file in which there is a `#pragma |
| 187 |
shader_stage()` directive, the directive is ignored and the `-fshader-stage=` |
| 188 |
argument is used instead. |
| 189 |
* If there is a `-fshader-stage=` before a file with a known shader file |
| 190 |
extension, the file extension is ignored and the `-fshader-stage=` argument |
| 191 |
is used instead. |
| 192 |
|
| 193 |
[[shader-stage-with-spirv-assembly]] |
| 194 |
CAUTION: `-fshader-stage=` overrides file extension; that means it should not |
| 195 |
be used together with SPIR-V assembly files because glslc will treat the given |
| 196 |
SPIR-V assembly files as GLSL source code of the given shader stage. If you |
| 197 |
need to supply both SPIR-V assembly files and `-fshader-stage=` on the same |
| 198 |
command line, please put SPIR-V assembly files ahead of the first |
| 199 |
`-fshader-stage=`, since `-fshader-stage=` only affects the treatment of |
| 200 |
subsequent files. |
| 201 |
|
| 202 |
==== `-std=` |
| 203 |
|
| 204 |
`-std=<value>` lets you specify a shader version and profile on the command |
| 205 |
line. ``<value>`` can be any valid concatenation of a GLSL version number and |
| 206 |
profile, e.g., `310es`, `450core`, etc. The profile can be omitted as allowed by |
| 207 |
GLSL, e.g., `450`. |
| 208 |
|
| 209 |
`-std=` behaves as follows: |
| 210 |
|
| 211 |
* `-std=` affects the version of all GLSL inputs passed to `glslc`. |
| 212 |
* `-std=` is ignored for HLSL inputs. |
| 213 |
* `-std=` overwrites `#version` directives in all input shaders, including those |
| 214 |
preceding the argument. |
| 215 |
* If a `-std=` argument specifies a different version from a `#version` |
| 216 |
directive in an input file, `glslc` will issue a warning. |
| 217 |
* If multiple `-std=` arguments are specified on the command line, only the last |
| 218 |
one takes effect. |
| 219 |
|
| 220 |
CAUTION: `-std=` does not affect the `#version` directive in the preprocessed |
| 221 |
output. That is, when `-std=` specifies a version different from the shader |
| 222 |
source code, the `#version` directive in preprocessed output will still be the |
| 223 |
one in the source code. But `-std=` does affect the behavior of `#line` |
| 224 |
directives in the preprocessed output. Behavior of `#line` directives will |
| 225 |
follow the version specified by `-std=`. |
| 226 |
|
| 227 |
==== `--target-env=` |
| 228 |
|
| 229 |
`--target-env=<value>` lets you specify a target environment on the command line. |
| 230 |
This affects the generation of warnings and errors. The ``<value>`` can be one of |
| 231 |
the following: |
| 232 |
|
| 233 |
* `vulkan`: create SPIR-V under Vulkan 1.0 semantics. |
| 234 |
* `vulkan1.0`: create SPIR-V under Vulkan 1.0 semantics. |
| 235 |
* `vulkan1.1`: create SPIR-V under Vulkan 1.1 semantics. |
| 236 |
* `vulkan1.2`: create SPIR-V under Vulkan 1.2 semantics. |
| 237 |
* `vulkan1.3`: create SPIR-V under Vulkan 1.3 semantics. |
| 238 |
* `vulkan1.4`: create SPIR-V under Vulkan 1.4 semantics. |
| 239 |
* `opengl`: create SPIR-V under OpenGL 4.5 semantics. |
| 240 |
* `opengl4.5`: create SPIR-V under OpenGL 4.5 semantics. |
| 241 |
|
| 242 |
Generated code uses SPIR-V 1.0, except for code compiled for Vulkan 1.1, which uses |
| 243 |
SPIR-V 1.3, and code compiled for Vulkan 1.2, which uses SPIR-V 1.5. |
| 244 |
|
| 245 |
If this option is not specified, a default of `vulkan1.0` is used. |
| 246 |
|
| 247 |
Note: Support for OpenGL compatibility profile, `opengl_compat`, has been removed. |
| 248 |
|
| 249 |
==== `--target-spv=` |
| 250 |
|
| 251 |
`--target-spv=<value>` lets you specify the SPIR-V version to be used by the generated |
| 252 |
module. The default is to use the highest version of SPIR-V required to be supported |
| 253 |
by the target environment. The defaults for specific Vulkan target environments are |
| 254 |
as follows: SPIR-V 1.0 for Vulkan 1.0, SPIR-V 1.3 for Vulkan 1.1, and SPIR-V 1.5 for |
| 255 |
Vulkan 1.2. |
| 256 |
|
| 257 |
The ``<value>`` can be one of the following: |
| 258 |
|
| 259 |
* `spv1.0` |
| 260 |
* `spv1.1` |
| 261 |
* `spv1.2` |
| 262 |
* `spv1.3` |
| 263 |
* `spv1.4` |
| 264 |
* `spv1.5` |
| 265 |
* `spv1.6` |
| 266 |
|
| 267 |
==== `-x` |
| 268 |
|
| 269 |
`-x` lets you specify the language of the input shader files. Valid languages |
| 270 |
are `glsl` and `hlsl`. If the file extension is `hlsl` then the default language |
| 271 |
is HLSL. Otherwise the default is 'glsl'. |
| 272 |
|
| 273 |
Note: HLSL compilation will use HLSL packing (offset) rules for variables |
| 274 |
that are vertex shader outputs, and inputs and outputs of both geometry |
| 275 |
and pixel shaders. |
| 276 |
|
| 277 |
[[compilation-stage-selection-options]] |
| 278 |
=== Compilation Stage Selection Options |
| 279 |
|
| 280 |
==== `-c` |
| 281 |
|
| 282 |
`-c` tells the glslc compiler to run the preprocessing and compiling stage. |
| 283 |
Each input shader file results in a SPIR-V binary file; these SPIR-V binary |
| 284 |
files are named by the rules in the <<output-file-naming,Output File Naming>> |
| 285 |
section. |
| 286 |
|
| 287 |
[[option-cap-e]] |
| 288 |
==== `-E` |
| 289 |
|
| 290 |
`-E` tells the glslc compiler to run only the preprocessing stage. It overrides |
| 291 |
`-c` and `-S`. Preprocessed output is written to standard output, while |
| 292 |
preprocessing errors are written to standard error. If multiple input shader |
| 293 |
files are given, their preprocessed output are all written to standard output, |
| 294 |
in the order specified on the command line. |
| 295 |
|
| 296 |
glslc will do nothing for SPIR-V assembly files with this option. |
| 297 |
|
| 298 |
[[option-cap-s]] |
| 299 |
==== `-S` |
| 300 |
|
| 301 |
`-S` tells the glslc compiler to run the preprocessing, compiling, and then |
| 302 |
disassembling stage. It overrides `-c`. Each input shader file results in a |
| 303 |
SPIR-V assembly file; these SPIR-V assembly files are named by the rules in the |
| 304 |
<<output-file-naming,Output File Naming>> section. |
| 305 |
|
| 306 |
glslc will do nothing for SPIR-V assembly files with this option. |
| 307 |
|
| 308 |
==== No Compilation Stage Selection |
| 309 |
|
| 310 |
If none of the above options is given, the glslc compiler will run |
| 311 |
preprocessing, compiling, and linking stages. |
| 312 |
|
| 313 |
WARNING: Linking of multiple input shader files are not supported yet. |
| 314 |
|
| 315 |
=== Preprocessor Options |
| 316 |
|
| 317 |
==== `-D` |
| 318 |
|
| 319 |
`-Dmacroname[=[value]]` lets you define a preprocessor macro before input shader |
| 320 |
files are preprocessed. If `value` is omitted, the macro is defined with an |
| 321 |
empty value. |
| 322 |
|
| 323 |
==== `-I` |
| 324 |
|
| 325 |
`-Idirectory` or `-I directory` adds the specified directory to the search path |
| 326 |
for include files. The directory may be an absolute path or a relative path to |
| 327 |
the current working directory. |
| 328 |
|
| 329 |
=== Code Generation Options |
| 330 |
|
| 331 |
==== `-g` |
| 332 |
|
| 333 |
Requests that the compiler place source-level debug information into the object |
| 334 |
code, such as identifier names and line numbers. |
| 335 |
|
| 336 |
This option restrains `-O` from turning on the strip-debug-info optimization |
| 337 |
pass. |
| 338 |
|
| 339 |
NOTE: Currently this option has no effect. Full functionality depends on |
| 340 |
glslang support for generating debug info. |
| 341 |
|
| 342 |
==== `-O0`, `-Os` |
| 343 |
|
| 344 |
`-O` specifies which optimization level to use: |
| 345 |
|
| 346 |
* `-O0` means "no optimization". This level generates the most debuggable code. |
| 347 |
* `-O` means the default optimization level for better performance. |
| 348 |
* `-Os` enables optimizations to reduce code size. |
| 349 |
|
| 350 |
==== `-mfmt=<format>` |
| 351 |
|
| 352 |
`-mfmt=<format>` selects output format for compilation output in SPIR-V binary |
| 353 |
code form. Supported options are listed in the |
| 354 |
<<binary-output-format-options,binary output format options>> table. This |
| 355 |
option is only valid to be used when the compilation output is SPIR-V binary |
| 356 |
code. Specifying any options listed below when the output is not SPIR-V binary |
| 357 |
code, like disassembly (with `-S` specified), text (with `-M`, `-MM` or `-E` |
| 358 |
specified) will trigger an error. |
| 359 |
|
| 360 |
[[binary-output-format-options]] |
| 361 |
.Binary Output Format Options |
| 362 |
[cols="20%,80%"] |
| 363 |
|=== |
| 364 |
|Format option |Description |
| 365 |
|
| 366 |
|bin |Output SPIR-V binary code as a sequence of binary 32-bitwords |
| 367 |
in host native endianness. This is the default format for |
| 368 |
SPIR-V binary compilation output. |
| 369 |
|num |Output SPIR-V binary code as a text file containing a list of |
| 370 |
comma-separated hex numbers. + |
| 371 |
Example: `glslc -c -mfmt=num main.vert -o output_file.txt` + |
| 372 |
Content of the output_file.txt: + |
| 373 |
0x07230203,0x00010000,0x00080001,0x00000006... |
| 374 |
|c |Output SPIR-V binary code as a text file containing C-style + |
| 375 |
initializer list. + |
| 376 |
This is just wrapping the output of `num` option with curly |
| 377 |
brackets. + |
| 378 |
Example: `glslc -c -mfmt=c main.vert -o output_file.txt` + |
| 379 |
Content of output_file.txt: + |
| 380 |
{0x07230203, 0x00010000, 0x00080001, 0x00000006...} |
| 381 |
|=== |
| 382 |
|
| 383 |
[[option-fhlsl-16bit-types]] |
| 384 |
==== `-fhlsl-16bit-types` |
| 385 |
|
| 386 |
Enables 16bit types for HLSL compilation. |
| 387 |
|
| 388 |
[[option-fhlsl-offsets]] |
| 389 |
==== `-fhlsl-offsets` |
| 390 |
|
| 391 |
Use HLSL packing rules instead of GLSL rules when determining offsets of |
| 392 |
members of blocks. This option is always on when compiling for HLSL. |
| 393 |
|
| 394 |
[[option-fhlsl-functionality1]] |
| 395 |
==== `-fhlsl-functionality1` |
| 396 |
|
| 397 |
Enable extension `SPV_GOOGLE_hlsl_functionality1`, and instructs the compiler |
| 398 |
to: |
| 399 |
|
| 400 |
- Annotate HLSL semantic string decorations on interface objects |
| 401 |
- Explicitly record the association of a UAV resource with its companion counter buffer. |
| 402 |
|
| 403 |
This option can also be spelled with an underscore: `-fhlsl_functionality1`. |
| 404 |
|
| 405 |
[[option-fentry-point]] |
| 406 |
==== `-fentry-point=<name>` |
| 407 |
|
| 408 |
`-fentry-point=<name>` lets you specify the entry point name. This is only |
| 409 |
significant for HLSL compilation. The default is "main". |
| 410 |
|
| 411 |
[[option-fauto-map-locations]] |
| 412 |
==== `-fauto-map-locations` |
| 413 |
|
| 414 |
For GLSL compilation, option `-fauto-map-locations` directs the compiler to automatically |
| 415 |
assign location numbers to user-defined stage input and output variables if not explicitly |
| 416 |
specified by the shader source. |
| 417 |
|
| 418 |
For HLSL compilation, this option is on by default. |
| 419 |
|
| 420 |
Client APIs normally require adjacent stages to agree on their I/O interface. |
| 421 |
The compiler only sees one stage at a time, so it is strongly recommended that |
| 422 |
you avoid relying on this option to assign locations. |
| 423 |
|
| 424 |
Instead, an explicit binding number should be specified in the shader source, as follows: |
| 425 |
|
| 426 |
* In a GLSL shader, use a `location` layout qualifier: |
| 427 |
|
| 428 |
---- |
| 429 |
layout(location = 1) in vec4 x; |
| 430 |
---- |
| 431 |
|
| 432 |
* In an HLSL shader, use a `vk::location` attribute: |
| 433 |
|
| 434 |
---- |
| 435 |
[[vk::location(1)]] float4 FooShader( |
| 436 |
[[vk::location(0)]] float4 a, |
| 437 |
[[vk::location(2)]] float4 b) : COLOR0 { |
| 438 |
return a + b; |
| 439 |
} |
| 440 |
---- |
| 441 |
|
| 442 |
[[option-fpreserve-bindings |
| 443 |
==== `-fpreserve-bindings` |
| 444 |
|
| 445 |
Directs the optimizer to preserve bindings declarations, even when those |
| 446 |
bindings are known to be unused. |
| 447 |
|
| 448 |
|
| 449 |
=== Warning and Error Options |
| 450 |
|
| 451 |
==== `-w` |
| 452 |
|
| 453 |
`-w` suppresses all warning output from `glslc`. Any warning that would have |
| 454 |
been generated is silently ignored. |
| 455 |
|
| 456 |
==== `-Werror` |
| 457 |
|
| 458 |
`-Werror` forces any warning to be treated as an error in `glslc`. This means |
| 459 |
that all `warning:` messages are shown as `error:` and any warnings will cause |
| 460 |
a non-zero exit code from `glslc`. If `-w` is specified the warnings |
| 461 |
generated are suppressed before they are converted to errors. |
| 462 |
|
| 463 |
=== Dependency Generation Options |
| 464 |
|
| 465 |
==== `-M` or `-MM` |
| 466 |
|
| 467 |
`-M` generates *make* dependencies. It outputs a rule suitable for *make* |
| 468 |
describing the dependencies of the input file. Instead of outputting the result |
| 469 |
of preprocessing, the preprocessor outputs one *make* rule containing the |
| 470 |
SPIR-V object file name for that source file, a colon, and the names of all the |
| 471 |
included files. |
| 472 |
|
| 473 |
Unless specified explicitly (with `-MT`), the SPIR-V object file name in the |
| 474 |
generated *make* rules follows the rules of <<output-file-naming,Output File |
| 475 |
Naming>> as in `-c` compilation stage. |
| 476 |
|
| 477 |
Specifying `-M` implies `-E`, and suppresses warnings with an implicit `-w`. |
| 478 |
By default the output will be written to stdout, unless `-MF` or `-o` is |
| 479 |
specified. |
| 480 |
|
| 481 |
The dependency info file name can be specified by `-o` and `-MF` options. When |
| 482 |
both are specified, `-o` option is ignored. |
| 483 |
|
| 484 |
Specifying multiple input files is valid when the *make* rules are written to |
| 485 |
stdout, which means neither `-MF` nor `-o` is specified. When `-o` or `-MF` is |
| 486 |
specified, only one input file is allowed. |
| 487 |
|
| 488 |
`-MM` is an alias for `-M`. |
| 489 |
|
| 490 |
E.g., `glslc -M main.vert` will dump `main.vert.spv: main.vert <other included |
| 491 |
files>` to stdout. More examples are listed in |
| 492 |
<<dependency-generation-examples,Dependency Generation Examples>> |
| 493 |
|
| 494 |
==== `-MD` |
| 495 |
|
| 496 |
`-MD` tells the glslc compiler to both compile the source and generate *make* |
| 497 |
dependencies. Dependencies are written to a file whose name is determined as |
| 498 |
follows: If option `-MF` is specified, use its argument. Otherwise, use the |
| 499 |
filename formed by appending *.d* to the name of the file containing |
| 500 |
compilation results. |
| 501 |
|
| 502 |
Specifying multiple input files is valid when neither `-MF` nor `-o` is |
| 503 |
specified. When `-o` or `-MF` is specified, only one input file is allowed. |
| 504 |
|
| 505 |
E.g., `glslc -c -MD main.vert` will generate `main.vert.spv` as the SPIR-V |
| 506 |
object file and `main.vert.spv.d` as the dependency info file. More examples |
| 507 |
are listed in <<dependency-generation-examples,Dependency Generation Examples>> |
| 508 |
|
| 509 |
==== `-MF` |
| 510 |
|
| 511 |
`-MF` lets you specify the dependency info file name when used with `-M` or |
| 512 |
`-MD`. This option is invalid when used with multiple input files. |
| 513 |
|
| 514 |
E.g., `glslc -c -MD main.vert -MF dep_info` will generate `main.vert.spv` as |
| 515 |
the SPIR-V object file and `dep_info` as the dependency info file. |
| 516 |
|
| 517 |
==== `-MT` |
| 518 |
|
| 519 |
`-MT` lets you specify the target of the rule emitted by dependency generation |
| 520 |
when used with `-M` or `-MD`. This option is invalid when used with multiple |
| 521 |
input files. |
| 522 |
|
| 523 |
E.g., `glslc -M main.vert -MT target` will dump following dependency info to |
| 524 |
stdout: `target: main.vert <other dependent files>`. |
| 525 |
|
| 526 |
[[dependency-generation-examples]] |
| 527 |
.Dependency Generation Examples |
| 528 |
|=== |
| 529 |
|Command Line Input|Compilation Output File|Dependency Output File|Dependency Info |
| 530 |
|
| 531 |
|glslc -M main.vert | <NA> | <Stdout> | main.vert.spv: main.vert |
| 532 |
.2+|glslc -M a.vert b.vert | <NA> | <Stdout> | a.vert.spv: a.vert |
| 533 |
| <NA> | <Stdout> | b.vert.spv: b.vert |
| 534 |
|glslc -M main.vert -o dep_info | <NA> | dep_info | main.vert.spv: main.vert |
| 535 |
|glslc -M main.vert -MF dep_info| <NA> | dep_info | main.vert.spv: main.vert |
| 536 |
|glslc -M main.vert -MT target | <NA> | <Stdout> | target: main.vert |
| 537 |
|glslc -MD main.vert |a.spv |main.vert.spv.d|main.vert.spv: main.vert |
| 538 |
|glslc -c -MD main.vert |main.vert.spv|main.vert.spv.d|main.vert.spv: main.vert |
| 539 |
.2+|glslc -c -MD a.vert b.vert | a.vert.spv | a.vert.spv.d | a.vert.spv: a.vert |
| 540 |
| b.vert.spv | b.vert.spv.d | b.vert.spv: b.vert |
| 541 |
|glslc -S -MD main.vert |main.vert.spvasm |main.vert.spvasm.d |main.vert.spvasm: main.vert |
| 542 |
|glslc -c -MD main.vert -MF dep_info |main.vert.spv|dep_info|main.vert.spv: main.vert |
| 543 |
|glslc -c -MD main.vert -o obj |obj |obj.d |obj: main.vert |
| 544 |
|glslc -c -MD main.vert -o obj -MF dep_info -MT target|obj|dep_info|target: main.vert |
| 545 |
|=== |
| 546 |
|
| 547 |
=== Resource Binding Options |
| 548 |
|
| 549 |
[[option-fauto-bind-uniforms]] |
| 550 |
==== `-fauto-bind-uniforms` |
| 551 |
|
| 552 |
Option `-fauto-bind-uniforms` directs the compiler to automatically assign |
| 553 |
binding numbers to uniform variables, when an explicit binding is not |
| 554 |
specified in the shader source. |
| 555 |
|
| 556 |
An explicit binding number can be specified in the shader source by using |
| 557 |
a `binding` layout qualifier. For example: |
| 558 |
|
| 559 |
---- |
| 560 |
layout(binding = 12) uniform texture2D; |
| 561 |
---- |
| 562 |
|
| 563 |
[[option-fhlsl-iomap]] |
| 564 |
==== `-fhlsl-iomap` |
| 565 |
|
| 566 |
Option `-fhlsl-iomap` directs the compiler to use HLSL register |
| 567 |
assignments as binding values. |
| 568 |
|
| 569 |
[[option-fimage-binding-base]] |
| 570 |
==== `-fimage-binding-base` |
| 571 |
|
| 572 |
Option `-fimage-binding-base [stage] base` sets the lowest automatically |
| 573 |
assigned binding for images. If a stage is specified, only affects the specified |
| 574 |
stage. |
| 575 |
|
| 576 |
For HLSL, sets one less than the base. |
| 577 |
|
| 578 |
[[option-fsampler-binding-base]] |
| 579 |
==== `-fsampler-binding-base` |
| 580 |
|
| 581 |
Option `-fsampler-binding-base [stage] base` sets the lowest automatically |
| 582 |
assigned binding for samplers. If a stage is specified, only affects the specified |
| 583 |
stage. |
| 584 |
|
| 585 |
For HLSL, sets one less than the base. |
| 586 |
|
| 587 |
[[option-ftexture-binding-base]] |
| 588 |
==== `-ftexture-binding-base` |
| 589 |
|
| 590 |
Option `-ftexture-binding-base [stage] base` sets the lowest automatically |
| 591 |
assigned binding for textures. If a stage is specified, only affects the specified |
| 592 |
stage. |
| 593 |
|
| 594 |
For HLSL, sets one less than the base. |
| 595 |
|
| 596 |
[[option-fubo-binding-base]] |
| 597 |
==== `-fubo-binding-base` |
| 598 |
|
| 599 |
Option `-fubo-binding-base [stage] base` sets the lowest automatically |
| 600 |
assigned binding for Uniform Buffer Objects (GLSL) or Cbuffers (HLSL). |
| 601 |
If a stage is specified, only affects the specified stage. |
| 602 |
|
| 603 |
For HLSL, sets one less than the base. |
| 604 |
|
| 605 |
[[option-fcbuffer-binding-base]] |
| 606 |
==== `-fcbuffer-binding-base` |
| 607 |
|
| 608 |
Option `-fcbuffer-binding-base [stage] base` is the same as |
| 609 |
`-fubo-binding-base [stage] base`. |
| 610 |
|
| 611 |
[[option-fssbo-binding-base]] |
| 612 |
==== `-fssbo-binding-base` |
| 613 |
|
| 614 |
Option `-fssbo-binding-base [stage] base` sets the lowest automatically |
| 615 |
assigned binding for Shader Storage Buffer Objects (GLSL). |
| 616 |
If a stage is specified, only affects the specified stage. |
| 617 |
|
| 618 |
This only affects GLSL compilation. |
| 619 |
|
| 620 |
[[option-fuav-binding-base]] |
| 621 |
==== `-fuav-binding-base` |
| 622 |
|
| 623 |
Option `-fuav-binding-base [stage] base` sets one less than the lowest |
| 624 |
automatically assigned binding for Unordered Access Views (UAV). |
| 625 |
If a stage is specified, only affects the specified stage. |
| 626 |
|
| 627 |
This only affects HLSL compilation. |
| 628 |
|
| 629 |
[[option-fregister-set-binding]] |
| 630 |
==== `-fresource-set-binding` |
| 631 |
|
| 632 |
Option `-fresource-set-binding [stage] <reg0> <set0> <binding0>` sets |
| 633 |
the descriptor set and binding for an HLSL resource, by register name. |
| 634 |
To specify settings for more registers, append their triples consisting |
| 635 |
of register name, descriptor set, and binding. |
| 636 |
|
| 637 |
Example: |
| 638 |
|
| 639 |
---- |
| 640 |
# For a texture in register t1, use set 1 binding 0. |
| 641 |
# For a texture in register t2, use set 1 binding 3 |
| 642 |
glslc -x hlsl foo.frag -fresource-set-binding t1 1 0 t2 1 3 |
| 643 |
---- |
| 644 |
|
| 645 |
If a stage is specified, only affects the specified stage. |
| 646 |
|
| 647 |
---- |
| 648 |
# Same as the previous example, but the settings only apply |
| 649 |
# to fragment (pixel) shaders. |
| 650 |
glslc -x hlsl foo.frag -fresource-set-binding frag t1 1 0 t2 1 3 |
| 651 |
---- |
| 652 |
|
| 653 |
|
| 654 |
== Divergence from and extensions to GLSL specifications |
| 655 |
|
| 656 |
=== Source-filename-based `#line` and `\\__FILE__` |
| 657 |
|
| 658 |
This section describes how the glslc compiler extends the syntax for the `#line` |
| 659 |
directive and the `\\__FILE__` macro. By default, the glslc compiler enables |
| 660 |
the `GL_GOOGLE_cpp_style_line_directive` extension. It will generate this |
| 661 |
extended syntax in the preprocessed output (obtained via the `-E` option). |
| 662 |
|
| 663 |
WARNING: This section is still evolving. Expect changes. |
| 664 |
|
| 665 |
GLSL specifications have a notion of source strings. |
| 666 |
|
| 667 |
[quote, Section 3.2 of both version 3.30 and 4.50] |
| 668 |
____ |
| 669 |
The source for a single shader is an array of strings of characters from the |
| 670 |
character set. A single shader is made from the concatenation of these strings. |
| 671 |
____ |
| 672 |
|
| 673 |
With the above notion, the second parameter to the `#line` directive should |
| 674 |
be a constant integer expressions representing the source string number. Also |
| 675 |
the `\\__FILE__` macro will "substitute a decimal integer constant that says |
| 676 |
which source string number is currently being processed." |
| 677 |
|
| 678 |
The glslc compiler implements the standard `#line` and `\\__FILE__` syntax. It |
| 679 |
also provides an extension, `GL_GOOGLE_cpp_style_line_directive`, to allow |
| 680 |
source filenames to be used instead of integer source string indices. |
| 681 |
Specifically, the `#line` directive can have, after macro substitution, one of |
| 682 |
the following three forms: |
| 683 |
|
| 684 |
[source,glsl] |
| 685 |
---- |
| 686 |
#line line-number |
| 687 |
#line line-number integer-source-string-index |
| 688 |
#line line-number "source-filename" |
| 689 |
---- |
| 690 |
|
| 691 |
where `source-filename` can be any combinations of characters except double |
| 692 |
quotation marks. (Note that according to the GLSL specification, "there are |
| 693 |
no escape sequences or other uses of the backslash beyond use as the |
| 694 |
line-continuation character".) |
| 695 |
|
| 696 |
And if source-filename-based `#line` is used, the `\\__FILE__` macro expands to |
| 697 |
a string whose contents are the filename quoted with double quotation marks. |
| 698 |
The filename is dertermined as the last of |
| 699 |
|
| 700 |
* The filename given to the glslc compiler, |
| 701 |
* The filename argument of the most recent `#line` directive, if any. |
| 702 |
|
| 703 |
[[include-directive]] |
| 704 |
=== `#include` |
| 705 |
|
| 706 |
The glslc compiler extends GLSL with the include syntax by turning on the |
| 707 |
`GL_GOOGLE_include_directive` extension. It will preprocess and substitute |
| 708 |
`#include` directives properly with the following behaviors. |
| 709 |
|
| 710 |
WARNING: This section is still evolving. Expect changes. |
| 711 |
|
| 712 |
If `#include` directives are used in a shader, there will be an `#extension |
| 713 |
GL_GOOGLE_include_directive : enable` line generated into the preprocessed |
| 714 |
output. |
| 715 |
|
| 716 |
The `GL_GOOGLE_cpp_style_line_directive` extension is implicitly turned on by |
| 717 |
the `GL_GOOGLE_include_directive` extension. |
| 718 |
|
| 719 |
The file argument to `#include` must be enclosed in double quotes. It must be a |
| 720 |
relative path, using whatever path separator the OS supports. However, the last |
| 721 |
path element -- the name of the file itself -- must not contain either '/' or |
| 722 |
'\', regardless of which path separator is used. This will not be flagged as an |
| 723 |
error but will instead trigger undefined behavior. For example, let's say there |
| 724 |
is a file named `f\ilename.vert` on a Unix OS. It is not possible to craft a |
| 725 |
`#include` that includes that file. |
| 726 |
|
| 727 |
Furthermore, it is not possible to escape any characters in a `#include` |
| 728 |
directive, so the file argument cannot contain any special characters that need |
| 729 |
escaping in C. |
| 730 |
|
| 731 |
The file argument is a relative path that is matched first against the including |
| 732 |
file's own directory and then against all `-I` arguments in order of their |
| 733 |
appearance on the command line. If the file cannot be found, `glslc` aborts |
| 734 |
with an error. |