Path: blob/21.2-virgl/src/amd/compiler/tests/test_isel.cpp
7097 views
/*1* Copyright © 2020 Valve Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22*/23#include "helpers.h"24#include "test_isel-spirv.h"2526#include <llvm/Config/llvm-config.h>2728using namespace aco;2930BEGIN_TEST(isel.interp.simple)31QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX,32layout(location = 0) in vec4 in_color;33layout(location = 0) out vec4 out_color;34void main() {35out_color = in_color;36}37);38QoShaderModuleCreateInfo fs = qoShaderModuleCreateInfoGLSL(FRAGMENT,39layout(location = 0) in vec4 in_color;40layout(location = 0) out vec4 out_color;41void main() {42//>> v1: %a_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.w43//! v1: %a = v_interp_p2_f32 %by, %pm:m0, (kill)%a_tmp attr0.w44//! v1: %b_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.z45//! v1: %b = v_interp_p2_f32 %by, %pm:m0, (kill)%b_tmp attr0.z46//! v1: %g_tmp = v_interp_p1_f32 %bx, %pm:m0 attr0.y47//! v1: %g = v_interp_p2_f32 %by, %pm:m0, (kill)%g_tmp attr0.y48//! v1: %r_tmp = v_interp_p1_f32 (kill)%bx, %pm:m0 attr0.x49//! v1: %r = v_interp_p2_f32 (kill)%by, (kill)%pm:m0, (kill)%r_tmp attr0.x50//! exp (kill)%r, (kill)%g, (kill)%b, (kill)%a mrt051out_color = in_color;52}53);5455PipelineBuilder pbld(get_vk_device(GFX9));56pbld.add_vsfs(vs, fs);57pbld.print_ir(VK_SHADER_STAGE_FRAGMENT_BIT, "ACO IR");58END_TEST5960BEGIN_TEST(isel.compute.simple)61for (unsigned i = GFX7; i <= GFX8; i++) {62if (!set_variant((chip_class)i))63continue;6465QoShaderModuleCreateInfo cs = qoShaderModuleCreateInfoGLSL(COMPUTE,66layout(local_size_x=1) in;67layout(binding=0) buffer Buf {68uint res;69};70void main() {71//>> v1: %data = p_parallelcopy 4272//buffer_store_dword %_, v1: undef, 0, %data disable_wqm storage:buffer semantics: scope:invocation73res = 42;74}75);7677PipelineBuilder pbld(get_vk_device((chip_class)i));78pbld.add_cs(cs);79pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "ACO IR", true);80}81END_TEST8283BEGIN_TEST(isel.gs.no_outputs)84for (unsigned i = GFX8; i <= GFX10; i++) {85if (!set_variant((chip_class)i))86continue;8788QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX,89void main() {}90);9192QoShaderModuleCreateInfo gs = qoShaderModuleCreateInfoGLSL(GEOMETRY,93layout(points) in;94layout(points, max_vertices = 1) out;9596void main() {97EmitVertex();98EndPrimitive();99}100);101102PipelineBuilder pbld(get_vk_device((chip_class)i));103pbld.add_stage(VK_SHADER_STAGE_VERTEX_BIT, vs);104pbld.add_stage(VK_SHADER_STAGE_GEOMETRY_BIT, gs);105pbld.create_pipeline();106107//! success108fprintf(output, "success\n");109}110END_TEST111112BEGIN_TEST(isel.gs.no_verts)113for (unsigned i = GFX8; i <= GFX10; i++) {114if (!set_variant((chip_class)i))115continue;116117QoShaderModuleCreateInfo vs = qoShaderModuleCreateInfoGLSL(VERTEX,118void main() {}119);120121QoShaderModuleCreateInfo gs = qoShaderModuleCreateInfoGLSL(GEOMETRY,122layout(points) in;123layout(points, max_vertices = 0) out;124125void main() {}126);127128PipelineBuilder pbld(get_vk_device((chip_class)i));129pbld.add_stage(VK_SHADER_STAGE_VERTEX_BIT, vs);130pbld.add_stage(VK_SHADER_STAGE_GEOMETRY_BIT, gs);131pbld.create_pipeline();132133//! success134fprintf(output, "success\n");135}136END_TEST137138BEGIN_TEST(isel.sparse.clause)139for (unsigned i = GFX10_3; i <= GFX10_3; i++) {140if (!set_variant((chip_class)i))141continue;142143QoShaderModuleCreateInfo cs = qoShaderModuleCreateInfoGLSL(COMPUTE,144QO_EXTENSION GL_ARB_sparse_texture2 : require145layout(local_size_x=1) in;146layout(binding=0) uniform sampler2D tex;147layout(binding=1) buffer Buf {148vec4 res[4];149uint code[4];150};151void main() {152//! llvm_version: #llvm_ver153//; if llvm_ver >= 12:154//; funcs['sample_res'] = lambda _: 'v[#_:#_]'155//; funcs['sample_coords'] = lambda _: '[v#_, v#_, v#_]'156//; else:157//; funcs['sample_res'] = lambda _: 'v#_'158//; funcs['sample_coords'] = lambda _: '[v#_, v#_, v#_, v#_]'159//>> v5: (noCSE)%zero0 = p_create_vector 0, 0, 0, 0, 0160//>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero0, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation161//>> v5: (noCSE)%zero1 = p_create_vector 0, 0, 0, 0, 0162//>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero1, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation163//>> v5: (noCSE)%zero2 = p_create_vector 0, 0, 0, 0, 0164//>> v5: %_ = image_sample_lz_o %_, %_, (kill)%zero2, (kill)%_, %_, %_ dmask:xyzw 2d tfe storage: semantics: scope:invocation165//>> v5: (noCSE)%zero3 = p_create_vector 0, 0, 0, 0, 0166//>> v5: %_ = image_sample_lz_o (kill)%_, (kill)%_, (kill)%zero3, (kill)%_, (kill)%_, (kill)%_ dmask:xyzw 2d tfe storage: semantics: scope:invocation167//>> s_clause 0x3168//! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe169//! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe170//! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe171//! image_sample_lz_o @sample_res, @sample_coords, @s256(img), @s128(samp) dmask:0xf dim:SQ_RSRC_IMG_2D tfe172code[0] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(1, 0), res[0]);173code[1] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(2, 0), res[1]);174code[2] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(3, 0), res[2]);175code[3] = sparseTextureOffsetARB(tex, vec2(0.5), ivec2(4, 0), res[3]);176}177);178179fprintf(output, "llvm_version: %u\n", LLVM_VERSION_MAJOR);180181PipelineBuilder pbld(get_vk_device((chip_class)i));182pbld.add_cs(cs);183pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "ACO IR", true);184pbld.print_ir(VK_SHADER_STAGE_COMPUTE_BIT, "Assembly", true);185}186END_TEST187188189