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 17SHADER vertex vert_shader GLSL 18#version 450 19layout(location = 0) in vec2 vertex_position; 20 21layout(set = 0, binding = 0) buffer block0 22{ 23 int data[20]; 24} ssbo; 25 26void main() 27{ 28 gl_Position = vec4(vertex_position, 0.0f, 1.0f); 29 30 // Only want to perform these operations once 31 if(gl_VertexIndex == 0) 32 { 33 // Zero constants 34 int ival = ssbo.data[0]; 35 float val = float(ival); 36 37 // int div 38 ssbo.data[1] = 7 / ival; 39 // float div 40 ssbo.data[2] = int(7.0 / val); 41 // normalize float 42 ssbo.data[3] = int(normalize(val)); 43 // normalize vec2 44 ssbo.data[4] = int(normalize(vec2(val))[ival]); 45 // normalize vec3 46 ssbo.data[5] = int(normalize(vec3(val))[ival]); 47 // normalize vec4 48 ssbo.data[6] = int(normalize(vec4(val))[ival]); 49 // integer mod 50 ssbo.data[7] = 7 % ival; 51 // float mod 52 ssbo.data[8] = int(mod(7.0, val)); 53 // vec2 mod 54 ssbo.data[9] = int(mod(vec2(7.0), vec2(val))[ival]); 55 // vec3 mod 56 ssbo.data[10] = int(mod(vec3(7.0), vec3(val))[ival]); 57 // vec4 mod 58 ssbo.data[11] = int(mod(vec4(7.0), vec4(val))[ival]); 59 // float smoothstep 60 ssbo.data[12] = int(smoothstep(val, val, 0.3)); 61 // vec2 smoothstep 62 ssbo.data[13] = int(smoothstep(vec2(val), vec2(val), vec2(0.3))[ival]); 63 // vec3 smoothstep 64 ssbo.data[14] = int(smoothstep(vec3(val), vec3(val), vec3(0.3))[ival]); 65 // vec4 smoothstep 66 ssbo.data[15] = int(smoothstep(vec4(val), vec4(val), vec4(0.3))[ival]); 67 // float atan2 68 ssbo.data[16] = int(atan(7.0, val)); 69 // vec2 atan2 70 ssbo.data[17] = int(atan(vec2(7.0), vec2(val))[ival]); 71 // vec3 atan2 72 ssbo.data[18] = int(atan(vec3(7.0), vec3(val))[ival]); 73 // vec4 atan2 74 ssbo.data[19] = int(atan(vec4(7.0), vec4(val))[ival]); 75 76 // Known good value 77 ssbo.data[0] = 42; 78 } 79} 80END 81 82 83SHADER fragment frag_shader GLSL 84#version 450 85layout(location = 0) out vec4 color_out; 86void main() { 87 color_out = vec4(1.0, 0.0, 0.0, 1.0); 88} 89END 90 91BUFFER ssbo_buffer DATA_TYPE int32 DATA 920 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 93END 94 95BUFFER framebuffer FORMAT B8G8R8A8_UNORM 96 97PIPELINE graphics my_pipeline 98 ATTACH vert_shader 99 ATTACH frag_shader 100 BIND BUFFER framebuffer AS color LOCATION 0 101 BIND BUFFER ssbo_buffer AS storage DESCRIPTOR_SET 0 BINDING 0 102END 103 104RUN my_pipeline DRAW_RECT POS 0 0 SIZE 32 32 105 106EXPECT ssbo_buffer IDX 0 EQ 42 107