Path: blob/21.2-virgl/src/amd/compiler/tests/helpers.h
7170 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#ifndef ACO_TEST_HELPERS_H24#define ACO_TEST_HELPERS_H2526#include "framework.h"27#include "vulkan/vulkan.h"2829enum QoShaderDeclType {30QoShaderDeclType_ubo,31QoShaderDeclType_ssbo,32QoShaderDeclType_img_buf,33QoShaderDeclType_img,34QoShaderDeclType_tex_buf,35QoShaderDeclType_combined,36QoShaderDeclType_tex,37QoShaderDeclType_samp,38QoShaderDeclType_in,39QoShaderDeclType_out,40};4142struct QoShaderDecl {43const char *name;44const char *type;45QoShaderDeclType decl_type;46//TODO: array size?47unsigned location;48unsigned component;49unsigned binding;50unsigned set;51};5253struct QoShaderModuleCreateInfo {54void *pNext;55size_t spirvSize;56const void *pSpirv;57uint32_t declarationCount;58const QoShaderDecl *pDeclarations;59VkShaderStageFlagBits stage;60};6162extern ac_shader_config config;63extern radv_shader_info info;64extern std::unique_ptr<aco::Program> program;65extern aco::Builder bld;66extern aco::Temp inputs[16];6768namespace aco {69struct ra_test_policy;70}7172void create_program(enum chip_class chip_class, aco::Stage stage,73unsigned wave_size=64, enum radeon_family family=CHIP_UNKNOWN);74bool setup_cs(const char *input_spec, enum chip_class chip_class,75enum radeon_family family=CHIP_UNKNOWN, const char* subvariant = "",76unsigned wave_size=64);7778void finish_program(aco::Program *program);79void finish_validator_test();80void finish_opt_test();81void finish_ra_test(aco::ra_test_policy);82void finish_optimizer_postRA_test();83void finish_to_hw_instr_test();84void finish_insert_nops_test();85void finish_form_hard_clause_test();86void finish_assembler_test();8788void writeout(unsigned i, aco::Temp tmp=aco::Temp(0, aco::s1));89void writeout(unsigned i, aco::Builder::Result res);90void writeout(unsigned i, aco::Operand op);91void writeout(unsigned i, aco::Operand op0, aco::Operand op1);9293aco::Temp fneg(aco::Temp src);94aco::Temp fabs(aco::Temp src);9596/* vulkan helpers */97VkDevice get_vk_device(enum chip_class chip_class);98VkDevice get_vk_device(enum radeon_family family);99100void print_pipeline_ir(VkDevice device, VkPipeline pipeline, VkShaderStageFlagBits stages,101const char *name, bool remove_encoding=false);102103VkShaderModule __qoCreateShaderModule(VkDevice dev, const QoShaderModuleCreateInfo *info);104105class PipelineBuilder {106public:107/* inputs */108VkDevice device;109VkFormat color_outputs[16];110VkFormat ds_output;111VkPrimitiveTopology topology;112VkSampleCountFlagBits samples;113bool sample_shading_enable;114float min_sample_shading;115uint32_t patch_size;116VkPipelineVertexInputStateCreateInfo vs_input;117VkVertexInputBindingDescription vs_bindings[16];118VkVertexInputAttributeDescription vs_attributes[16];119VkPushConstantRange push_constant_range;120uint64_t desc_layouts_used;121unsigned num_desc_bindings[64];122VkDescriptorSetLayoutBinding desc_bindings[64][64];123VkPipelineShaderStageCreateInfo stages[5];124VkShaderStageFlags owned_stages;125126/* outputs */127VkGraphicsPipelineCreateInfo gfx_pipeline_info;128VkComputePipelineCreateInfo cs_pipeline_info;129VkDescriptorSetLayout desc_layouts[64];130VkPipelineLayout pipeline_layout;131VkRenderPass render_pass;132VkPipeline pipeline;133134PipelineBuilder(VkDevice dev);135~PipelineBuilder();136137PipelineBuilder(const PipelineBuilder&) = delete;138PipelineBuilder& operator = (const PipelineBuilder&) = delete;139140void add_desc_binding(VkShaderStageFlags stage_flags, uint32_t layout,141uint32_t binding, VkDescriptorType type, uint32_t count=1);142143void add_vertex_binding(uint32_t binding, uint32_t stride, VkVertexInputRate rate=VK_VERTEX_INPUT_RATE_VERTEX);144void add_vertex_attribute(uint32_t location, uint32_t binding, VkFormat format, uint32_t offset);145146void add_resource_decls(QoShaderModuleCreateInfo *module);147void add_io_decls(QoShaderModuleCreateInfo *module);148149void add_stage(VkShaderStageFlagBits stage, VkShaderModule module, const char *name="main");150void add_stage(VkShaderStageFlagBits stage, QoShaderModuleCreateInfo module, const char *name="main");151void add_vsfs(VkShaderModule vs, VkShaderModule fs);152void add_vsfs(QoShaderModuleCreateInfo vs, QoShaderModuleCreateInfo fs);153void add_cs(VkShaderModule cs);154void add_cs(QoShaderModuleCreateInfo cs);155156bool is_compute();157158void create_pipeline();159160void print_ir(VkShaderStageFlagBits stages, const char *name, bool remove_encoding=false);161private:162void create_compute_pipeline();163void create_graphics_pipeline();164};165166#endif /* ACO_TEST_HELPERS_H */167168169