Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/parameter_tests.py
1560 views
1
# 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
15
import expect
16
import os.path
17
from glslc_test_framework import inside_glslc_testsuite
18
from placeholder import FileShader, StdinShader, TempFileName
19
20
21
@inside_glslc_testsuite('File')
22
class 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')
30
class NotSpecifyingOutputName(expect.SuccessfulReturn,
31
expect.CorrectObjectFilePreamble):
32
"""Tests that when there is no -o and -E/-S/-c specified, output as a.spv."""
33
34
shader = FileShader('#version 140\nvoid main() {}', '.frag')
35
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')
43
class 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
49
expected_stdout = '''glslc - Compile shaders into SPIR-V
50
51
Usage: glslc [options] file...
52
53
An input file of - represents standard input.
54
55
Options:
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.
59
Output defaults to standard output.
60
-fauto-bind-uniforms
61
Automatically assign bindings to uniform variables that
62
don't have an explicit 'binding' layout in the shader
63
source.
64
-fauto-map-locations
65
Automatically assign locations to uniform variables that
66
don't have an explicit 'location' layout in the shader
67
source.
68
-fauto-combined-image-sampler
69
Removes sampler variables and converts existing textures
70
to combined image-samplers.
71
-fentry-point=<name>
72
Specify the entry point name for HLSL compilation, for
73
all subsequent source files. Default is "main".
74
-fhlsl-16bit-types
75
Enable 16-bit type support for HLSL.
76
-fhlsl_functionality1, -fhlsl-functionality1
77
Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
78
compilation.
79
-fhlsl-iomap Use HLSL IO mappings for bindings.
80
-fhlsl-offsets Use HLSL offset rules for packing members of blocks.
81
Affects only GLSL. HLSL rules are always used for HLSL.
82
-finvert-y Invert position.Y output in vertex shader.
83
-flimit=<settings>
84
Specify resource limits. Each limit is specified by a limit
85
name followed by an integer value. Tokens should be
86
separated by whitespace. If the same limit is specified
87
several times, only the last setting takes effect.
88
-flimit-file <file>
89
Set limits as specified in the given file.
90
-fnan-clamp Generate code for max and min builtins so that, when given
91
a NaN operand, the other operand is returned. Similarly,
92
the clamp builtin will favour the non-NaN operands, as if
93
clamp were implemented as a composition of max and min.
94
-fpreserve-bindings
95
Preserve all binding declarations, even if those bindings
96
are not used.
97
-fresource-set-binding [stage] <reg0> <set0> <binding0>
98
[<reg1> <set1> <binding1>...]
99
Explicitly sets the descriptor set and binding for
100
HLSL resources, by register name. Optionally restrict
101
it to a single stage.
102
-fcbuffer-binding-base [stage] <value>
103
Same as -fubo-binding-base.
104
-fimage-binding-base [stage] <value>
105
Sets the lowest automatically assigned binding number for
106
images. Optionally only set it for a single shader stage.
107
For HLSL, the resource register number is added to this
108
base.
109
-fsampler-binding-base [stage] <value>
110
Sets the lowest automatically assigned binding number for
111
samplers Optionally only set it for a single shader stage.
112
For HLSL, the resource register number is added to this
113
base.
114
-fssbo-binding-base [stage] <value>
115
Sets the lowest automatically assigned binding number for
116
shader storage buffer objects (SSBO). Optionally only set
117
it for a single shader stage. Only affects GLSL.
118
-ftexture-binding-base [stage] <value>
119
Sets the lowest automatically assigned binding number for
120
textures. Optionally only set it for a single shader stage.
121
For HLSL, the resource register number is added to this
122
base.
123
-fuav-binding-base [stage] <value>
124
For automatically assigned bindings for unordered access
125
views (UAV), the register number is added to this base to
126
determine the binding number. Optionally only set it for
127
a single shader stage. Only affects HLSL.
128
-fubo-binding-base [stage] <value>
129
Sets the lowest automatically assigned binding number for
130
uniform buffer objects (UBO). Optionally only set it for
131
a single shader stage.
132
For HLSL, the resource register number is added to this
133
base.
134
-fshader-stage=<stage>
135
Treat subsequent input files as having stage <stage>.
136
Valid stages are vertex, vert, fragment, frag, tesscontrol,
137
tesc, tesseval, tese, geometry, geom, compute, and comp.
138
-g Generate source-level debug information.
139
-h Display available options.
140
--help Display available options.
141
-I <value> Add directory to include search path.
142
-mfmt=<format> Output SPIR-V binary code using the selected format. This
143
option may be specified only when the compilation output is
144
in SPIR-V binary code form. Available options are:
145
bin - SPIR-V binary words. This is the default.
146
c - Binary words as C initializer list of 32-bit ints
147
num - List of comma-separated 32-bit hex integers
148
-M Generate make dependencies. Implies -E and -w.
149
-MM An alias for -M.
150
-MD Generate make dependencies and compile.
151
-MF <file> Write dependency output to the given file.
152
-MT <target> Specify the target of the rule emitted by dependency
153
generation.
154
-O Optimize the generated SPIR-V code for better performance.
155
-Os Optimize the generated SPIR-V code for smaller size.
156
-O0 Disable optimization.
157
-o <file> Write output to <file>.
158
A file name of '-' represents standard output.
159
-std=<value> Version and profile for GLSL input files. Possible values
160
are concatenations of version and profile, e.g. 310es,
161
450core, etc. Ignored for HLSL files.
162
-S Emit SPIR-V assembly instead of binary.
163
--show-limits Display available limit names and their default values.
164
--target-env=<environment>
165
Set the target client environment, and the semantics
166
of warnings and errors. An optional suffix can specify
167
the client version. Values are:
168
vulkan1.0 # The default
169
vulkan1.1
170
vulkan1.2
171
vulkan1.3
172
vulkan # Same as vulkan1.0
173
opengl4.5
174
opengl # Same as opengl4.5
175
--target-spv=<spirv-version>
176
Set the SPIR-V version to be used for the generated SPIR-V
177
module. The default is the highest version of SPIR-V
178
required to be supported for the target environment.
179
For example, default for vulkan1.0 is spv1.0, and
180
the default for vulkan1.1 is spv1.3,
181
the default for vulkan1.2 is spv1.5.
182
the default for vulkan1.3 is spv1.6.
183
Values are:
184
spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6
185
--version Display compiler version information.
186
-w Suppresses all warning messages.
187
-Werror Treat all warnings as errors.
188
-x <language> Treat subsequent input files as having type <language>.
189
Valid languages are: glsl, hlsl.
190
For files ending in .hlsl the default is hlsl.
191
Otherwise the default is glsl.
192
'''
193
194
expected_stderr = ''
195
196
197
@inside_glslc_testsuite('Parameters')
198
class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
199
"""Tests that --help output is not too wide."""
200
201
glslc_args = ['--help']
202
203
204
@inside_glslc_testsuite('Parameters')
205
class UnknownSingleLetterArgument(expect.ErrorMessage):
206
"""Tests that an unknown argument triggers an error message."""
207
208
glslc_args = ['-a']
209
expected_error = ["glslc: error: unknown argument: '-a'\n"]
210
211
212
@inside_glslc_testsuite('Parameters')
213
class UnknownMultiLetterArgument(expect.ErrorMessage):
214
"""Tests that an unknown argument triggers an error message."""
215
216
glslc_args = ['-zzz']
217
expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
218
219
220
@inside_glslc_testsuite('Parameters')
221
class UnsupportedOption(expect.ErrorMessage):
222
"""Tests that an unsupported option triggers an error message."""
223
224
glslc_args = ['--unsupported-option']
225
expected_error = [
226
"glslc: error: unsupported option: '--unsupported-option'\n"]
227
228
229
@inside_glslc_testsuite('File')
230
class FileNotFound(expect.ErrorMessage):
231
"""Tests the error message if a file cannot be found."""
232
233
blabla_file = TempFileName('blabla.frag')
234
glslc_args = [blabla_file]
235
expected_error = [
236
"glslc: error: cannot open input file: '", blabla_file,
237
"': No such file or directory\n"]
238
239
240
@inside_glslc_testsuite('Unsupported')
241
class LinkingNotSupported(expect.ErrorMessage):
242
"""Tests the error message generated by linking not supported yet."""
243
244
shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
245
shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
246
glslc_args = [shader1, shader2]
247
expected_error = [
248
'glslc: error: linking multiple files is not supported yet. ',
249
'Use -c to compile files individually.\n']
250
251
252
@inside_glslc_testsuite('Unsupported')
253
class MultipleStdinUnsupported(expect.ErrorMessage):
254
"""Tests the error message generated by having more than one - input."""
255
256
glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
257
expected_error = [
258
'glslc: error: specifying standard input "-" as input more'
259
' than once is not allowed.\n']
260
261
262
@inside_glslc_testsuite('Parameters')
263
class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
264
"""Tests that you must use -fshader-stage when specifying - as input."""
265
shader = StdinShader(
266
"""#version 140
267
int a() {
268
}
269
void main() {
270
int x = a();
271
}
272
""")
273
glslc_args = [shader]
274
275
expected_stdout = ''
276
expected_stderr = [
277
"glslc: error: '-': -fshader-stage required when input is from "
278
'standard input "-"\n']
279
280
281
@inside_glslc_testsuite('Parameters')
282
class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
283
"""Tests --show-limits shows correct output."""
284
285
glslc_args = ['--show-limits']
286
287
expected_stderr = ''
288
expected_stdout = """MaxLights 8
289
MaxClipPlanes 6
290
MaxTextureUnits 2
291
MaxTextureCoords 8
292
MaxVertexAttribs 16
293
MaxVertexUniformComponents 4096
294
MaxVaryingFloats 60
295
MaxVertexTextureImageUnits 16
296
MaxCombinedTextureImageUnits 80
297
MaxTextureImageUnits 16
298
MaxFragmentUniformComponents 1024
299
MaxDrawBuffers 8
300
MaxVertexUniformVectors 256
301
MaxVaryingVectors 15
302
MaxFragmentUniformVectors 256
303
MaxVertexOutputVectors 16
304
MaxFragmentInputVectors 15
305
MinProgramTexelOffset -8
306
MaxProgramTexelOffset 7
307
MaxClipDistances 8
308
MaxComputeWorkGroupCountX 65535
309
MaxComputeWorkGroupCountY 65535
310
MaxComputeWorkGroupCountZ 65535
311
MaxComputeWorkGroupSizeX 1024
312
MaxComputeWorkGroupSizeY 1024
313
MaxComputeWorkGroupSizeZ 64
314
MaxComputeUniformComponents 512
315
MaxComputeTextureImageUnits 16
316
MaxComputeImageUniforms 8
317
MaxComputeAtomicCounters 8
318
MaxComputeAtomicCounterBuffers 1
319
MaxVaryingComponents 60
320
MaxVertexOutputComponents 64
321
MaxGeometryInputComponents 64
322
MaxGeometryOutputComponents 128
323
MaxFragmentInputComponents 128
324
MaxImageUnits 8
325
MaxCombinedImageUnitsAndFragmentOutputs 8
326
MaxCombinedShaderOutputResources 8
327
MaxImageSamples 0
328
MaxVertexImageUniforms 0
329
MaxTessControlImageUniforms 0
330
MaxTessEvaluationImageUniforms 0
331
MaxGeometryImageUniforms 0
332
MaxFragmentImageUniforms 8
333
MaxCombinedImageUniforms 8
334
MaxGeometryTextureImageUnits 16
335
MaxGeometryOutputVertices 256
336
MaxGeometryTotalOutputComponents 1024
337
MaxGeometryUniformComponents 512
338
MaxGeometryVaryingComponents 60
339
MaxTessControlInputComponents 128
340
MaxTessControlOutputComponents 128
341
MaxTessControlTextureImageUnits 16
342
MaxTessControlUniformComponents 1024
343
MaxTessControlTotalOutputComponents 4096
344
MaxTessEvaluationInputComponents 128
345
MaxTessEvaluationOutputComponents 128
346
MaxTessEvaluationTextureImageUnits 16
347
MaxTessEvaluationUniformComponents 1024
348
MaxTessPatchComponents 120
349
MaxPatchVertices 32
350
MaxTessGenLevel 64
351
MaxViewports 16
352
MaxVertexAtomicCounters 0
353
MaxTessControlAtomicCounters 0
354
MaxTessEvaluationAtomicCounters 0
355
MaxGeometryAtomicCounters 0
356
MaxFragmentAtomicCounters 8
357
MaxCombinedAtomicCounters 8
358
MaxAtomicCounterBindings 1
359
MaxVertexAtomicCounterBuffers 0
360
MaxTessControlAtomicCounterBuffers 0
361
MaxTessEvaluationAtomicCounterBuffers 0
362
MaxGeometryAtomicCounterBuffers 0
363
MaxFragmentAtomicCounterBuffers 0
364
MaxCombinedAtomicCounterBuffers 1
365
MaxAtomicCounterBufferSize 32
366
MaxTransformFeedbackBuffers 4
367
MaxTransformFeedbackInterleavedComponents 64
368
MaxCullDistances 8
369
MaxCombinedClipAndCullDistances 8
370
MaxSamples 4
371
MaxMeshOutputVerticesNV 256
372
MaxMeshOutputPrimitivesNV 512
373
MaxMeshWorkGroupSizeX_NV 32
374
MaxMeshWorkGroupSizeY_NV 1
375
MaxMeshWorkGroupSizeZ_NV 1
376
MaxTaskWorkGroupSizeX_NV 32
377
MaxTaskWorkGroupSizeY_NV 1
378
MaxTaskWorkGroupSizeZ_NV 1
379
MaxMeshViewCountNV 4
380
MaxMeshOutputVerticesEXT 256
381
MaxMeshOutputPrimitivesEXT 256
382
MaxMeshWorkGroupSizeX_EXT 128
383
MaxMeshWorkGroupSizeY_EXT 128
384
MaxMeshWorkGroupSizeZ_EXT 128
385
MaxTaskWorkGroupSizeX_EXT 128
386
MaxTaskWorkGroupSizeY_EXT 128
387
MaxTaskWorkGroupSizeZ_EXT 128
388
MaxMeshViewCountEXT 4
389
MaxDualSourceDrawBuffersEXT 1
390
"""
391
392