blob: f83d10e4de5cedad01f5e4720b0ab0ab1c407a3b [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.
Benjamin Chrétiend1f763c2018-02-09 18:08:58 +010064 -fauto-map-locations
65 Automatically assign locations to uniform variables that
66 don't have an explicit 'location' layout in the shader
67 source.
Lei Zhang9340ae52018-09-20 11:05:50 -040068 -fentry-point=<name>
69 Specify the entry point name for HLSL compilation, for
70 all subsequent source files. Default is "main".
David Neto5fd1b252018-04-13 16:27:04 -040071 -fhlsl_functionality1, -fhlsl-functionality1
72 Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
73 compilation.
Lei Zhang9340ae52018-09-20 11:05:50 -040074 -fhlsl-iomap Use HLSL IO mappings for bindings.
75 -fhlsl-offsets Use HLSL offset rules for packing members of blocks.
76 Affects only GLSL. HLSL rules are always used for HLSL.
77 -flimit=<settings>
78 Specify resource limits. Each limit is specified by a limit
79 name followed by an integer value. Tokens should be
80 separated by whitespace. If the same limit is specified
81 several times, only the last setting takes effect.
82 -flimit-file <file>
83 Set limits as specified in the given file.
84 -fresource-set-binding [stage] <reg0> <set0> <binding0>
85 [<reg1> <set1> <binding1>...]
86 Explicitly sets the descriptor set and binding for
87 HLSL resources, by register name. Optionally restrict
88 it to a single stage.
89 -fcbuffer-binding-base [stage] <value>
90 Same as -fubo-binding-base.
David Neto357d24b2017-06-04 18:27:12 -040091 -fimage-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080092 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040093 images. Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070094 For HLSL, the resource register number is added to this
95 base.
David Neto357d24b2017-06-04 18:27:12 -040096 -fsampler-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -080097 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -040098 samplers Optionally only set it for a single shader stage.
David Neto63313f92017-06-07 09:15:34 -070099 For HLSL, the resource register number is added to this
100 base.
Lei Zhang9340ae52018-09-20 11:05:50 -0400101 -fssbo-binding-base [stage] <value>
102 Sets the lowest automatically assigned binding number for
103 shader storage buffer objects (SSBO). Optionally only set
104 it for a single shader stage. Only affects GLSL.
105 -ftexture-binding-base [stage] <value>
106 Sets the lowest automatically assigned binding number for
107 textures. Optionally only set it for a single shader stage.
108 For HLSL, the resource register number is added to this
109 base.
110 -fuav-binding-base [stage] <value>
111 For automatically assigned bindings for unordered access
112 views (UAV), the register number is added to this base to
113 determine the binding number. Optionally only set it for
114 a single shader stage. Only affects HLSL.
David Neto357d24b2017-06-04 18:27:12 -0400115 -fubo-binding-base [stage] <value>
David Netoa2900672017-01-28 13:03:24 -0800116 Sets the lowest automatically assigned binding number for
David Neto357d24b2017-06-04 18:27:12 -0400117 uniform buffer objects (UBO). Optionally only set it for
118 a single shader stage.
David Neto63313f92017-06-07 09:15:34 -0700119 For HLSL, the resource register number is added to this
120 base.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400121 -fshader-stage=<stage>
122 Treat subsequent input files as having stage <stage>.
David Neto357d24b2017-06-04 18:27:12 -0400123 Valid stages are vertex, vert, fragment, frag, tesscontrol,
124 tesc, tesseval, tese, geometry, geom, compute, and comp.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400125 -g Generate source-level debug information.
126 Currently this option has no effect.
127 --help Display available options.
128 -I <value> Add directory to include search path.
qiningb3cfde42016-05-14 01:43:31 -0400129 -mfmt=<format> Output SPIR-V binary code using the selected format. This
130 option may be specified only when the compilation output is
131 in SPIR-V binary code form. Available options include bin, c
132 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -0500133 -M Generate make dependencies. Implies -E and -w.
134 -MM An alias for -M.
135 -MD Generate make dependencies and compile.
136 -MF <file> Write dependency output to the given file.
137 -MT <target> Specify the target of the rule emitted by dependency
138 generation.
Lei Zhang9340ae52018-09-20 11:05:50 -0400139 -O Optimize the generated SPIR-V code for better performance.
140 -Os Optimize the generated SPIR-V code for smaller size.
141 -O0 Disable optimization.
142 -o <file> Write output to <file>.
143 A file name of '-' represents standard output.
144 -std=<value> Version and profile for GLSL input files. Possible values
145 are concatenations of version and profile, e.g. 310es,
146 450core, etc. Ignored for HLSL files.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400147 -S Only run preprocess and compilation steps.
Lei Zhang9340ae52018-09-20 11:05:50 -0400148 --show-limits Display available limit names and their default values.
qiningf6d83742016-01-28 16:05:11 -0500149 --target-env=<environment>
David Netoc9931582018-03-22 07:32:14 -0700150 Set the target client environment, and the semantics
151 of warnings and errors. An optional suffix can specify
152 the client version. Values are:
153 vulkan1.0 # The default
154 vulkan1.1
155 vulkan # Same as vulkan1.0
156 opengl4.5
157 opengl # Same as opengl4.5
Lei Zhang9340ae52018-09-20 11:05:50 -0400158 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400159 -w Suppresses all warning messages.
160 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400161 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400162 Valid languages are: glsl, hlsl.
163 For files ending in .hlsl the default is hlsl.
164 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400165'''
166
167 expected_stderr = ''
168
169
170@inside_glslc_testsuite('Parameters')
171class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
172 """Tests that --help output is not too wide."""
173
174 glslc_args = ['--help']
175
176
177@inside_glslc_testsuite('Parameters')
178class UnknownSingleLetterArgument(expect.ErrorMessage):
179 """Tests that an unknown argument triggers an error message."""
180
181 glslc_args = ['-a']
182 expected_error = ["glslc: error: unknown argument: '-a'\n"]
183
184
185@inside_glslc_testsuite('Parameters')
186class UnknownMultiLetterArgument(expect.ErrorMessage):
187 """Tests that an unknown argument triggers an error message."""
188
189 glslc_args = ['-zzz']
190 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
191
192
193@inside_glslc_testsuite('Parameters')
194class UnsupportedOption(expect.ErrorMessage):
195 """Tests that an unsupported option triggers an error message."""
196
197 glslc_args = ['--unsupported-option']
198 expected_error = [
199 "glslc: error: unsupported option: '--unsupported-option'\n"]
200
201
202@inside_glslc_testsuite('File')
203class FileNotFound(expect.ErrorMessage):
204 """Tests the error message if a file cannot be found."""
205
206 blabla_file = TempFileName('blabla.frag')
207 glslc_args = [blabla_file]
208 expected_error = [
209 "glslc: error: cannot open input file: '", blabla_file,
210 "': No such file or directory\n"]
211
212
213@inside_glslc_testsuite('Unsupported')
214class LinkingNotSupported(expect.ErrorMessage):
215 """Tests the error message generated by linking not supported yet."""
216
David Netofab64112016-02-02 16:24:06 -0500217 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
218 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400219 glslc_args = [shader1, shader2]
220 expected_error = [
221 'glslc: error: linking multiple files is not supported yet. ',
222 'Use -c to compile files individually.\n']
223
224
225@inside_glslc_testsuite('Unsupported')
226class MultipleStdinUnsupported(expect.ErrorMessage):
227 """Tests the error message generated by having more than one - input."""
228
229 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
230 expected_error = [
231 'glslc: error: specifying standard input "-" as input more'
232 ' than once is not allowed.\n']
233
234
235@inside_glslc_testsuite('Parameters')
236class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
237 """Tests that you must use -fshader-stage when specifying - as input."""
238 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500239 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400240 int a() {
241 }
242 void main() {
243 int x = a();
244 }
245 """)
246 glslc_args = [shader]
247
248 expected_stdout = ''
249 expected_stderr = [
250 "glslc: error: '-': -fshader-stage required when input is from "
251 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800252
253
254@inside_glslc_testsuite('Parameters')
255class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
256 """Tests --show-limits shows correct output."""
257
258 glslc_args = ['--show-limits']
259
260 expected_stderr = ''
261 expected_stdout = """MaxLights 8
262MaxClipPlanes 6
263MaxTextureUnits 2
264MaxTextureCoords 8
265MaxVertexAttribs 16
266MaxVertexUniformComponents 4096
267MaxVaryingFloats 60
268MaxVertexTextureImageUnits 16
269MaxCombinedTextureImageUnits 80
270MaxTextureImageUnits 16
271MaxFragmentUniformComponents 1024
David Netoef03acd2017-06-30 10:30:17 -0400272MaxDrawBuffers 8
David Neto2df47b52016-11-12 13:55:21 -0800273MaxVertexUniformVectors 256
274MaxVaryingVectors 15
275MaxFragmentUniformVectors 256
276MaxVertexOutputVectors 16
277MaxFragmentInputVectors 15
278MinProgramTexelOffset -8
279MaxProgramTexelOffset 7
280MaxClipDistances 8
281MaxComputeWorkGroupCountX 65535
282MaxComputeWorkGroupCountY 65535
283MaxComputeWorkGroupCountZ 65535
284MaxComputeWorkGroupSizeX 1024
285MaxComputeWorkGroupSizeY 1024
286MaxComputeWorkGroupSizeZ 64
287MaxComputeUniformComponents 512
288MaxComputeTextureImageUnits 16
289MaxComputeImageUniforms 8
290MaxComputeAtomicCounters 8
291MaxComputeAtomicCounterBuffers 1
292MaxVaryingComponents 60
293MaxVertexOutputComponents 64
294MaxGeometryInputComponents 64
295MaxGeometryOutputComponents 128
296MaxFragmentInputComponents 128
297MaxImageUnits 8
298MaxCombinedImageUnitsAndFragmentOutputs 8
299MaxCombinedShaderOutputResources 8
300MaxImageSamples 0
301MaxVertexImageUniforms 0
302MaxTessControlImageUniforms 0
303MaxTessEvaluationImageUniforms 0
304MaxGeometryImageUniforms 0
305MaxFragmentImageUniforms 8
306MaxCombinedImageUniforms 8
307MaxGeometryTextureImageUnits 16
308MaxGeometryOutputVertices 256
309MaxGeometryTotalOutputComponents 1024
310MaxGeometryUniformComponents 512
311MaxGeometryVaryingComponents 60
312MaxTessControlInputComponents 128
313MaxTessControlOutputComponents 128
314MaxTessControlTextureImageUnits 16
315MaxTessControlUniformComponents 1024
316MaxTessControlTotalOutputComponents 4096
317MaxTessEvaluationInputComponents 128
318MaxTessEvaluationOutputComponents 128
319MaxTessEvaluationTextureImageUnits 16
320MaxTessEvaluationUniformComponents 1024
321MaxTessPatchComponents 120
322MaxPatchVertices 32
323MaxTessGenLevel 64
324MaxViewports 16
325MaxVertexAtomicCounters 0
326MaxTessControlAtomicCounters 0
327MaxTessEvaluationAtomicCounters 0
328MaxGeometryAtomicCounters 0
329MaxFragmentAtomicCounters 8
330MaxCombinedAtomicCounters 8
331MaxAtomicCounterBindings 1
332MaxVertexAtomicCounterBuffers 0
333MaxTessControlAtomicCounterBuffers 0
334MaxTessEvaluationAtomicCounterBuffers 0
335MaxGeometryAtomicCounterBuffers 0
336MaxFragmentAtomicCounterBuffers 0
337MaxCombinedAtomicCounterBuffers 1
338MaxAtomicCounterBufferSize 32
339MaxTransformFeedbackBuffers 4
340MaxTransformFeedbackInterleavedComponents 64
341MaxCullDistances 8
342MaxCombinedClipAndCullDistances 8
343MaxSamples 4
344"""