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