1#!amber
2# Copyright 2022 Google LLC
3# Copyright 2022 LunarG, Inc.
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#     http://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
17DEVICE_FEATURE tessellationShader
18
19SHADER vertex vert_shader PASSTHROUGH
20
21SHADER tessellation_control tesc_shader GLSL
22#version 450
23
24layout (vertices = 3) out;
25in gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_in[gl_MaxPatchVertices];
26
27void main(void)
28{
29  gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
30
31  if(gl_InvocationID == 0)
32  {
33    gl_TessLevelInner[0] = 1.0;
34    gl_TessLevelInner[1] = 1.0;
35    gl_TessLevelOuter[0] = 1.0;
36    gl_TessLevelOuter[1] = 1.0;
37    gl_TessLevelOuter[2] = 1.0;
38  }
39}
40END
41
42SHADER tessellation_evaluation tese_shader GLSL
43#version 450
44
45layout (triangles, equal_spacing, cw) in;
46
47layout(set = 0, binding = 0) buffer block0
48{
49    int data[20];
50} ssbo;
51
52void main(void)
53{
54  gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) +
55                (gl_TessCoord.y * gl_in[1].gl_Position) +
56                (gl_TessCoord.z * gl_in[2].gl_Position);
57
58  // Only want to perform these operations once
59  if(gl_Position.x == 0.5f && gl_Position.y == -0.5f)
60  {
61    // Zero constants
62    int ival = ssbo.data[0];
63    float val = float(ival);
64
65    // int div
66    ssbo.data[1] = 7 / ival;
67    // float div
68    ssbo.data[2] = int(7.0 / val);
69    // normalize float
70    ssbo.data[3] = int(normalize(val));
71    // normalize vec2
72    ssbo.data[4] = int(normalize(vec2(val))[ival]);
73    // normalize vec3
74    ssbo.data[5] = int(normalize(vec3(val))[ival]);
75    // normalize vec4
76    ssbo.data[6] = int(normalize(vec4(val))[ival]);
77    // integer mod
78    ssbo.data[7] = 7 % ival;
79    // float mod
80    ssbo.data[8] = int(mod(7.0, val));
81    // vec2 mod
82    ssbo.data[9] = int(mod(vec2(7.0), vec2(val))[ival]);
83    // vec3 mod
84    ssbo.data[10] = int(mod(vec3(7.0), vec3(val))[ival]);
85    // vec4 mod
86    ssbo.data[11] = int(mod(vec4(7.0), vec4(val))[ival]);
87    // float smoothstep
88    ssbo.data[12] = int(smoothstep(val, val, 0.3));
89    // vec2 smoothstep
90    ssbo.data[13] = int(smoothstep(vec2(val), vec2(val), vec2(0.3))[ival]);
91    // vec3 smoothstep
92    ssbo.data[14] = int(smoothstep(vec3(val), vec3(val), vec3(0.3))[ival]);
93    // vec4 smoothstep
94    ssbo.data[15] = int(smoothstep(vec4(val), vec4(val), vec4(0.3))[ival]);
95    // float atan2
96    ssbo.data[16] = int(atan(7.0, val));
97    // vec2 atan2
98    ssbo.data[17] = int(atan(vec2(7.0), vec2(val))[ival]);
99    // vec3 atan2
100    ssbo.data[18] = int(atan(vec3(7.0), vec3(val))[ival]);
101    // vec4 atan2
102    ssbo.data[19] = int(atan(vec4(7.0), vec4(val))[ival]);
103
104    // Known good value
105    ssbo.data[0] = 42;
106  }
107}
108END
109
110SHADER fragment frag_shader GLSL
111#version 450
112
113layout (location = 0) out vec4 outColor;
114
115void main(void)
116{
117  outColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
118}
119END
120
121BUFFER vertexPosition DATA_TYPE vec3<float> DATA
122-0.50 -0.50  0.0
123 0.50 -0.50  0.0
124 0.50  0.50  0.0
125 0.50  0.50  0.0
126-0.50  0.50  0.0
127-0.50 -0.50  0.0
128END
129
130BUFFER ssbo_buffer DATA_TYPE int32 DATA
1310 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
132END
133
134BUFFER framebuffer FORMAT R8G8B8A8_UNORM
135
136PIPELINE graphics my_pipeline
137  ATTACH vert_shader
138  ATTACH tesc_shader
139  ATTACH tese_shader
140  ATTACH frag_shader
141
142  VERTEX_DATA vertexPosition LOCATION 0
143  BIND BUFFER framebuffer AS color LOCATION 0
144  BIND BUFFER ssbo_buffer AS storage DESCRIPTOR_SET 0 BINDING 0
145END
146
147RUN my_pipeline DRAW_ARRAY AS PATCH_LIST START_IDX 0 COUNT 6
148
149EXPECT ssbo_buffer IDX 0 EQ 42