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