Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_std.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
from glslc_test_framework import inside_glslc_testsuite
17
from placeholder import FileShader
18
19
20
def core_vert_shader_without_version():
21
# gl_ClipDistance doesn't exist in es profile (at least until 3.10).
22
return 'void main() { gl_ClipDistance[0] = 5.; }'
23
24
25
def core_frag_shader_without_version():
26
# gl_SampleID appears in core profile from 4.00.
27
# gl_sampleID doesn't exsit in es profile (at least until 3.10).
28
return 'void main() { int temp = gl_SampleID; }'
29
30
31
def hlsl_compute_shader_with_barriers():
32
# Use "main" to avoid the need for -fentry-point
33
return 'void main() { AllMemoryBarrierWithGroupSync(); }'
34
35
36
@inside_glslc_testsuite('OptionStd')
37
class TestStdNoArg(expect.ErrorMessage):
38
"""Tests -std alone."""
39
40
glslc_args = ['-std']
41
expected_error = ["glslc: error: unknown argument: '-std'\n"]
42
43
44
@inside_glslc_testsuite('OptionStd')
45
class TestStdEqNoArg(expect.ErrorMessage):
46
"""Tests -std= with no argument."""
47
48
glslc_args = ['-std=']
49
expected_error = ["glslc: error: invalid value '' in '-std='\n"]
50
51
52
@inside_glslc_testsuite('OptionStd')
53
class TestStdEqSpaceArg(expect.ErrorMessage):
54
"""Tests -std= <version-profile>."""
55
56
shader = FileShader(core_frag_shader_without_version(), '.frag')
57
glslc_args = ['-c', '-std=', '450core', shader]
58
expected_error = ["glslc: error: invalid value '' in '-std='\n"]
59
60
61
# TODO(dneto): The error message changes with different versions of glslang.
62
@inside_glslc_testsuite('OptionStd')
63
class TestMissingVersionAndStd(expect.ErrorMessageSubstr):
64
"""Tests that missing both #version and -std results in errors."""
65
66
shader = FileShader(core_frag_shader_without_version(), '.frag')
67
glslc_args = ['-c', shader]
68
expected_error_substr = ['error:']
69
70
71
@inside_glslc_testsuite('OptionStd')
72
class TestMissingVersionButHavingStd(expect.ValidObjectFile):
73
"""Tests that correct -std fixes missing #version."""
74
75
shader = FileShader(core_frag_shader_without_version(), '.frag')
76
glslc_args = ['-c', '-std=450core', shader]
77
78
79
@inside_glslc_testsuite('OptionStd')
80
class TestGLSL460(expect.ValidObjectFile):
81
"""Tests that GLSL version 4.6 is supported."""
82
83
shader = FileShader(core_frag_shader_without_version(), '.frag')
84
glslc_args = ['-c', '-std=460', shader]
85
86
87
@inside_glslc_testsuite('OptionStd')
88
class TestGLSL460Core(expect.ValidObjectFile):
89
"""Tests that GLSL version 4.6 core profile is supported."""
90
91
shader = FileShader(core_frag_shader_without_version(), '.frag')
92
glslc_args = ['-c', '-std=460core', shader]
93
94
95
@inside_glslc_testsuite('OptionStd')
96
class TestESSL320(expect.ValidObjectFile):
97
"""Tests that ESSL version 3.2 is supported."""
98
99
shader = FileShader(core_frag_shader_without_version(), '.frag')
100
glslc_args = ['-c', '-std=320es', shader]
101
102
103
@inside_glslc_testsuite('OptionStd')
104
class TestStdIgnoredInHlsl(expect.ValidObjectFile):
105
"""Tests HLSL compilation ignores -std."""
106
107
# Compute shaders are not available in OpenGL 150
108
shader = FileShader(hlsl_compute_shader_with_barriers(), '.comp')
109
glslc_args = ['-c', '-x', 'hlsl', '-std=150', shader]
110
111
112
@inside_glslc_testsuite('OptionStd')
113
class TestMissingVersionAndWrongStd(expect.ErrorMessage):
114
"""Tests missing #version and wrong -std results in errors."""
115
116
shader = FileShader(core_frag_shader_without_version(), '.frag')
117
glslc_args = ['-c', '-std=310es', shader]
118
expected_error = [
119
shader, ":1: error: 'gl_SampleID' : required extension not requested: "
120
'GL_OES_sample_variables\n1 error generated.\n']
121
122
123
@inside_glslc_testsuite('OptionStd')
124
class TestConflictingVersionAndStd(expect.ValidObjectFileWithWarning):
125
"""Tests that with both #version and -std, -std takes precedence."""
126
127
# Wrong #version here on purpose.
128
shader = FileShader(
129
'#version 310 es\n' + core_frag_shader_without_version(), '.frag')
130
# -std overwrites the wrong #version.
131
glslc_args = ['-c', '-std=450core', shader]
132
133
expected_warning = [
134
shader, ': warning: (version, profile) forced to be (450, core), while '
135
'in source code it is (310, es)\n1 warning generated.\n']
136
137
138
@inside_glslc_testsuite('OptionStd')
139
class TestMultipleStd(expect.ValidObjectFile):
140
"""Tests that for multiple -std, the last one takes effect."""
141
142
shader = FileShader(core_frag_shader_without_version(), '.frag')
143
glslc_args = ['-c', '-std=100', '-std=310es', shader, '-std=450core']
144
145
146
@inside_glslc_testsuite('OptionStd')
147
class TestMultipleFiles(expect.ValidObjectFileWithWarning):
148
"""Tests that -std covers all files."""
149
150
shader1 = FileShader(core_frag_shader_without_version(), '.frag')
151
shader2 = FileShader(core_vert_shader_without_version(), '.vert')
152
shader3 = FileShader(
153
'#version 310 es\n' + core_frag_shader_without_version(), '.frag')
154
glslc_args = ['-c', '-std=450core', shader1, shader2, shader3]
155
156
expected_warning = [
157
shader3, ': warning: (version, profile) forced to be (450, '
158
'core), while in source code it is (310, es)\n'
159
'1 warning generated.\n']
160
161
162
@inside_glslc_testsuite('OptionStd')
163
class TestUnkownProfile(expect.ErrorMessage):
164
"""Tests that -std rejects unknown profile."""
165
166
shader = FileShader(core_frag_shader_without_version(), '.frag')
167
glslc_args = ['-c', '-std=450google', shader]
168
expected_error = [
169
"glslc: error: invalid value '450google' in '-std=450google'\n"]
170
171
172
@inside_glslc_testsuite('OptionStd')
173
class TestUnkownVersion(expect.ErrorMessage):
174
"""Tests that -std rejects unknown version."""
175
176
shader = FileShader(core_frag_shader_without_version(), '.frag')
177
glslc_args = ['-c', '-std=42core', shader]
178
expected_error = [
179
"glslc: error: invalid value '42core' in '-std=42core'\n"]
180
181
182
@inside_glslc_testsuite('OptionStd')
183
class TestTotallyWrongStdValue(expect.ErrorMessage):
184
"""Tests that -std rejects totally wrong -std value."""
185
186
shader = FileShader(core_vert_shader_without_version(), '.vert')
187
glslc_args = ['-c', '-std=wrong42', shader]
188
189
expected_error = [
190
"glslc: error: invalid value 'wrong42' in '-std=wrong42'\n"]
191
192
193
@inside_glslc_testsuite('OptionStd')
194
class TestVersionInsideSlashSlashComment(expect.ValidObjectFileWithWarning):
195
"""Tests that -std substitutes the correct #version string."""
196
197
# The second #version string should be substituted and this shader
198
# should compile successfully with -std=450core.
199
shader = FileShader(
200
'// #version 310 es\n#version 310 es\n' +
201
core_vert_shader_without_version(), '.vert')
202
glslc_args = ['-c', '-std=450core', shader]
203
204
expected_warning = [
205
shader, ': warning: (version, profile) forced to be (450, core), while '
206
'in source code it is (310, es)\n1 warning generated.\n']
207
208
209
@inside_glslc_testsuite('OptionStd')
210
class TestVersionInsideSlashStarComment(expect.ValidObjectFileWithWarning):
211
"""Tests that -std substitutes the correct #version string."""
212
213
# The second #version string should be substituted and this shader
214
# should compile successfully with -std=450core.
215
shader = FileShader(
216
'/* #version 310 es */\n#version 310 es\n' +
217
core_vert_shader_without_version(), '.vert')
218
glslc_args = ['-c', '-std=450core', shader]
219
220
expected_warning = [
221
shader, ': warning: (version, profile) forced to be (450, core), while '
222
'in source code it is (310, es)\n1 warning generated.\n']
223
224
225
@inside_glslc_testsuite('OptionStd')
226
class TestCommentBeforeVersion(expect.ValidObjectFileWithWarning):
227
"""Tests that comments before #version (same line) is correctly handled."""
228
229
shader = FileShader(
230
'/* some comment */ #version 150\n' +
231
core_vert_shader_without_version(), '.vert')
232
glslc_args = ['-c', '-std=450', shader]
233
234
expected_warning = [
235
shader, ': warning: (version, profile) forced to be (450, none), while '
236
'in source code it is (150, none)\n1 warning generated.\n']
237
238
239
@inside_glslc_testsuite('OptionStd')
240
class TestCommentAfterVersion(expect.ValidObjectFileWithWarning):
241
"""Tests that multiple-line comments after #version is correctly handled."""
242
243
shader = FileShader(
244
'#version 150 compatibility ' +
245
'/* start \n second line \n end */\n' +
246
core_vert_shader_without_version(), '.vert')
247
glslc_args = ['-c', '-std=450core', shader]
248
249
expected_warning = [
250
shader, ': warning: (version, profile) forced to be (450, core), while '
251
'in source code it is (150, compatibility)\n1 warning generated.\n']
252
253
254
# The following test case is disabled because of a bug in glslang.
255
# When checking non-newline whitespaces, glslang only recognizes
256
# ' ' and '\t', leaving '\v' and '\f' unhandled. The following test
257
# case exposes this problem. It should be turned on once a fix for
258
# glslang is landed.
259
#@inside_glslc_testsuite('OptionStd')
260
class TestSpaceAroundVersion(expect.ValidObjectFileWithWarning):
261
"""Tests that space around #version is correctly handled."""
262
263
shader = FileShader(
264
'\t \t # \t \f\f version \v \t\t 310 \v\v \t es \n' +
265
core_vert_shader_without_version(), '.vert')
266
glslc_args = ['-c', '-std=450core', shader]
267
268
expected_warning = [
269
shader, ': warning: (version, profile) forced to be (450, core), while '
270
'in source code it is (310, es)\n1 warning generated.\n']
271
272
273
@inside_glslc_testsuite('OptionStd')
274
class TestVersionInsideCrazyComment(expect.ValidObjectFileWithWarning):
275
"""Tests that -std substitutes the correct #version string."""
276
277
# The fourth #version string should be substituted and this shader
278
# should compile successfully with -std=450core.
279
shader = FileShader(
280
'/* */ /* // /* #version 310 es */\n' + # /*-style comment
281
'// /* */ /* /* // #version 310 es\n' + # //-style comment
282
'///*////*//*/*/ #version 310 es*/\n' + # //-style comment
283
'#version 310 es\n' + core_vert_shader_without_version(), '.vert')
284
glslc_args = ['-c', '-std=450core', shader]
285
286
expected_warning = [
287
shader, ': warning: (version, profile) forced to be (450, core), while '
288
'in source code it is (310, es)\n1 warning generated.\n']
289
290
291
@inside_glslc_testsuite('OptionStd')
292
class TestVersionMissingProfile(expect.ErrorMessage):
293
"""Tests that missing required profile in -std results in an error."""
294
295
shader = FileShader('#version 140\nvoid main() {}', '.vert')
296
glslc_args = ['-c', '-std=310', shader]
297
298
expected_error = [
299
shader, ': error: #version: versions 300, 310, and 320 require ',
300
"specifying the 'es' profile\n1 error generated.\n"]
301
302
303
@inside_glslc_testsuite('OptionStd')
304
class TestVersionRedundantProfile(expect.ErrorMessageSubstr):
305
"""Tests that adding non-required profile in -std results in an error."""
306
307
shader = FileShader('#version 140\nvoid main() {}', '.vert')
308
glslc_args = ['-c', '-std=100core', shader]
309
310
expected_error_substr = [
311
shader, ': error: #version: versions before 150 do not allow '
312
'a profile token\n']
313
314