blob: 233e2974ea583bc0df0b6362a8645d06bd5a84e2 [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.
David Neto63313f92017-06-07 09:15:34 -070064 -fhlsl-iomap Use HLSL IO mappings for bindings.
David Neto357d24b2017-06-04 18:27:12 -040065 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080066 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040067 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070068 For HLSL, the resource register number is added to this
69 base.
David Neto357d24b2017-06-04 18:27:12 -040070 -ftexture-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080071 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040072 textures. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070073 For HLSL, the resource register number is added to this
74 base.
David Neto357d24b2017-06-04 18:27:12 -040075 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080076 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040077 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070078 For HLSL, the resource register number is added to this
79 base.
David Neto357d24b2017-06-04 18:27:12 -040080 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080081 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040082 uniform buffer objects (UBO). Optionally only set it for
83 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070084 For HLSL, the resource register number is added to this
85 base.
David Netocdcc0152017-06-04 19:53:34 -040086 -fcbuffer-binding-base [stage] <value>
87 Same as -fubo-binding-base.
88 -fssbo-binding-base [stage] <value>
89 Sets the lowest automatically assigned binding number for
90 shader storage buffer objects (SSBO). Optionally only set
91 it for a single shader stage. Only affects GLSL.
David Neto63313f92017-06-07 09:15:34 -070092 -fuav-binding-base [stage] <value>
93 For automatically assigned bindings for unordered access
94 views (UAV), the register number is added to this base to
95 determine the binding number. Optionally only set it for
96 a single shader stage. Only affects HLSL.
David Neto2df47b52016-11-12 13:55:21 -080097 -fentry-point=<name>
98 Specify the entry point name for HLSL compilation, for
99 all subsequent source files. Default is "main".
100 -flimit=<settings>
101 Specify resource limits. Each limit is specified by a limit
102 name followed by an integer value. Tokens should be
103 separated by whitespace. If the same limit is specified
104 several times, only the last setting takes effect.
105 --show-limits Display available limit names and their default values.
106 -flimit-file <file>
107 Set limits as specified in the given file.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400108 -fshader-stage=<stage>
109 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400110 Valid stages are vertex, vert, fragment, frag, tesscontrol,
111 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400112 -g Generate source-level debug information.
113 Currently this option has no effect.
114 --help Display available options.
Dejan Mircevski29174452016-02-18 18:11:57 -0500115 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400116 -I <value> Add directory to include search path.
117 -o <file> Write output to <file>.
118 A file name of '-' represents standard output.
David Netocdefe182016-10-21 01:12:53 -0400119 -std=<value> Version and profile for GLSL input files. Possible values
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400120 are concatenations of version and profile, e.g. 310es,
David Netocdefe182016-10-21 01:12:53 -0400121 450core, etc. Ignored for HLSL files.
qiningb3cfde42016-05-14 01:43:31 -0400122 -mfmt=<format> Output SPIR-V binary code using the selected format. This
123 option may be specified only when the compilation output is
124 in SPIR-V binary code form. Available options include bin, c
125 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -0500126 -M Generate make dependencies. Implies -E and -w.
127 -MM An alias for -M.
128 -MD Generate make dependencies and compile.
129 -MF <file> Write dependency output to the given file.
130 -MT <target> Specify the target of the rule emitted by dependency
131 generation.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400132 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -0500133 --target-env=<environment>
134 Set the target shader environment, and the semantics
135 of warnings and errors. Valid values are 'opengl',
136 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400137 -w Suppresses all warning messages.
138 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400139 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400140 Valid languages are: glsl, hlsl.
141 For files ending in .hlsl the default is hlsl.
142 Otherwise the default is glsl.
David Neto44dff892017-06-08 00:15:58 -0700143 -fhlsl-offsets Use HLSL offset rules for packing members of blocks.
144 Affects only GLSL. HLSL rules are always used for HLSL.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400145'''
146
147 expected_stderr = ''
148
149
150@inside_glslc_testsuite('Parameters')
151class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
152 """Tests that --help output is not too wide."""
153
154 glslc_args = ['--help']
155
156
157@inside_glslc_testsuite('Parameters')
158class UnknownSingleLetterArgument(expect.ErrorMessage):
159 """Tests that an unknown argument triggers an error message."""
160
161 glslc_args = ['-a']
162 expected_error = ["glslc: error: unknown argument: '-a'\n"]
163
164
165@inside_glslc_testsuite('Parameters')
166class UnknownMultiLetterArgument(expect.ErrorMessage):
167 """Tests that an unknown argument triggers an error message."""
168
169 glslc_args = ['-zzz']
170 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
171
172
173@inside_glslc_testsuite('Parameters')
174class UnsupportedOption(expect.ErrorMessage):
175 """Tests that an unsupported option triggers an error message."""
176
177 glslc_args = ['--unsupported-option']
178 expected_error = [
179 "glslc: error: unsupported option: '--unsupported-option'\n"]
180
181
182@inside_glslc_testsuite('File')
183class FileNotFound(expect.ErrorMessage):
184 """Tests the error message if a file cannot be found."""
185
186 blabla_file = TempFileName('blabla.frag')
187 glslc_args = [blabla_file]
188 expected_error = [
189 "glslc: error: cannot open input file: '", blabla_file,
190 "': No such file or directory\n"]
191
192
193@inside_glslc_testsuite('Unsupported')
194class LinkingNotSupported(expect.ErrorMessage):
195 """Tests the error message generated by linking not supported yet."""
196
David Netofab64112016-02-02 16:24:06 -0500197 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
198 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400199 glslc_args = [shader1, shader2]
200 expected_error = [
201 'glslc: error: linking multiple files is not supported yet. ',
202 'Use -c to compile files individually.\n']
203
204
205@inside_glslc_testsuite('Unsupported')
206class MultipleStdinUnsupported(expect.ErrorMessage):
207 """Tests the error message generated by having more than one - input."""
208
209 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
210 expected_error = [
211 'glslc: error: specifying standard input "-" as input more'
212 ' than once is not allowed.\n']
213
214
215@inside_glslc_testsuite('Parameters')
216class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
217 """Tests that you must use -fshader-stage when specifying - as input."""
218 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500219 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400220 int a() {
221 }
222 void main() {
223 int x = a();
224 }
225 """)
226 glslc_args = [shader]
227
228 expected_stdout = ''
229 expected_stderr = [
230 "glslc: error: '-': -fshader-stage required when input is from "
231 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800232
233
234@inside_glslc_testsuite('Parameters')
235class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
236 """Tests --show-limits shows correct output."""
237
238 glslc_args = ['--show-limits']
239
240 expected_stderr = ''
241 expected_stdout = """MaxLights 8
242MaxClipPlanes 6
243MaxTextureUnits 2
244MaxTextureCoords 8
245MaxVertexAttribs 16
246MaxVertexUniformComponents 4096
247MaxVaryingFloats 60
248MaxVertexTextureImageUnits 16
249MaxCombinedTextureImageUnits 80
250MaxTextureImageUnits 16
251MaxFragmentUniformComponents 1024
Andrew Woloszyn01921d42016-12-12 16:48:49 -0500252MaxDrawBuffers 4
David Neto2df47b52016-11-12 13:55:21 -0800253MaxVertexUniformVectors 256
254MaxVaryingVectors 15
255MaxFragmentUniformVectors 256
256MaxVertexOutputVectors 16
257MaxFragmentInputVectors 15
258MinProgramTexelOffset -8
259MaxProgramTexelOffset 7
260MaxClipDistances 8
261MaxComputeWorkGroupCountX 65535
262MaxComputeWorkGroupCountY 65535
263MaxComputeWorkGroupCountZ 65535
264MaxComputeWorkGroupSizeX 1024
265MaxComputeWorkGroupSizeY 1024
266MaxComputeWorkGroupSizeZ 64
267MaxComputeUniformComponents 512
268MaxComputeTextureImageUnits 16
269MaxComputeImageUniforms 8
270MaxComputeAtomicCounters 8
271MaxComputeAtomicCounterBuffers 1
272MaxVaryingComponents 60
273MaxVertexOutputComponents 64
274MaxGeometryInputComponents 64
275MaxGeometryOutputComponents 128
276MaxFragmentInputComponents 128
277MaxImageUnits 8
278MaxCombinedImageUnitsAndFragmentOutputs 8
279MaxCombinedShaderOutputResources 8
280MaxImageSamples 0
281MaxVertexImageUniforms 0
282MaxTessControlImageUniforms 0
283MaxTessEvaluationImageUniforms 0
284MaxGeometryImageUniforms 0
285MaxFragmentImageUniforms 8
286MaxCombinedImageUniforms 8
287MaxGeometryTextureImageUnits 16
288MaxGeometryOutputVertices 256
289MaxGeometryTotalOutputComponents 1024
290MaxGeometryUniformComponents 512
291MaxGeometryVaryingComponents 60
292MaxTessControlInputComponents 128
293MaxTessControlOutputComponents 128
294MaxTessControlTextureImageUnits 16
295MaxTessControlUniformComponents 1024
296MaxTessControlTotalOutputComponents 4096
297MaxTessEvaluationInputComponents 128
298MaxTessEvaluationOutputComponents 128
299MaxTessEvaluationTextureImageUnits 16
300MaxTessEvaluationUniformComponents 1024
301MaxTessPatchComponents 120
302MaxPatchVertices 32
303MaxTessGenLevel 64
304MaxViewports 16
305MaxVertexAtomicCounters 0
306MaxTessControlAtomicCounters 0
307MaxTessEvaluationAtomicCounters 0
308MaxGeometryAtomicCounters 0
309MaxFragmentAtomicCounters 8
310MaxCombinedAtomicCounters 8
311MaxAtomicCounterBindings 1
312MaxVertexAtomicCounterBuffers 0
313MaxTessControlAtomicCounterBuffers 0
314MaxTessEvaluationAtomicCounterBuffers 0
315MaxGeometryAtomicCounterBuffers 0
316MaxFragmentAtomicCounterBuffers 0
317MaxCombinedAtomicCounterBuffers 1
318MaxAtomicCounterBufferSize 32
319MaxTransformFeedbackBuffers 4
320MaxTransformFeedbackInterleavedComponents 64
321MaxCullDistances 8
322MaxCombinedClipAndCullDistances 8
323MaxSamples 4
324"""