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
90 VkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
91 void radv_device_finish_meta_clear_state(struct radv_device *device);
92
93 VkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
94 void radv_device_finish_meta_resolve_state(struct radv_device *device);
95
96 VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
97 void radv_device_finish_meta_depth_decomp_state(struct radv_device *device);
98
99 VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
100 void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);
101
102 VkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
103 void radv_device_finish_meta_blit_state(struct radv_device *device);
104
105 VkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
106 void radv_device_finish_meta_blit2d_state(struct radv_device *device);
107
108 VkResult radv_device_init_meta_buffer_state(struct radv_device *device);
109 void radv_device_finish_meta_buffer_state(struct radv_device *device);
110
111 VkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
112 void radv_device_finish_meta_query_state(struct radv_device *device);
113
114 VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
115 void radv_device_finish_meta_resolve_compute_state(struct radv_device *device);
116
117 VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
118 void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);
119
120 VkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
121 void radv_device_finish_meta_fmask_expand_state(struct radv_device *device);
122
123 void radv_meta_save(struct radv_meta_saved_state *saved_state,
124 struct radv_cmd_buffer *cmd_buffer, uint32_t flags);
125
126 void radv_meta_restore(const struct radv_meta_saved_state *state,
127 struct radv_cmd_buffer *cmd_buffer);
128
129 VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
130
131 uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
132 const VkImageSubresourceLayers *dest_subresource,
133 const VkOffset3D *dest_offset);
134
135 struct radv_meta_blit2d_surf {
136 /** The size of an element in bytes. */
137 uint8_t bs;
138 VkFormat format;
139
140 struct radv_image *image;
141 unsigned level;
142 unsigned layer;
143 VkImageAspectFlags aspect_mask;
144 VkImageLayout current_layout;
145 };
146
147 struct radv_meta_blit2d_buffer {
148 struct radv_buffer *buffer;
149 uint32_t offset;
150 uint32_t pitch;
151 uint8_t bs;
152 VkFormat format;
153 };
154
155 struct radv_meta_blit2d_rect {
156 uint32_t src_x, src_y;
157 uint32_t dst_x, dst_y;
158 uint32_t width, height;
159 };
160
161 void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer,
162 struct radv_meta_saved_state *save);
163
164 void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer,
165 struct radv_meta_blit2d_surf *src_img,
166 struct radv_meta_blit2d_buffer *src_buf,
167 struct radv_meta_blit2d_surf *dst,
168 unsigned num_rects,
169 struct radv_meta_blit2d_rect *rects);
170
171 void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer,
172 struct radv_meta_saved_state *save);
173
174
175 VkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
176 void radv_device_finish_meta_bufimage_state(struct radv_device *device);
177 void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
178 struct radv_meta_blit2d_surf *src,
179 struct radv_meta_blit2d_buffer *dst,
180 unsigned num_rects,
181 struct radv_meta_blit2d_rect *rects);
182
183 void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
184 struct radv_meta_blit2d_buffer *src,
185 struct radv_meta_blit2d_surf *dst,
186 unsigned num_rects,
187 struct radv_meta_blit2d_rect *rects);
188 void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
189 struct radv_meta_blit2d_surf *src,
190 struct radv_meta_blit2d_surf *dst,
191 unsigned num_rects,
192 struct radv_meta_blit2d_rect *rects);
193 void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer,
194 struct radv_meta_blit2d_surf *dst,
195 const VkClearColorValue *clear_color);
196
197 void radv_decompress_depth_stencil(struct radv_cmd_buffer *cmd_buffer,
198 struct radv_image *image,
199 const VkImageSubresourceRange *subresourceRange,
200 struct radv_sample_locations_state *sample_locs);
201 void radv_resummarize_depth_stencil(struct radv_cmd_buffer *cmd_buffer,
202 struct radv_image *image,
203 const VkImageSubresourceRange *subresourceRange,
204 struct radv_sample_locations_state *sample_locs);
205 void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
206 struct radv_image *image,
207 const VkImageSubresourceRange *subresourceRange);
208 void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer,
209 struct radv_image *image,
210 const VkImageSubresourceRange *subresourceRange);
211 void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer,
212 struct radv_image *image,
213 const VkImageSubresourceRange *subresourceRange);
214
215 void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
216 struct radv_image *src_image,
217 VkFormat src_format,
218 VkImageLayout src_image_layout,
219 struct radv_image *dest_image,
220 VkFormat dest_format,
221 VkImageLayout dest_image_layout,
222 const VkImageResolve2KHR *region);
223
224 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
225 struct radv_image *src_image,
226 VkImageLayout src_image_layout,
227 struct radv_image *dest_image,
228 VkImageLayout dest_image_layout,
229 const VkImageResolve2KHR *region);
230
231 void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
232
233 void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
234 struct radv_image *src_image,
235 VkImageLayout src_image_layout,
236 const VkImageResolve2KHR *region);
237
238 uint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer,
239 struct radv_image *image,
240 const VkImageSubresourceRange *range, uint32_t value);
241 uint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer,
242 struct radv_image *image,
243 const VkImageSubresourceRange *range, uint32_t value);
244 uint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer,
245 struct radv_image *image,
246 const VkImageSubresourceRange *range, uint32_t value);
247 uint32_t radv_clear_htile(struct radv_cmd_buffer *cmd_buffer,
248 const struct radv_image *image,
249 const VkImageSubresourceRange *range, uint32_t value);
250
251 /**
252 * Return whether the bound pipeline is the FMASK decompress pass.
253 */
254 static inline bool
radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer * cmd_buffer)255 radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
256 {
257 struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
258 struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;
259
260 return radv_pipeline_to_handle(pipeline) ==
261 meta_state->fast_clear_flush.fmask_decompress_pipeline;
262 }
263
264 /**
265 * Return whether the bound pipeline is the DCC decompress pass.
266 */
267 static inline bool
radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer * cmd_buffer)268 radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
269 {
270 struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
271 struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;
272
273 return radv_pipeline_to_handle(pipeline) ==
274 meta_state->fast_clear_flush.dcc_decompress_pipeline;
275 }
276
277 /**
278 * Return whether the bound pipeline is the hardware resolve path.
279 */
280 static inline bool
radv_is_hw_resolve_pipeline(struct radv_cmd_buffer * cmd_buffer)281 radv_is_hw_resolve_pipeline(struct radv_cmd_buffer *cmd_buffer)
282 {
283 struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
284 struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;
285
286 if (!pipeline)
287 return false;
288
289 for (uint32_t i = 0; i < NUM_META_FS_KEYS; ++i) {
290 if (radv_pipeline_to_handle(pipeline) == meta_state->resolve.pipeline[i])
291 return true;
292 }
293 return false;
294 }
295
296 /* common nir builder helpers */
297 #include "nir/nir_builder.h"
298
299 nir_ssa_def *radv_meta_gen_rect_vertices(nir_builder *vs_b);
300 nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2);
301 nir_shader *radv_meta_build_nir_vs_generate_vertices(void);
302 nir_shader *radv_meta_build_nir_fs_noop(void);
303
304 void radv_meta_build_resolve_shader_core(nir_builder *b,
305 bool is_integer,
306 int samples,
307 nir_variable *input_img,
308 nir_variable *color,
309 nir_ssa_def *img_coord);
310
311 nir_ssa_def *radv_meta_load_descriptor(nir_builder *b, unsigned desc_set,
312 unsigned binding);
313
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif /* RADV_META_H */
319