Path: blob/main/glslc/test/option_fpreserve_bindings.py
1560 views
# Copyright 2023 The Shaderc Authors. All rights reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.1314import expect15from glslc_test_framework import inside_glslc_testsuite16from placeholder import FileShader1718# A GLSL shader with unused bindings.19GLSL_SHADER_WITH_UNUSED_BINDINGS = """#version 45020layout(binding=0) buffer InputA { vec4 x[]; } inputA;21layout(binding=1) buffer InputB { vec4 x[]; } inputB;22layout(binding=2) buffer Output { vec4 x[]; } outputO;2324void main() {}25"""262728@inside_glslc_testsuite('OptionFPreserveBindings')29class TestFPreserveBindingsInputA(expect.ValidAssemblyFileWithSubstr):30"""Tests that the compiler preserves bindings when optimizations are31enabled."""3233shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')34glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']35# Check the first buffer.36expected_assembly_substr = "Binding 0"373839@inside_glslc_testsuite('OptionFPreserveBindings')40class TestFPreserveBindingsInputB(expect.ValidAssemblyFileWithSubstr):41"""Tests that the compiler preserves bindings when optimizations are42enabled."""4344shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')45glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']46# Check the first buffer.47expected_assembly_substr = "Binding 1"484950@inside_glslc_testsuite('OptionFPreserveBindings')51class TestFPreserveBindingsOutputO(expect.ValidAssemblyFileWithSubstr):52"""Tests that the compiler preserves bindings when optimizations are53enabled."""5455shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')56glslc_args = ['-S', '-O', shader, '-fpreserve-bindings']57# Check the first buffer.58expected_assembly_substr = "Binding 2"596061@inside_glslc_testsuite('OptionFPreserveBindings')62class TestFNoPreserveBindings(expect.ValidAssemblyFileWithoutSubstr):63"""Tests that the compiler removes bindings when -fpreserve-bindings is not64set."""6566shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp')67glslc_args = ['-S', '-O', shader]68# Check that all binding decorations are gone.69unexpected_assembly_substr = "OpDecorate"707172