1 /* 2 * Copyright © 2020 Valve Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 */ 24 #ifndef ACO_TEST_HELPERS_H 25 #define ACO_TEST_HELPERS_H 26 27 #include "framework.h" 28 #include "vulkan/vulkan.h" 29 30 enum QoShaderDeclType { 31 QoShaderDeclType_ubo, 32 QoShaderDeclType_ssbo, 33 QoShaderDeclType_img_buf, 34 QoShaderDeclType_img, 35 QoShaderDeclType_tex_buf, 36 QoShaderDeclType_combined, 37 QoShaderDeclType_tex, 38 QoShaderDeclType_samp, 39 QoShaderDeclType_in, 40 QoShaderDeclType_out, 41 }; 42 43 struct QoShaderDecl { 44 const char *name; 45 const char *type; 46 QoShaderDeclType decl_type; 47 //TODO: array size? 48 unsigned location; 49 unsigned component; 50 unsigned binding; 51 unsigned set; 52 }; 53 54 struct QoShaderModuleCreateInfo { 55 void *pNext; 56 size_t spirvSize; 57 const void *pSpirv; 58 uint32_t declarationCount; 59 const QoShaderDecl *pDeclarations; 60 VkShaderStageFlagBits stage; 61 }; 62 63 extern ac_shader_config config; 64 extern radv_shader_info info; 65 extern std::unique_ptr<aco::Program> program; 66 extern aco::Builder bld; 67 extern aco::Temp exec_input; 68 extern aco::Temp inputs[16]; 69 extern const char *subvariant; 70 71 void create_program(enum chip_class chip_class, aco::Stage stage, 72 unsigned wave_size=64, enum radeon_family family=CHIP_UNKNOWN); 73 bool setup_cs(const char *input_spec, enum chip_class chip_class, 74 enum radeon_family family=CHIP_UNKNOWN, unsigned wave_size=64); 75 76 void finish_program(aco::Program *program); 77 void finish_validator_test(); 78 void finish_opt_test(); 79 void finish_to_hw_instr_test(); 80 void finish_assembler_test(); 81 82 void writeout(unsigned i, aco::Temp tmp=aco::Temp(0, aco::s1)); 83 84 /* vulkan helpers */ 85 VkDevice get_vk_device(enum chip_class chip_class); 86 VkDevice get_vk_device(enum radeon_family family); 87 88 void print_pipeline_ir(VkDevice device, VkPipeline pipeline, VkShaderStageFlagBits stages, 89 const char *name, bool remove_encoding=false); 90 91 VkShaderModule __qoCreateShaderModule(VkDevice dev, const QoShaderModuleCreateInfo *info); 92 93 class PipelineBuilder { 94 public: 95 /* inputs */ 96 VkDevice device; 97 VkFormat color_outputs[16]; 98 VkFormat ds_output; 99 VkPrimitiveTopology topology; 100 VkSampleCountFlagBits samples; 101 bool sample_shading_enable; 102 float min_sample_shading; 103 uint32_t patch_size; 104 VkPipelineVertexInputStateCreateInfo vs_input; 105 VkVertexInputBindingDescription vs_bindings[16]; 106 VkVertexInputAttributeDescription vs_attributes[16]; 107 VkPushConstantRange push_constant_range; 108 uint64_t desc_layouts_used; 109 unsigned num_desc_bindings[64]; 110 VkDescriptorSetLayoutBinding desc_bindings[64][64]; 111 VkPipelineShaderStageCreateInfo stages[5]; 112 VkShaderStageFlags owned_stages; 113 114 /* outputs */ 115 VkGraphicsPipelineCreateInfo gfx_pipeline_info; 116 VkComputePipelineCreateInfo cs_pipeline_info; 117 VkDescriptorSetLayout desc_layouts[64]; 118 VkPipelineLayout pipeline_layout; 119 VkRenderPass render_pass; 120 VkPipeline pipeline; 121 122 PipelineBuilder(VkDevice dev); 123 ~PipelineBuilder(); 124 125 PipelineBuilder(const PipelineBuilder&) = delete; 126 PipelineBuilder& operator = (const PipelineBuilder&) = delete; 127 128 void add_desc_binding(VkShaderStageFlags stage_flags, uint32_t layout, 129 uint32_t binding, VkDescriptorType type, uint32_t count=1); 130 131 void add_vertex_binding(uint32_t binding, uint32_t stride, VkVertexInputRate rate=VK_VERTEX_INPUT_RATE_VERTEX); 132 void add_vertex_attribute(uint32_t location, uint32_t binding, VkFormat format, uint32_t offset); 133 134 void add_resource_decls(QoShaderModuleCreateInfo *module); 135 void add_io_decls(QoShaderModuleCreateInfo *module); 136 137 void add_stage(VkShaderStageFlagBits stage, VkShaderModule module, const char *name="main"); 138 void add_vsfs(VkShaderModule vs, VkShaderModule fs); 139 void add_vsfs(QoShaderModuleCreateInfo vs, QoShaderModuleCreateInfo fs); 140 void add_cs(VkShaderModule cs); 141 void add_cs(QoShaderModuleCreateInfo cs); 142 143 bool is_compute(); 144 145 void create_pipeline(); 146 147 void print_ir(VkShaderStageFlagBits stages, const char *name, bool remove_encoding=false); 148 private: 149 void create_compute_pipeline(); 150 void create_graphics_pipeline(); 151 }; 152 153 #endif /* ACO_TEST_HELPERS_H */ 154