• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H11-Nov-2021-2,3781,584

test/H03-May-2022-8,4295,923

README.asciidocH A D11-Nov-202126.2 KiB719528

README.asciidoc

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