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