blob: c8dd862bb8983f25a6dfd15832f050d900a7cffa [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 Neto63313f92017-06-07 09:15:34 -070068 -fhlsl-iomap Use HLSL IO mappings for bindings.
David Neto357d24b2017-06-04 18:27:12 -040069 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080070 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040071 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070072 For HLSL, the resource register number is added to this
73 base.
David Neto357d24b2017-06-04 18:27:12 -040074 -ftexture-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080075 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040076 textures. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070077 For HLSL, the resource register number is added to this
78 base.
David Neto357d24b2017-06-04 18:27:12 -040079 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080080 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040081 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070082 For HLSL, the resource register number is added to this
83 base.
David Neto357d24b2017-06-04 18:27:12 -040084 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080085 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040086 uniform buffer objects (UBO). Optionally only set it for
87 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070088 For HLSL, the resource register number is added to this
89 base.
David Netocdcc0152017-06-04 19:53:34 -040090 -fcbuffer-binding-base [stage] <value>
91 Same as -fubo-binding-base.
92 -fssbo-binding-base [stage] <value>
93 Sets the lowest automatically assigned binding number for
94 shader storage buffer objects (SSBO). Optionally only set
95 it for a single shader stage. Only affects GLSL.
David Neto63313f92017-06-07 09:15:34 -070096 -fuav-binding-base [stage] <value>
97 For automatically assigned bindings for unordered access
98 views (UAV), the register number is added to this base to
99 determine the binding number. Optionally only set it for
100 a single shader stage. Only affects HLSL.
David Neto63d0f822017-06-10 01:11:51 -0700101 -fresource-set-binding [stage] <reg0> <set0> <binding0>
102 [<reg1> <set1> <binding1>...]
103 Explicitly sets the descriptor set and binding for
104 HLSL resources, by register name. Optionally restrict
105 it to a single stage.
David Neto2df47b52016-11-12 13:55:21 -0800106 -fentry-point=<name>
107 Specify the entry point name for HLSL compilation, for
108 all subsequent source files. Default is "main".
109 -flimit=<settings>
110 Specify resource limits. Each limit is specified by a limit
111 name followed by an integer value. Tokens should be
112 separated by whitespace. If the same limit is specified
113 several times, only the last setting takes effect.
114 --show-limits Display available limit names and their default values.
115 -flimit-file <file>
116 Set limits as specified in the given file.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400117 -fshader-stage=<stage>
118 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400119 Valid stages are vertex, vert, fragment, frag, tesscontrol,
120 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400121 -g Generate source-level debug information.
122 Currently this option has no effect.
123 --help Display available options.
Dejan Mircevski29174452016-02-18 18:11:57 -0500124 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400125 -I <value> Add directory to include search path.
126 -o <file> Write output to <file>.
127 A file name of '-' represents standard output.
David Netocdefe182016-10-21 01:12:53 -0400128 -std=<value> Version and profile for GLSL input files. Possible values
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400129 are concatenations of version and profile, e.g. 310es,
David Netocdefe182016-10-21 01:12:53 -0400130 450core, etc. Ignored for HLSL files.
qiningb3cfde42016-05-14 01:43:31 -0400131 -mfmt=<format> Output SPIR-V binary code using the selected format. This
132 option may be specified only when the compilation output is
133 in SPIR-V binary code form. Available options include bin, c
134 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -0500135 -M Generate make dependencies. Implies -E and -w.
136 -MM An alias for -M.
137 -MD Generate make dependencies and compile.
138 -MF <file> Write dependency output to the given file.
139 -MT <target> Specify the target of the rule emitted by dependency
140 generation.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400141 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -0500142 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700143 Set the target client environment, and the semantics
144 of warnings and errors. An optional suffix can specify
145 the client version. Values are:
146 vulkan1.0 # The default
147 vulkan1.1
148 vulkan # Same as vulkan1.0
149 opengl4.5
150 opengl # Same as opengl4.5
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400151 -w Suppresses all warning messages.
152 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400153 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400154 Valid languages are: glsl, hlsl.
155 For files ending in .hlsl the default is hlsl.
156 Otherwise the default is glsl.
David Neto44dff892017-06-08 00:15:58 -0700157 -fhlsl-offsets Use HLSL offset rules for packing members of blocks.
158 Affects only GLSL. HLSL rules are always used for HLSL.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400159'''
160
161 expected_stderr = ''
162
163
164@inside_glslc_testsuite('Parameters')
165class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
166 """Tests that --help output is not too wide."""
167
168 glslc_args = ['--help']
169
170
171@inside_glslc_testsuite('Parameters')
172class UnknownSingleLetterArgument(expect.ErrorMessage):
173 """Tests that an unknown argument triggers an error message."""
174
175 glslc_args = ['-a']
176 expected_error = ["glslc: error: unknown argument: '-a'\n"]
177
178
179@inside_glslc_testsuite('Parameters')
180class UnknownMultiLetterArgument(expect.ErrorMessage):
181 """Tests that an unknown argument triggers an error message."""
182
183 glslc_args = ['-zzz']
184 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
185
186
187@inside_glslc_testsuite('Parameters')
188class UnsupportedOption(expect.ErrorMessage):
189 """Tests that an unsupported option triggers an error message."""
190
191 glslc_args = ['--unsupported-option']
192 expected_error = [
193 "glslc: error: unsupported option: '--unsupported-option'\n"]
194
195
196@inside_glslc_testsuite('File')
197class FileNotFound(expect.ErrorMessage):
198 """Tests the error message if a file cannot be found."""
199
200 blabla_file = TempFileName('blabla.frag')
201 glslc_args = [blabla_file]
202 expected_error = [
203 "glslc: error: cannot open input file: '", blabla_file,
204 "': No such file or directory\n"]
205
206
207@inside_glslc_testsuite('Unsupported')
208class LinkingNotSupported(expect.ErrorMessage):
209 """Tests the error message generated by linking not supported yet."""
210
David Netofab64112016-02-02 16:24:06 -0500211 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
212 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400213 glslc_args = [shader1, shader2]
214 expected_error = [
215 'glslc: error: linking multiple files is not supported yet. ',
216 'Use -c to compile files individually.\n']
217
218
219@inside_glslc_testsuite('Unsupported')
220class MultipleStdinUnsupported(expect.ErrorMessage):
221 """Tests the error message generated by having more than one - input."""
222
223 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
224 expected_error = [
225 'glslc: error: specifying standard input "-" as input more'
226 ' than once is not allowed.\n']
227
228
229@inside_glslc_testsuite('Parameters')
230class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
231 """Tests that you must use -fshader-stage when specifying - as input."""
232 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500233 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400234 int a() {
235 }
236 void main() {
237 int x = a();
238 }
239 """)
240 glslc_args = [shader]
241
242 expected_stdout = ''
243 expected_stderr = [
244 "glslc: error: '-': -fshader-stage required when input is from "
245 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800246
247
248@inside_glslc_testsuite('Parameters')
249class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
250 """Tests --show-limits shows correct output."""
251
252 glslc_args = ['--show-limits']
253
254 expected_stderr = ''
255 expected_stdout = """MaxLights 8
256MaxClipPlanes 6
257MaxTextureUnits 2
258MaxTextureCoords 8
259MaxVertexAttribs 16
260MaxVertexUniformComponents 4096
261MaxVaryingFloats 60
262MaxVertexTextureImageUnits 16
263MaxCombinedTextureImageUnits 80
264MaxTextureImageUnits 16
265MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400266MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800267MaxVertexUniformVectors 256
268MaxVaryingVectors 15
269MaxFragmentUniformVectors 256
270MaxVertexOutputVectors 16
271MaxFragmentInputVectors 15
272MinProgramTexelOffset -8
273MaxProgramTexelOffset 7
274MaxClipDistances 8
275MaxComputeWorkGroupCountX 65535
276MaxComputeWorkGroupCountY 65535
277MaxComputeWorkGroupCountZ 65535
278MaxComputeWorkGroupSizeX 1024
279MaxComputeWorkGroupSizeY 1024
280MaxComputeWorkGroupSizeZ 64
281MaxComputeUniformComponents 512
282MaxComputeTextureImageUnits 16
283MaxComputeImageUniforms 8
284MaxComputeAtomicCounters 8
285MaxComputeAtomicCounterBuffers 1
286MaxVaryingComponents 60
287MaxVertexOutputComponents 64
288MaxGeometryInputComponents 64
289MaxGeometryOutputComponents 128
290MaxFragmentInputComponents 128
291MaxImageUnits 8
292MaxCombinedImageUnitsAndFragmentOutputs 8
293MaxCombinedShaderOutputResources 8
294MaxImageSamples 0
295MaxVertexImageUniforms 0
296MaxTessControlImageUniforms 0
297MaxTessEvaluationImageUniforms 0
298MaxGeometryImageUniforms 0
299MaxFragmentImageUniforms 8
300MaxCombinedImageUniforms 8
301MaxGeometryTextureImageUnits 16
302MaxGeometryOutputVertices 256
303MaxGeometryTotalOutputComponents 1024
304MaxGeometryUniformComponents 512
305MaxGeometryVaryingComponents 60
306MaxTessControlInputComponents 128
307MaxTessControlOutputComponents 128
308MaxTessControlTextureImageUnits 16
309MaxTessControlUniformComponents 1024
310MaxTessControlTotalOutputComponents 4096
311MaxTessEvaluationInputComponents 128
312MaxTessEvaluationOutputComponents 128
313MaxTessEvaluationTextureImageUnits 16
314MaxTessEvaluationUniformComponents 1024
315MaxTessPatchComponents 120
316MaxPatchVertices 32
317MaxTessGenLevel 64
318MaxViewports 16
319MaxVertexAtomicCounters 0
320MaxTessControlAtomicCounters 0
321MaxTessEvaluationAtomicCounters 0
322MaxGeometryAtomicCounters 0
323MaxFragmentAtomicCounters 8
324MaxCombinedAtomicCounters 8
325MaxAtomicCounterBindings 1
326MaxVertexAtomicCounterBuffers 0
327MaxTessControlAtomicCounterBuffers 0
328MaxTessEvaluationAtomicCounterBuffers 0
329MaxGeometryAtomicCounterBuffers 0
330MaxFragmentAtomicCounterBuffers 0
331MaxCombinedAtomicCounterBuffers 1
332MaxAtomicCounterBufferSize 32
333MaxTransformFeedbackBuffers 4
334MaxTransformFeedbackInterleavedComponents 64
335MaxCullDistances 8
336MaxCombinedClipAndCullDistances 8
337MaxSamples 4
338"""