• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    RADV_META_SAVE_SAMPLE_LOCATIONS = (1 << 5),
43    RADV_META_SUSPEND_PREDICATING = (1 << 6),
44 };
45 
46 struct radv_meta_saved_state {
47    uint32_t flags;
48 
49    struct radv_descriptor_set *old_descriptor_set0;
50    struct radv_graphics_pipeline *old_graphics_pipeline;
51    struct radv_compute_pipeline *old_compute_pipeline;
52    struct radv_dynamic_state dynamic;
53 
54    char push_constants[MAX_PUSH_CONSTANTS_SIZE];
55 
56    struct radv_render_pass *pass;
57    const struct radv_subpass *subpass;
58    struct radv_attachment_state *attachments;
59    struct vk_framebuffer *framebuffer;
60    VkRect2D render_area;
61 
62    unsigned active_pipeline_gds_queries;
63 
64    bool predicating;
65 };
66 
67 VkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
68 void radv_device_finish_meta_clear_state(struct radv_device *device);
69 
70 VkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
71 void radv_device_finish_meta_resolve_state(struct radv_device *device);
72 
73 VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
74 void radv_device_finish_meta_depth_decomp_state(struct radv_device *device);
75 
76 VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
77 void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);
78 
79 VkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
80 void radv_device_finish_meta_blit_state(struct radv_device *device);
81 
82 VkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
83 void radv_device_finish_meta_blit2d_state(struct radv_device *device);
84 
85 VkResult radv_device_init_meta_buffer_state(struct radv_device *device);
86 void radv_device_finish_meta_buffer_state(struct radv_device *device);
87 
88 VkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
89 void radv_device_finish_meta_query_state(struct radv_device *device);
90 
91 VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
92 void radv_device_finish_meta_resolve_compute_state(struct radv_device *device);
93 
94 VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
95 void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);
96 
97 VkResult radv_device_init_meta_fmask_copy_state(struct radv_device *device);
98 void radv_device_finish_meta_fmask_copy_state(struct radv_device *device);
99 
100 VkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
101 void radv_device_finish_meta_fmask_expand_state(struct radv_device *device);
102 
103 void radv_device_finish_meta_dcc_retile_state(struct radv_device *device);
104 
105 void radv_device_finish_meta_copy_vrs_htile_state(struct radv_device *device);
106 
107 VkResult radv_device_init_accel_struct_build_state(struct radv_device *device);
108 void radv_device_finish_accel_struct_build_state(struct radv_device *device);
109 
110 VkResult radv_device_init_meta_etc_decode_state(struct radv_device *device, bool on_demand);
111 void radv_device_finish_meta_etc_decode_state(struct radv_device *device);
112 
113 VkResult radv_device_init_dgc_prepare_state(struct radv_device *device);
114 void radv_device_finish_dgc_prepare_state(struct radv_device *device);
115 
116 void radv_meta_save(struct radv_meta_saved_state *saved_state, struct radv_cmd_buffer *cmd_buffer,
117                     uint32_t flags);
118 
119 void radv_meta_restore(const struct radv_meta_saved_state *state,
120                        struct radv_cmd_buffer *cmd_buffer);
121 
122 VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
123 
124 uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
125                                    const VkImageSubresourceLayers *dest_subresource,
126                                    const VkOffset3D *dest_offset);
127 
128 struct radv_meta_blit2d_surf {
129    /** The size of an element in bytes. */
130    uint8_t bs;
131    VkFormat format;
132 
133    struct radv_image *image;
134    unsigned level;
135    unsigned layer;
136    VkImageAspectFlags aspect_mask;
137    VkImageLayout current_layout;
138    bool disable_compression;
139 };
140 
141 struct radv_meta_blit2d_buffer {
142    struct radv_buffer *buffer;
143    uint32_t offset;
144    uint32_t pitch;
145    uint8_t bs;
146    VkFormat format;
147 };
148 
149 struct radv_meta_blit2d_rect {
150    uint32_t src_x, src_y;
151    uint32_t dst_x, dst_y;
152    uint32_t width, height;
153 };
154 
155 void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_saved_state *save);
156 
157 void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *src_img,
158                       struct radv_meta_blit2d_buffer *src_buf, struct radv_meta_blit2d_surf *dst,
159                       unsigned num_rects, struct radv_meta_blit2d_rect *rects);
160 
161 void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_saved_state *save);
162 
163 VkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
164 void radv_device_finish_meta_bufimage_state(struct radv_device *device);
165 void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
166                                struct radv_meta_blit2d_surf *src,
167                                struct radv_meta_blit2d_buffer *dst, unsigned num_rects,
168                                struct radv_meta_blit2d_rect *rects);
169 
170 void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
171                                   struct radv_meta_blit2d_buffer *src,
172                                   struct radv_meta_blit2d_surf *dst, unsigned num_rects,
173                                   struct radv_meta_blit2d_rect *rects);
174 void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
175                                  struct radv_meta_blit2d_surf *src,
176                                  struct radv_meta_blit2d_surf *dst, unsigned num_rects,
177                                  struct radv_meta_blit2d_rect *rects);
178 void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *dst,
179                               const VkClearColorValue *clear_color);
180 
181 void radv_expand_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
182                                const VkImageSubresourceRange *subresourceRange,
183                                struct radv_sample_locations_state *sample_locs);
184 void radv_resummarize_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
185                                     const VkImageSubresourceRange *subresourceRange,
186                                     struct radv_sample_locations_state *sample_locs);
187 void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
188                                          struct radv_image *image,
189                                          const VkImageSubresourceRange *subresourceRange);
190 void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
191                          const VkImageSubresourceRange *subresourceRange);
192 void radv_retile_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image);
193 void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
194                                      const VkImageSubresourceRange *subresourceRange);
195 void radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_image,
196                          VkExtent2D *extent, struct radv_image *dst_image,
197                          struct radv_buffer *htile_buffer, bool read_htile_value);
198 
199 bool radv_can_use_fmask_copy(struct radv_cmd_buffer *cmd_buffer,
200                              const struct radv_image *src_image, const struct radv_image *dst_image,
201                              unsigned num_rects, const struct radv_meta_blit2d_rect *rects);
202 void radv_fmask_copy(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *src,
203                      struct radv_meta_blit2d_surf *dst);
204 
205 void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
206                                      struct radv_image *src_image, VkFormat src_format,
207                                      VkImageLayout src_image_layout, struct radv_image *dest_image,
208                                      VkFormat dest_format, VkImageLayout dest_image_layout,
209                                      const VkImageResolve2 *region);
210 
211 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
212                                       struct radv_image *src_image, VkImageLayout src_image_layout,
213                                       struct radv_image *dest_image,
214                                       VkImageLayout dest_image_layout,
215                                       const VkImageResolve2 *region);
216 
217 void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
218 
219 void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer, struct radv_image *src_image,
220                                  VkImageLayout src_image_layout, const VkImageResolve2 *region);
221 
222 uint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
223                           const VkImageSubresourceRange *range, uint32_t value);
224 uint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
225                           const VkImageSubresourceRange *range, uint32_t value);
226 uint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
227                         const VkImageSubresourceRange *range, uint32_t value);
228 uint32_t radv_clear_htile(struct radv_cmd_buffer *cmd_buffer, const struct radv_image *image,
229                           const VkImageSubresourceRange *range, uint32_t value);
230 
231 void radv_update_buffer_cp(struct radv_cmd_buffer *cmd_buffer, uint64_t va, const void *data,
232                            uint64_t size);
233 
234 void radv_meta_decode_etc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
235                           VkImageLayout layout, const VkImageSubresourceLayers *subresource,
236                           VkOffset3D offset, VkExtent3D extent);
237 
238 /**
239  * Return whether the bound pipeline is the FMASK decompress pass.
240  */
241 static inline bool
radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer * cmd_buffer)242 radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
243 {
244    struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
245    struct radv_graphics_pipeline *pipeline = cmd_buffer->state.graphics_pipeline;
246 
247    return radv_pipeline_to_handle(&pipeline->base) ==
248           meta_state->fast_clear_flush.fmask_decompress_pipeline;
249 }
250 
251 /**
252  * Return whether the bound pipeline is the DCC decompress pass.
253  */
254 static inline bool
radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer * cmd_buffer)255 radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
256 {
257    struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
258    struct radv_graphics_pipeline *pipeline = cmd_buffer->state.graphics_pipeline;
259 
260    return radv_pipeline_to_handle(&pipeline->base) ==
261           meta_state->fast_clear_flush.dcc_decompress_pipeline;
262 }
263 
264 /* common nir builder helpers */
265 #include "nir/nir_builder.h"
266 
267 nir_builder PRINTFLIKE(3, 4)
268    radv_meta_init_shader(struct radv_device *dev, gl_shader_stage stage, const char *name, ...);
269 
270 nir_shader *radv_meta_build_nir_vs_generate_vertices(struct radv_device *dev);
271 nir_shader *radv_meta_build_nir_fs_noop(struct radv_device *dev);
272 
273 void radv_meta_build_resolve_shader_core(nir_builder *b, bool is_integer, int samples,
274                                          nir_variable *input_img, nir_variable *color,
275                                          nir_ssa_def *img_coord);
276 
277 nir_ssa_def *radv_meta_load_descriptor(nir_builder *b, unsigned desc_set, unsigned binding);
278 
279 nir_ssa_def *get_global_ids(nir_builder *b, unsigned num_components);
280 
281 void radv_break_on_count(nir_builder *b, nir_variable *var, nir_ssa_def *count);
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /* RADV_META_H */
288