radv: Make fs key exemplars ordered to be a reverse fs_key lookup.
[mesa.git] / src / amd / vulkan / radv_meta_resolve_fs.c
1 /*
2 * Copyright © 2016 Dave Airlie
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24
25 #include <assert.h>
26 #include <stdbool.h>
27
28 #include "radv_meta.h"
29 #include "radv_private.h"
30 #include "nir/nir_builder.h"
31 #include "sid.h"
32 #include "vk_format.h"
33
34 static nir_shader *
35 build_nir_vertex_shader(void)
36 {
37 const struct glsl_type *vec4 = glsl_vec4_type();
38 nir_builder b;
39
40 nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_VERTEX, NULL);
41 b.shader->info.name = ralloc_strdup(b.shader, "meta_resolve_vs");
42
43 nir_variable *pos_out = nir_variable_create(b.shader, nir_var_shader_out,
44 vec4, "gl_Position");
45 pos_out->data.location = VARYING_SLOT_POS;
46
47 nir_ssa_def *outvec = radv_meta_gen_rect_vertices(&b);
48
49 nir_store_var(&b, pos_out, outvec, 0xf);
50 return b.shader;
51 }
52
53 static nir_shader *
54 build_resolve_fragment_shader(struct radv_device *dev, bool is_integer, int samples)
55 {
56 nir_builder b;
57 char name[64];
58 const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
59 const struct glsl_type *vec4 = glsl_vec4_type();
60 const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_SAMPLER_DIM_MS,
61 false,
62 false,
63 GLSL_TYPE_FLOAT);
64
65 snprintf(name, 64, "meta_resolve_fs-%d-%s", samples, is_integer ? "int" : "float");
66 nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL);
67 b.shader->info.name = ralloc_strdup(b.shader, name);
68
69 nir_variable *input_img = nir_variable_create(b.shader, nir_var_uniform,
70 sampler_type, "s_tex");
71 input_img->data.descriptor_set = 0;
72 input_img->data.binding = 0;
73
74 nir_variable *fs_pos_in = nir_variable_create(b.shader, nir_var_shader_in, vec2, "fs_pos_in");
75 fs_pos_in->data.location = VARYING_SLOT_POS;
76
77 nir_variable *color_out = nir_variable_create(b.shader, nir_var_shader_out,
78 vec4, "f_color");
79 color_out->data.location = FRAG_RESULT_DATA0;
80
81 nir_ssa_def *pos_in = nir_load_var(&b, fs_pos_in);
82 nir_intrinsic_instr *src_offset = nir_intrinsic_instr_create(b.shader, nir_intrinsic_load_push_constant);
83 nir_intrinsic_set_base(src_offset, 0);
84 nir_intrinsic_set_range(src_offset, 8);
85 src_offset->src[0] = nir_src_for_ssa(nir_imm_int(&b, 0));
86 src_offset->num_components = 2;
87 nir_ssa_dest_init(&src_offset->instr, &src_offset->dest, 2, 32, "src_offset");
88 nir_builder_instr_insert(&b, &src_offset->instr);
89
90 nir_ssa_def *pos_int = nir_f2i32(&b, pos_in);
91
92 nir_ssa_def *img_coord = nir_channels(&b, nir_iadd(&b, pos_int, &src_offset->dest.ssa), 0x3);
93 nir_variable *color = nir_local_variable_create(b.impl, glsl_vec4_type(), "color");
94
95 radv_meta_build_resolve_shader_core(&b, is_integer, samples, input_img,
96 color, img_coord);
97
98 nir_ssa_def *outval = nir_load_var(&b, color);
99 nir_store_var(&b, color_out, outval, 0xf);
100 return b.shader;
101 }
102
103
104 static VkResult
105 create_layout(struct radv_device *device)
106 {
107 VkResult result;
108 /*
109 * one descriptors for the image being sampled
110 */
111 VkDescriptorSetLayoutCreateInfo ds_create_info = {
112 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
113 .flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR,
114 .bindingCount = 1,
115 .pBindings = (VkDescriptorSetLayoutBinding[]) {
116 {
117 .binding = 0,
118 .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
119 .descriptorCount = 1,
120 .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
121 .pImmutableSamplers = NULL
122 },
123 }
124 };
125
126 result = radv_CreateDescriptorSetLayout(radv_device_to_handle(device),
127 &ds_create_info,
128 &device->meta_state.alloc,
129 &device->meta_state.resolve_fragment.ds_layout);
130 if (result != VK_SUCCESS)
131 goto fail;
132
133
134 VkPipelineLayoutCreateInfo pl_create_info = {
135 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
136 .setLayoutCount = 1,
137 .pSetLayouts = &device->meta_state.resolve_fragment.ds_layout,
138 .pushConstantRangeCount = 1,
139 .pPushConstantRanges = &(VkPushConstantRange){VK_SHADER_STAGE_FRAGMENT_BIT, 0, 8},
140 };
141
142 result = radv_CreatePipelineLayout(radv_device_to_handle(device),
143 &pl_create_info,
144 &device->meta_state.alloc,
145 &device->meta_state.resolve_fragment.p_layout);
146 if (result != VK_SUCCESS)
147 goto fail;
148 return VK_SUCCESS;
149 fail:
150 return result;
151 }
152
153 static const VkPipelineVertexInputStateCreateInfo normal_vi_create_info = {
154 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
155 .vertexBindingDescriptionCount = 0,
156 .vertexAttributeDescriptionCount = 0,
157 };
158
159 static VkResult
160 create_resolve_pipeline(struct radv_device *device,
161 int samples_log2,
162 VkFormat format)
163 {
164 VkResult result;
165 bool is_integer = false;
166 uint32_t samples = 1 << samples_log2;
167 unsigned fs_key = radv_format_meta_fs_key(format);
168 const VkPipelineVertexInputStateCreateInfo *vi_create_info;
169 vi_create_info = &normal_vi_create_info;
170 if (vk_format_is_int(format))
171 is_integer = true;
172
173 struct radv_shader_module fs = { .nir = NULL };
174 fs.nir = build_resolve_fragment_shader(device, is_integer, samples);
175 struct radv_shader_module vs = {
176 .nir = build_nir_vertex_shader(),
177 };
178
179 VkRenderPass *rp = &device->meta_state.resolve_fragment.rc[samples_log2].render_pass[fs_key][0];
180
181 assert(!*rp);
182
183 VkPipeline *pipeline = &device->meta_state.resolve_fragment.rc[samples_log2].pipeline[fs_key];
184 assert(!*pipeline);
185
186 VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = {
187 {
188 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
189 .stage = VK_SHADER_STAGE_VERTEX_BIT,
190 .module = radv_shader_module_to_handle(&vs),
191 .pName = "main",
192 .pSpecializationInfo = NULL
193 }, {
194 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
195 .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
196 .module = radv_shader_module_to_handle(&fs),
197 .pName = "main",
198 .pSpecializationInfo = NULL
199 },
200 };
201
202
203 for (unsigned dst_layout = 0; dst_layout < RADV_META_DST_LAYOUT_COUNT; ++dst_layout) {
204 VkImageLayout layout = radv_meta_dst_layout_to_layout(dst_layout);
205 result = radv_CreateRenderPass(radv_device_to_handle(device),
206 &(VkRenderPassCreateInfo) {
207 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
208 .attachmentCount = 1,
209 .pAttachments = &(VkAttachmentDescription) {
210 .format = format,
211 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
212 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
213 .initialLayout = layout,
214 .finalLayout = layout,
215 },
216 .subpassCount = 1,
217 .pSubpasses = &(VkSubpassDescription) {
218 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
219 .inputAttachmentCount = 0,
220 .colorAttachmentCount = 1,
221 .pColorAttachments = &(VkAttachmentReference) {
222 .attachment = 0,
223 .layout = layout,
224 },
225 .pResolveAttachments = NULL,
226 .pDepthStencilAttachment = &(VkAttachmentReference) {
227 .attachment = VK_ATTACHMENT_UNUSED,
228 .layout = VK_IMAGE_LAYOUT_GENERAL,
229 },
230 .preserveAttachmentCount = 1,
231 .pPreserveAttachments = (uint32_t[]) { 0 },
232 },
233 .dependencyCount = 0,
234 }, &device->meta_state.alloc, rp + dst_layout);
235 }
236
237
238 const VkGraphicsPipelineCreateInfo vk_pipeline_info = {
239 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
240 .stageCount = ARRAY_SIZE(pipeline_shader_stages),
241 .pStages = pipeline_shader_stages,
242 .pVertexInputState = vi_create_info,
243 .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
244 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
245 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
246 .primitiveRestartEnable = false,
247 },
248 .pViewportState = &(VkPipelineViewportStateCreateInfo) {
249 .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
250 .viewportCount = 1,
251 .scissorCount = 1,
252 },
253 .pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
254 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
255 .rasterizerDiscardEnable = false,
256 .polygonMode = VK_POLYGON_MODE_FILL,
257 .cullMode = VK_CULL_MODE_NONE,
258 .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE
259 },
260 .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
261 .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
262 .rasterizationSamples = 1,
263 .sampleShadingEnable = false,
264 .pSampleMask = (VkSampleMask[]) { UINT32_MAX },
265 },
266 .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
267 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
268 .attachmentCount = 1,
269 .pAttachments = (VkPipelineColorBlendAttachmentState []) {
270 { .colorWriteMask =
271 VK_COLOR_COMPONENT_A_BIT |
272 VK_COLOR_COMPONENT_R_BIT |
273 VK_COLOR_COMPONENT_G_BIT |
274 VK_COLOR_COMPONENT_B_BIT },
275 }
276 },
277 .pDynamicState = &(VkPipelineDynamicStateCreateInfo) {
278 .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
279 .dynamicStateCount = 9,
280 .pDynamicStates = (VkDynamicState[]) {
281 VK_DYNAMIC_STATE_VIEWPORT,
282 VK_DYNAMIC_STATE_SCISSOR,
283 VK_DYNAMIC_STATE_LINE_WIDTH,
284 VK_DYNAMIC_STATE_DEPTH_BIAS,
285 VK_DYNAMIC_STATE_BLEND_CONSTANTS,
286 VK_DYNAMIC_STATE_DEPTH_BOUNDS,
287 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
288 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
289 VK_DYNAMIC_STATE_STENCIL_REFERENCE,
290 },
291 },
292 .flags = 0,
293 .layout = device->meta_state.resolve_fragment.p_layout,
294 .renderPass = *rp,
295 .subpass = 0,
296 };
297
298 const struct radv_graphics_pipeline_create_info radv_pipeline_info = {
299 .use_rectlist = true
300 };
301
302 result = radv_graphics_pipeline_create(radv_device_to_handle(device),
303 radv_pipeline_cache_to_handle(&device->meta_state.cache),
304 &vk_pipeline_info, &radv_pipeline_info,
305 &device->meta_state.alloc,
306 pipeline);
307 ralloc_free(vs.nir);
308 ralloc_free(fs.nir);
309
310 return result;
311 }
312
313 VkResult
314 radv_device_init_meta_resolve_fragment_state(struct radv_device *device)
315 {
316 VkResult res;
317
318 res = create_layout(device);
319 if (res != VK_SUCCESS)
320 goto fail;
321
322 for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
323 for (unsigned j = 0; j < NUM_META_FS_KEYS; ++j) {
324 res = create_resolve_pipeline(device, i, radv_fs_key_format_exemplars[j]);
325 if (res != VK_SUCCESS)
326 goto fail;
327 }
328 }
329
330 return VK_SUCCESS;
331 fail:
332 radv_device_finish_meta_resolve_fragment_state(device);
333 return res;
334 }
335
336 void
337 radv_device_finish_meta_resolve_fragment_state(struct radv_device *device)
338 {
339 struct radv_meta_state *state = &device->meta_state;
340 for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
341 for (unsigned j = 0; j < NUM_META_FS_KEYS; ++j) {
342 for(unsigned k =0; k < RADV_META_DST_LAYOUT_COUNT; ++k) {
343 radv_DestroyRenderPass(radv_device_to_handle(device),
344 state->resolve_fragment.rc[i].render_pass[j][k],
345 &state->alloc);
346 }
347 radv_DestroyPipeline(radv_device_to_handle(device),
348 state->resolve_fragment.rc[i].pipeline[j],
349 &state->alloc);
350 }
351 }
352
353 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
354 state->resolve_fragment.ds_layout,
355 &state->alloc);
356 radv_DestroyPipelineLayout(radv_device_to_handle(device),
357 state->resolve_fragment.p_layout,
358 &state->alloc);
359 }
360
361 static void
362 emit_resolve(struct radv_cmd_buffer *cmd_buffer,
363 struct radv_image_view *src_iview,
364 struct radv_image_view *dest_iview,
365 const VkOffset2D *src_offset,
366 const VkOffset2D *dest_offset,
367 const VkExtent2D *resolve_extent)
368 {
369 struct radv_device *device = cmd_buffer->device;
370 VkCommandBuffer cmd_buffer_h = radv_cmd_buffer_to_handle(cmd_buffer);
371 const uint32_t samples = src_iview->image->info.samples;
372 const uint32_t samples_log2 = ffs(samples) - 1;
373 radv_meta_push_descriptor_set(cmd_buffer,
374 VK_PIPELINE_BIND_POINT_GRAPHICS,
375 cmd_buffer->device->meta_state.resolve_fragment.p_layout,
376 0, /* set */
377 1, /* descriptorWriteCount */
378 (VkWriteDescriptorSet[]) {
379 {
380 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
381 .dstBinding = 0,
382 .dstArrayElement = 0,
383 .descriptorCount = 1,
384 .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
385 .pImageInfo = (VkDescriptorImageInfo[]) {
386 {
387 .sampler = VK_NULL_HANDLE,
388 .imageView = radv_image_view_to_handle(src_iview),
389 .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
390 },
391 }
392 },
393 });
394
395 cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_FLUSH_AND_INV_CB;
396
397 unsigned push_constants[2] = {
398 src_offset->x - dest_offset->x,
399 src_offset->y - dest_offset->y,
400 };
401 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer),
402 device->meta_state.resolve_fragment.p_layout,
403 VK_SHADER_STAGE_FRAGMENT_BIT, 0, 8,
404 push_constants);
405
406 unsigned fs_key = radv_format_meta_fs_key(dest_iview->vk_format);
407 VkPipeline pipeline_h = device->meta_state.resolve_fragment.rc[samples_log2].pipeline[fs_key];
408
409 radv_CmdBindPipeline(cmd_buffer_h, VK_PIPELINE_BIND_POINT_GRAPHICS,
410 pipeline_h);
411
412 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer), 0, 1, &(VkViewport) {
413 .x = dest_offset->x,
414 .y = dest_offset->y,
415 .width = resolve_extent->width,
416 .height = resolve_extent->height,
417 .minDepth = 0.0f,
418 .maxDepth = 1.0f
419 });
420
421 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer), 0, 1, &(VkRect2D) {
422 .offset = *dest_offset,
423 .extent = *resolve_extent,
424 });
425
426 radv_CmdDraw(cmd_buffer_h, 3, 1, 0, 0);
427 cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_FLUSH_AND_INV_CB;
428 }
429
430 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
431 struct radv_image *src_image,
432 VkImageLayout src_image_layout,
433 struct radv_image *dest_image,
434 VkImageLayout dest_image_layout,
435 uint32_t region_count,
436 const VkImageResolve *regions)
437 {
438 struct radv_device *device = cmd_buffer->device;
439 struct radv_meta_saved_state saved_state;
440 const uint32_t samples = src_image->info.samples;
441 const uint32_t samples_log2 = ffs(samples) - 1;
442 unsigned fs_key = radv_format_meta_fs_key(dest_image->vk_format);
443 unsigned dst_layout = radv_meta_dst_layout_from_layout(dest_image_layout);
444 VkRenderPass rp;
445
446 radv_decompress_resolve_src(cmd_buffer, src_image, src_image_layout,
447 region_count, regions);
448
449 rp = device->meta_state.resolve_fragment.rc[samples_log2].render_pass[fs_key][dst_layout];
450
451 radv_meta_save(&saved_state, cmd_buffer,
452 RADV_META_SAVE_GRAPHICS_PIPELINE |
453 RADV_META_SAVE_CONSTANTS |
454 RADV_META_SAVE_DESCRIPTORS);
455
456 for (uint32_t r = 0; r < region_count; ++r) {
457 const VkImageResolve *region = &regions[r];
458
459 assert(region->srcSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
460 assert(region->dstSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
461 assert(region->srcSubresource.layerCount == region->dstSubresource.layerCount);
462
463 const uint32_t src_base_layer =
464 radv_meta_get_iview_layer(src_image, &region->srcSubresource,
465 &region->srcOffset);
466
467 const uint32_t dest_base_layer =
468 radv_meta_get_iview_layer(dest_image, &region->dstSubresource,
469 &region->dstOffset);
470
471 const struct VkExtent3D extent =
472 radv_sanitize_image_extent(src_image->type, region->extent);
473 const struct VkOffset3D srcOffset =
474 radv_sanitize_image_offset(src_image->type, region->srcOffset);
475 const struct VkOffset3D dstOffset =
476 radv_sanitize_image_offset(dest_image->type, region->dstOffset);
477
478 for (uint32_t layer = 0; layer < region->srcSubresource.layerCount;
479 ++layer) {
480
481 struct radv_image_view src_iview;
482 radv_image_view_init(&src_iview, cmd_buffer->device,
483 &(VkImageViewCreateInfo) {
484 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
485 .image = radv_image_to_handle(src_image),
486 .viewType = radv_meta_get_view_type(src_image),
487 .format = src_image->vk_format,
488 .subresourceRange = {
489 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
490 .baseMipLevel = region->srcSubresource.mipLevel,
491 .levelCount = 1,
492 .baseArrayLayer = src_base_layer + layer,
493 .layerCount = 1,
494 },
495 });
496
497 struct radv_image_view dest_iview;
498 radv_image_view_init(&dest_iview, cmd_buffer->device,
499 &(VkImageViewCreateInfo) {
500 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
501 .image = radv_image_to_handle(dest_image),
502 .viewType = radv_meta_get_view_type(dest_image),
503 .format = dest_image->vk_format,
504 .subresourceRange = {
505 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
506 .baseMipLevel = region->dstSubresource.mipLevel,
507 .levelCount = 1,
508 .baseArrayLayer = dest_base_layer + layer,
509 .layerCount = 1,
510 },
511 });
512
513
514 VkFramebuffer fb;
515 radv_CreateFramebuffer(radv_device_to_handle(cmd_buffer->device),
516 &(VkFramebufferCreateInfo) {
517 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
518 .attachmentCount = 1,
519 .pAttachments = (VkImageView[]) {
520 radv_image_view_to_handle(&dest_iview),
521 },
522 .width = extent.width + dstOffset.x,
523 .height = extent.height + dstOffset.y,
524 .layers = 1
525 }, &cmd_buffer->pool->alloc, &fb);
526
527 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer),
528 &(VkRenderPassBeginInfo) {
529 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
530 .renderPass = rp,
531 .framebuffer = fb,
532 .renderArea = {
533 .offset = { dstOffset.x, dstOffset.y, },
534 .extent = { extent.width, extent.height },
535 },
536 .clearValueCount = 0,
537 .pClearValues = NULL,
538 }, VK_SUBPASS_CONTENTS_INLINE);
539
540
541
542 emit_resolve(cmd_buffer,
543 &src_iview,
544 &dest_iview,
545 &(VkOffset2D) { srcOffset.x, srcOffset.y },
546 &(VkOffset2D) { dstOffset.x, dstOffset.y },
547 &(VkExtent2D) { extent.width, extent.height });
548
549 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer));
550
551 radv_DestroyFramebuffer(radv_device_to_handle(cmd_buffer->device), fb, &cmd_buffer->pool->alloc);
552 }
553 }
554
555 radv_meta_restore(&saved_state, cmd_buffer);
556 }
557
558
559 /**
560 * Emit any needed resolves for the current subpass.
561 */
562 void
563 radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer)
564 {
565 struct radv_framebuffer *fb = cmd_buffer->state.framebuffer;
566 const struct radv_subpass *subpass = cmd_buffer->state.subpass;
567 struct radv_meta_saved_state saved_state;
568 struct radv_subpass_barrier barrier;
569
570 /* Resolves happen before the end-of-subpass barriers get executed,
571 * so we have to make the attachment shader-readable */
572 barrier.src_stage_mask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
573 barrier.src_access_mask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
574 barrier.dst_access_mask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
575 radv_subpass_barrier(cmd_buffer, &barrier);
576
577 radv_decompress_resolve_subpass_src(cmd_buffer);
578
579 radv_meta_save(&saved_state, cmd_buffer,
580 RADV_META_SAVE_GRAPHICS_PIPELINE |
581 RADV_META_SAVE_CONSTANTS |
582 RADV_META_SAVE_DESCRIPTORS);
583
584 for (uint32_t i = 0; i < subpass->color_count; ++i) {
585 struct radv_subpass_attachment src_att = subpass->color_attachments[i];
586 struct radv_subpass_attachment dest_att = subpass->resolve_attachments[i];
587
588 if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
589 dest_att.attachment == VK_ATTACHMENT_UNUSED)
590 continue;
591
592 struct radv_image_view *dest_iview = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment;
593 struct radv_image_view *src_iview = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment;
594
595 struct radv_subpass resolve_subpass = {
596 .color_count = 1,
597 .color_attachments = (struct radv_subpass_attachment[]) { dest_att },
598 .depth_stencil_attachment = { .attachment = VK_ATTACHMENT_UNUSED },
599 };
600
601 radv_cmd_buffer_set_subpass(cmd_buffer, &resolve_subpass, false);
602
603 emit_resolve(cmd_buffer,
604 src_iview,
605 dest_iview,
606 &(VkOffset2D) { 0, 0 },
607 &(VkOffset2D) { 0, 0 },
608 &(VkExtent2D) { fb->width, fb->height });
609 }
610
611 cmd_buffer->state.subpass = subpass;
612 radv_meta_restore(&saved_state, cmd_buffer);
613 }