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