1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2020 Valve Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci#include "helpers.h" 25bf215546Sopenharmony_ci#include "test_isel-spirv.h" 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include <llvm/Config/llvm-config.h> 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ciusing namespace aco; 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ciBEGIN_TEST(isel.interp.simple) 32bf215546Sopenharmony_ci QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX, 33bf215546Sopenharmony_ci layout(location = 0) in vec4 in_color; 34bf215546Sopenharmony_ci layout(location = 0) out vec4 out_color; 35bf215546Sopenharmony_ci void main() { 36bf215546Sopenharmony_ci out_color = in_color; 37bf215546Sopenharmony_ci } 38bf215546Sopenharmony_ci ); 39bf215546Sopenharmony_ci QoShaderModuleCreateInfo fs = qoShaderModuleCreateInfoGLSL(FRAGMENT, 40bf215546Sopenharmony_ci layout(location = 0) in vec4 in_color; 41bf215546Sopenharmony_ci layout(location = 0) out vec4 out_color; 42bf215546Sopenharmony_ci void main() { 43bf215546Sopenharmony_ci //>> v1: %a_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.w 44bf215546Sopenharmony_ci //! v1: %a = v_interp_p2_f32 %by, %pm:m0, (kill)%a_tmp attr0.w 45bf215546Sopenharmony_ci //! v1: %r_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.x 46bf215546Sopenharmony_ci //! v1: %r = v_interp_p2_f32 %by, %pm:m0, (kill)%r_tmp attr0.x 47bf215546Sopenharmony_ci //! v1: %g_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.y 48bf215546Sopenharmony_ci //! v1: %g = v_interp_p2_f32 %by, %pm:m0, (kill)%g_tmp attr0.y 49bf215546Sopenharmony_ci //! v1: %b_tmp = v_interp_p1_f32 (kill)%bx, %pm:m0 attr0.z 50bf215546Sopenharmony_ci //! v1: %b = v_interp_p2_f32 (kill)%by, (kill)%pm:m0, (kill)%b_tmp attr0.z 51bf215546Sopenharmony_ci //! exp (kill)%r, (kill)%g, (kill)%b, (kill)%a mrt0 52bf215546Sopenharmony_ci out_color = in_color; 53bf215546Sopenharmony_ci } 54bf215546Sopenharmony_ci ); 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci PipelineBuilder pbld(get_vk_device(GFX9)); 57bf215546Sopenharmony_ci pbld.add_vsfs(vs, fs); 58bf215546Sopenharmony_ci pbld.print_ir(VK_SHADER_STAGE_FRAGMENT_BIT, "ACO IR"); 59bf215546Sopenharmony_ciEND_TEST 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ciBEGIN_TEST(isel.compute.simple) 62bf215546Sopenharmony_ci for (unsigned i = GFX7; i <= GFX8; i++) { 63bf215546Sopenharmony_ci if (!set_variant((amd_gfx_level)i)) 64bf215546Sopenharmony_ci continue; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci QoShaderModuleCreateInfo cs = qoShaderModuleCreateInfoGLSL(COMPUTE, 67bf215546Sopenharmony_ci layout(local_size_x=1) in; 68bf215546Sopenharmony_ci layout(binding=0) buffer Buf { 69bf215546Sopenharmony_ci uint res; 70bf215546Sopenharmony_ci }; 71bf215546Sopenharmony_ci void main() { 72bf215546Sopenharmony_ci //>> v1: %data = p_parallelcopy 42 73bf215546Sopenharmony_ci //buffer_store_dword %_, v1: undef, 0, %data disable_wqm storage:buffer semantics: scope:invocation 74bf215546Sopenharmony_ci res = 42; 75bf215546Sopenharmony_ci } 76bf215546Sopenharmony_ci ); 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci PipelineBuilder pbld(get_vk_device((amd_gfx_level)i)); 79bf215546Sopenharmony_ci pbld.add_cs(cs); 80bf215546Sopenharmony_ci pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "ACO IR", true); 81bf215546Sopenharmony_ci } 82bf215546Sopenharmony_ciEND_TEST 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ciBEGIN_TEST(isel.gs.no_outputs) 85bf215546Sopenharmony_ci for (unsigned i = GFX8; i <= GFX10; i++) { 86bf215546Sopenharmony_ci if (!set_variant((amd_gfx_level)i)) 87bf215546Sopenharmony_ci continue; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX, 90bf215546Sopenharmony_ci void main() {} 91bf215546Sopenharmony_ci ); 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci QoShaderModuleCreateInfo gs = qoShaderModuleCreateInfoGLSL(GEOMETRY, 94bf215546Sopenharmony_ci layout(points) in; 95bf215546Sopenharmony_ci layout(points, max_vertices = 1) out; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci void main() { 98bf215546Sopenharmony_ci EmitVertex(); 99bf215546Sopenharmony_ci EndPrimitive(); 100bf215546Sopenharmony_ci } 101bf215546Sopenharmony_ci ); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci PipelineBuilder pbld(get_vk_device((amd_gfx_level)i)); 104bf215546Sopenharmony_ci pbld.add_stage(VK_SHADER_STAGE_VERTEX_BIT, vs); 105bf215546Sopenharmony_ci pbld.add_stage(VK_SHADER_STAGE_GEOMETRY_BIT, gs); 106bf215546Sopenharmony_ci pbld.create_pipeline(); 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci //! success 109bf215546Sopenharmony_ci fprintf(output, "success\n"); 110bf215546Sopenharmony_ci } 111bf215546Sopenharmony_ciEND_TEST 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ciBEGIN_TEST(isel.gs.no_verts) 114bf215546Sopenharmony_ci for (unsigned i = GFX8; i <= GFX10; i++) { 115bf215546Sopenharmony_ci if (!set_variant((amd_gfx_level)i)) 116bf215546Sopenharmony_ci continue; 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX, 119bf215546Sopenharmony_ci void main() {} 120bf215546Sopenharmony_ci ); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci QoShaderModuleCreateInfo gs = qoShaderModuleCreateInfoGLSL(GEOMETRY, 123bf215546Sopenharmony_ci layout(points) in; 124bf215546Sopenharmony_ci layout(points, max_vertices = 0) out; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci void main() {} 127bf215546Sopenharmony_ci ); 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci PipelineBuilder pbld(get_vk_device((amd_gfx_level)i)); 130bf215546Sopenharmony_ci pbld.add_stage(VK_SHADER_STAGE_VERTEX_BIT, vs); 131bf215546Sopenharmony_ci pbld.add_stage(VK_SHADER_STAGE_GEOMETRY_BIT, gs); 132bf215546Sopenharmony_ci pbld.create_pipeline(); 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci //! success 135bf215546Sopenharmony_ci fprintf(output, "success\n"); 136bf215546Sopenharmony_ci } 137bf215546Sopenharmony_ciEND_TEST 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ciBEGIN_TEST(isel.sparse.clause) 140bf215546Sopenharmony_ci for (unsigned i = GFX10_3; i <= GFX10_3; i++) { 141bf215546Sopenharmony_ci if (!set_variant((amd_gfx_level)i)) 142bf215546Sopenharmony_ci continue; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci QoShaderModuleCreateInfo cs = qoShaderModuleCreateInfoGLSL(COMPUTE, 145bf215546Sopenharmony_ci QO_EXTENSION GL_ARB_sparse_texture2 : require 146bf215546Sopenharmony_ci layout(local_size_x=1) in; 147bf215546Sopenharmony_ci layout(binding=0) uniform sampler2D tex; 148bf215546Sopenharmony_ci layout(binding=1) buffer Buf { 149bf215546Sopenharmony_ci vec4 res[4]; 150bf215546Sopenharmony_ci uint code[4]; 151bf215546Sopenharmony_ci }; 152bf215546Sopenharmony_ci void main() { 153bf215546Sopenharmony_ci //! llvm_version: #llvm_ver 154bf215546Sopenharmony_ci //; if llvm_ver >= 12: 155bf215546Sopenharmony_ci //; funcs['sample_res'] = lambda _: 'v[#_:#_]' 156bf215546Sopenharmony_ci //; funcs['sample_coords'] = lambda _: '[v#_, v#_, v#_]' 157bf215546Sopenharmony_ci //; else: 158bf215546Sopenharmony_ci //; funcs['sample_res'] = lambda _: 'v#_' 159bf215546Sopenharmony_ci //; funcs['sample_coords'] = lambda _: '[v#_, v#_, v#_, v#_]' 160bf215546Sopenharmony_ci //>> v5: (noCSE)%zero0 = p_create_vector 0, 0, 0, 0, 0 161bf215546Sopenharmony_ci //>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero0, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation 162bf215546Sopenharmony_ci //>> v5: (noCSE)%zero1 = p_create_vector 0, 0, 0, 0, 0 163bf215546Sopenharmony_ci //>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero1, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation 164bf215546Sopenharmony_ci //>> v5: (noCSE)%zero2 = p_create_vector 0, 0, 0, 0, 0 165bf215546Sopenharmony_ci //>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero2, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation 166bf215546Sopenharmony_ci //>> v5: (noCSE)%zero3 = p_create_vector 0, 0, 0, 0, 0 167bf215546Sopenharmony_ci //>> v5: %_ = image_sample_lz_o (kill)%_, (kill)%_, (kill)%zero3, (kill)%_, (kill)%_, (kill)%_ dmask:xyzw 2d tfe storage: semantics: scope:invocation 168bf215546Sopenharmony_ci //>> s_clause 0x3 169bf215546Sopenharmony_ci //! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe 170bf215546Sopenharmony_ci //! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe 171bf215546Sopenharmony_ci //! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe 172bf215546Sopenharmony_ci //! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe 173bf215546Sopenharmony_ci code[0] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(1, 0), res[0]); 174bf215546Sopenharmony_ci code[1] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(2, 0), res[1]); 175bf215546Sopenharmony_ci code[2] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(3, 0), res[2]); 176bf215546Sopenharmony_ci code[3] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(4, 0), res[3]); 177bf215546Sopenharmony_ci } 178bf215546Sopenharmony_ci ); 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci fprintf(output, "llvm_version: %u\n", LLVM_VERSION_MAJOR); 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci PipelineBuilder pbld(get_vk_device((amd_gfx_level)i)); 183bf215546Sopenharmony_ci pbld.add_cs(cs); 184bf215546Sopenharmony_ci pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "ACO IR", true); 185bf215546Sopenharmony_ci pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "Assembly", true); 186bf215546Sopenharmony_ci } 187bf215546Sopenharmony_ciEND_TEST 188