Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_fpreserve_bindings.py
1560 views
1
# Copyright 2023 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
# A GLSL shader with unused bindings.
20
GLSL_SHADER_WITH_UNUSED_BINDINGS = """#version 450
21
layout(binding=0) buffer InputA { vec4 x[]; } inputA;
22
layout(binding=1) buffer InputB { vec4 x[]; } inputB;
23
layout(binding=2) buffer Output { vec4 x[]; } outputO;
24
25
void main() {}
26
"""
27
28
29
@inside_glslc_testsuite('OptionFPreserveBindings')
30
class TestFPreserveBindingsInputA(expect.ValidAssemblyFileWithSubstr):
31
"""Tests that the compiler preserves bindings when optimizations are
32
enabled."""
33
34
shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')
35
glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']
36
# Check the first buffer.
37
expected_assembly_substr = "Binding 0"
38
39
40
@inside_glslc_testsuite('OptionFPreserveBindings')
41
class TestFPreserveBindingsInputB(expect.ValidAssemblyFileWithSubstr):
42
"""Tests that the compiler preserves bindings when optimizations are
43
enabled."""
44
45
shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')
46
glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']
47
# Check the first buffer.
48
expected_assembly_substr = "Binding 1"
49
50
51
@inside_glslc_testsuite('OptionFPreserveBindings')
52
class TestFPreserveBindingsOutputO(expect.ValidAssemblyFileWithSubstr):
53
"""Tests that the compiler preserves bindings when optimizations are
54
enabled."""
55
56
shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')
57
glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']
58
# Check the first buffer.
59
expected_assembly_substr = "Binding 2"
60
61
62
@inside_glslc_testsuite('OptionFPreserveBindings')
63
class TestFNoPreserveBindings(expect.ValidAssemblyFileWithoutSubstr):
64
"""Tests that the compiler removes bindings when -fpreserve-bindings is not
65
set."""
66
67
shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')
68
glslc_args = ['-S', '-O', shader]
69
# Check that all binding decorations are gone.
70
unexpected_assembly_substr = "OpDecorate"
71
72