2 * Copyright © 2020 Valve Corporation
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:
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
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
24 #ifndef ACO_TEST_HELPERS_H
25 #define ACO_TEST_HELPERS_H
27 #include "framework.h"
28 #include "vulkan/vulkan.h"
30 enum QoShaderDeclType
{
32 QoShaderDeclType_ssbo
,
33 QoShaderDeclType_img_buf
,
35 QoShaderDeclType_tex_buf
,
36 QoShaderDeclType_combined
,
38 QoShaderDeclType_samp
,
46 QoShaderDeclType decl_type
;
54 struct QoShaderModuleCreateInfo
{
58 uint32_t declarationCount
;
59 const QoShaderDecl
*pDeclarations
;
60 VkShaderStageFlagBits stage
;
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
;
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);
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();
82 void writeout(unsigned i
, aco::Temp tmp
=aco::Temp(0, aco::s1
));
85 VkDevice
get_vk_device(enum chip_class chip_class
);
86 VkDevice
get_vk_device(enum radeon_family family
);
88 void print_pipeline_ir(VkDevice device
, VkPipeline pipeline
, VkShaderStageFlagBits stages
,
89 const char *name
, bool remove_encoding
=false);
91 VkShaderModule
__qoCreateShaderModule(VkDevice dev
, const QoShaderModuleCreateInfo
*info
);
93 class PipelineBuilder
{
97 VkFormat color_outputs
[16];
99 VkPrimitiveTopology topology
;
100 VkSampleCountFlagBits samples
;
101 bool sample_shading_enable
;
102 float min_sample_shading
;
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
;
115 VkGraphicsPipelineCreateInfo gfx_pipeline_info
;
116 VkComputePipelineCreateInfo cs_pipeline_info
;
117 VkDescriptorSetLayout desc_layouts
[64];
118 VkPipelineLayout pipeline_layout
;
119 VkRenderPass render_pass
;
122 PipelineBuilder(VkDevice dev
);
125 PipelineBuilder(const PipelineBuilder
&) = delete;
126 PipelineBuilder
& operator = (const PipelineBuilder
&) = delete;
128 void add_desc_binding(VkShaderStageFlags stage_flags
, uint32_t layout
,
129 uint32_t binding
, VkDescriptorType type
, uint32_t count
=1);
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
);
134 void add_resource_decls(QoShaderModuleCreateInfo
*module
);
135 void add_io_decls(QoShaderModuleCreateInfo
*module
);
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
);
145 void create_pipeline();
147 void print_ir(VkShaderStageFlagBits stages
, const char *name
, bool remove_encoding
=false);
149 void create_compute_pipeline();
150 void create_graphics_pipeline();
153 #endif /* ACO_TEST_HELPERS_H */