1#!amber 2 3# Copyright 2020 Valve Corporation. 4# Copyright 2020 The Khronos Group Inc. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18SHADER vertex vtx_passthrough PASSTHROUGH 19 20SHADER fragment frag_green GLSL 21#version 450 22layout(location=0) out vec4 out_color; 23void main() { 24 out_color = vec4(0.0, 1.0, 0.0, 1.0); 25} 26END 27 28SHADER vertex vtx_shader GLSL 29#version 450 30 31layout(location = 0) in vec4 position; 32layout(location = 0) out vec2 textureCoordinates; 33 34void main() { 35 gl_Position = position; 36 textureCoordinates = vec2(0.0, 0.0); 37} 38END 39 40SHADER fragment frag_shader SPIRV-ASM 41 OpCapability Shader 42 OpMemoryModel Logical GLSL450 43 OpEntryPoint Fragment %main "main" %fragColor %vtxTexCoords 44 OpExecutionMode %main OriginUpperLeft 45 OpDecorate %fragColor Location 0 ; Output 46 OpDecorate %vtxTexCoords Location 0 ; Input 47 OpDecorate %sampler_ptr DescriptorSet 0 48 OpDecorate %sampler_ptr Binding 0 49 50 ; Basic types. 51 %void = OpTypeVoid 52 %void_func_t = OpTypeFunction %void 53 %float = OpTypeFloat 32 54 %v2float = OpTypeVector %float 2 55 %v4float = OpTypeVector %float 4 56 %image_2d = OpTypeImage %float 2D 0 0 0 1 Unknown 57 %sampled_img = OpTypeSampledImage %image_2d 58 %sampling_func_t = OpTypeFunction %v4float %sampled_img %v2float 59 60 ; Pointer types. 61%sampled_img_uniform_ptr = OpTypePointer UniformConstant %sampled_img 62 %v4float_out_ptr = OpTypePointer Output %v4float 63 %v2float_input_ptr = OpTypePointer Input %v2float 64 65 ; In/Out variables. 66 %fragColor = OpVariable %v4float_out_ptr Output 67 %sampler_ptr = OpVariable %sampled_img_uniform_ptr UniformConstant 68 %vtxTexCoords = OpVariable %v2float_input_ptr Input 69 70 ; Main function. 71 %main = OpFunction %void None %void_func_t 72 %main_label = OpLabel 73 %tex_coords = OpLoad %v2float %vtxTexCoords 74 %sampler_arg = OpLoad %sampled_img %sampler_ptr 75 %frag_color_val = OpFunctionCall %v4float %sampling_func %sampler_arg %tex_coords 76 OpStore %fragColor %frag_color_val 77 OpReturn 78 OpFunctionEnd 79 80 ; Auxiliar texture sampling function, receiving a sampled image as its argument. 81 %sampling_func = OpFunction %v4float None %sampling_func_t 82 %sampler = OpFunctionParameter %sampled_img 83 %coords = OpFunctionParameter %v2float 84 %sampling_func_label = OpLabel 85 %retval = OpImageSampleImplicitLod %v4float %sampler %coords 86 OpReturnValue %retval 87 OpFunctionEnd 88END 89 90# Full-screen quad. 91BUFFER position_buf DATA_TYPE vec4<float> DATA 92-1 -1 0 1 93 1 -1 0 1 94-1 1 0 1 95-1 1 0 1 96 1 -1 0 1 97 1 1 0 1 98END 99 100BUFFER framebuffer FORMAT B8G8R8A8_UNORM 101BUFFER texture FORMAT R8G8B8A8_UNORM 102SAMPLER sampler 103 104PIPELINE graphics texgen_pipeline 105 ATTACH vtx_passthrough 106 ATTACH frag_green 107 108 FRAMEBUFFER_SIZE 1 1 109 BIND BUFFER texture AS color LOCATION 0 110END 111 112PIPELINE graphics main_pipeline 113 ATTACH vtx_shader 114 ATTACH frag_shader 115 116 VERTEX_DATA position_buf LOCATION 0 117 BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0 118 119 FRAMEBUFFER_SIZE 64 64 120 BIND BUFFER framebuffer AS color LOCATION 0 121END 122 123CLEAR texgen_pipeline 124RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 1 1 125EXPECT texture IDX 0 0 SIZE 1 1 EQ_RGBA 0 255 0 255 126 127CLEAR_COLOR main_pipeline 0 0 0 255 128CLEAR main_pipeline 129RUN main_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 6 130EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 131