blob: 7fceb55c6491eadd57a5e3192b82808ef4de9d84 [file] [log] [blame]
#!amber
# Copyright 2021 Google LLC.
# Copyright 2021 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
#
# http://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.
#
# Red rect. fragDepth: 0.17
# Green rect. fragDepth: 0.18
# Depth color format: D16_UNORM
# Depth bias: -0.01068115234375 (-700.0 / 2^16)
# Draw method: Patch List
# Polygon Mode: Fill
# TES primitive ordering: trianges, cw
# Result: Green rectangle should be on top.
DEVICE_FEATURE tessellationShader
SHADER vertex vert GLSL
#version 450
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main(void)
{
gl_Position = vec4(inPosition, 1.0);
outColor = inColor;
}
END
SHADER tessellation_control tesc GLSL
#version 450
layout (location = 0) in vec4 inColor[];
layout (location = 0) patch out vec4 tcColor;
layout (vertices = 3) out;
void main(void)
{
float tessLevel = 2.0;
gl_TessLevelInner[0] = tessLevel;
gl_TessLevelInner[1] = tessLevel;
gl_TessLevelOuter[0] = 1.0;
gl_TessLevelOuter[1] = 1.0;
gl_TessLevelOuter[2] = 1.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
tcColor = inColor[gl_InvocationID];
}
END
SHADER tessellation_evaluation tese GLSL
#version 450
layout (triangles, equal_spacing, cw) in;
layout (location = 0) patch in vec4 patch_color;
layout (location = 0) out vec4 tes_color;
void main(void)
{
gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) +
(gl_TessCoord.y * gl_in[1].gl_Position) +
(gl_TessCoord.z * gl_in[2].gl_Position);
tes_color = patch_color;
}
END
SHADER fragment frag GLSL
#version 450
layout (location = 0) in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main(void)
{
outColor = inColor;
}
END
BUFFER vertexPositionA DATA_TYPE vec3<float> DATA
-0.50 -0.50 0.17
0.50 -0.50 0.17
0.50 0.50 0.17
0.50 0.50 0.17
-0.50 0.50 0.17
-0.50 -0.50 0.17
END
BUFFER vertexPositionB DATA_TYPE vec3<float> DATA
-0.50 -0.50 0.18
0.50 -0.50 0.18
0.50 0.50 0.18
0.50 0.50 0.18
-0.50 0.50 0.18
-0.50 -0.50 0.18
END
BUFFER vertexColorA DATA_TYPE vec4<float> DATA
1.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
END
BUFFER vertexColorB DATA_TYPE vec4<float> DATA
0.0 1.0 0.0 1.0
0.0 1.0 0.0 1.0
0.0 1.0 0.0 1.0
0.0 1.0 0.0 1.0
0.0 1.0 0.0 1.0
0.0 1.0 0.0 1.0
END
BUFFER framebuffer FORMAT R8G8B8A8_UNORM
IMAGE verifyImage FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 100 HEIGHT 100 FILL 0
BUFFER depth_buf FORMAT D16_UNORM
PIPELINE graphics pipeline1
ATTACH vert
ATTACH tesc
ATTACH tese
ATTACH frag
POLYGON_MODE fill
PATCH_CONTROL_POINTS 3
DEPTH
TEST on
WRITE on
COMPARE_OP less
CLAMP off
BOUNDS min 0.0 max 1.0
BIAS constant 0.0 clamp 0.0 slope 0.0
END
FRAMEBUFFER_SIZE 100 100
VERTEX_DATA vertexPositionA LOCATION 0
VERTEX_DATA vertexColorA LOCATION 1
BIND BUFFER framebuffer AS color LOCATION 0
BIND BUFFER depth_buf AS depth_stencil
END
PIPELINE graphics pipeline2
ATTACH vert
ATTACH tesc
ATTACH tese
ATTACH frag
POLYGON_MODE fill
PATCH_CONTROL_POINTS 3
DEPTH
TEST on
WRITE on
COMPARE_OP less
CLAMP off
BOUNDS min 0.0 max 1.0
BIAS constant -700.0 clamp 0.0 slope 0.0
END
FRAMEBUFFER_SIZE 100 100
VERTEX_DATA vertexPositionB LOCATION 0
VERTEX_DATA vertexColorB LOCATION 1
BIND BUFFER framebuffer AS color LOCATION 0
BIND BUFFER depth_buf AS depth_stencil
END
CLEAR_COLOR pipeline1 0 0 0 255
CLEAR_DEPTH pipeline1 0.3
CLEAR pipeline1
CLEAR_COLOR pipeline2 0 0 0 255
RUN pipeline1 DRAW_ARRAY AS PATCH_LIST START_IDX 0 COUNT 6
RUN pipeline2 DRAW_ARRAY AS PATCH_LIST START_IDX 0 COUNT 6
# ---------------- VERIFY PIPELINE ------------------
# This pipeline verifies the frame buffer contents.
# The compute shader writes color green if the value is expected,
# otherwise red.
SHADER compute comp_shader GLSL
#version 450
layout(local_size_x=10,local_size_y=10) in;
uniform layout(set=0, binding=0, rgba8) image2D resultImage;
uniform layout(set=0, binding=1, rgba8) image2D verifyImage;
void main()
{
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec4 color = imageLoad(resultImage, uv);
if(color.r == 0.0 && color.a == 1.0) imageStore(verifyImage, uv, vec4(0.0, 1.0, 0.0, 1.0));
else imageStore(verifyImage, uv, vec4(1.0, 0.0, 0.0, 1.0));
}
END
PIPELINE compute verify_pipeline
ATTACH comp_shader
FRAMEBUFFER_SIZE 100 100
BIND BUFFER framebuffer AS storage_image DESCRIPTOR_SET 0 BINDING 0
BIND BUFFER verifyImage AS storage_image DESCRIPTOR_SET 0 BINDING 1
END
RUN verify_pipeline 10 10 1
EXPECT verifyImage IDX 0 0 SIZE 100 100 EQ_RGBA 0 255 0 255