Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_dash_cap_O.py
1560 views
1
# Copyright 2016 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 environment import File, Directory
17
from glslc_test_framework import inside_glslc_testsuite
18
from placeholder import FileShader
19
20
MINIMAL_SHADER = '#version 310 es\nvoid main() {}'
21
EMPTY_SHADER_IN_CWD = Directory('.', [File('shader.vert', MINIMAL_SHADER)])
22
23
ASSEMBLY_WITH_DEBUG_SOURCE = [
24
'; SPIR-V\n',
25
'; Version: 1.0\n',
26
'; Generator: Google Shaderc over Glslang; 11\n',
27
'; Bound: 7\n',
28
'; Schema: 0\n',
29
' OpCapability Shader\n',
30
' %2 = OpExtInstImport "GLSL.std.450"\n',
31
' OpMemoryModel Logical GLSL450\n',
32
' OpEntryPoint Vertex %main "main"\n',
33
' %1 = OpString "shader.vert"\n',
34
' OpSource ESSL 310 %1 "// OpModuleProcessed entry-point main\n',
35
'// OpModuleProcessed client vulkan100\n',
36
'// OpModuleProcessed target-env vulkan1.0\n',
37
'// OpModuleProcessed entry-point main\n',
38
'#line 1\n',
39
'#version 310 es\n',
40
'void main() {}"\n',
41
' OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"\n',
42
' OpSourceExtension "GL_GOOGLE_include_directive"\n',
43
' OpName %main "main"\n',
44
' %void = OpTypeVoid\n',
45
' %4 = OpTypeFunction %void\n',
46
' OpLine %1 2 11\n',
47
' %main = OpFunction %void None %4\n',
48
' %6 = OpLabel\n',
49
' OpReturn\n',
50
' OpFunctionEnd\n']
51
52
ASSEMBLY_WITH_DEBUG = [
53
'; SPIR-V\n',
54
'; Version: 1.0\n',
55
'; Generator: Google Shaderc over Glslang; 11\n',
56
'; Bound: 6\n',
57
'; Schema: 0\n',
58
' OpCapability Shader\n',
59
' %1 = OpExtInstImport "GLSL.std.450"\n',
60
' OpMemoryModel Logical GLSL450\n',
61
' OpEntryPoint Vertex %main "main"\n',
62
' OpSource ESSL 310\n',
63
' OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"\n',
64
' OpSourceExtension "GL_GOOGLE_include_directive"\n',
65
' OpName %main "main"\n',
66
' %void = OpTypeVoid\n',
67
' %3 = OpTypeFunction %void\n',
68
' %main = OpFunction %void None %3\n',
69
' %5 = OpLabel\n',
70
' OpReturn\n',
71
' OpFunctionEnd\n']
72
73
ASSEMBLY_WITHOUT_DEBUG = [
74
'; SPIR-V\n',
75
'; Version: 1.0\n',
76
'; Generator: Google Shaderc over Glslang; 11\n',
77
'; Bound: 6\n',
78
'; Schema: 0\n',
79
' OpCapability Shader\n',
80
' %1 = OpExtInstImport "GLSL.std.450"\n',
81
' OpMemoryModel Logical GLSL450\n',
82
' OpEntryPoint Vertex %4 "main"\n',
83
' %void = OpTypeVoid\n',
84
' %3 = OpTypeFunction %void\n',
85
' %4 = OpFunction %void None %3\n', # %4 vs. %main
86
' %5 = OpLabel\n',
87
' OpReturn\n',
88
' OpFunctionEnd\n']
89
90
91
@inside_glslc_testsuite('OptionDashCapO')
92
class TestDashCapO0(expect.ValidFileContents):
93
"""Tests that -O0 works."""
94
95
environment = EMPTY_SHADER_IN_CWD
96
glslc_args = ['-S', '-O0', 'shader.vert']
97
target_filename = 'shader.vert.spvasm'
98
expected_file_contents = ASSEMBLY_WITH_DEBUG
99
100
@inside_glslc_testsuite('OptionDashCapO')
101
class TestDashCapOPerformance(expect.ValidFileContents):
102
"""Tests -O works."""
103
104
environment = EMPTY_SHADER_IN_CWD
105
glslc_args = ['-S', '-O', 'shader.vert']
106
target_filename = 'shader.vert.spvasm'
107
expected_file_contents = ASSEMBLY_WITHOUT_DEBUG
108
109
@inside_glslc_testsuite('OptionDashCapO')
110
class TestDashCapOs(expect.ValidFileContents):
111
"""Tests that -Os works."""
112
113
environment = EMPTY_SHADER_IN_CWD
114
glslc_args = ['-S', '-Os', 'shader.vert']
115
target_filename = 'shader.vert.spvasm'
116
expected_file_contents = ASSEMBLY_WITHOUT_DEBUG
117
118
119
@inside_glslc_testsuite('OptionDashCapO')
120
class TestDashCapOOverriding(expect.ValidFileContents):
121
"""Tests that if there are multiple -O's, only the last one takes effect."""
122
123
environment = EMPTY_SHADER_IN_CWD
124
glslc_args = ['-S', '-Os', '-O0', '-Os', '-O0', 'shader.vert']
125
target_filename = 'shader.vert.spvasm'
126
expected_file_contents = ASSEMBLY_WITH_DEBUG
127
128
129
@inside_glslc_testsuite('OptionDashCapO')
130
class TestDashCapOWithDashG(expect.ValidFileContents):
131
"""Tests that -g restrains -O from turning on strip debug info."""
132
133
environment = EMPTY_SHADER_IN_CWD
134
glslc_args = ['-S', '-Os', '-g', 'shader.vert']
135
target_filename = 'shader.vert.spvasm'
136
expected_file_contents = ASSEMBLY_WITH_DEBUG_SOURCE
137
138
139
@inside_glslc_testsuite('OptionDashCapO')
140
class TestDashGWithDashCapO(expect.ValidFileContents):
141
"""Tests that -g restrains -O from turning on strip debug info."""
142
143
environment = EMPTY_SHADER_IN_CWD
144
glslc_args = ['-S', '-g', '-Os', 'shader.vert']
145
target_filename = 'shader.vert.spvasm'
146
expected_file_contents = ASSEMBLY_WITH_DEBUG_SOURCE
147
148
149
@inside_glslc_testsuite('OptionDashCapO')
150
class TestWrongOptLevel(expect.NoGeneratedFiles, expect.ErrorMessage):
151
"""Tests erroring out with wrong optimization level."""
152
153
shader = FileShader(MINIMAL_SHADER, '.vert')
154
glslc_args = ['-c', '-O2', shader]
155
expected_error = "glslc: error: invalid value '2' in '-O2'\n"
156
157