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