1 /* 2 * Copyright © 2016 Red Hat 3 * based on intel anv code: 4 * Copyright © 2015 Intel Corporation 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 * IN THE SOFTWARE. 24 */ 25 26 #ifndef RADV_META_H 27 #define RADV_META_H 28 29 #include "radv_private.h" 30 #include "radv_shader.h" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 enum radv_meta_save_flags { 37 RADV_META_SAVE_PASS = (1 << 0), 38 RADV_META_SAVE_CONSTANTS = (1 << 1), 39 RADV_META_SAVE_DESCRIPTORS = (1 << 2), 40 RADV_META_SAVE_GRAPHICS_PIPELINE = (1 << 3), 41 RADV_META_SAVE_COMPUTE_PIPELINE = (1 << 4), 42 }; 43 44 struct radv_meta_saved_state { 45 uint32_t flags; 46 47 struct radv_descriptor_set *old_descriptor_set0; 48 struct radv_pipeline *old_pipeline; 49 struct radv_viewport_state viewport; 50 struct radv_scissor_state scissor; 51 52 char push_constants[128]; 53 54 struct radv_render_pass *pass; 55 const struct radv_subpass *subpass; 56 struct radv_attachment_state *attachments; 57 struct radv_framebuffer *framebuffer; 58 VkRect2D render_area; 59 }; 60 61 VkResult radv_device_init_meta_clear_state(struct radv_device *device); 62 void radv_device_finish_meta_clear_state(struct radv_device *device); 63 64 VkResult radv_device_init_meta_resolve_state(struct radv_device *device); 65 void radv_device_finish_meta_resolve_state(struct radv_device *device); 66 67 VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device); 68 void radv_device_finish_meta_depth_decomp_state(struct radv_device *device); 69 70 VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device); 71 void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device); 72 73 VkResult radv_device_init_meta_blit_state(struct radv_device *device); 74 void radv_device_finish_meta_blit_state(struct radv_device *device); 75 76 VkResult radv_device_init_meta_blit2d_state(struct radv_device *device); 77 void radv_device_finish_meta_blit2d_state(struct radv_device *device); 78 79 VkResult radv_device_init_meta_buffer_state(struct radv_device *device); 80 void radv_device_finish_meta_buffer_state(struct radv_device *device); 81 82 VkResult radv_device_init_meta_query_state(struct radv_device *device); 83 void radv_device_finish_meta_query_state(struct radv_device *device); 84 85 VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device); 86 void radv_device_finish_meta_resolve_compute_state(struct radv_device *device); 87 88 VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device); 89 void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device); 90 91 void radv_meta_save(struct radv_meta_saved_state *saved_state, 92 struct radv_cmd_buffer *cmd_buffer, uint32_t flags); 93 94 void radv_meta_restore(const struct radv_meta_saved_state *state, 95 struct radv_cmd_buffer *cmd_buffer); 96 97 VkImageViewType radv_meta_get_view_type(const struct radv_image *image); 98 99 uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image, 100 const VkImageSubresourceLayers *dest_subresource, 101 const VkOffset3D *dest_offset); 102 103 struct radv_meta_blit2d_surf { 104 /** The size of an element in bytes. */ 105 uint8_t bs; 106 VkFormat format; 107 108 struct radv_image *image; 109 unsigned level; 110 unsigned layer; 111 VkImageAspectFlags aspect_mask; 112 VkImageLayout current_layout; 113 }; 114 115 struct radv_meta_blit2d_buffer { 116 struct radv_buffer *buffer; 117 uint32_t offset; 118 uint32_t pitch; 119 uint8_t bs; 120 VkFormat format; 121 }; 122 123 struct radv_meta_blit2d_rect { 124 uint32_t src_x, src_y; 125 uint32_t dst_x, dst_y; 126 uint32_t width, height; 127 }; 128 129 void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer, 130 struct radv_meta_saved_state *save); 131 132 void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer, 133 struct radv_meta_blit2d_surf *src_img, 134 struct radv_meta_blit2d_buffer *src_buf, 135 struct radv_meta_blit2d_surf *dst, 136 unsigned num_rects, 137 struct radv_meta_blit2d_rect *rects); 138 139 void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer, 140 struct radv_meta_saved_state *save); 141 142 143 VkResult radv_device_init_meta_bufimage_state(struct radv_device *device); 144 void radv_device_finish_meta_bufimage_state(struct radv_device *device); 145 void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer, 146 struct radv_meta_blit2d_surf *src, 147 struct radv_meta_blit2d_buffer *dst, 148 unsigned num_rects, 149 struct radv_meta_blit2d_rect *rects); 150 151 void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer, 152 struct radv_meta_blit2d_buffer *src, 153 struct radv_meta_blit2d_surf *dst, 154 unsigned num_rects, 155 struct radv_meta_blit2d_rect *rects); 156 void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer, 157 struct radv_meta_blit2d_surf *src, 158 struct radv_meta_blit2d_surf *dst, 159 unsigned num_rects, 160 struct radv_meta_blit2d_rect *rects); 161 void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer, 162 struct radv_meta_blit2d_surf *dst, 163 const VkClearColorValue *clear_color); 164 165 void radv_decompress_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer, 166 struct radv_image *image, 167 VkImageSubresourceRange *subresourceRange); 168 void radv_resummarize_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer, 169 struct radv_image *image, 170 VkImageSubresourceRange *subresourceRange); 171 void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer, 172 struct radv_image *image, 173 const VkImageSubresourceRange *subresourceRange); 174 void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer, 175 struct radv_image *image, 176 const VkImageSubresourceRange *subresourceRange); 177 178 void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer, 179 struct radv_image *src_image, 180 VkImageLayout src_image_layout, 181 struct radv_image *dest_image, 182 VkImageLayout dest_image_layout, 183 uint32_t region_count, 184 const VkImageResolve *regions); 185 186 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer, 187 struct radv_image *src_image, 188 VkImageLayout src_image_layout, 189 struct radv_image *dest_image, 190 VkImageLayout dest_image_layout, 191 uint32_t region_count, 192 const VkImageResolve *regions); 193 194 void radv_blit_to_prime_linear(struct radv_cmd_buffer *cmd_buffer, 195 struct radv_image *image, 196 struct radv_image *linear_image); 197 198 /* common nir builder helpers */ 199 #include "nir/nir_builder.h" 200 201 nir_ssa_def *radv_meta_gen_rect_vertices(nir_builder *vs_b); 202 nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2); 203 nir_shader *radv_meta_build_nir_vs_generate_vertices(void); 204 nir_shader *radv_meta_build_nir_fs_noop(void); 205 206 void radv_meta_build_resolve_shader_core(nir_builder *b, 207 bool is_integer, 208 int samples, 209 nir_variable *input_img, 210 nir_variable *color, 211 nir_ssa_def *img_coord); 212 #ifdef __cplusplus 213 } 214 #endif 215 216 #endif /* RADV_META_H */ 217