• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2# Copyright 2019 The Amber Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16SHADER vertex vert_shader_mipclear PASSTHROUGH
17
18SHADER vertex vert_shader_lod GLSL
19#version 430
20
21layout(location = 0) in vec3 position_in;
22layout(location = 0) out vec4 color_out;
23layout(set = 0, binding = 0) uniform highp sampler2D tex;
24
25void main() {
26  gl_Position = vec4(position_in, 1.0);
27  // Pick a color from the center of a mipmap. Each corner point gets its own mip level.
28  color_out = vec4(textureLod(tex, vec2(0.5), float(gl_VertexIndex % 4)));
29}
30END
31
32SHADER fragment frag_shader GLSL
33#version 430
34
35layout(location = 0) in vec4 color_in;
36layout(location = 0) out vec4 color_out;
37
38void main() {
39  color_out = color_in;
40}
41END
42
43BUFFER texture FORMAT B8G8R8A8_UNORM MIP_LEVELS 4
44BUFFER framebuffer FORMAT B8G8R8A8_UNORM
45SAMPLER sampler MAX_LOD 4.0
46
47PIPELINE graphics mipclear_pipeline0
48  ATTACH vert_shader_mipclear
49  ATTACH frag_shader
50  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 0
51  FRAMEBUFFER_SIZE 512 512
52END
53
54PIPELINE graphics mipclear_pipeline1
55  ATTACH vert_shader_mipclear
56  ATTACH frag_shader
57  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 1
58  FRAMEBUFFER_SIZE 256 256
59END
60
61PIPELINE graphics mipclear_pipeline2
62  ATTACH vert_shader_mipclear
63  ATTACH frag_shader
64  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 2
65  FRAMEBUFFER_SIZE 128 128
66END
67
68PIPELINE graphics mipclear_pipeline3
69  ATTACH vert_shader_mipclear
70  ATTACH frag_shader
71  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 3
72  FRAMEBUFFER_SIZE 64 64
73END
74
75PIPELINE graphics lod_pipeline
76  ATTACH vert_shader_lod
77  ATTACH frag_shader
78  BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
79  BIND BUFFER framebuffer AS color LOCATION 0
80  FRAMEBUFFER_SIZE 512 512
81END
82
83# Clear all mip levels to different color.
84CLEAR_COLOR mipclear_pipeline0 255 0 0 255
85CLEAR mipclear_pipeline0
86CLEAR_COLOR mipclear_pipeline1 0 255 0 255
87CLEAR mipclear_pipeline1
88CLEAR_COLOR mipclear_pipeline2 0 0 255 255
89CLEAR mipclear_pipeline2
90CLEAR_COLOR mipclear_pipeline3 255 255 0 255
91CLEAR mipclear_pipeline3
92
93CLEAR_COLOR lod_pipeline 0 0 0 255
94CLEAR lod_pipeline
95RUN lod_pipeline DRAW_RECT POS 0 0 SIZE 512 512
96
97# Check corners of the frame buffer: each should have a color from a different mip level.
98EXPECT framebuffer IDX 0   511 SIZE 1 1 EQ_RGBA 255 0   0   255
99EXPECT framebuffer IDX 511 0   SIZE 1 1 EQ_RGBA 255 255 0   255
100EXPECT framebuffer IDX 511 511 SIZE 1 1 EQ_RGBA 0   0   255 255
101EXPECT framebuffer IDX 0   0   SIZE 1 1 EQ_RGBA 0   255 0   255
102