blob: b0c3923e7c36f5e6a7fc71a89789067e163d6085 [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 Neto357d24b2017-06-04 18:27:12 -040064 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080065 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040066 images. Optionally only set it for a single shader stage.
67 -ftexture-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080068 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040069 textures. Optionally only set it for a single shader stage.
70 -fsampler-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 samplers Optionally only set it for a single shader stage.
73 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080074 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040075 uniform buffer objects (UBO). Optionally only set it for
76 a single shader stage.
David Netocdcc0152017-06-04 19:53:34 -040077 -fcbuffer-binding-base [stage] <value>
78 Same as -fubo-binding-base.
79 -fssbo-binding-base [stage] <value>
80 Sets the lowest automatically assigned binding number for
81 shader storage buffer objects (SSBO). Optionally only set
82 it for a single shader stage. Only affects GLSL.
David Neto2df47b52016-11-12 13:55:21 -080083 -fentry-point=<name>
84 Specify the entry point name for HLSL compilation, for
85 all subsequent source files. Default is "main".
86 -flimit=<settings>
87 Specify resource limits. Each limit is specified by a limit
88 name followed by an integer value. Tokens should be
89 separated by whitespace. If the same limit is specified
90 several times, only the last setting takes effect.
91 --show-limits Display available limit names and their default values.
92 -flimit-file <file>
93 Set limits as specified in the given file.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040094 -fshader-stage=<stage>
95 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -040096 Valid stages are vertex, vert, fragment, frag, tesscontrol,
97 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040098 -g Generate source-level debug information.
99 Currently this option has no effect.
100 --help Display available options.
Dejan Mircevski29174452016-02-18 18:11:57 -0500101 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400102 -I <value> Add directory to include search path.
103 -o <file> Write output to <file>.
104 A file name of '-' represents standard output.
David Netocdefe182016-10-21 01:12:53 -0400105 -std=<value> Version and profile for GLSL input files. Possible values
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400106 are concatenations of version and profile, e.g. 310es,
David Netocdefe182016-10-21 01:12:53 -0400107 450core, etc. Ignored for HLSL files.
qiningb3cfde42016-05-14 01:43:31 -0400108 -mfmt=<format> Output SPIR-V binary code using the selected format. This
109 option may be specified only when the compilation output is
110 in SPIR-V binary code form. Available options include bin, c
111 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -0500112 -M Generate make dependencies. Implies -E and -w.
113 -MM An alias for -M.
114 -MD Generate make dependencies and compile.
115 -MF <file> Write dependency output to the given file.
116 -MT <target> Specify the target of the rule emitted by dependency
117 generation.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400118 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -0500119 --target-env=<environment>
120 Set the target shader environment, and the semantics
121 of warnings and errors. Valid values are 'opengl',
122 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400123 -w Suppresses all warning messages.
124 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400125 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400126 Valid languages are: glsl, hlsl.
127 For files ending in .hlsl the default is hlsl.
128 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400129'''
130
131 expected_stderr = ''
132
133
134@inside_glslc_testsuite('Parameters')
135class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
136 """Tests that --help output is not too wide."""
137
138 glslc_args = ['--help']
139
140
141@inside_glslc_testsuite('Parameters')
142class UnknownSingleLetterArgument(expect.ErrorMessage):
143 """Tests that an unknown argument triggers an error message."""
144
145 glslc_args = ['-a']
146 expected_error = ["glslc: error: unknown argument: '-a'\n"]
147
148
149@inside_glslc_testsuite('Parameters')
150class UnknownMultiLetterArgument(expect.ErrorMessage):
151 """Tests that an unknown argument triggers an error message."""
152
153 glslc_args = ['-zzz']
154 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
155
156
157@inside_glslc_testsuite('Parameters')
158class UnsupportedOption(expect.ErrorMessage):
159 """Tests that an unsupported option triggers an error message."""
160
161 glslc_args = ['--unsupported-option']
162 expected_error = [
163 "glslc: error: unsupported option: '--unsupported-option'\n"]
164
165
166@inside_glslc_testsuite('File')
167class FileNotFound(expect.ErrorMessage):
168 """Tests the error message if a file cannot be found."""
169
170 blabla_file = TempFileName('blabla.frag')
171 glslc_args = [blabla_file]
172 expected_error = [
173 "glslc: error: cannot open input file: '", blabla_file,
174 "': No such file or directory\n"]
175
176
177@inside_glslc_testsuite('Unsupported')
178class LinkingNotSupported(expect.ErrorMessage):
179 """Tests the error message generated by linking not supported yet."""
180
David Netofab64112016-02-02 16:24:06 -0500181 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
182 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400183 glslc_args = [shader1, shader2]
184 expected_error = [
185 'glslc: error: linking multiple files is not supported yet. ',
186 'Use -c to compile files individually.\n']
187
188
189@inside_glslc_testsuite('Unsupported')
190class MultipleStdinUnsupported(expect.ErrorMessage):
191 """Tests the error message generated by having more than one - input."""
192
193 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
194 expected_error = [
195 'glslc: error: specifying standard input "-" as input more'
196 ' than once is not allowed.\n']
197
198
199@inside_glslc_testsuite('Parameters')
200class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
201 """Tests that you must use -fshader-stage when specifying - as input."""
202 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500203 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400204 int a() {
205 }
206 void main() {
207 int x = a();
208 }
209 """)
210 glslc_args = [shader]
211
212 expected_stdout = ''
213 expected_stderr = [
214 "glslc: error: '-': -fshader-stage required when input is from "
215 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800216
217
218@inside_glslc_testsuite('Parameters')
219class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
220 """Tests --show-limits shows correct output."""
221
222 glslc_args = ['--show-limits']
223
224 expected_stderr = ''
225 expected_stdout = """MaxLights 8
226MaxClipPlanes 6
227MaxTextureUnits 2
228MaxTextureCoords 8
229MaxVertexAttribs 16
230MaxVertexUniformComponents 4096
231MaxVaryingFloats 60
232MaxVertexTextureImageUnits 16
233MaxCombinedTextureImageUnits 80
234MaxTextureImageUnits 16
235MaxFragmentUniformComponents 1024
Andrew Woloszyn01921d42016-12-12 16:48:49 -0500236MaxDrawBuffers 4
David Neto2df47b52016-11-12 13:55:21 -0800237MaxVertexUniformVectors 256
238MaxVaryingVectors 15
239MaxFragmentUniformVectors 256
240MaxVertexOutputVectors 16
241MaxFragmentInputVectors 15
242MinProgramTexelOffset -8
243MaxProgramTexelOffset 7
244MaxClipDistances 8
245MaxComputeWorkGroupCountX 65535
246MaxComputeWorkGroupCountY 65535
247MaxComputeWorkGroupCountZ 65535
248MaxComputeWorkGroupSizeX 1024
249MaxComputeWorkGroupSizeY 1024
250MaxComputeWorkGroupSizeZ 64
251MaxComputeUniformComponents 512
252MaxComputeTextureImageUnits 16
253MaxComputeImageUniforms 8
254MaxComputeAtomicCounters 8
255MaxComputeAtomicCounterBuffers 1
256MaxVaryingComponents 60
257MaxVertexOutputComponents 64
258MaxGeometryInputComponents 64
259MaxGeometryOutputComponents 128
260MaxFragmentInputComponents 128
261MaxImageUnits 8
262MaxCombinedImageUnitsAndFragmentOutputs 8
263MaxCombinedShaderOutputResources 8
264MaxImageSamples 0
265MaxVertexImageUniforms 0
266MaxTessControlImageUniforms 0
267MaxTessEvaluationImageUniforms 0
268MaxGeometryImageUniforms 0
269MaxFragmentImageUniforms 8
270MaxCombinedImageUniforms 8
271MaxGeometryTextureImageUnits 16
272MaxGeometryOutputVertices 256
273MaxGeometryTotalOutputComponents 1024
274MaxGeometryUniformComponents 512
275MaxGeometryVaryingComponents 60
276MaxTessControlInputComponents 128
277MaxTessControlOutputComponents 128
278MaxTessControlTextureImageUnits 16
279MaxTessControlUniformComponents 1024
280MaxTessControlTotalOutputComponents 4096
281MaxTessEvaluationInputComponents 128
282MaxTessEvaluationOutputComponents 128
283MaxTessEvaluationTextureImageUnits 16
284MaxTessEvaluationUniformComponents 1024
285MaxTessPatchComponents 120
286MaxPatchVertices 32
287MaxTessGenLevel 64
288MaxViewports 16
289MaxVertexAtomicCounters 0
290MaxTessControlAtomicCounters 0
291MaxTessEvaluationAtomicCounters 0
292MaxGeometryAtomicCounters 0
293MaxFragmentAtomicCounters 8
294MaxCombinedAtomicCounters 8
295MaxAtomicCounterBindings 1
296MaxVertexAtomicCounterBuffers 0
297MaxTessControlAtomicCounterBuffers 0
298MaxTessEvaluationAtomicCounterBuffers 0
299MaxGeometryAtomicCounterBuffers 0
300MaxFragmentAtomicCounterBuffers 0
301MaxCombinedAtomicCounterBuffers 1
302MaxAtomicCounterBufferSize 32
303MaxTransformFeedbackBuffers 4
304MaxTransformFeedbackInterleavedComponents 64
305MaxCullDistances 8
306MaxCombinedClipAndCullDistances 8
307MaxSamples 4
308"""