blob: cc1f8760f6e850d502ad63de67fc0691a79a588e [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.
85 -fresource-set-binding [stage] <reg0> <set0> <binding0>
86 [<reg1> <set1> <binding1>...]
87 Explicitly sets the descriptor set and binding for
88 HLSL resources, by register name. Optionally restrict
89 it to a single stage.
90 -fcbuffer-binding-base [stage] <value>
91 Same as -fubo-binding-base.
David Neto357d24b2017-06-04 18:27:12 -040092 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080093 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040094 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070095 For HLSL, the resource register number is added to this
96 base.
David Neto357d24b2017-06-04 18:27:12 -040097 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080098 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040099 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700100 For HLSL, the resource register number is added to this
101 base.
Lei Zhang9340ae52018-09-20 11:05:50 -0400102 -fssbo-binding-base [stage] <value>
103 Sets the lowest automatically assigned binding number for
104 shader storage buffer objects (SSBO). Optionally only set
105 it for a single shader stage. Only affects GLSL.
106 -ftexture-binding-base [stage] <value>
107 Sets the lowest automatically assigned binding number for
108 textures. Optionally only set it for a single shader stage.
109 For HLSL, the resource register number is added to this
110 base.
111 -fuav-binding-base [stage] <value>
112 For automatically assigned bindings for unordered access
113 views (UAV), the register number is added to this base to
114 determine the binding number. Optionally only set it for
115 a single shader stage. Only affects HLSL.
David Neto357d24b2017-06-04 18:27:12 -0400116 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800117 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400118 uniform buffer objects (UBO). Optionally only set it for
119 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700120 For HLSL, the resource register number is added to this
121 base.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400122 -fshader-stage=<stage>
123 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400124 Valid stages are vertex, vert, fragment, frag, tesscontrol,
125 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400126 -g Generate source-level debug information.
127 Currently this option has no effect.
128 --help Display available options.
129 -I <value> Add directory to include search path.
qiningb3cfde42016-05-14 01:43:31 -0400130 -mfmt=<format> Output SPIR-V binary code using the selected format. This
131 option may be specified only when the compilation output is
132 in SPIR-V binary code form. Available options include bin, c
133 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -0500134 -M Generate make dependencies. Implies -E and -w.
135 -MM An alias for -M.
136 -MD Generate make dependencies and compile.
137 -MF <file> Write dependency output to the given file.
138 -MT <target> Specify the target of the rule emitted by dependency
139 generation.
Lei Zhang9340ae52018-09-20 11:05:50 -0400140 -O Optimize the generated SPIR-V code for better performance.
141 -Os Optimize the generated SPIR-V code for smaller size.
142 -O0 Disable optimization.
143 -o <file> Write output to <file>.
144 A file name of '-' represents standard output.
145 -std=<value> Version and profile for GLSL input files. Possible values
146 are concatenations of version and profile, e.g. 310es,
147 450core, etc. Ignored for HLSL files.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400148 -S Only run preprocess and compilation steps.
Lei Zhang9340ae52018-09-20 11:05:50 -0400149 --show-limits Display available limit names and their default values.
qiningf6d83742016-01-28 16:05:11 -0500150 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700151 Set the target client environment, and the semantics
152 of warnings and errors. An optional suffix can specify
153 the client version. Values are:
154 vulkan1.0 # The default
155 vulkan1.1
156 vulkan # Same as vulkan1.0
157 opengl4.5
158 opengl # Same as opengl4.5
Lei Zhang9340ae52018-09-20 11:05:50 -0400159 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400160 -w Suppresses all warning messages.
161 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400162 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400163 Valid languages are: glsl, hlsl.
164 For files ending in .hlsl the default is hlsl.
165 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400166'''
167
168 expected_stderr = ''
169
170
171@inside_glslc_testsuite('Parameters')
172class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
173 """Tests that --help output is not too wide."""
174
175 glslc_args = ['--help']
176
177
178@inside_glslc_testsuite('Parameters')
179class UnknownSingleLetterArgument(expect.ErrorMessage):
180 """Tests that an unknown argument triggers an error message."""
181
182 glslc_args = ['-a']
183 expected_error = ["glslc: error: unknown argument: '-a'\n"]
184
185
186@inside_glslc_testsuite('Parameters')
187class UnknownMultiLetterArgument(expect.ErrorMessage):
188 """Tests that an unknown argument triggers an error message."""
189
190 glslc_args = ['-zzz']
191 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
192
193
194@inside_glslc_testsuite('Parameters')
195class UnsupportedOption(expect.ErrorMessage):
196 """Tests that an unsupported option triggers an error message."""
197
198 glslc_args = ['--unsupported-option']
199 expected_error = [
200 "glslc: error: unsupported option: '--unsupported-option'\n"]
201
202
203@inside_glslc_testsuite('File')
204class FileNotFound(expect.ErrorMessage):
205 """Tests the error message if a file cannot be found."""
206
207 blabla_file = TempFileName('blabla.frag')
208 glslc_args = [blabla_file]
209 expected_error = [
210 "glslc: error: cannot open input file: '", blabla_file,
211 "': No such file or directory\n"]
212
213
214@inside_glslc_testsuite('Unsupported')
215class LinkingNotSupported(expect.ErrorMessage):
216 """Tests the error message generated by linking not supported yet."""
217
David Netofab64112016-02-02 16:24:06 -0500218 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
219 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400220 glslc_args = [shader1, shader2]
221 expected_error = [
222 'glslc: error: linking multiple files is not supported yet. ',
223 'Use -c to compile files individually.\n']
224
225
226@inside_glslc_testsuite('Unsupported')
227class MultipleStdinUnsupported(expect.ErrorMessage):
228 """Tests the error message generated by having more than one - input."""
229
230 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
231 expected_error = [
232 'glslc: error: specifying standard input "-" as input more'
233 ' than once is not allowed.\n']
234
235
236@inside_glslc_testsuite('Parameters')
237class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
238 """Tests that you must use -fshader-stage when specifying - as input."""
239 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500240 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400241 int a() {
242 }
243 void main() {
244 int x = a();
245 }
246 """)
247 glslc_args = [shader]
248
249 expected_stdout = ''
250 expected_stderr = [
251 "glslc: error: '-': -fshader-stage required when input is from "
252 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800253
254
255@inside_glslc_testsuite('Parameters')
256class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
257 """Tests --show-limits shows correct output."""
258
259 glslc_args = ['--show-limits']
260
261 expected_stderr = ''
262 expected_stdout = """MaxLights 8
263MaxClipPlanes 6
264MaxTextureUnits 2
265MaxTextureCoords 8
266MaxVertexAttribs 16
267MaxVertexUniformComponents 4096
268MaxVaryingFloats 60
269MaxVertexTextureImageUnits 16
270MaxCombinedTextureImageUnits 80
271MaxTextureImageUnits 16
272MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400273MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800274MaxVertexUniformVectors 256
275MaxVaryingVectors 15
276MaxFragmentUniformVectors 256
277MaxVertexOutputVectors 16
278MaxFragmentInputVectors 15
279MinProgramTexelOffset -8
280MaxProgramTexelOffset 7
281MaxClipDistances 8
282MaxComputeWorkGroupCountX 65535
283MaxComputeWorkGroupCountY 65535
284MaxComputeWorkGroupCountZ 65535
285MaxComputeWorkGroupSizeX 1024
286MaxComputeWorkGroupSizeY 1024
287MaxComputeWorkGroupSizeZ 64
288MaxComputeUniformComponents 512
289MaxComputeTextureImageUnits 16
290MaxComputeImageUniforms 8
291MaxComputeAtomicCounters 8
292MaxComputeAtomicCounterBuffers 1
293MaxVaryingComponents 60
294MaxVertexOutputComponents 64
295MaxGeometryInputComponents 64
296MaxGeometryOutputComponents 128
297MaxFragmentInputComponents 128
298MaxImageUnits 8
299MaxCombinedImageUnitsAndFragmentOutputs 8
300MaxCombinedShaderOutputResources 8
301MaxImageSamples 0
302MaxVertexImageUniforms 0
303MaxTessControlImageUniforms 0
304MaxTessEvaluationImageUniforms 0
305MaxGeometryImageUniforms 0
306MaxFragmentImageUniforms 8
307MaxCombinedImageUniforms 8
308MaxGeometryTextureImageUnits 16
309MaxGeometryOutputVertices 256
310MaxGeometryTotalOutputComponents 1024
311MaxGeometryUniformComponents 512
312MaxGeometryVaryingComponents 60
313MaxTessControlInputComponents 128
314MaxTessControlOutputComponents 128
315MaxTessControlTextureImageUnits 16
316MaxTessControlUniformComponents 1024
317MaxTessControlTotalOutputComponents 4096
318MaxTessEvaluationInputComponents 128
319MaxTessEvaluationOutputComponents 128
320MaxTessEvaluationTextureImageUnits 16
321MaxTessEvaluationUniformComponents 1024
322MaxTessPatchComponents 120
323MaxPatchVertices 32
324MaxTessGenLevel 64
325MaxViewports 16
326MaxVertexAtomicCounters 0
327MaxTessControlAtomicCounters 0
328MaxTessEvaluationAtomicCounters 0
329MaxGeometryAtomicCounters 0
330MaxFragmentAtomicCounters 8
331MaxCombinedAtomicCounters 8
332MaxAtomicCounterBindings 1
333MaxVertexAtomicCounterBuffers 0
334MaxTessControlAtomicCounterBuffers 0
335MaxTessEvaluationAtomicCounterBuffers 0
336MaxGeometryAtomicCounterBuffers 0
337MaxFragmentAtomicCounterBuffers 0
338MaxCombinedAtomicCounterBuffers 1
339MaxAtomicCounterBufferSize 32
340MaxTransformFeedbackBuffers 4
341MaxTransformFeedbackInterleavedComponents 64
342MaxCullDistances 8
343MaxCombinedClipAndCullDistances 8
344MaxSamples 4
345"""