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