| #!amber |
| |
| # Copyright 2020 Valve Corporation. |
| # Copyright 2020 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. |
| |
| SHADER vertex vtx_passthrough PASSTHROUGH |
| |
| SHADER fragment frag_green GLSL |
| #version 450 |
| layout(location=0) out vec4 out_color; |
| void main() { |
| out_color = vec4(0.0, 1.0, 0.0, 1.0); |
| } |
| END |
| |
| SHADER vertex vtx_shader GLSL |
| #version 450 |
| |
| layout(location = 0) in vec4 position; |
| layout(location = 0) out vec2 textureCoordinates; |
| |
| void main() { |
| gl_Position = position; |
| textureCoordinates = vec2(0.0, 0.0); |
| } |
| END |
| |
| SHADER fragment frag_shader SPIRV-ASM |
| OpCapability Shader |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Fragment %main "main" %fragColor %vtxTexCoords |
| OpExecutionMode %main OriginUpperLeft |
| OpDecorate %fragColor Location 0 ; Output |
| OpDecorate %vtxTexCoords Location 0 ; Input |
| OpDecorate %sampler_ptr DescriptorSet 0 |
| OpDecorate %sampler_ptr Binding 0 |
| |
| ; Basic types. |
| %void = OpTypeVoid |
| %void_func_t = OpTypeFunction %void |
| %float = OpTypeFloat 32 |
| %v2float = OpTypeVector %float 2 |
| %v4float = OpTypeVector %float 4 |
| %image_2d = OpTypeImage %float 2D 0 0 0 1 Unknown |
| %sampled_img = OpTypeSampledImage %image_2d |
| %sampling_func_t = OpTypeFunction %v4float %sampled_img %v2float |
| |
| ; Pointer types. |
| %sampled_img_uniform_ptr = OpTypePointer UniformConstant %sampled_img |
| %v4float_out_ptr = OpTypePointer Output %v4float |
| %v2float_input_ptr = OpTypePointer Input %v2float |
| |
| ; In/Out variables. |
| %fragColor = OpVariable %v4float_out_ptr Output |
| %sampler_ptr = OpVariable %sampled_img_uniform_ptr UniformConstant |
| %vtxTexCoords = OpVariable %v2float_input_ptr Input |
| |
| ; Main function. |
| %main = OpFunction %void None %void_func_t |
| %main_label = OpLabel |
| %tex_coords = OpLoad %v2float %vtxTexCoords |
| %sampler_arg = OpLoad %sampled_img %sampler_ptr |
| %frag_color_val = OpFunctionCall %v4float %sampling_func %sampler_arg %tex_coords |
| OpStore %fragColor %frag_color_val |
| OpReturn |
| OpFunctionEnd |
| |
| ; Auxiliar texture sampling function, receiving a sampled image as its argument. |
| %sampling_func = OpFunction %v4float None %sampling_func_t |
| %sampler = OpFunctionParameter %sampled_img |
| %coords = OpFunctionParameter %v2float |
| %sampling_func_label = OpLabel |
| %retval = OpImageSampleImplicitLod %v4float %sampler %coords |
| OpReturnValue %retval |
| OpFunctionEnd |
| END |
| |
| # Full-screen quad. |
| BUFFER position_buf DATA_TYPE vec4<float> DATA |
| -1 -1 0 1 |
| 1 -1 0 1 |
| -1 1 0 1 |
| -1 1 0 1 |
| 1 -1 0 1 |
| 1 1 0 1 |
| END |
| |
| BUFFER framebuffer FORMAT B8G8R8A8_UNORM |
| BUFFER texture FORMAT R8G8B8A8_UNORM |
| SAMPLER sampler |
| |
| PIPELINE graphics texgen_pipeline |
| ATTACH vtx_passthrough |
| ATTACH frag_green |
| |
| FRAMEBUFFER_SIZE 1 1 |
| BIND BUFFER texture AS color LOCATION 0 |
| END |
| |
| PIPELINE graphics main_pipeline |
| ATTACH vtx_shader |
| ATTACH frag_shader |
| |
| VERTEX_DATA position_buf LOCATION 0 |
| BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0 |
| |
| FRAMEBUFFER_SIZE 64 64 |
| BIND BUFFER framebuffer AS color LOCATION 0 |
| END |
| |
| CLEAR texgen_pipeline |
| RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 1 1 |
| EXPECT texture IDX 0 0 SIZE 1 1 EQ_RGBA 0 255 0 255 |
| |
| CLEAR_COLOR main_pipeline 0 0 0 255 |
| CLEAR main_pipeline |
| RUN main_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 6 |
| EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 |