2 * Copyright © 2016 Red Hat
3 * based on intel anv code:
4 * Copyright © 2015 Intel Corporation
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:
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
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
29 #include "radv_private.h"
30 #include "radv_shader.h"
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),
45 struct radv_meta_saved_state
{
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
;
54 char push_constants
[128];
56 struct radv_render_pass
*pass
;
57 const struct radv_subpass
*subpass
;
58 struct radv_attachment_state
*attachments
;
59 struct radv_framebuffer
*framebuffer
;
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
);
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
);
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
);
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
);
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
);
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
);
81 VkResult
radv_device_init_meta_buffer_state(struct radv_device
*device
);
82 void radv_device_finish_meta_buffer_state(struct radv_device
*device
);
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
);
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
);
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
);
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
);
96 void radv_meta_save(struct radv_meta_saved_state
*saved_state
,
97 struct radv_cmd_buffer
*cmd_buffer
, uint32_t flags
);
99 void radv_meta_restore(const struct radv_meta_saved_state
*state
,
100 struct radv_cmd_buffer
*cmd_buffer
);
102 VkImageViewType
radv_meta_get_view_type(const struct radv_image
*image
);
104 uint32_t radv_meta_get_iview_layer(const struct radv_image
*dest_image
,
105 const VkImageSubresourceLayers
*dest_subresource
,
106 const VkOffset3D
*dest_offset
);
108 struct radv_meta_blit2d_surf
{
109 /** The size of an element in bytes. */
113 struct radv_image
*image
;
116 VkImageAspectFlags aspect_mask
;
117 VkImageLayout current_layout
;
120 struct radv_meta_blit2d_buffer
{
121 struct radv_buffer
*buffer
;
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
;
134 void radv_meta_begin_blit2d(struct radv_cmd_buffer
*cmd_buffer
,
135 struct radv_meta_saved_state
*save
);
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
,
142 struct radv_meta_blit2d_rect
*rects
);
144 void radv_meta_end_blit2d(struct radv_cmd_buffer
*cmd_buffer
,
145 struct radv_meta_saved_state
*save
);
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
,
154 struct radv_meta_blit2d_rect
*rects
);
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
,
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
,
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
);
170 void radv_decompress_depth_stencil(struct radv_cmd_buffer
*cmd_buffer
,
171 struct radv_image
*image
,
172 const VkImageSubresourceRange
*subresourceRange
,
173 struct radv_sample_locations_state
*sample_locs
);
174 void radv_resummarize_depth_stencil(struct radv_cmd_buffer
*cmd_buffer
,
175 struct radv_image
*image
,
176 const 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
);
188 void radv_meta_resolve_compute_image(struct radv_cmd_buffer
*cmd_buffer
,
189 struct radv_image
*src_image
,
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
);
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
);
206 void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer
*cmd_buffer
);
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
);
214 uint32_t radv_clear_cmask(struct radv_cmd_buffer
*cmd_buffer
,
215 struct radv_image
*image
,
216 const VkImageSubresourceRange
*range
, uint32_t value
);
217 uint32_t radv_clear_fmask(struct radv_cmd_buffer
*cmd_buffer
,
218 struct radv_image
*image
,
219 const VkImageSubresourceRange
*range
, uint32_t value
);
220 uint32_t radv_clear_dcc(struct radv_cmd_buffer
*cmd_buffer
,
221 struct radv_image
*image
,
222 const VkImageSubresourceRange
*range
, uint32_t value
);
223 uint32_t radv_clear_htile(struct radv_cmd_buffer
*cmd_buffer
,
224 const struct radv_image
*image
,
225 const VkImageSubresourceRange
*range
, uint32_t value
);
228 * Return whether the bound pipeline is the FMASK decompress pass.
231 radv_is_fmask_decompress_pipeline(struct radv_cmd_buffer
*cmd_buffer
)
233 struct radv_meta_state
*meta_state
= &cmd_buffer
->device
->meta_state
;
234 struct radv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
236 return radv_pipeline_to_handle(pipeline
) ==
237 meta_state
->fast_clear_flush
.fmask_decompress_pipeline
;
241 * Return whether the bound pipeline is the DCC decompress pass.
244 radv_is_dcc_decompress_pipeline(struct radv_cmd_buffer
*cmd_buffer
)
246 struct radv_meta_state
*meta_state
= &cmd_buffer
->device
->meta_state
;
247 struct radv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
249 return radv_pipeline_to_handle(pipeline
) ==
250 meta_state
->fast_clear_flush
.dcc_decompress_pipeline
;
253 /* common nir builder helpers */
254 #include "nir/nir_builder.h"
256 nir_ssa_def
*radv_meta_gen_rect_vertices(nir_builder
*vs_b
);
257 nir_ssa_def
*radv_meta_gen_rect_vertices_comp2(nir_builder
*vs_b
, nir_ssa_def
*comp2
);
258 nir_shader
*radv_meta_build_nir_vs_generate_vertices(void);
259 nir_shader
*radv_meta_build_nir_fs_noop(void);
261 void radv_meta_build_resolve_shader_core(nir_builder
*b
,
264 nir_variable
*input_img
,
266 nir_ssa_def
*img_coord
);
271 #endif /* RADV_META_H */