1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat
3bf215546Sopenharmony_ci * based on intel anv code:
4bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
15bf215546Sopenharmony_ci * Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23bf215546Sopenharmony_ci * IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef RADV_META_H
27bf215546Sopenharmony_ci#define RADV_META_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "radv_private.h"
30bf215546Sopenharmony_ci#include "radv_shader.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#ifdef __cplusplus
33bf215546Sopenharmony_ciextern "C" {
34bf215546Sopenharmony_ci#endif
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cienum radv_meta_save_flags {
37bf215546Sopenharmony_ci   RADV_META_SAVE_PASS = (1 << 0),
38bf215546Sopenharmony_ci   RADV_META_SAVE_CONSTANTS = (1 << 1),
39bf215546Sopenharmony_ci   RADV_META_SAVE_DESCRIPTORS = (1 << 2),
40bf215546Sopenharmony_ci   RADV_META_SAVE_GRAPHICS_PIPELINE = (1 << 3),
41bf215546Sopenharmony_ci   RADV_META_SAVE_COMPUTE_PIPELINE = (1 << 4),
42bf215546Sopenharmony_ci   RADV_META_SAVE_SAMPLE_LOCATIONS = (1 << 5),
43bf215546Sopenharmony_ci   RADV_META_SUSPEND_PREDICATING = (1 << 6),
44bf215546Sopenharmony_ci};
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_cistruct radv_meta_saved_state {
47bf215546Sopenharmony_ci   uint32_t flags;
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   struct radv_descriptor_set *old_descriptor_set0;
50bf215546Sopenharmony_ci   struct radv_graphics_pipeline *old_graphics_pipeline;
51bf215546Sopenharmony_ci   struct radv_compute_pipeline *old_compute_pipeline;
52bf215546Sopenharmony_ci   struct radv_dynamic_state dynamic;
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci   char push_constants[MAX_PUSH_CONSTANTS_SIZE];
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   struct radv_render_pass *pass;
57bf215546Sopenharmony_ci   const struct radv_subpass *subpass;
58bf215546Sopenharmony_ci   struct radv_attachment_state *attachments;
59bf215546Sopenharmony_ci   struct vk_framebuffer *framebuffer;
60bf215546Sopenharmony_ci   VkRect2D render_area;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   unsigned active_pipeline_gds_queries;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   bool predicating;
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ciVkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
68bf215546Sopenharmony_civoid radv_device_finish_meta_clear_state(struct radv_device *device);
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ciVkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
71bf215546Sopenharmony_civoid radv_device_finish_meta_resolve_state(struct radv_device *device);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ciVkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
74bf215546Sopenharmony_civoid radv_device_finish_meta_depth_decomp_state(struct radv_device *device);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ciVkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
77bf215546Sopenharmony_civoid radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ciVkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
80bf215546Sopenharmony_civoid radv_device_finish_meta_blit_state(struct radv_device *device);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ciVkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
83bf215546Sopenharmony_civoid radv_device_finish_meta_blit2d_state(struct radv_device *device);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ciVkResult radv_device_init_meta_buffer_state(struct radv_device *device);
86bf215546Sopenharmony_civoid radv_device_finish_meta_buffer_state(struct radv_device *device);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ciVkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
89bf215546Sopenharmony_civoid radv_device_finish_meta_query_state(struct radv_device *device);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ciVkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
92bf215546Sopenharmony_civoid radv_device_finish_meta_resolve_compute_state(struct radv_device *device);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ciVkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
95bf215546Sopenharmony_civoid radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ciVkResult radv_device_init_meta_fmask_copy_state(struct radv_device *device);
98bf215546Sopenharmony_civoid radv_device_finish_meta_fmask_copy_state(struct radv_device *device);
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ciVkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
101bf215546Sopenharmony_civoid radv_device_finish_meta_fmask_expand_state(struct radv_device *device);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_civoid radv_device_finish_meta_dcc_retile_state(struct radv_device *device);
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_civoid radv_device_finish_meta_copy_vrs_htile_state(struct radv_device *device);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ciVkResult radv_device_init_accel_struct_build_state(struct radv_device *device);
108bf215546Sopenharmony_civoid radv_device_finish_accel_struct_build_state(struct radv_device *device);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ciVkResult radv_device_init_meta_etc_decode_state(struct radv_device *device, bool on_demand);
111bf215546Sopenharmony_civoid radv_device_finish_meta_etc_decode_state(struct radv_device *device);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ciVkResult radv_device_init_dgc_prepare_state(struct radv_device *device);
114bf215546Sopenharmony_civoid radv_device_finish_dgc_prepare_state(struct radv_device *device);
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_civoid radv_meta_save(struct radv_meta_saved_state *saved_state, struct radv_cmd_buffer *cmd_buffer,
117bf215546Sopenharmony_ci                    uint32_t flags);
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_civoid radv_meta_restore(const struct radv_meta_saved_state *state,
120bf215546Sopenharmony_ci                       struct radv_cmd_buffer *cmd_buffer);
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ciVkImageViewType radv_meta_get_view_type(const struct radv_image *image);
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ciuint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
125bf215546Sopenharmony_ci                                   const VkImageSubresourceLayers *dest_subresource,
126bf215546Sopenharmony_ci                                   const VkOffset3D *dest_offset);
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_cistruct radv_meta_blit2d_surf {
129bf215546Sopenharmony_ci   /** The size of an element in bytes. */
130bf215546Sopenharmony_ci   uint8_t bs;
131bf215546Sopenharmony_ci   VkFormat format;
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci   struct radv_image *image;
134bf215546Sopenharmony_ci   unsigned level;
135bf215546Sopenharmony_ci   unsigned layer;
136bf215546Sopenharmony_ci   VkImageAspectFlags aspect_mask;
137bf215546Sopenharmony_ci   VkImageLayout current_layout;
138bf215546Sopenharmony_ci   bool disable_compression;
139bf215546Sopenharmony_ci};
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_cistruct radv_meta_blit2d_buffer {
142bf215546Sopenharmony_ci   struct radv_buffer *buffer;
143bf215546Sopenharmony_ci   uint32_t offset;
144bf215546Sopenharmony_ci   uint32_t pitch;
145bf215546Sopenharmony_ci   uint8_t bs;
146bf215546Sopenharmony_ci   VkFormat format;
147bf215546Sopenharmony_ci};
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_cistruct radv_meta_blit2d_rect {
150bf215546Sopenharmony_ci   uint32_t src_x, src_y;
151bf215546Sopenharmony_ci   uint32_t dst_x, dst_y;
152bf215546Sopenharmony_ci   uint32_t width, height;
153bf215546Sopenharmony_ci};
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_civoid radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_saved_state *save);
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_civoid radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *src_img,
158bf215546Sopenharmony_ci                      struct radv_meta_blit2d_buffer *src_buf, struct radv_meta_blit2d_surf *dst,
159bf215546Sopenharmony_ci                      unsigned num_rects, struct radv_meta_blit2d_rect *rects);
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_civoid radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_saved_state *save);
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ciVkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
164bf215546Sopenharmony_civoid radv_device_finish_meta_bufimage_state(struct radv_device *device);
165bf215546Sopenharmony_civoid radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
166bf215546Sopenharmony_ci                               struct radv_meta_blit2d_surf *src,
167bf215546Sopenharmony_ci                               struct radv_meta_blit2d_buffer *dst, unsigned num_rects,
168bf215546Sopenharmony_ci                               struct radv_meta_blit2d_rect *rects);
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_civoid radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
171bf215546Sopenharmony_ci                                  struct radv_meta_blit2d_buffer *src,
172bf215546Sopenharmony_ci                                  struct radv_meta_blit2d_surf *dst, unsigned num_rects,
173bf215546Sopenharmony_ci                                  struct radv_meta_blit2d_rect *rects);
174bf215546Sopenharmony_civoid radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
175bf215546Sopenharmony_ci                                 struct radv_meta_blit2d_surf *src,
176bf215546Sopenharmony_ci                                 struct radv_meta_blit2d_surf *dst, unsigned num_rects,
177bf215546Sopenharmony_ci                                 struct radv_meta_blit2d_rect *rects);
178bf215546Sopenharmony_civoid radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *dst,
179bf215546Sopenharmony_ci                              const VkClearColorValue *clear_color);
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_civoid radv_expand_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
182bf215546Sopenharmony_ci                               const VkImageSubresourceRange *subresourceRange,
183bf215546Sopenharmony_ci                               struct radv_sample_locations_state *sample_locs);
184bf215546Sopenharmony_civoid radv_resummarize_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
185bf215546Sopenharmony_ci                                    const VkImageSubresourceRange *subresourceRange,
186bf215546Sopenharmony_ci                                    struct radv_sample_locations_state *sample_locs);
187bf215546Sopenharmony_civoid radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
188bf215546Sopenharmony_ci                                         struct radv_image *image,
189bf215546Sopenharmony_ci                                         const VkImageSubresourceRange *subresourceRange);
190bf215546Sopenharmony_civoid radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
191bf215546Sopenharmony_ci                         const VkImageSubresourceRange *subresourceRange);
192bf215546Sopenharmony_civoid radv_retile_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image);
193bf215546Sopenharmony_civoid radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
194bf215546Sopenharmony_ci                                     const VkImageSubresourceRange *subresourceRange);
195bf215546Sopenharmony_civoid radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_image,
196bf215546Sopenharmony_ci                         VkExtent2D *extent, struct radv_image *dst_image,
197bf215546Sopenharmony_ci                         struct radv_buffer *htile_buffer, bool read_htile_value);
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_cibool radv_can_use_fmask_copy(struct radv_cmd_buffer *cmd_buffer,
200bf215546Sopenharmony_ci                             const struct radv_image *src_image, const struct radv_image *dst_image,
201bf215546Sopenharmony_ci                             unsigned num_rects, const struct radv_meta_blit2d_rect *rects);
202bf215546Sopenharmony_civoid radv_fmask_copy(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_blit2d_surf *src,
203bf215546Sopenharmony_ci                     struct radv_meta_blit2d_surf *dst);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_civoid radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
206bf215546Sopenharmony_ci                                     struct radv_image *src_image, VkFormat src_format,
207bf215546Sopenharmony_ci                                     VkImageLayout src_image_layout, struct radv_image *dest_image,
208bf215546Sopenharmony_ci                                     VkFormat dest_format, VkImageLayout dest_image_layout,
209bf215546Sopenharmony_ci                                     const VkImageResolve2 *region);
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_civoid radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
212bf215546Sopenharmony_ci                                      struct radv_image *src_image, VkImageLayout src_image_layout,
213bf215546Sopenharmony_ci                                      struct radv_image *dest_image,
214bf215546Sopenharmony_ci                                      VkImageLayout dest_image_layout,
215bf215546Sopenharmony_ci                                      const VkImageResolve2 *region);
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_civoid radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_civoid radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer, struct radv_image *src_image,
220bf215546Sopenharmony_ci                                 VkImageLayout src_image_layout, const VkImageResolve2 *region);
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_ciuint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
223bf215546Sopenharmony_ci                          const VkImageSubresourceRange *range, uint32_t value);
224bf215546Sopenharmony_ciuint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
225bf215546Sopenharmony_ci                          const VkImageSubresourceRange *range, uint32_t value);
226bf215546Sopenharmony_ciuint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
227bf215546Sopenharmony_ci                        const VkImageSubresourceRange *range, uint32_t value);
228bf215546Sopenharmony_ciuint32_t radv_clear_htile(struct radv_cmd_buffer *cmd_buffer, const struct radv_image *image,
229bf215546Sopenharmony_ci                          const VkImageSubresourceRange *range, uint32_t value);
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_civoid radv_update_buffer_cp(struct radv_cmd_buffer *cmd_buffer, uint64_t va, const void *data,
232bf215546Sopenharmony_ci                           uint64_t size);
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_civoid radv_meta_decode_etc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
235bf215546Sopenharmony_ci                          VkImageLayout layout, const VkImageSubresourceLayers *subresource,
236bf215546Sopenharmony_ci                          VkOffset3D offset, VkExtent3D extent);
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ci/**
239bf215546Sopenharmony_ci * Return whether the bound pipeline is the FMASK decompress pass.
240bf215546Sopenharmony_ci */
241bf215546Sopenharmony_cistatic inline bool
242bf215546Sopenharmony_ciradv_is_fmask_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
243bf215546Sopenharmony_ci{
244bf215546Sopenharmony_ci   struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
245bf215546Sopenharmony_ci   struct radv_graphics_pipeline *pipeline = cmd_buffer->state.graphics_pipeline;
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci   return radv_pipeline_to_handle(&pipeline->base) ==
248bf215546Sopenharmony_ci          meta_state->fast_clear_flush.fmask_decompress_pipeline;
249bf215546Sopenharmony_ci}
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci/**
252bf215546Sopenharmony_ci * Return whether the bound pipeline is the DCC decompress pass.
253bf215546Sopenharmony_ci */
254bf215546Sopenharmony_cistatic inline bool
255bf215546Sopenharmony_ciradv_is_dcc_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
256bf215546Sopenharmony_ci{
257bf215546Sopenharmony_ci   struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
258bf215546Sopenharmony_ci   struct radv_graphics_pipeline *pipeline = cmd_buffer->state.graphics_pipeline;
259bf215546Sopenharmony_ci
260bf215546Sopenharmony_ci   return radv_pipeline_to_handle(&pipeline->base) ==
261bf215546Sopenharmony_ci          meta_state->fast_clear_flush.dcc_decompress_pipeline;
262bf215546Sopenharmony_ci}
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci/* common nir builder helpers */
265bf215546Sopenharmony_ci#include "nir/nir_builder.h"
266bf215546Sopenharmony_ci
267bf215546Sopenharmony_cinir_builder PRINTFLIKE(3, 4)
268bf215546Sopenharmony_ci   radv_meta_init_shader(struct radv_device *dev, gl_shader_stage stage, const char *name, ...);
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_cinir_shader *radv_meta_build_nir_vs_generate_vertices(struct radv_device *dev);
271bf215546Sopenharmony_cinir_shader *radv_meta_build_nir_fs_noop(struct radv_device *dev);
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_civoid radv_meta_build_resolve_shader_core(nir_builder *b, bool is_integer, int samples,
274bf215546Sopenharmony_ci                                         nir_variable *input_img, nir_variable *color,
275bf215546Sopenharmony_ci                                         nir_ssa_def *img_coord);
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_cinir_ssa_def *radv_meta_load_descriptor(nir_builder *b, unsigned desc_set, unsigned binding);
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_cinir_ssa_def *get_global_ids(nir_builder *b, unsigned num_components);
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_civoid radv_break_on_count(nir_builder *b, nir_variable *var, nir_ssa_def *count);
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ci#ifdef __cplusplus
284bf215546Sopenharmony_ci}
285bf215546Sopenharmony_ci#endif
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci#endif /* RADV_META_H */
288