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