| #!amber |
| |
| # Copyright 2019 Google LLC. |
| # Copyright 2019 The Khronos Group Inc. |
| # |
| # 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); |
| // Vary dPdx and dPdy based on vertex index to force |
| // LOD 0 or LOD 1. |
| vec2 v = vec2(0); |
| if (gl_VertexIndex % 2 != 0) |
| v = vec2(1); |
| |
| color_out = vec4(textureGrad(tex, vec2(0.5), v, v)); |
| } |
| 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 2 |
| BUFFER framebuffer FORMAT B8G8R8A8_UNORM |
| SAMPLER sampler MAX_LOD 2.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 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 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: even vertices should have LOD 0 and odd ones LOD 1. |
| EXPECT framebuffer IDX 0 511 SIZE 1 1 EQ_RGBA 255 0 0 255 |
| EXPECT framebuffer IDX 511 0 SIZE 1 1 EQ_RGBA 0 255 0 255 |
| EXPECT framebuffer IDX 511 511 SIZE 1 1 EQ_RGBA 255 0 0 255 |
| EXPECT framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 0 255 0 255 |