summaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan/radv_meta.h
blob: 53c562b5df65f56993c52fffd1ece4d265a95fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
 * Copyright © 2016 Red Hat
 * based on intel anv code:
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#ifndef RADV_META_H
#define RADV_META_H

#include "radv_private.h"
#include "radv_shader.h"

#ifdef __cplusplus
extern "C" {
#endif

enum radv_meta_save_flags {
	RADV_META_SAVE_PASS		 = (1 << 0),
	RADV_META_SAVE_CONSTANTS         = (1 << 1),
	RADV_META_SAVE_DESCRIPTORS       = (1 << 2),
	RADV_META_SAVE_GRAPHICS_PIPELINE = (1 << 3),
	RADV_META_SAVE_COMPUTE_PIPELINE  = (1 << 4),
	RADV_META_SAVE_SAMPLE_LOCATIONS  = (1 << 5),
};

struct radv_meta_saved_state {
	uint32_t flags;

	struct radv_descriptor_set *old_descriptor_set0;
	struct radv_pipeline *old_pipeline;
	struct radv_viewport_state viewport;
	struct radv_scissor_state scissor;
	struct radv_sample_locations_state sample_location;

	char push_constants[128];

	struct radv_render_pass *pass;
	const struct radv_subpass *subpass;
	struct radv_attachment_state *attachments;
	struct radv_framebuffer *framebuffer;
	VkRect2D render_area;
};

VkResult radv_device_init_meta_clear_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_clear_state(struct radv_device *device);

VkResult radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_resolve_state(struct radv_device *device);

VkResult radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_depth_decomp_state(struct radv_device *device);

VkResult radv_device_init_meta_fast_clear_flush_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device);

VkResult radv_device_init_meta_blit_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_blit_state(struct radv_device *device);

VkResult radv_device_init_meta_blit2d_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_blit2d_state(struct radv_device *device);

VkResult radv_device_init_meta_buffer_state(struct radv_device *device);
void radv_device_finish_meta_buffer_state(struct radv_device *device);

VkResult radv_device_init_meta_query_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_query_state(struct radv_device *device);

VkResult radv_device_init_meta_resolve_compute_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_resolve_compute_state(struct radv_device *device);

VkResult radv_device_init_meta_resolve_fragment_state(struct radv_device *device, bool on_demand);
void radv_device_finish_meta_resolve_fragment_state(struct radv_device *device);

VkResult radv_device_init_meta_fmask_expand_state(struct radv_device *device);
void radv_device_finish_meta_fmask_expand_state(struct radv_device *device);

void radv_meta_save(struct radv_meta_saved_state *saved_state,
		    struct radv_cmd_buffer *cmd_buffer, uint32_t flags);

void radv_meta_restore(const struct radv_meta_saved_state *state,
		       struct radv_cmd_buffer *cmd_buffer);

VkImageViewType radv_meta_get_view_type(const struct radv_image *image);

uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
				   const VkImageSubresourceLayers *dest_subresource,
				   const VkOffset3D *dest_offset);

struct radv_meta_blit2d_surf {
	/** The size of an element in bytes. */
	uint8_t bs;
	VkFormat format;

	struct radv_image *image;
	unsigned level;
	unsigned layer;
	VkImageAspectFlags aspect_mask;
	VkImageLayout current_layout;
};

struct radv_meta_blit2d_buffer {
	struct radv_buffer *buffer;
	uint32_t offset;
	uint32_t pitch;
	uint8_t bs;
	VkFormat format;
};

struct radv_meta_blit2d_rect {
	uint32_t src_x, src_y;
	uint32_t dst_x, dst_y;
	uint32_t width, height;
};

void radv_meta_begin_blit2d(struct radv_cmd_buffer *cmd_buffer,
			    struct radv_meta_saved_state *save);

void radv_meta_blit2d(struct radv_cmd_buffer *cmd_buffer,
		      struct radv_meta_blit2d_surf *src_img,
		      struct radv_meta_blit2d_buffer *src_buf,
		      struct radv_meta_blit2d_surf *dst,
		      unsigned num_rects,
		      struct radv_meta_blit2d_rect *rects);

void radv_meta_end_blit2d(struct radv_cmd_buffer *cmd_buffer,
			  struct radv_meta_saved_state *save);


VkResult radv_device_init_meta_bufimage_state(struct radv_device *device);
void radv_device_finish_meta_bufimage_state(struct radv_device *device);
void radv_meta_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
			       struct radv_meta_blit2d_surf *src,
			       struct radv_meta_blit2d_buffer *dst,
			       unsigned num_rects,
			       struct radv_meta_blit2d_rect *rects);

void radv_meta_buffer_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
				  struct radv_meta_blit2d_buffer *src,
				  struct radv_meta_blit2d_surf *dst,
				  unsigned num_rects,
				  struct radv_meta_blit2d_rect *rects);
void radv_meta_image_to_image_cs(struct radv_cmd_buffer *cmd_buffer,
				 struct radv_meta_blit2d_surf *src,
				 struct radv_meta_blit2d_surf *dst,
				 unsigned num_rects,
				 struct radv_meta_blit2d_rect *rects);
void radv_meta_clear_image_cs(struct radv_cmd_buffer *cmd_buffer,
			      struct radv_meta_blit2d_surf *dst,
			      const VkClearColorValue *clear_color);

void radv_decompress_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
					 struct radv_image *image,
					 const VkImageSubresourceRange *subresourceRange,
					 struct radv_sample_locations_state *sample_locs);
void radv_resummarize_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
					  struct radv_image *image,
					  const VkImageSubresourceRange *subresourceRange,
					  struct radv_sample_locations_state *sample_locs);
void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
					 struct radv_image *image,
					 const VkImageSubresourceRange *subresourceRange);
void radv_decompress_dcc(struct radv_cmd_buffer *cmd_buffer,
			struct radv_image *image,
                        const VkImageSubresourceRange *subresourceRange);
void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer,
				     struct radv_image *image,
				     const VkImageSubresourceRange *subresourceRange);

void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
				     struct radv_image *src_image,
				     VkFormat src_format,
				     VkImageLayout src_image_layout,
				     struct radv_image *dest_image,
				     VkFormat dest_format,
				     VkImageLayout dest_image_layout,
				     uint32_t region_count,
				     const VkImageResolve *regions);

void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
				      struct radv_image *src_image,
				      VkImageLayout src_image_layout,
				      struct radv_image *dest_image,
				      VkImageLayout dest_image_layout,
				      uint32_t region_count,
				      const VkImageResolve *regions);

void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);

void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
				 struct radv_image *src_image,
				 VkImageLayout src_image_layout,
				 uint32_t region_count,
				 const VkImageResolve *regions);

uint32_t radv_clear_cmask(struct radv_cmd_buffer *cmd_buffer,
			  struct radv_image *image,
			  const VkImageSubresourceRange *range, uint32_t value);
uint32_t radv_clear_fmask(struct radv_cmd_buffer *cmd_buffer,
			  struct radv_image *image,
			  const VkImageSubresourceRange *range, uint32_t value);
uint32_t radv_clear_dcc(struct radv_cmd_buffer *cmd_buffer,
			struct radv_image *image,
			const VkImageSubresourceRange *range, uint32_t value);
uint32_t radv_clear_htile(struct radv_cmd_buffer *cmd_buffer,
			  struct radv_image *image,
			  const VkImageSubresourceRange *range, uint32_t value);

/**
 * Return whether the bound pipeline is the FMASK decompress pass.
 */
static inline bool
radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
{
	struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
	struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;

	return radv_pipeline_to_handle(pipeline) ==
	       meta_state->fast_clear_flush.fmask_decompress_pipeline;
}

/**
 * Return whether the bound pipeline is the DCC decompress pass.
 */
static inline bool
radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer *cmd_buffer)
{
	struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
	struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;

	return radv_pipeline_to_handle(pipeline) ==
	       meta_state->fast_clear_flush.dcc_decompress_pipeline;
}

/* common nir builder helpers */
#include "nir/nir_builder.h"

nir_ssa_def *radv_meta_gen_rect_vertices(nir_builder *vs_b);
nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2);
nir_shader *radv_meta_build_nir_vs_generate_vertices(void);
nir_shader *radv_meta_build_nir_fs_noop(void);

void radv_meta_build_resolve_shader_core(nir_builder *b,
					 bool is_integer,
					 int samples,
					 nir_variable *input_img,
					 nir_variable *color,
					 nir_ssa_def *img_coord);
#ifdef __cplusplus
}
#endif

#endif /* RADV_META_H */