2 * Copyright © 2016 Dave Airlie
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:
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
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
28 #include "radv_meta.h"
29 #include "radv_private.h"
30 #include "nir/nir_builder.h"
32 #include "vk_format.h"
35 build_nir_vertex_shader(void)
37 const struct glsl_type
*vec4
= glsl_vec4_type();
40 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
41 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "meta_resolve_vs");
43 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
45 pos_out
->data
.location
= VARYING_SLOT_POS
;
47 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices(&b
);
49 nir_store_var(&b
, pos_out
, outvec
, 0xf);
54 build_resolve_fragment_shader(struct radv_device
*dev
, bool is_integer
, bool is_srgb
, int samples
)
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
,
65 snprintf(name
, 64, "meta_resolve_fs-%d-%s", samples
, is_integer
? "int" : (is_srgb
? "srgb" : "float"));
66 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
67 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, name
);
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;
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
;
77 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
79 color_out
->data
.location
= FRAG_RESULT_DATA0
;
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
);
90 nir_ssa_def
*pos_int
= nir_f2i32(&b
, pos_in
);
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");
95 radv_meta_build_resolve_shader_core(&b
, is_integer
, is_srgb
,samples
,
96 input_img
, color
, img_coord
);
98 nir_ssa_def
*outval
= nir_load_var(&b
, color
);
99 nir_store_var(&b
, color_out
, outval
, 0xf);
105 create_layout(struct radv_device
*device
)
109 * one descriptors for the image being sampled
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
,
115 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
118 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
119 .descriptorCount
= 1,
120 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
121 .pImmutableSamplers
= NULL
126 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
128 &device
->meta_state
.alloc
,
129 &device
->meta_state
.resolve_fragment
.ds_layout
);
130 if (result
!= VK_SUCCESS
)
134 VkPipelineLayoutCreateInfo pl_create_info
= {
135 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
137 .pSetLayouts
= &device
->meta_state
.resolve_fragment
.ds_layout
,
138 .pushConstantRangeCount
= 1,
139 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_FRAGMENT_BIT
, 0, 8},
142 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
144 &device
->meta_state
.alloc
,
145 &device
->meta_state
.resolve_fragment
.p_layout
);
146 if (result
!= VK_SUCCESS
)
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,
159 static VkFormat pipeline_formats
[] = {
160 VK_FORMAT_R8G8B8A8_UNORM
,
161 VK_FORMAT_R8G8B8A8_UINT
,
162 VK_FORMAT_R8G8B8A8_SINT
,
163 VK_FORMAT_R16G16B16A16_UNORM
,
164 VK_FORMAT_R16G16B16A16_SNORM
,
165 VK_FORMAT_R16G16B16A16_UINT
,
166 VK_FORMAT_R16G16B16A16_SINT
,
167 VK_FORMAT_R32_SFLOAT
,
168 VK_FORMAT_R32G32_SFLOAT
,
169 VK_FORMAT_R32G32B32A32_SFLOAT
173 create_resolve_pipeline(struct radv_device
*device
,
178 bool is_integer
= false, is_srgb
= false;
179 uint32_t samples
= 1 << samples_log2
;
180 unsigned fs_key
= radv_format_meta_fs_key(format
);
181 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
182 vi_create_info
= &normal_vi_create_info
;
183 if (vk_format_is_int(format
))
185 else if (vk_format_is_srgb(format
))
188 struct radv_shader_module fs
= { .nir
= NULL
};
189 fs
.nir
= build_resolve_fragment_shader(device
, is_integer
, is_srgb
, samples
);
190 struct radv_shader_module vs
= {
191 .nir
= build_nir_vertex_shader(),
194 VkRenderPass
*rp
= is_srgb
?
195 &device
->meta_state
.resolve_fragment
.rc
[samples_log2
].srgb_render_pass
:
196 &device
->meta_state
.resolve_fragment
.rc
[samples_log2
].render_pass
[fs_key
];
200 VkPipeline
*pipeline
= is_srgb
?
201 &device
->meta_state
.resolve_fragment
.rc
[samples_log2
].srgb_pipeline
:
202 &device
->meta_state
.resolve_fragment
.rc
[samples_log2
].pipeline
[fs_key
];
205 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
207 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
208 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
209 .module
= radv_shader_module_to_handle(&vs
),
211 .pSpecializationInfo
= NULL
213 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
214 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
215 .module
= radv_shader_module_to_handle(&fs
),
217 .pSpecializationInfo
= NULL
222 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
223 &(VkRenderPassCreateInfo
) {
224 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
225 .attachmentCount
= 1,
226 .pAttachments
= &(VkAttachmentDescription
) {
228 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
229 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
230 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
231 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
234 .pSubpasses
= &(VkSubpassDescription
) {
235 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
236 .inputAttachmentCount
= 0,
237 .colorAttachmentCount
= 1,
238 .pColorAttachments
= &(VkAttachmentReference
) {
240 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
242 .pResolveAttachments
= NULL
,
243 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
244 .attachment
= VK_ATTACHMENT_UNUSED
,
245 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
247 .preserveAttachmentCount
= 1,
248 .pPreserveAttachments
= (uint32_t[]) { 0 },
250 .dependencyCount
= 0,
251 }, &device
->meta_state
.alloc
, rp
);
254 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
255 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
256 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
257 .pStages
= pipeline_shader_stages
,
258 .pVertexInputState
= vi_create_info
,
259 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
260 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
261 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
262 .primitiveRestartEnable
= false,
264 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
265 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
269 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
270 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
271 .rasterizerDiscardEnable
= false,
272 .polygonMode
= VK_POLYGON_MODE_FILL
,
273 .cullMode
= VK_CULL_MODE_NONE
,
274 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
276 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
277 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
278 .rasterizationSamples
= 1,
279 .sampleShadingEnable
= false,
280 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
282 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
283 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
284 .attachmentCount
= 1,
285 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
287 VK_COLOR_COMPONENT_A_BIT
|
288 VK_COLOR_COMPONENT_R_BIT
|
289 VK_COLOR_COMPONENT_G_BIT
|
290 VK_COLOR_COMPONENT_B_BIT
},
293 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
294 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
295 .dynamicStateCount
= 9,
296 .pDynamicStates
= (VkDynamicState
[]) {
297 VK_DYNAMIC_STATE_VIEWPORT
,
298 VK_DYNAMIC_STATE_SCISSOR
,
299 VK_DYNAMIC_STATE_LINE_WIDTH
,
300 VK_DYNAMIC_STATE_DEPTH_BIAS
,
301 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
302 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
303 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
304 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
305 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
309 .layout
= device
->meta_state
.resolve_fragment
.p_layout
,
314 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
318 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
319 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
320 &vk_pipeline_info
, &radv_pipeline_info
,
321 &device
->meta_state
.alloc
,
326 if (result
!= VK_SUCCESS
)
337 radv_device_init_meta_resolve_fragment_state(struct radv_device
*device
)
339 struct radv_meta_state
*state
= &device
->meta_state
;
341 memset(&state
->resolve_fragment
, 0, sizeof(state
->resolve_fragment
));
343 res
= create_layout(device
);
344 if (res
!= VK_SUCCESS
)
347 for (uint32_t i
= 0; i
< MAX_SAMPLES_LOG2
; ++i
) {
348 for (unsigned j
= 0; j
< ARRAY_SIZE(pipeline_formats
); ++j
) {
349 res
= create_resolve_pipeline(device
, i
, pipeline_formats
[j
]);
352 res
= create_resolve_pipeline(device
, i
, VK_FORMAT_R8G8B8A8_SRGB
);
359 radv_device_finish_meta_resolve_fragment_state(struct radv_device
*device
)
361 struct radv_meta_state
*state
= &device
->meta_state
;
362 for (uint32_t i
= 0; i
< MAX_SAMPLES_LOG2
; ++i
) {
363 for (unsigned j
= 0; j
< NUM_META_FS_KEYS
; ++j
) {
364 radv_DestroyRenderPass(radv_device_to_handle(device
),
365 state
->resolve_fragment
.rc
[i
].render_pass
[j
],
367 radv_DestroyPipeline(radv_device_to_handle(device
),
368 state
->resolve_fragment
.rc
[i
].pipeline
[j
],
371 radv_DestroyRenderPass(radv_device_to_handle(device
),
372 state
->resolve_fragment
.rc
[i
].srgb_render_pass
,
374 radv_DestroyPipeline(radv_device_to_handle(device
),
375 state
->resolve_fragment
.rc
[i
].srgb_pipeline
,
379 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
380 state
->resolve_fragment
.ds_layout
,
382 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
383 state
->resolve_fragment
.p_layout
,
388 emit_resolve(struct radv_cmd_buffer
*cmd_buffer
,
389 struct radv_image_view
*src_iview
,
390 struct radv_image_view
*dest_iview
,
391 const VkOffset2D
*src_offset
,
392 const VkOffset2D
*dest_offset
,
393 const VkExtent2D
*resolve_extent
)
395 struct radv_device
*device
= cmd_buffer
->device
;
396 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
397 const uint32_t samples
= src_iview
->image
->info
.samples
;
398 const uint32_t samples_log2
= ffs(samples
) - 1;
399 radv_meta_push_descriptor_set(cmd_buffer
,
400 VK_PIPELINE_BIND_POINT_GRAPHICS
,
401 cmd_buffer
->device
->meta_state
.resolve_fragment
.p_layout
,
403 1, /* descriptorWriteCount */
404 (VkWriteDescriptorSet
[]) {
406 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
408 .dstArrayElement
= 0,
409 .descriptorCount
= 1,
410 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
411 .pImageInfo
= (VkDescriptorImageInfo
[]) {
413 .sampler
= VK_NULL_HANDLE
,
414 .imageView
= radv_image_view_to_handle(src_iview
),
415 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
421 cmd_buffer
->state
.flush_bits
|= RADV_CMD_FLAG_FLUSH_AND_INV_CB
;
423 unsigned push_constants
[2] = {
427 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
428 device
->meta_state
.resolve_fragment
.p_layout
,
429 VK_SHADER_STAGE_FRAGMENT_BIT
, 0, 8,
432 unsigned fs_key
= radv_format_meta_fs_key(dest_iview
->vk_format
);
433 VkPipeline pipeline_h
= vk_format_is_srgb(dest_iview
->vk_format
) ?
434 device
->meta_state
.resolve_fragment
.rc
[samples_log2
].srgb_pipeline
:
435 device
->meta_state
.resolve_fragment
.rc
[samples_log2
].pipeline
[fs_key
];
437 radv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
440 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
443 .width
= resolve_extent
->width
,
444 .height
= resolve_extent
->height
,
449 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
450 .offset
= *dest_offset
,
451 .extent
= *resolve_extent
,
454 radv_CmdDraw(cmd_buffer_h
, 3, 1, 0, 0);
455 cmd_buffer
->state
.flush_bits
|= RADV_CMD_FLAG_FLUSH_AND_INV_CB
;
458 void radv_meta_resolve_fragment_image(struct radv_cmd_buffer
*cmd_buffer
,
459 struct radv_image
*src_image
,
460 VkImageLayout src_image_layout
,
461 struct radv_image
*dest_image
,
462 VkImageLayout dest_image_layout
,
463 uint32_t region_count
,
464 const VkImageResolve
*regions
)
466 struct radv_device
*device
= cmd_buffer
->device
;
467 struct radv_meta_saved_state saved_state
;
468 const uint32_t samples
= src_image
->info
.samples
;
469 const uint32_t samples_log2
= ffs(samples
) - 1;
470 unsigned fs_key
= radv_format_meta_fs_key(dest_image
->vk_format
);
472 for (uint32_t r
= 0; r
< region_count
; ++r
) {
473 const VkImageResolve
*region
= ®ions
[r
];
474 const uint32_t src_base_layer
=
475 radv_meta_get_iview_layer(src_image
, ®ion
->srcSubresource
,
477 VkImageSubresourceRange range
;
478 range
.aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
;
479 range
.baseMipLevel
= region
->srcSubresource
.mipLevel
;
480 range
.levelCount
= 1;
481 range
.baseArrayLayer
= src_base_layer
;
482 range
.layerCount
= region
->srcSubresource
.layerCount
;
483 radv_fast_clear_flush_image_inplace(cmd_buffer
, src_image
, &range
);
486 rp
= vk_format_is_srgb(dest_image
->vk_format
) ?
487 device
->meta_state
.resolve_fragment
.rc
[samples_log2
].srgb_render_pass
:
488 device
->meta_state
.resolve_fragment
.rc
[samples_log2
].render_pass
[fs_key
];
489 radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state
, cmd_buffer
);
491 for (uint32_t r
= 0; r
< region_count
; ++r
) {
492 const VkImageResolve
*region
= ®ions
[r
];
494 assert(region
->srcSubresource
.aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
495 assert(region
->dstSubresource
.aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
496 assert(region
->srcSubresource
.layerCount
== region
->dstSubresource
.layerCount
);
498 const uint32_t src_base_layer
=
499 radv_meta_get_iview_layer(src_image
, ®ion
->srcSubresource
,
502 const uint32_t dest_base_layer
=
503 radv_meta_get_iview_layer(dest_image
, ®ion
->dstSubresource
,
506 const struct VkExtent3D extent
=
507 radv_sanitize_image_extent(src_image
->type
, region
->extent
);
508 const struct VkOffset3D srcOffset
=
509 radv_sanitize_image_offset(src_image
->type
, region
->srcOffset
);
510 const struct VkOffset3D dstOffset
=
511 radv_sanitize_image_offset(dest_image
->type
, region
->dstOffset
);
513 for (uint32_t layer
= 0; layer
< region
->srcSubresource
.layerCount
;
516 struct radv_image_view src_iview
;
517 radv_image_view_init(&src_iview
, cmd_buffer
->device
,
518 &(VkImageViewCreateInfo
) {
519 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
520 .image
= radv_image_to_handle(src_image
),
521 .viewType
= radv_meta_get_view_type(src_image
),
522 .format
= src_image
->vk_format
,
523 .subresourceRange
= {
524 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
525 .baseMipLevel
= region
->srcSubresource
.mipLevel
,
527 .baseArrayLayer
= src_base_layer
+ layer
,
532 struct radv_image_view dest_iview
;
533 radv_image_view_init(&dest_iview
, cmd_buffer
->device
,
534 &(VkImageViewCreateInfo
) {
535 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
536 .image
= radv_image_to_handle(dest_image
),
537 .viewType
= radv_meta_get_view_type(dest_image
),
538 .format
= dest_image
->vk_format
,
539 .subresourceRange
= {
540 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
541 .baseMipLevel
= region
->dstSubresource
.mipLevel
,
543 .baseArrayLayer
= dest_base_layer
+ layer
,
550 radv_CreateFramebuffer(radv_device_to_handle(cmd_buffer
->device
),
551 &(VkFramebufferCreateInfo
) {
552 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
553 .attachmentCount
= 1,
554 .pAttachments
= (VkImageView
[]) {
555 radv_image_view_to_handle(&dest_iview
),
557 .width
= extent
.width
,
558 .height
= extent
.height
,
560 }, &cmd_buffer
->pool
->alloc
, &fb
);
562 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
563 &(VkRenderPassBeginInfo
) {
564 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
568 .offset
= { dstOffset
.x
, dstOffset
.y
, },
569 .extent
= { extent
.width
, extent
.height
},
571 .clearValueCount
= 0,
572 .pClearValues
= NULL
,
573 }, VK_SUBPASS_CONTENTS_INLINE
);
577 emit_resolve(cmd_buffer
,
580 &(VkOffset2D
) { srcOffset
.x
, srcOffset
.y
},
581 &(VkOffset2D
) { dstOffset
.x
, dstOffset
.y
},
582 &(VkExtent2D
) { extent
.width
, extent
.height
});
584 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
));
586 radv_DestroyFramebuffer(radv_device_to_handle(cmd_buffer
->device
), fb
, &cmd_buffer
->pool
->alloc
);
590 radv_meta_restore(&saved_state
, cmd_buffer
);
595 * Emit any needed resolves for the current subpass.
598 radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer
*cmd_buffer
)
600 struct radv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
601 const struct radv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
602 struct radv_meta_saved_state saved_state
;
604 /* FINISHME(perf): Skip clears for resolve attachments.
606 * From the Vulkan 1.0 spec:
608 * If the first use of an attachment in a render pass is as a resolve
609 * attachment, then the loadOp is effectively ignored as the resolve is
610 * guaranteed to overwrite all pixels in the render area.
613 if (!subpass
->has_resolve
)
616 radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state
, cmd_buffer
);
618 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
619 VkAttachmentReference src_att
= subpass
->color_attachments
[i
];
620 VkAttachmentReference dest_att
= subpass
->resolve_attachments
[i
];
622 if (src_att
.attachment
== VK_ATTACHMENT_UNUSED
||
623 dest_att
.attachment
== VK_ATTACHMENT_UNUSED
)
626 struct radv_image_view
*dest_iview
= cmd_buffer
->state
.framebuffer
->attachments
[dest_att
.attachment
].attachment
;
627 struct radv_image
*dst_img
= dest_iview
->image
;
628 struct radv_image_view
*src_iview
= cmd_buffer
->state
.framebuffer
->attachments
[src_att
.attachment
].attachment
;
630 if (dst_img
->surface
.dcc_size
) {
631 radv_initialize_dcc(cmd_buffer
, dst_img
, 0xffffffff);
632 cmd_buffer
->state
.attachments
[dest_att
.attachment
].current_layout
= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
;
635 VkImageSubresourceRange range
;
636 range
.aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
;
637 range
.baseMipLevel
= 0;
638 range
.levelCount
= 1;
639 range
.baseArrayLayer
= 0;
640 range
.layerCount
= 1;
641 radv_fast_clear_flush_image_inplace(cmd_buffer
, src_iview
->image
, &range
);
644 struct radv_subpass resolve_subpass
= {
646 .color_attachments
= (VkAttachmentReference
[]) { dest_att
},
647 .depth_stencil_attachment
= { .attachment
= VK_ATTACHMENT_UNUSED
},
650 radv_cmd_buffer_set_subpass(cmd_buffer
, &resolve_subpass
, false);
652 /* Subpass resolves must respect the render area. We can ignore the
653 * render area here because vkCmdBeginRenderPass set the render area
654 * with 3DSTATE_DRAWING_RECTANGLE.
656 * XXX(chadv): Does the hardware really respect
657 * 3DSTATE_DRAWING_RECTANGLE when draing a 3DPRIM_RECTLIST?
659 emit_resolve(cmd_buffer
,
662 &(VkOffset2D
) { 0, 0 },
663 &(VkOffset2D
) { 0, 0 },
664 &(VkExtent2D
) { fb
->width
, fb
->height
});
667 cmd_buffer
->state
.subpass
= subpass
;
668 radv_meta_restore(&saved_state
, cmd_buffer
);