Path: blob/main/glslc/test/option_fauto_combined_image_sampler.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 a separate sampler and texture2D object19GLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """#version 46020layout (location=0) in vec2 in_UV;21layout (location=0) out vec4 out_Color;22layout (set=0,binding=0) uniform sampler u_Sampler;23layout (set=0,binding=0) uniform texture2D u_Tex;24void main() {25out_Color = texture(sampler2D(u_Tex, u_Sampler), in_UV);26}"""272829# An HLSL fragment shader with the usual Texture2D and SamplerState pair30HLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """31Texture2D u_Tex;32SamplerState u_Sampler;33float4 Frag(float2 uv) : COLOR0 {34return u_Tex.Sample(u_Sampler, uv);35}"""363738@inside_glslc_testsuite('OptionFAutoCombinedImageSampler')39class FAutoCombinedImageSamplerCheckGLSL(expect.ValidAssemblyFileWithSubstr):40"""Tests that the compiler combines GLSL sampler and texture2D objects."""41shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag')42glslc_args = ['-S', '-fauto-combined-image-sampler', shader]43expected_assembly_substr = """%10 = OpTypeImage %float 2D 0 0 0 1 Unknown44%11 = OpTypeSampledImage %1045%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %1146%u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant"""4748@inside_glslc_testsuite('OptionFAutoCombinedImageSampler')49class FAutoCombinedImageSamplerCheckHLSL(expect.ValidAssemblyFileWithSubstr):50"""Tests that the HLSL compiler combines HLSL Texture2D and SamplerState objects into SPIRV SampledImage."""5152shader = FileShader(HLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.hlsl')53glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Frag', '-fauto-combined-image-sampler', shader]54expected_assembly_substr = """%14 = OpTypeImage %float 2D 0 0 0 1 Unknown55%15 = OpTypeSampledImage %1456%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %1557%u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant"""58596061