Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_fauto_combined_image_sampler.py
1560 views
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
layout (location=0) in vec2 in_UV;
22
layout (location=0) 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('OptionFAutoCombinedImageSampler')
40
class FAutoCombinedImageSamplerCheckGLSL(expect.ValidAssemblyFileWithSubstr):
41
"""Tests that the compiler combines GLSL sampler and texture2D objects."""
42
shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag')
43
glslc_args = ['-S', '-fauto-combined-image-sampler', shader]
44
expected_assembly_substr = """%10 = OpTypeImage %float 2D 0 0 0 1 Unknown
45
%11 = OpTypeSampledImage %10
46
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
47
%u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant"""
48
49
@inside_glslc_testsuite('OptionFAutoCombinedImageSampler')
50
class FAutoCombinedImageSamplerCheckHLSL(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-combined-image-sampler', shader]
55
expected_assembly_substr = """%14 = OpTypeImage %float 2D 0 0 0 1 Unknown
56
%15 = OpTypeSampledImage %14
57
%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
58
%u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant"""
59
60
61