blob: 18b43f4ea90091ced0c09f54d052507da1e3c7ca [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.
Lei Zhang9340ae52018-09-20 11:05:50 -040068 -fentry-point=<name>
69 Specify the entry point name for HLSL compilation, for
70 all subsequent source files. Default is "main".
David Neto5fd1b252018-04-13 16:27:04 -040071 -fhlsl_functionality1, -fhlsl-functionality1
72 Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
73 compilation.
David Netoc21dd102019-06-13 17:44:25 -040074 -finvert-y Invert position.Y output in vertex shader.
Lei Zhang9340ae52018-09-20 11:05:50 -040075 -fhlsl-iomap Use HLSL IO mappings for bindings.
76 -fhlsl-offsets Use HLSL offset rules for packing members of blocks.
77 Affects only GLSL. HLSL rules are always used for HLSL.
78 -flimit=<settings>
79 Specify resource limits. Each limit is specified by a limit
80 name followed by an integer value. Tokens should be
81 separated by whitespace. If the same limit is specified
82 several times, only the last setting takes effect.
83 -flimit-file <file>
84 Set limits as specified in the given file.
David Neto2cbf7902019-06-19 00:23:21 -040085 -fnan-clamp Generate code for max and min builtins so that, when given
86 a NaN operand, the other operand is returned. Similarly,
87 the clamp builtin will favour the non-NaN operands, as if
88 clamp were implemented as a composition of max and min.
Lei Zhang9340ae52018-09-20 11:05:50 -040089 -fresource-set-binding [stage] <reg0> <set0> <binding0>
90 [<reg1> <set1> <binding1>...]
91 Explicitly sets the descriptor set and binding for
92 HLSL resources, by register name. Optionally restrict
93 it to a single stage.
94 -fcbuffer-binding-base [stage] <value>
95 Same as -fubo-binding-base.
David Neto357d24b2017-06-04 18:27:12 -040096 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080097 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040098 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070099 For HLSL, the resource register number is added to this
100 base.
David Neto357d24b2017-06-04 18:27:12 -0400101 -fsampler-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 samplers 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.
Lei Zhang9340ae52018-09-20 11:05:50 -0400106 -fssbo-binding-base [stage] <value>
107 Sets the lowest automatically assigned binding number for
108 shader storage buffer objects (SSBO). Optionally only set
109 it for a single shader stage. Only affects GLSL.
110 -ftexture-binding-base [stage] <value>
111 Sets the lowest automatically assigned binding number for
112 textures. Optionally only set it for a single shader stage.
113 For HLSL, the resource register number is added to this
114 base.
115 -fuav-binding-base [stage] <value>
116 For automatically assigned bindings for unordered access
117 views (UAV), the register number is added to this base to
118 determine the binding number. Optionally only set it for
119 a single shader stage. Only affects HLSL.
David Neto357d24b2017-06-04 18:27:12 -0400120 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800121 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400122 uniform buffer objects (UBO). Optionally only set it for
123 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700124 For HLSL, the resource register number is added to this
125 base.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400126 -fshader-stage=<stage>
127 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400128 Valid stages are vertex, vert, fragment, frag, tesscontrol,
129 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400130 -g Generate source-level debug information.
131 Currently this option has no effect.
David Neto9eb2d252020-07-06 10:04:25 -0700132 -h Display available options.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400133 --help Display available options.
134 -I <value> Add directory to include search path.
qiningb3cfde42016-05-14 01:43:31 -0400135 -mfmt=<format> Output SPIR-V binary code using the selected format. This
136 option may be specified only when the compilation output is
David Netoba92b112020-07-22 08:54:14 -0700137 in SPIR-V binary code form. Available options are:
138 bin - SPIR-V binary words. This is the default.
139 c - Binary words as C initializer list of 32-bit ints
140 num - List of comma-separated 32-bit hex integers
qiningbde33a92016-02-01 14:30:07 -0500141 -M Generate make dependencies. Implies -E and -w.
142 -MM An alias for -M.
143 -MD Generate make dependencies and compile.
144 -MF <file> Write dependency output to the given file.
145 -MT <target> Specify the target of the rule emitted by dependency
146 generation.
Lei Zhang9340ae52018-09-20 11:05:50 -0400147 -O Optimize the generated SPIR-V code for better performance.
148 -Os Optimize the generated SPIR-V code for smaller size.
149 -O0 Disable optimization.
150 -o <file> Write output to <file>.
151 A file name of '-' represents standard output.
152 -std=<value> Version and profile for GLSL input files. Possible values
153 are concatenations of version and profile, e.g. 310es,
154 450core, etc. Ignored for HLSL files.
David Neto9f95ca92020-01-30 09:19:24 -0500155 -S Emit SPIR-V assembly instead of binary.
Lei Zhang9340ae52018-09-20 11:05:50 -0400156 --show-limits Display available limit names and their default values.
qiningf6d83742016-01-28 16:05:11 -0500157 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700158 Set the target client environment, and the semantics
159 of warnings and errors. An optional suffix can specify
160 the client version. Values are:
161 vulkan1.0 # The default
162 vulkan1.1
David Netocdac1242020-01-15 12:51:13 -0800163 vulkan1.2
David Netoc9931582018-03-22 07:32:14 -0700164 vulkan # Same as vulkan1.0
165 opengl4.5
166 opengl # Same as opengl4.5
David Neto23bbb322019-07-02 10:17:31 -0400167 --target-spv=<spirv-version>
168 Set the SPIR-V version to be used for the generated SPIR-V
169 module. The default is the highest version of SPIR-V
170 required to be supported for the target environment.
171 For example, default for vulkan1.0 is spv1.0, and
David Netocdac1242020-01-15 12:51:13 -0800172 the default for vulkan1.1 is spv1.3,
173 the default for vulkan1.2 is spv1.5.
David Neto23bbb322019-07-02 10:17:31 -0400174 Values are:
David Neto0d8908a2019-10-04 15:31:15 -0400175 spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5
Lei Zhang9340ae52018-09-20 11:05:50 -0400176 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400177 -w Suppresses all warning messages.
178 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400179 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400180 Valid languages are: glsl, hlsl.
181 For files ending in .hlsl the default is hlsl.
182 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400183'''
184
185 expected_stderr = ''
186
187
188@inside_glslc_testsuite('Parameters')
189class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
190 """Tests that --help output is not too wide."""
191
192 glslc_args = ['--help']
193
194
195@inside_glslc_testsuite('Parameters')
196class UnknownSingleLetterArgument(expect.ErrorMessage):
197 """Tests that an unknown argument triggers an error message."""
198
199 glslc_args = ['-a']
200 expected_error = ["glslc: error: unknown argument: '-a'\n"]
201
202
203@inside_glslc_testsuite('Parameters')
204class UnknownMultiLetterArgument(expect.ErrorMessage):
205 """Tests that an unknown argument triggers an error message."""
206
207 glslc_args = ['-zzz']
208 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
209
210
211@inside_glslc_testsuite('Parameters')
212class UnsupportedOption(expect.ErrorMessage):
213 """Tests that an unsupported option triggers an error message."""
214
215 glslc_args = ['--unsupported-option']
216 expected_error = [
217 "glslc: error: unsupported option: '--unsupported-option'\n"]
218
219
220@inside_glslc_testsuite('File')
221class FileNotFound(expect.ErrorMessage):
222 """Tests the error message if a file cannot be found."""
223
224 blabla_file = TempFileName('blabla.frag')
225 glslc_args = [blabla_file]
226 expected_error = [
227 "glslc: error: cannot open input file: '", blabla_file,
228 "': No such file or directory\n"]
229
230
231@inside_glslc_testsuite('Unsupported')
232class LinkingNotSupported(expect.ErrorMessage):
233 """Tests the error message generated by linking not supported yet."""
234
David Netofab64112016-02-02 16:24:06 -0500235 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
236 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400237 glslc_args = [shader1, shader2]
238 expected_error = [
239 'glslc: error: linking multiple files is not supported yet. ',
240 'Use -c to compile files individually.\n']
241
242
243@inside_glslc_testsuite('Unsupported')
244class MultipleStdinUnsupported(expect.ErrorMessage):
245 """Tests the error message generated by having more than one - input."""
246
247 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
248 expected_error = [
249 'glslc: error: specifying standard input "-" as input more'
250 ' than once is not allowed.\n']
251
252
253@inside_glslc_testsuite('Parameters')
254class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
255 """Tests that you must use -fshader-stage when specifying - as input."""
256 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500257 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400258 int a() {
259 }
260 void main() {
261 int x = a();
262 }
263 """)
264 glslc_args = [shader]
265
266 expected_stdout = ''
267 expected_stderr = [
268 "glslc: error: '-': -fshader-stage required when input is from "
269 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800270
271
272@inside_glslc_testsuite('Parameters')
273class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
274 """Tests --show-limits shows correct output."""
275
276 glslc_args = ['--show-limits']
277
278 expected_stderr = ''
279 expected_stdout = """MaxLights 8
280MaxClipPlanes 6
281MaxTextureUnits 2
282MaxTextureCoords 8
283MaxVertexAttribs 16
284MaxVertexUniformComponents 4096
285MaxVaryingFloats 60
286MaxVertexTextureImageUnits 16
287MaxCombinedTextureImageUnits 80
288MaxTextureImageUnits 16
289MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400290MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800291MaxVertexUniformVectors 256
292MaxVaryingVectors 15
293MaxFragmentUniformVectors 256
294MaxVertexOutputVectors 16
295MaxFragmentInputVectors 15
296MinProgramTexelOffset -8
297MaxProgramTexelOffset 7
298MaxClipDistances 8
299MaxComputeWorkGroupCountX 65535
300MaxComputeWorkGroupCountY 65535
301MaxComputeWorkGroupCountZ 65535
302MaxComputeWorkGroupSizeX 1024
303MaxComputeWorkGroupSizeY 1024
304MaxComputeWorkGroupSizeZ 64
305MaxComputeUniformComponents 512
306MaxComputeTextureImageUnits 16
307MaxComputeImageUniforms 8
308MaxComputeAtomicCounters 8
309MaxComputeAtomicCounterBuffers 1
310MaxVaryingComponents 60
311MaxVertexOutputComponents 64
312MaxGeometryInputComponents 64
313MaxGeometryOutputComponents 128
314MaxFragmentInputComponents 128
315MaxImageUnits 8
316MaxCombinedImageUnitsAndFragmentOutputs 8
317MaxCombinedShaderOutputResources 8
318MaxImageSamples 0
319MaxVertexImageUniforms 0
320MaxTessControlImageUniforms 0
321MaxTessEvaluationImageUniforms 0
322MaxGeometryImageUniforms 0
323MaxFragmentImageUniforms 8
324MaxCombinedImageUniforms 8
325MaxGeometryTextureImageUnits 16
326MaxGeometryOutputVertices 256
327MaxGeometryTotalOutputComponents 1024
328MaxGeometryUniformComponents 512
329MaxGeometryVaryingComponents 60
330MaxTessControlInputComponents 128
331MaxTessControlOutputComponents 128
332MaxTessControlTextureImageUnits 16
333MaxTessControlUniformComponents 1024
334MaxTessControlTotalOutputComponents 4096
335MaxTessEvaluationInputComponents 128
336MaxTessEvaluationOutputComponents 128
337MaxTessEvaluationTextureImageUnits 16
338MaxTessEvaluationUniformComponents 1024
339MaxTessPatchComponents 120
340MaxPatchVertices 32
341MaxTessGenLevel 64
342MaxViewports 16
343MaxVertexAtomicCounters 0
344MaxTessControlAtomicCounters 0
345MaxTessEvaluationAtomicCounters 0
346MaxGeometryAtomicCounters 0
347MaxFragmentAtomicCounters 8
348MaxCombinedAtomicCounters 8
349MaxAtomicCounterBindings 1
350MaxVertexAtomicCounterBuffers 0
351MaxTessControlAtomicCounterBuffers 0
352MaxTessEvaluationAtomicCounterBuffers 0
353MaxGeometryAtomicCounterBuffers 0
354MaxFragmentAtomicCounterBuffers 0
355MaxCombinedAtomicCounterBuffers 1
356MaxAtomicCounterBufferSize 32
357MaxTransformFeedbackBuffers 4
358MaxTransformFeedbackInterleavedComponents 64
359MaxCullDistances 8
360MaxCombinedClipAndCullDistances 8
361MaxSamples 4
362"""