|
| 1 | +# Copyright 2018 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 a separate sampler and texture2D object |
| 20 | +GLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """#version 460 |
| 21 | + in vec2 in_UV; |
| 22 | + out vec4 out_Color; |
| 23 | + layout (set=0,binding=0) uniform sampler u_Sampler; |
| 24 | + layout (set=0,binding=0) uniform texture2D u_Tex; |
| 25 | + void main() { |
| 26 | + out_Color = texture(sampler2D(u_Tex, u_Sampler), in_UV); |
| 27 | + }""" |
| 28 | + |
| 29 | + |
| 30 | +# An HLSL fragment shader with the usual Texture2D and SamplerState pair |
| 31 | +HLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """ |
| 32 | + Texture2D u_Tex; |
| 33 | + SamplerState u_Sampler; |
| 34 | + float4 Frag(float2 uv) : COLOR0 { |
| 35 | + return u_Tex.Sample(u_Sampler, uv); |
| 36 | + }""" |
| 37 | + |
| 38 | + |
| 39 | +@inside_glslc_testsuite('OptionFAutoSampledTextures') |
| 40 | +class FAutoSampledTexturesCheckGLSL(expect.ValidAssemblyFileWithSubstr): |
| 41 | + """Tests that the compiler combines GLSL sampler and texture2D objects.""" |
| 42 | + |
| 43 | + exit(17) |
| 44 | + |
| 45 | + shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag') |
| 46 | + glslc_args = ['-S', '-fauto-sampled-textures', shader] |
| 47 | + expected_assembly_substr = "%11 = OpTypeSampledImage %10\n%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11\n %u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant" |
| 48 | + |
| 49 | +@inside_glslc_testsuite('OptionFAutoSampledTextures') |
| 50 | +class FAutoSampledTexturesCheckHLSL(expect.ValidAssemblyFileWithSubstr): |
| 51 | + """Tests that the HLSL compiler combines HLSL Texture2D and SamplerState objects into SPIRV SampledImage.""" |
| 52 | + |
| 53 | + shader = FileShader(HLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.hlsl') |
| 54 | + glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Frag', '-fauto-sampled-textures', shader] |
| 55 | + expected_assembly_substr = "%15 = OpTypeSampledImage %14\n%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15\n %u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant" |
| 56 | + |
0 commit comments