blob: 5e0afd11a001709849f2beb26df1979186bffd2b [file] [log] [blame]
Dave Airlief4e499e2016-10-07 09:16:09 +10001/*
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
Edward O'Callaghanba437682016-10-07 22:19:19 +110026#ifndef RADV_META_H
27#define RADV_META_H
Dave Airlief4e499e2016-10-07 09:16:09 +100028
29#include "radv_private.h"
Samuel Pitoisetd4d77732017-09-01 11:41:18 +020030#include "radv_shader.h"
Dave Airlief4e499e2016-10-07 09:16:09 +100031
32#ifdef __cplusplus
33extern "C" {
34#endif
35
Samuel Pitoiset807f2d42017-10-03 14:12:05 +020036enum 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),
Samuel Pitoiset213f86e2017-10-03 14:47:32 +020041 RADV_META_SAVE_COMPUTE_PIPELINE = (1 << 4),
Samuel Pitoiset807f2d42017-10-03 14:12:05 +020042};
43
Dave Airlief4e499e2016-10-07 09:16:09 +100044struct radv_meta_saved_state {
Samuel Pitoiset807f2d42017-10-03 14:12:05 +020045 uint32_t flags;
46
Dave Airlief45e7682017-09-06 13:37:42 +100047 struct radv_descriptor_set *old_descriptor_set0;
48 struct radv_pipeline *old_pipeline;
Samuel Pitoiset1cf508b2017-09-25 14:02:49 +020049 struct radv_viewport_state viewport;
50 struct radv_scissor_state scissor;
Dave Airlief4e499e2016-10-07 09:16:09 +100051
52 char push_constants[128];
Dave Airlief4e499e2016-10-07 09:16:09 +100053
Dave Airlief4e499e2016-10-07 09:16:09 +100054 struct radv_render_pass *pass;
55 const struct radv_subpass *subpass;
56 struct radv_attachment_state *attachments;
57 struct radv_framebuffer *framebuffer;
58 VkRect2D render_area;
59};
60
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020061VkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100062void radv_device_finish_meta_clear_state(struct radv_device *device);
63
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020064VkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100065void radv_device_finish_meta_resolve_state(struct radv_device *device);
66
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020067VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100068void radv_device_finish_meta_depth_decomp_state(struct radv_device *device);
69
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020070VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100071void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);
72
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020073VkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100074void radv_device_finish_meta_blit_state(struct radv_device *device);
75
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020076VkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100077void radv_device_finish_meta_blit2d_state(struct radv_device *device);
78
79VkResult radv_device_init_meta_buffer_state(struct radv_device *device);
80void radv_device_finish_meta_buffer_state(struct radv_device *device);
81
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020082VkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
Bas Nieuwenhuizence0c8cf2017-02-26 18:21:01 +010083void radv_device_finish_meta_query_state(struct radv_device *device);
84
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020085VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
Dave Airlief4e499e2016-10-07 09:16:09 +100086void radv_device_finish_meta_resolve_compute_state(struct radv_device *device);
Dave Airlie69136f42017-04-27 01:47:22 +010087
Bas Nieuwenhuizenfbcd1672018-08-14 00:07:57 +020088VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
Dave Airlie69136f42017-04-27 01:47:22 +010089void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);
90
Samuel Pitoiset6b976022018-12-17 20:59:33 +010091VkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
92void radv_device_finish_meta_fmask_expand_state(struct radv_device *device);
93
Samuel Pitoisetba3dc352017-10-03 14:37:56 +020094void radv_meta_save(struct radv_meta_saved_state *saved_state,
95 struct radv_cmd_buffer *cmd_buffer, uint32_t flags);
96
Dave Airlief4e499e2016-10-07 09:16:09 +100097void radv_meta_restore(const struct radv_meta_saved_state *state,
98 struct radv_cmd_buffer *cmd_buffer);
99
Dave Airlief4e499e2016-10-07 09:16:09 +1000100VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
101
102uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
103 const VkImageSubresourceLayers *dest_subresource,
104 const VkOffset3D *dest_offset);
105
106struct radv_meta_blit2d_surf {
107 /** The size of an element in bytes. */
108 uint8_t bs;
109 VkFormat format;
110
111 struct radv_image *image;
112 unsigned level;
113 unsigned layer;
114 VkImageAspectFlags aspect_mask;
Dave Airlie821b5372017-12-21 16:23:30 +1000115 VkImageLayout current_layout;
Dave Airlief4e499e2016-10-07 09:16:09 +1000116};
117
118struct radv_meta_blit2d_buffer {
119 struct radv_buffer *buffer;
120 uint32_t offset;
121 uint32_t pitch;
122 uint8_t bs;
123 VkFormat format;
124};
125
126struct radv_meta_blit2d_rect {
127 uint32_t src_x, src_y;
128 uint32_t dst_x, dst_y;
129 uint32_t width, height;
130};
131
132void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer,
133 struct radv_meta_saved_state *save);
134
135void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer,
136 struct radv_meta_blit2d_surf *src_img,
137 struct radv_meta_blit2d_buffer *src_buf,
138 struct radv_meta_blit2d_surf *dst,
139 unsigned num_rects,
140 struct radv_meta_blit2d_rect *rects);
141
142void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer,
143 struct radv_meta_saved_state *save);
144
145
146VkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
147void radv_device_finish_meta_bufimage_state(struct radv_device *device);
Dave Airlief4e499e2016-10-07 09:16:09 +1000148void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
149 struct radv_meta_blit2d_surf *src,
150 struct radv_meta_blit2d_buffer *dst,
151 unsigned num_rects,
152 struct radv_meta_blit2d_rect *rects);
153
Dave Airlie983af3a2016-11-29 23:52:55 +0000154void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
155 struct radv_meta_blit2d_buffer *src,
156 struct radv_meta_blit2d_surf *dst,
157 unsigned num_rects,
158 struct radv_meta_blit2d_rect *rects);
Dave Airlieef5f59c2016-11-30 00:26:47 +0000159void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
160 struct radv_meta_blit2d_surf *src,
161 struct radv_meta_blit2d_surf *dst,
162 unsigned num_rects,
163 struct radv_meta_blit2d_rect *rects);
Dave Airlief11ea872016-11-30 01:45:24 +0000164void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer,
165 struct radv_meta_blit2d_surf *dst,
166 const VkClearColorValue *clear_color);
Dave Airlie983af3a2016-11-29 23:52:55 +0000167
Dave Airlief4e499e2016-10-07 09:16:09 +1000168void radv_decompress_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
169 struct radv_image *image,
170 VkImageSubresourceRange *subresourceRange);
171void radv_resummarize_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
172 struct radv_image *image,
173 VkImageSubresourceRange *subresourceRange);
174void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
Dave Airlie9aec76a2017-02-19 16:33:14 +1000175 struct radv_image *image,
176 const VkImageSubresourceRange *subresourceRange);
Bas Nieuwenhuizen3e2a6192017-12-23 13:17:52 +0100177void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer,
178 struct radv_image *image,
179 const VkImageSubresourceRange *subresourceRange);
Samuel Pitoiset6b976022018-12-17 20:59:33 +0100180void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer,
181 struct radv_image *image,
182 const VkImageSubresourceRange *subresourceRange);
Dave Airlief4e499e2016-10-07 09:16:09 +1000183
Dave Airlief4e499e2016-10-07 09:16:09 +1000184void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
185 struct radv_image *src_image,
186 VkImageLayout src_image_layout,
187 struct radv_image *dest_image,
188 VkImageLayout dest_image_layout,
189 uint32_t region_count,
190 const VkImageResolve *regions);
191
Dave Airlie69136f42017-04-27 01:47:22 +0100192void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
193 struct radv_image *src_image,
194 VkImageLayout src_image_layout,
195 struct radv_image *dest_image,
196 VkImageLayout dest_image_layout,
197 uint32_t region_count,
198 const VkImageResolve *regions);
199
Samuel Pitoisetab0e6252018-04-11 14:09:16 +0200200void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
201
202void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
203 struct radv_image *src_image,
Samuel Pitoisetdc3d3972018-04-17 16:05:17 +0200204 VkImageLayout src_image_layout,
Samuel Pitoisetab0e6252018-04-11 14:09:16 +0200205 uint32_t region_count,
206 const VkImageResolve *regions);
207
Samuel Pitoisetf882c622018-04-06 12:22:02 +0200208uint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer,
209 struct radv_image *image, uint32_t value);
Samuel Pitoisetfa16da52018-12-17 21:23:42 +0100210uint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer,
211 struct radv_image *image, uint32_t value);
Samuel Pitoisetf882c622018-04-06 12:22:02 +0200212uint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer,
213 struct radv_image *image, uint32_t value);
214
Dave Airlie399ebd22017-04-19 06:18:23 +1000215/* common nir builder helpers */
Mike Lothian2284d6b2017-04-19 03:09:05 +0100216#include "nir/nir_builder.h"
Dave Airlie399ebd22017-04-19 06:18:23 +1000217
218nir_ssa_def *radv_meta_gen_rect_vertices(nir_builder *vs_b);
Dave Airliedd17e4c2017-04-18 15:50:10 +1000219nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2);
Dave Airlie03a2ca62017-04-19 09:13:06 +1000220nir_shader *radv_meta_build_nir_vs_generate_vertices(void);
221nir_shader *radv_meta_build_nir_fs_noop(void);
Dave Airlieff478662017-05-03 04:23:04 +0100222
223void radv_meta_build_resolve_shader_core(nir_builder *b,
224 bool is_integer,
Dave Airlieff478662017-05-03 04:23:04 +0100225 int samples,
226 nir_variable *input_img,
227 nir_variable *color,
228 nir_ssa_def *img_coord);
Dave Airlief4e499e2016-10-07 09:16:09 +1000229#ifdef __cplusplus
230}
231#endif
Edward O'Callaghanba437682016-10-07 22:19:19 +1100232
233#endif /* RADV_META_H */