1#!amber 2# 3# Copyright 2021 The Amber Authors. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# https://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17SHADER vertex vert_shader GLSL 18#version 430 19 20layout(location = 0) in vec4 position; 21layout(location = 0) out vec4 frag_color; 22 23layout(set = 0, binding = 0) readonly buffer block1 { 24 vec4 in_color; 25 float depth; 26}; 27 28void main() { 29 gl_Position = vec4(position.xy, depth, 1.0); 30 frag_color = in_color; 31} 32END 33 34SHADER fragment frag_shader GLSL 35#version 430 36 37layout(location = 0) in vec4 frag_color; 38layout(location = 0) out vec4 final_color; 39 40void main() { 41 final_color = frag_color; 42} 43END 44 45SHADER vertex vert_shader_tex GLSL 46#version 430 47layout(location = 0) in vec4 position; 48layout(location = 1) in vec2 texcoords_in; 49layout(location = 0) out vec2 texcoords_out; 50void main() { 51 gl_Position = position; 52 texcoords_out = texcoords_in; 53} 54END 55 56SHADER fragment frag_shader_tex GLSL 57#version 430 58layout(location = 0) in vec2 texcoords_in; 59layout(location = 0) out vec4 color_out; 60uniform layout(set=0, binding=0) sampler2D tex_sampler; 61void main() { 62 float f = texture(tex_sampler, texcoords_in).r; 63 color_out = vec4(f, f, f, 1); 64} 65END 66 67BUFFER data_buf1 DATA_TYPE float DATA 1.0 0.0 0.0 1.0 0.3 END 68BUFFER data_buf2 DATA_TYPE float DATA 0.0 1.0 0.0 1.0 0.5 END 69 70BUFFER position DATA_TYPE vec2<float> DATA 71-1.0 -1.0 72 1.0 -1.0 73 1.0 1.0 74-1.0 1.0 75END 76BUFFER texcoords DATA_TYPE vec2<float> DATA 770.0 0.0 781.0 0.0 791.0 1.0 800.0 1.0 81END 82 83BUFFER framebuffer FORMAT B8G8R8A8_UNORM 84BUFFER ddump FORMAT B8G8R8A8_UNORM 85BUFFER depthstencil FORMAT X8_D24_UNORM_PACK32 86 87SAMPLER sampler 88 89PIPELINE graphics pipeline1 90 ATTACH vert_shader 91 ATTACH frag_shader 92 93 FRAMEBUFFER_SIZE 256 256 94 BIND BUFFER framebuffer AS color LOCATION 0 95 BIND BUFFER depthstencil AS depth_stencil 96 BIND BUFFER data_buf1 AS storage DESCRIPTOR_SET 0 BINDING 0 97 98 DEPTH 99 TEST on 100 WRITE on 101 COMPARE_OP less 102 CLAMP off 103 BOUNDS min 0.0 max 1.0 104 BIAS constant 0.0 clamp 0.0 slope 0.0 105 END 106END 107 108DERIVE_PIPELINE pipeline2 FROM pipeline1 109 BIND BUFFER data_buf2 AS storage DESCRIPTOR_SET 0 BINDING 0 110END 111 112PIPELINE graphics depthdump 113 ATTACH vert_shader_tex 114 ATTACH frag_shader_tex 115 BIND BUFFER depthstencil AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0 116 VERTEX_DATA position LOCATION 0 117 VERTEX_DATA texcoords LOCATION 1 118 FRAMEBUFFER_SIZE 256 256 119 BIND BUFFER ddump AS color LOCATION 0 120END 121 122CLEAR_DEPTH pipeline1 1.0 123CLEAR_COLOR pipeline1 255 255 255 255 124CLEAR pipeline1 125RUN pipeline1 DRAW_RECT POS 0 0 SIZE 200 200 126RUN pipeline2 DRAW_RECT POS 56 56 SIZE 200 200 127RUN depthdump DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 128 129EXPECT framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255 130EXPECT framebuffer IDX 128 128 SIZE 1 1 EQ_RGBA 255 0 0 255 131EXPECT framebuffer IDX 255 255 SIZE 1 1 EQ_RGBA 0 255 0 255 132EXPECT ddump IDX 0 0 SIZE 1 1 EQ_RGBA 76 76 76 255 TOLERANCE 5% 5% 5% 0 133EXPECT ddump IDX 255 0 SIZE 1 1 EQ_RGBA 255 255 255 255 TOLERANCE 5% 5% 5% 0 134EXPECT ddump IDX 0 255 SIZE 1 1 EQ_RGBA 255 255 255 255 TOLERANCE 5% 5% 5% 0 135EXPECT ddump IDX 255 255 SIZE 1 1 EQ_RGBA 128 128 128 255 TOLERANCE 5% 5% 5% 0 136