Path: blob/main/glslc/test/option_fauto_map_locations.py
1560 views
# Copyright 2018 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 inputs and outputs explicit locations.19GLSL_SHADER_IO_WITHOUT_LOCATIONS = """#version 310 es20in vec4 m_in;21in vec4 m_in1;22out vec4 m_out;23out vec4 m_out1;24void main() {25m_out = m_in;26m_out1 = m_in1;27}"""282930# An HLSL fragment shader with inputs and outputs explicit locations.31HLSL_SHADER_IO_WITHOUT_LOCATIONS = """32float4 Foo(float4 a, float4 b) : COLOR0 {33return a + b;34}"""353637@inside_glslc_testsuite('OptionFAutoMapLocations')38class MissingLocationsResultsInError(expect.ErrorMessageSubstr):39"""Tests that compilation fails when inputs or outputs have no location."""4041shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')42glslc_args = ['-S', shader]43expected_error_substr = "SPIR-V requires location for user input/output"444546@inside_glslc_testsuite('OptionFAutoMapLocations')47class FAutoMapLocationsGeneratesLocationsCheckInput(expect.ValidAssemblyFileWithSubstr):48"""Tests that the compiler generates locations upon request: Input 0"""4950shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')51glslc_args = ['-S', shader, '-fauto-map-locations']52expected_assembly_substr = "OpDecorate %m_in Location 0"535455@inside_glslc_testsuite('OptionFAutoMapLocations')56class FAutoMapLocationsGeneratesLocationsCheckOutput0(expect.ValidAssemblyFileWithSubstr):57"""Tests that the compiler generates locations upon request: Output 0"""5859shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')60glslc_args = ['-S', shader, '-fauto-map-locations']61expected_assembly_substr = "OpDecorate %m_out Location 0"626364# Currently Glslang only generates Location 0.65# See https://github.com/KhronosGroup/glslang/issues/126166# TODO(dneto): Write tests that check Location 1 is generated for inputs and67# outputs.686970# Glslang's HLSL compiler automatically assigns locations inptus and outputs.71@inside_glslc_testsuite('OptionFAutoMapLocations')72class HLSLCompilerGeneratesLocationsCheckInput0(expect.ValidAssemblyFileWithSubstr):73"""Tests that the HLSL compiler generates locations automatically: Input 0."""7475shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl')76glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader]77expected_assembly_substr = "OpDecorate %a Location 0"787980@inside_glslc_testsuite('OptionFAutoMapLocations')81class HLSLCompilerGeneratesLocationsCheckOutput(expect.ValidAssemblyFileWithSubstr):82"""Tests that the HLSL compiler generates locations automatically: Output."""8384shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl')85glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader]86expected_assembly_substr = "OpDecorate %_entryPointOutput Location 0"878889