blob: 866da93ad18e10e4b7f944e3d07e378924b08ea1 [file] [log] [blame]
Andrew Woloszyne549e7b2015-07-16 11:07:40 -04001# Copyright 2015 The Shaderc Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import expect
16import os.path
17from glslc_test_framework import inside_glslc_testsuite
18from placeholder import FileShader, StdinShader, TempFileName
19
20
21@inside_glslc_testsuite('File')
22class SimpleFileCompiled(expect.ValidObjectFile):
23 """Tests whether or not a simple glsl file compiles."""
24
25 shader = FileShader('#version 310 es\nvoid main() {}', '.frag')
26 glslc_args = ['-c', shader]
27
28
29@inside_glslc_testsuite('File')
30class NotSpecifyingOutputName(expect.SuccessfulReturn,
31 expect.CorrectObjectFilePreamble):
32 """Tests that when there is no -o and -E/-S/-c specified, output as a.spv."""
33
David Netofab64112016-02-02 16:24:06 -050034 shader = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040035 glslc_args = [shader]
36
37 def check_output_a_spv(self, status):
38 output_name = os.path.join(status.directory, 'a.spv')
39 return self.verify_object_file_preamble(output_name)
40
41
42@inside_glslc_testsuite('Parameters')
43class HelpParameters(
44 expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch):
45 """Tests the --help flag outputs correctly and does not produce and error."""
46
47 glslc_args = ['--help']
48
David Neto91bfb4c2016-02-23 22:26:18 -050049 expected_stdout = '''glslc - Compile shaders into SPIR-V
50
51Usage: glslc [options] file...
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040052
53An input file of - represents standard input.
54
55Options:
56 -c Only run preprocess, compile, and assemble steps.
57 -Dmacro[=defn] Add an implicit macro definition.
58 -E Outputs only the results of the preprocessing step.
Lei Zhang1ccede12016-02-24 09:30:32 -050059 Output defaults to standard output.
David Neto7ae44a12017-01-23 17:24:33 -050060 -fauto-bind-uniforms
61 Automatically assign bindings to uniform variables that
62 don't have an explicit 'binding' layout in the shader
63 source.
Benjamin Chrétiend1f763c2018-02-09 18:08:58 +010064 -fauto-map-locations
65 Automatically assign locations to uniform variables that
66 don't have an explicit 'location' layout in the shader
67 source.
David Neto620ee652021-04-22 10:22:30 -040068 -fauto-combined-image-sampler
69 Removes sampler variables and converts existing textures
70 to combined image-samplers.
Lei Zhang9340ae52018-09-20 11:05:50 -040071 -fentry-point=<name>
72 Specify the entry point name for HLSL compilation, for
73 all subsequent source files. Default is "main".
David Netoa0a247d2022-06-30 09:59:13 -040074 -fhlsl-16bit-types
75 Enable 16-bit type support for HLSL.
David Neto5fd1b252018-04-13 16:27:04 -040076 -fhlsl_functionality1, -fhlsl-functionality1
77 Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
78 compilation.
Lei Zhang9340ae52018-09-20 11:05:50 -040079 -fhlsl-iomap Use HLSL IO mappings for bindings.
80 -fhlsl-offsets Use HLSL offset rules for packing members of blocks.
81 Affects only GLSL. HLSL rules are always used for HLSL.
David Netoa0a247d2022-06-30 09:59:13 -040082 -finvert-y Invert position.Y output in vertex shader.
Lei Zhang9340ae52018-09-20 11:05:50 -040083 -flimit=<settings>
84 Specify resource limits. Each limit is specified by a limit
85 name followed by an integer value. Tokens should be
86 separated by whitespace. If the same limit is specified
87 several times, only the last setting takes effect.
88 -flimit-file <file>
89 Set limits as specified in the given file.
David Neto2cbf7902019-06-19 00:23:21 -040090 -fnan-clamp Generate code for max and min builtins so that, when given
91 a NaN operand, the other operand is returned. Similarly,
92 the clamp builtin will favour the non-NaN operands, as if
93 clamp were implemented as a composition of max and min.
Jakub Kuderskica4c38c2023-01-23 17:09:23 -050094 -fpreserve-bindings
95 Preserve all binding declarations, even if those bindings
96 are not used.
Lei Zhang9340ae52018-09-20 11:05:50 -040097 -fresource-set-binding [stage] <reg0> <set0> <binding0>
98 [<reg1> <set1> <binding1>...]
99 Explicitly sets the descriptor set and binding for
100 HLSL resources, by register name. Optionally restrict
101 it to a single stage.
102 -fcbuffer-binding-base [stage] <value>
103 Same as -fubo-binding-base.
David Neto357d24b2017-06-04 18:27:12 -0400104 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800105 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400106 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700107 For HLSL, the resource register number is added to this
108 base.
David Neto357d24b2017-06-04 18:27:12 -0400109 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800110 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400111 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700112 For HLSL, the resource register number is added to this
113 base.
Lei Zhang9340ae52018-09-20 11:05:50 -0400114 -fssbo-binding-base [stage] <value>
115 Sets the lowest automatically assigned binding number for
116 shader storage buffer objects (SSBO). Optionally only set
117 it for a single shader stage. Only affects GLSL.
118 -ftexture-binding-base [stage] <value>
119 Sets the lowest automatically assigned binding number for
120 textures. Optionally only set it for a single shader stage.
121 For HLSL, the resource register number is added to this
122 base.
123 -fuav-binding-base [stage] <value>
124 For automatically assigned bindings for unordered access
125 views (UAV), the register number is added to this base to
126 determine the binding number. Optionally only set it for
127 a single shader stage. Only affects HLSL.
David Neto357d24b2017-06-04 18:27:12 -0400128 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800129 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400130 uniform buffer objects (UBO). Optionally only set it for
131 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700132 For HLSL, the resource register number is added to this
133 base.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400134 -fshader-stage=<stage>
135 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400136 Valid stages are vertex, vert, fragment, frag, tesscontrol,
137 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400138 -g Generate source-level debug information.
David Neto9eb2d252020-07-06 10:04:25 -0700139 -h Display available options.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400140 --help Display available options.
141 -I <value> Add directory to include search path.
qiningb3cfde42016-05-14 01:43:31 -0400142 -mfmt=<format> Output SPIR-V binary code using the selected format. This
143 option may be specified only when the compilation output is
David Netoba92b112020-07-22 08:54:14 -0700144 in SPIR-V binary code form. Available options are:
145 bin - SPIR-V binary words. This is the default.
146 c - Binary words as C initializer list of 32-bit ints
147 num - List of comma-separated 32-bit hex integers
qiningbde33a92016-02-01 14:30:07 -0500148 -M Generate make dependencies. Implies -E and -w.
149 -MM An alias for -M.
150 -MD Generate make dependencies and compile.
151 -MF <file> Write dependency output to the given file.
152 -MT <target> Specify the target of the rule emitted by dependency
153 generation.
Lei Zhang9340ae52018-09-20 11:05:50 -0400154 -O Optimize the generated SPIR-V code for better performance.
155 -Os Optimize the generated SPIR-V code for smaller size.
156 -O0 Disable optimization.
157 -o <file> Write output to <file>.
158 A file name of '-' represents standard output.
159 -std=<value> Version and profile for GLSL input files. Possible values
160 are concatenations of version and profile, e.g. 310es,
161 450core, etc. Ignored for HLSL files.
David Neto9f95ca92020-01-30 09:19:24 -0500162 -S Emit SPIR-V assembly instead of binary.
Lei Zhang9340ae52018-09-20 11:05:50 -0400163 --show-limits Display available limit names and their default values.
qiningf6d83742016-01-28 16:05:11 -0500164 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700165 Set the target client environment, and the semantics
166 of warnings and errors. An optional suffix can specify
167 the client version. Values are:
168 vulkan1.0 # The default
169 vulkan1.1
David Netocdac1242020-01-15 12:51:13 -0800170 vulkan1.2
David Neto50c1da32022-01-27 12:02:25 -0500171 vulkan1.3
David Netoc9931582018-03-22 07:32:14 -0700172 vulkan # Same as vulkan1.0
173 opengl4.5
174 opengl # Same as opengl4.5
David Neto23bbb322019-07-02 10:17:31 -0400175 --target-spv=<spirv-version>
176 Set the SPIR-V version to be used for the generated SPIR-V
177 module. The default is the highest version of SPIR-V
178 required to be supported for the target environment.
179 For example, default for vulkan1.0 is spv1.0, and
David Netocdac1242020-01-15 12:51:13 -0800180 the default for vulkan1.1 is spv1.3,
181 the default for vulkan1.2 is spv1.5.
David Neto50c1da32022-01-27 12:02:25 -0500182 the default for vulkan1.3 is spv1.6.
David Neto23bbb322019-07-02 10:17:31 -0400183 Values are:
David Neto48642972021-12-17 14:09:48 -0500184 spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6
Lei Zhang9340ae52018-09-20 11:05:50 -0400185 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400186 -w Suppresses all warning messages.
187 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400188 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400189 Valid languages are: glsl, hlsl.
190 For files ending in .hlsl the default is hlsl.
191 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400192'''
193
194 expected_stderr = ''
195
196
197@inside_glslc_testsuite('Parameters')
198class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
199 """Tests that --help output is not too wide."""
200
201 glslc_args = ['--help']
202
203
204@inside_glslc_testsuite('Parameters')
205class UnknownSingleLetterArgument(expect.ErrorMessage):
206 """Tests that an unknown argument triggers an error message."""
207
208 glslc_args = ['-a']
209 expected_error = ["glslc: error: unknown argument: '-a'\n"]
210
211
212@inside_glslc_testsuite('Parameters')
213class UnknownMultiLetterArgument(expect.ErrorMessage):
214 """Tests that an unknown argument triggers an error message."""
215
216 glslc_args = ['-zzz']
217 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
218
219
220@inside_glslc_testsuite('Parameters')
221class UnsupportedOption(expect.ErrorMessage):
222 """Tests that an unsupported option triggers an error message."""
223
224 glslc_args = ['--unsupported-option']
225 expected_error = [
226 "glslc: error: unsupported option: '--unsupported-option'\n"]
227
228
229@inside_glslc_testsuite('File')
230class FileNotFound(expect.ErrorMessage):
231 """Tests the error message if a file cannot be found."""
232
233 blabla_file = TempFileName('blabla.frag')
234 glslc_args = [blabla_file]
235 expected_error = [
236 "glslc: error: cannot open input file: '", blabla_file,
237 "': No such file or directory\n"]
238
239
240@inside_glslc_testsuite('Unsupported')
241class LinkingNotSupported(expect.ErrorMessage):
242 """Tests the error message generated by linking not supported yet."""
243
David Netofab64112016-02-02 16:24:06 -0500244 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
245 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400246 glslc_args = [shader1, shader2]
247 expected_error = [
248 'glslc: error: linking multiple files is not supported yet. ',
249 'Use -c to compile files individually.\n']
250
251
252@inside_glslc_testsuite('Unsupported')
253class MultipleStdinUnsupported(expect.ErrorMessage):
254 """Tests the error message generated by having more than one - input."""
255
256 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
257 expected_error = [
258 'glslc: error: specifying standard input "-" as input more'
259 ' than once is not allowed.\n']
260
261
262@inside_glslc_testsuite('Parameters')
263class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
264 """Tests that you must use -fshader-stage when specifying - as input."""
265 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500266 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400267 int a() {
268 }
269 void main() {
270 int x = a();
271 }
272 """)
273 glslc_args = [shader]
274
275 expected_stdout = ''
276 expected_stderr = [
277 "glslc: error: '-': -fshader-stage required when input is from "
278 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800279
280
281@inside_glslc_testsuite('Parameters')
282class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
283 """Tests --show-limits shows correct output."""
284
285 glslc_args = ['--show-limits']
286
287 expected_stderr = ''
288 expected_stdout = """MaxLights 8
289MaxClipPlanes 6
290MaxTextureUnits 2
291MaxTextureCoords 8
292MaxVertexAttribs 16
293MaxVertexUniformComponents 4096
294MaxVaryingFloats 60
295MaxVertexTextureImageUnits 16
296MaxCombinedTextureImageUnits 80
297MaxTextureImageUnits 16
298MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400299MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800300MaxVertexUniformVectors 256
301MaxVaryingVectors 15
302MaxFragmentUniformVectors 256
303MaxVertexOutputVectors 16
304MaxFragmentInputVectors 15
305MinProgramTexelOffset -8
306MaxProgramTexelOffset 7
307MaxClipDistances 8
308MaxComputeWorkGroupCountX 65535
309MaxComputeWorkGroupCountY 65535
310MaxComputeWorkGroupCountZ 65535
311MaxComputeWorkGroupSizeX 1024
312MaxComputeWorkGroupSizeY 1024
313MaxComputeWorkGroupSizeZ 64
314MaxComputeUniformComponents 512
315MaxComputeTextureImageUnits 16
316MaxComputeImageUniforms 8
317MaxComputeAtomicCounters 8
318MaxComputeAtomicCounterBuffers 1
319MaxVaryingComponents 60
320MaxVertexOutputComponents 64
321MaxGeometryInputComponents 64
322MaxGeometryOutputComponents 128
323MaxFragmentInputComponents 128
324MaxImageUnits 8
325MaxCombinedImageUnitsAndFragmentOutputs 8
326MaxCombinedShaderOutputResources 8
327MaxImageSamples 0
328MaxVertexImageUniforms 0
329MaxTessControlImageUniforms 0
330MaxTessEvaluationImageUniforms 0
331MaxGeometryImageUniforms 0
332MaxFragmentImageUniforms 8
333MaxCombinedImageUniforms 8
334MaxGeometryTextureImageUnits 16
335MaxGeometryOutputVertices 256
336MaxGeometryTotalOutputComponents 1024
337MaxGeometryUniformComponents 512
338MaxGeometryVaryingComponents 60
339MaxTessControlInputComponents 128
340MaxTessControlOutputComponents 128
341MaxTessControlTextureImageUnits 16
342MaxTessControlUniformComponents 1024
343MaxTessControlTotalOutputComponents 4096
344MaxTessEvaluationInputComponents 128
345MaxTessEvaluationOutputComponents 128
346MaxTessEvaluationTextureImageUnits 16
347MaxTessEvaluationUniformComponents 1024
348MaxTessPatchComponents 120
349MaxPatchVertices 32
350MaxTessGenLevel 64
351MaxViewports 16
352MaxVertexAtomicCounters 0
353MaxTessControlAtomicCounters 0
354MaxTessEvaluationAtomicCounters 0
355MaxGeometryAtomicCounters 0
356MaxFragmentAtomicCounters 8
357MaxCombinedAtomicCounters 8
358MaxAtomicCounterBindings 1
359MaxVertexAtomicCounterBuffers 0
360MaxTessControlAtomicCounterBuffers 0
361MaxTessEvaluationAtomicCounterBuffers 0
362MaxGeometryAtomicCounterBuffers 0
363MaxFragmentAtomicCounterBuffers 0
364MaxCombinedAtomicCounterBuffers 1
365MaxAtomicCounterBufferSize 32
366MaxTransformFeedbackBuffers 4
367MaxTransformFeedbackInterleavedComponents 64
368MaxCullDistances 8
369MaxCombinedClipAndCullDistances 8
370MaxSamples 4
371"""