radv: implement compressed FMASK texture reads with RADV_PERFTEST=tccompatcmask
[mesa.git] / src / amd / vulkan / radv_meta.h
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
63 VkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
64 void radv_device_finish_meta_clear_state(struct radv_device *device);
65
66 VkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
67 void radv_device_finish_meta_resolve_state(struct radv_device *device);
68
69 VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
70 void radv_device_finish_meta_depth_decomp_state(struct radv_device *device);
71
72 VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
73 void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);
74
75 VkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
76 void radv_device_finish_meta_blit_state(struct radv_device *device);
77
78 VkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
79 void radv_device_finish_meta_blit2d_state(struct radv_device *device);
80
81 VkResult radv_device_init_meta_buffer_state(struct radv_device *device);
82 void radv_device_finish_meta_buffer_state(struct radv_device *device);
83
84 VkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
85 void radv_device_finish_meta_query_state(struct radv_device *device);
86
87 VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
88 void radv_device_finish_meta_resolve_compute_state(struct radv_device *device);
89
90 VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
91 void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);
92
93 VkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
94 void radv_device_finish_meta_fmask_expand_state(struct radv_device *device);
95
96 void radv_meta_save(struct radv_meta_saved_state *saved_state,
97 struct radv_cmd_buffer *cmd_buffer, uint32_t flags);
98
99 void radv_meta_restore(const struct radv_meta_saved_state *state,
100 struct radv_cmd_buffer *cmd_buffer);
101
102 VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
103
104 uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
105 const VkImageSubresourceLayers *dest_subresource,
106 const VkOffset3D *dest_offset);
107
108 struct radv_meta_blit2d_surf {
109 /** The size of an element in bytes. */
110 uint8_t bs;
111 VkFormat format;
112
113 struct radv_image *image;
114 unsigned level;
115 unsigned layer;
116 VkImageAspectFlags aspect_mask;
117 VkImageLayout current_layout;
118 };
119
120 struct radv_meta_blit2d_buffer {
121 struct radv_buffer *buffer;
122 uint32_t offset;
123 uint32_t pitch;
124 uint8_t bs;
125 VkFormat format;
126 };
127
128 struct radv_meta_blit2d_rect {
129 uint32_t src_x, src_y;
130 uint32_t dst_x, dst_y;
131 uint32_t width, height;
132 };
133
134 void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer,
135 struct radv_meta_saved_state *save);
136
137 void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer,
138 struct radv_meta_blit2d_surf *src_img,
139 struct radv_meta_blit2d_buffer *src_buf,
140 struct radv_meta_blit2d_surf *dst,
141 unsigned num_rects,
142 struct radv_meta_blit2d_rect *rects);
143
144 void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer,
145 struct radv_meta_saved_state *save);
146
147
148 VkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
149 void radv_device_finish_meta_bufimage_state(struct radv_device *device);
150 void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
151 struct radv_meta_blit2d_surf *src,
152 struct radv_meta_blit2d_buffer *dst,
153 unsigned num_rects,
154 struct radv_meta_blit2d_rect *rects);
155
156 void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
157 struct radv_meta_blit2d_buffer *src,
158 struct radv_meta_blit2d_surf *dst,
159 unsigned num_rects,
160 struct radv_meta_blit2d_rect *rects);
161 void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
162 struct radv_meta_blit2d_surf *src,
163 struct radv_meta_blit2d_surf *dst,
164 unsigned num_rects,
165 struct radv_meta_blit2d_rect *rects);
166 void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer,
167 struct radv_meta_blit2d_surf *dst,
168 const VkClearColorValue *clear_color);
169
170 void radv_decompress_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
171 struct radv_image *image,
172 VkImageSubresourceRange *subresourceRange,
173 struct radv_sample_locations_state *sample_locs);
174 void radv_resummarize_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
175 struct radv_image *image,
176 VkImageSubresourceRange *subresourceRange,
177 struct radv_sample_locations_state *sample_locs);
178 void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
179 struct radv_image *image,
180 const VkImageSubresourceRange *subresourceRange);
181 void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer,
182 struct radv_image *image,
183 const VkImageSubresourceRange *subresourceRange);
184 void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer,
185 struct radv_image *image,
186 const VkImageSubresourceRange *subresourceRange);
187
188 void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
189 struct radv_image *src_image,
190 VkFormat src_format,
191 VkImageLayout src_image_layout,
192 struct radv_image *dest_image,
193 VkFormat dest_format,
194 VkImageLayout dest_image_layout,
195 uint32_t region_count,
196 const VkImageResolve *regions);
197
198 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
199 struct radv_image *src_image,
200 VkImageLayout src_image_layout,
201 struct radv_image *dest_image,
202 VkImageLayout dest_image_layout,
203 uint32_t region_count,
204 const VkImageResolve *regions);
205
206 void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
207
208 void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
209 struct radv_image *src_image,
210 VkImageLayout src_image_layout,
211 uint32_t region_count,
212 const VkImageResolve *regions);
213
214 uint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer,
215 struct radv_image *image, uint32_t value);
216 uint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer,
217 struct radv_image *image, uint32_t value);
218 uint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer,
219 struct radv_image *image,
220 const VkImageSubresourceRange *range, uint32_t value);
221 uint32_t radv_clear_htile(struct radv_cmd_buffer *cmd_buffer,
222 struct radv_image *image,
223 const VkImageSubresourceRange *range, uint32_t value);
224
225 /**
226 * Return whether the bound pipeline is the FMASK decompress pass.
227 */
228 static inline bool
229 radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
230 {
231 struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
232 struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;
233
234 return radv_pipeline_to_handle(pipeline) ==
235 meta_state->fast_clear_flush.fmask_decompress_pipeline;
236 }
237
238 /**
239 * Return whether the bound pipeline is the DCC decompress pass.
240 */
241 static inline bool
242 radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
243 {
244 struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
245 struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;
246
247 return radv_pipeline_to_handle(pipeline) ==
248 meta_state->fast_clear_flush.dcc_decompress_pipeline;
249 }
250
251 /* common nir builder helpers */
252 #include "nir/nir_builder.h"
253
254 nir_ssa_def *radv_meta_gen_rect_vertices(nir_builder *vs_b);
255 nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2);
256 nir_shader *radv_meta_build_nir_vs_generate_vertices(void);
257 nir_shader *radv_meta_build_nir_fs_noop(void);
258
259 void radv_meta_build_resolve_shader_core(nir_builder *b,
260 bool is_integer,
261 int samples,
262 nir_variable *input_img,
263 nir_variable *color,
264 nir_ssa_def *img_coord);
265 #ifdef __cplusplus
266 }
267 #endif
268
269 #endif /* RADV_META_H */