blob: c8cfa0c1d06464867392fc0aef5aabe45697d343 [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.
Lei Zhang9340ae52018-09-20 11:05:50 -040094 -fresource-set-binding [stage] <reg0> <set0> <binding0>
95 [<reg1> <set1> <binding1>...]
96 Explicitly sets the descriptor set and binding for
97 HLSL resources, by register name. Optionally restrict
98 it to a single stage.
99 -fcbuffer-binding-base [stage] <value>
100 Same as -fubo-binding-base.
David Neto357d24b2017-06-04 18:27:12 -0400101 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800102 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400103 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700104 For HLSL, the resource register number is added to this
105 base.
David Neto357d24b2017-06-04 18:27:12 -0400106 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800107 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400108 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700109 For HLSL, the resource register number is added to this
110 base.
Lei Zhang9340ae52018-09-20 11:05:50 -0400111 -fssbo-binding-base [stage] <value>
112 Sets the lowest automatically assigned binding number for
113 shader storage buffer objects (SSBO). Optionally only set
114 it for a single shader stage. Only affects GLSL.
115 -ftexture-binding-base [stage] <value>
116 Sets the lowest automatically assigned binding number for
117 textures. Optionally only set it for a single shader stage.
118 For HLSL, the resource register number is added to this
119 base.
120 -fuav-binding-base [stage] <value>
121 For automatically assigned bindings for unordered access
122 views (UAV), the register number is added to this base to
123 determine the binding number. Optionally only set it for
124 a single shader stage. Only affects HLSL.
David Neto357d24b2017-06-04 18:27:12 -0400125 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800126 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400127 uniform buffer objects (UBO). Optionally only set it for
128 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700129 For HLSL, the resource register number is added to this
130 base.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400131 -fshader-stage=<stage>
132 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400133 Valid stages are vertex, vert, fragment, frag, tesscontrol,
134 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400135 -g Generate source-level debug information.
David Neto9eb2d252020-07-06 10:04:25 -0700136 -h Display available options.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400137 --help Display available options.
138 -I <value> Add directory to include search path.
qiningb3cfde42016-05-14 01:43:31 -0400139 -mfmt=<format> Output SPIR-V binary code using the selected format. This
140 option may be specified only when the compilation output is
David Netoba92b112020-07-22 08:54:14 -0700141 in SPIR-V binary code form. Available options are:
142 bin - SPIR-V binary words. This is the default.
143 c - Binary words as C initializer list of 32-bit ints
144 num - List of comma-separated 32-bit hex integers
qiningbde33a92016-02-01 14:30:07 -0500145 -M Generate make dependencies. Implies -E and -w.
146 -MM An alias for -M.
147 -MD Generate make dependencies and compile.
148 -MF <file> Write dependency output to the given file.
149 -MT <target> Specify the target of the rule emitted by dependency
150 generation.
Lei Zhang9340ae52018-09-20 11:05:50 -0400151 -O Optimize the generated SPIR-V code for better performance.
152 -Os Optimize the generated SPIR-V code for smaller size.
153 -O0 Disable optimization.
154 -o <file> Write output to <file>.
155 A file name of '-' represents standard output.
156 -std=<value> Version and profile for GLSL input files. Possible values
157 are concatenations of version and profile, e.g. 310es,
158 450core, etc. Ignored for HLSL files.
David Neto9f95ca92020-01-30 09:19:24 -0500159 -S Emit SPIR-V assembly instead of binary.
Lei Zhang9340ae52018-09-20 11:05:50 -0400160 --show-limits Display available limit names and their default values.
qiningf6d83742016-01-28 16:05:11 -0500161 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700162 Set the target client environment, and the semantics
163 of warnings and errors. An optional suffix can specify
164 the client version. Values are:
165 vulkan1.0 # The default
166 vulkan1.1
David Netocdac1242020-01-15 12:51:13 -0800167 vulkan1.2
David Neto50c1da32022-01-27 12:02:25 -0500168 vulkan1.3
David Netoc9931582018-03-22 07:32:14 -0700169 vulkan # Same as vulkan1.0
170 opengl4.5
171 opengl # Same as opengl4.5
David Neto23bbb322019-07-02 10:17:31 -0400172 --target-spv=<spirv-version>
173 Set the SPIR-V version to be used for the generated SPIR-V
174 module. The default is the highest version of SPIR-V
175 required to be supported for the target environment.
176 For example, default for vulkan1.0 is spv1.0, and
David Netocdac1242020-01-15 12:51:13 -0800177 the default for vulkan1.1 is spv1.3,
178 the default for vulkan1.2 is spv1.5.
David Neto50c1da32022-01-27 12:02:25 -0500179 the default for vulkan1.3 is spv1.6.
David Neto23bbb322019-07-02 10:17:31 -0400180 Values are:
David Neto48642972021-12-17 14:09:48 -0500181 spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6
Lei Zhang9340ae52018-09-20 11:05:50 -0400182 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400183 -w Suppresses all warning messages.
184 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400185 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400186 Valid languages are: glsl, hlsl.
187 For files ending in .hlsl the default is hlsl.
188 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400189'''
190
191 expected_stderr = ''
192
193
194@inside_glslc_testsuite('Parameters')
195class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
196 """Tests that --help output is not too wide."""
197
198 glslc_args = ['--help']
199
200
201@inside_glslc_testsuite('Parameters')
202class UnknownSingleLetterArgument(expect.ErrorMessage):
203 """Tests that an unknown argument triggers an error message."""
204
205 glslc_args = ['-a']
206 expected_error = ["glslc: error: unknown argument: '-a'\n"]
207
208
209@inside_glslc_testsuite('Parameters')
210class UnknownMultiLetterArgument(expect.ErrorMessage):
211 """Tests that an unknown argument triggers an error message."""
212
213 glslc_args = ['-zzz']
214 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
215
216
217@inside_glslc_testsuite('Parameters')
218class UnsupportedOption(expect.ErrorMessage):
219 """Tests that an unsupported option triggers an error message."""
220
221 glslc_args = ['--unsupported-option']
222 expected_error = [
223 "glslc: error: unsupported option: '--unsupported-option'\n"]
224
225
226@inside_glslc_testsuite('File')
227class FileNotFound(expect.ErrorMessage):
228 """Tests the error message if a file cannot be found."""
229
230 blabla_file = TempFileName('blabla.frag')
231 glslc_args = [blabla_file]
232 expected_error = [
233 "glslc: error: cannot open input file: '", blabla_file,
234 "': No such file or directory\n"]
235
236
237@inside_glslc_testsuite('Unsupported')
238class LinkingNotSupported(expect.ErrorMessage):
239 """Tests the error message generated by linking not supported yet."""
240
David Netofab64112016-02-02 16:24:06 -0500241 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
242 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400243 glslc_args = [shader1, shader2]
244 expected_error = [
245 'glslc: error: linking multiple files is not supported yet. ',
246 'Use -c to compile files individually.\n']
247
248
249@inside_glslc_testsuite('Unsupported')
250class MultipleStdinUnsupported(expect.ErrorMessage):
251 """Tests the error message generated by having more than one - input."""
252
253 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
254 expected_error = [
255 'glslc: error: specifying standard input "-" as input more'
256 ' than once is not allowed.\n']
257
258
259@inside_glslc_testsuite('Parameters')
260class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
261 """Tests that you must use -fshader-stage when specifying - as input."""
262 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500263 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400264 int a() {
265 }
266 void main() {
267 int x = a();
268 }
269 """)
270 glslc_args = [shader]
271
272 expected_stdout = ''
273 expected_stderr = [
274 "glslc: error: '-': -fshader-stage required when input is from "
275 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800276
277
278@inside_glslc_testsuite('Parameters')
279class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
280 """Tests --show-limits shows correct output."""
281
282 glslc_args = ['--show-limits']
283
284 expected_stderr = ''
285 expected_stdout = """MaxLights 8
286MaxClipPlanes 6
287MaxTextureUnits 2
288MaxTextureCoords 8
289MaxVertexAttribs 16
290MaxVertexUniformComponents 4096
291MaxVaryingFloats 60
292MaxVertexTextureImageUnits 16
293MaxCombinedTextureImageUnits 80
294MaxTextureImageUnits 16
295MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400296MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800297MaxVertexUniformVectors 256
298MaxVaryingVectors 15
299MaxFragmentUniformVectors 256
300MaxVertexOutputVectors 16
301MaxFragmentInputVectors 15
302MinProgramTexelOffset -8
303MaxProgramTexelOffset 7
304MaxClipDistances 8
305MaxComputeWorkGroupCountX 65535
306MaxComputeWorkGroupCountY 65535
307MaxComputeWorkGroupCountZ 65535
308MaxComputeWorkGroupSizeX 1024
309MaxComputeWorkGroupSizeY 1024
310MaxComputeWorkGroupSizeZ 64
311MaxComputeUniformComponents 512
312MaxComputeTextureImageUnits 16
313MaxComputeImageUniforms 8
314MaxComputeAtomicCounters 8
315MaxComputeAtomicCounterBuffers 1
316MaxVaryingComponents 60
317MaxVertexOutputComponents 64
318MaxGeometryInputComponents 64
319MaxGeometryOutputComponents 128
320MaxFragmentInputComponents 128
321MaxImageUnits 8
322MaxCombinedImageUnitsAndFragmentOutputs 8
323MaxCombinedShaderOutputResources 8
324MaxImageSamples 0
325MaxVertexImageUniforms 0
326MaxTessControlImageUniforms 0
327MaxTessEvaluationImageUniforms 0
328MaxGeometryImageUniforms 0
329MaxFragmentImageUniforms 8
330MaxCombinedImageUniforms 8
331MaxGeometryTextureImageUnits 16
332MaxGeometryOutputVertices 256
333MaxGeometryTotalOutputComponents 1024
334MaxGeometryUniformComponents 512
335MaxGeometryVaryingComponents 60
336MaxTessControlInputComponents 128
337MaxTessControlOutputComponents 128
338MaxTessControlTextureImageUnits 16
339MaxTessControlUniformComponents 1024
340MaxTessControlTotalOutputComponents 4096
341MaxTessEvaluationInputComponents 128
342MaxTessEvaluationOutputComponents 128
343MaxTessEvaluationTextureImageUnits 16
344MaxTessEvaluationUniformComponents 1024
345MaxTessPatchComponents 120
346MaxPatchVertices 32
347MaxTessGenLevel 64
348MaxViewports 16
349MaxVertexAtomicCounters 0
350MaxTessControlAtomicCounters 0
351MaxTessEvaluationAtomicCounters 0
352MaxGeometryAtomicCounters 0
353MaxFragmentAtomicCounters 8
354MaxCombinedAtomicCounters 8
355MaxAtomicCounterBindings 1
356MaxVertexAtomicCounterBuffers 0
357MaxTessControlAtomicCounterBuffers 0
358MaxTessEvaluationAtomicCounterBuffers 0
359MaxGeometryAtomicCounterBuffers 0
360MaxFragmentAtomicCounterBuffers 0
361MaxCombinedAtomicCounterBuffers 1
362MaxAtomicCounterBufferSize 32
363MaxTransformFeedbackBuffers 4
364MaxTransformFeedbackInterleavedComponents 64
365MaxCullDistances 8
366MaxCombinedClipAndCullDistances 8
367MaxSamples 4
368"""