aboutsummaryrefslogtreecommitdiff
path: root/tests/cases/texture_lod.amber
blob: ee6a787ee6e51114b8ea1a341fcbeeada568b128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!amber
# Copyright 2019 The Amber Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SHADER vertex vert_shader_mipclear PASSTHROUGH

SHADER vertex vert_shader_lod GLSL
#version 430

layout(location = 0) in vec3 position_in;
layout(location = 0) out vec4 color_out;
layout(set = 0, binding = 0) uniform highp sampler2D tex;

void main() {
  gl_Position = vec4(position_in, 1.0);
  // Pick a color from the center of a mipmap. Each corner point gets its own mip level.
  color_out = vec4(textureLod(tex, vec2(0.5), float(gl_VertexIndex % 4)));
}
END

SHADER fragment frag_shader GLSL
#version 430

layout(location = 0) in vec4 color_in;
layout(location = 0) out vec4 color_out;

void main() {
  color_out = color_in;
}
END

BUFFER texture FORMAT B8G8R8A8_UNORM MIP_LEVELS 4
BUFFER framebuffer FORMAT B8G8R8A8_UNORM
SAMPLER sampler MAX_LOD 4.0

PIPELINE graphics mipclear_pipeline0
  ATTACH vert_shader_mipclear
  ATTACH frag_shader
  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 0
  FRAMEBUFFER_SIZE 512 512
END

PIPELINE graphics mipclear_pipeline1
  ATTACH vert_shader_mipclear
  ATTACH frag_shader
  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 1
  FRAMEBUFFER_SIZE 256 256
END

PIPELINE graphics mipclear_pipeline2
  ATTACH vert_shader_mipclear
  ATTACH frag_shader
  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 2
  FRAMEBUFFER_SIZE 128 128
END

PIPELINE graphics mipclear_pipeline3
  ATTACH vert_shader_mipclear
  ATTACH frag_shader
  BIND BUFFER texture AS color LOCATION 0 BASE_MIP_LEVEL 3
  FRAMEBUFFER_SIZE 64 64
END

PIPELINE graphics lod_pipeline
  ATTACH vert_shader_lod
  ATTACH frag_shader
  BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
  BIND BUFFER framebuffer AS color LOCATION 0
  FRAMEBUFFER_SIZE 512 512
END

# Clear all mip levels to different color.
CLEAR_COLOR mipclear_pipeline0 255 0 0 255
CLEAR mipclear_pipeline0
CLEAR_COLOR mipclear_pipeline1 0 255 0 255
CLEAR mipclear_pipeline1
CLEAR_COLOR mipclear_pipeline2 0 0 255 255
CLEAR mipclear_pipeline2
CLEAR_COLOR mipclear_pipeline3 255 255 0 255
CLEAR mipclear_pipeline3

CLEAR_COLOR lod_pipeline 0 0 0 255
CLEAR lod_pipeline
RUN lod_pipeline DRAW_RECT POS 0 0 SIZE 512 512

# Check corners of the frame buffer: each should have a color from a different mip level.
EXPECT framebuffer IDX 0   511 SIZE 1 1 EQ_RGBA 255 0   0   255
EXPECT framebuffer IDX 511 0   SIZE 1 1 EQ_RGBA 255 255 0   255
EXPECT framebuffer IDX 511 511 SIZE 1 1 EQ_RGBA 0   0   255 255
EXPECT framebuffer IDX 0   0   SIZE 1 1 EQ_RGBA 0   255 0   255