2 * Copyright © 2016 Intel Corporation
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
27 #include "radv_meta.h"
28 #include "radv_private.h"
32 create_pass(struct radv_device
*device
)
35 VkDevice device_h
= radv_device_to_handle(device
);
36 const VkAllocationCallbacks
*alloc
= &device
->meta_state
.alloc
;
37 VkAttachmentDescription attachment
;
39 attachment
.format
= VK_FORMAT_UNDEFINED
;
40 attachment
.samples
= 1;
41 attachment
.loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
;
42 attachment
.storeOp
= VK_ATTACHMENT_STORE_OP_STORE
;
43 attachment
.initialLayout
= VK_IMAGE_LAYOUT_GENERAL
;
44 attachment
.finalLayout
= VK_IMAGE_LAYOUT_GENERAL
;
46 result
= radv_CreateRenderPass(device_h
,
47 &(VkRenderPassCreateInfo
) {
48 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
50 .pAttachments
= &attachment
,
52 .pSubpasses
= &(VkSubpassDescription
) {
53 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
54 .inputAttachmentCount
= 0,
55 .colorAttachmentCount
= 1,
56 .pColorAttachments
= (VkAttachmentReference
[]) {
59 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
62 .pResolveAttachments
= NULL
,
63 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
64 .attachment
= VK_ATTACHMENT_UNUSED
,
66 .preserveAttachmentCount
= 0,
67 .pPreserveAttachments
= NULL
,
72 &device
->meta_state
.fast_clear_flush
.pass
);
78 create_pipeline(struct radv_device
*device
,
79 VkShaderModule vs_module_h
)
82 VkDevice device_h
= radv_device_to_handle(device
);
84 struct radv_shader_module fs_module
= {
85 .nir
= radv_meta_build_nir_fs_noop(),
89 /* XXX: Need more accurate error */
90 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
94 const VkPipelineShaderStageCreateInfo stages
[2] = {
96 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
97 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
98 .module
= vs_module_h
,
102 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
103 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
104 .module
= radv_shader_module_to_handle(&fs_module
),
109 const VkPipelineVertexInputStateCreateInfo vi_state
= {
110 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
111 .vertexBindingDescriptionCount
= 0,
112 .vertexAttributeDescriptionCount
= 0,
115 const VkPipelineInputAssemblyStateCreateInfo ia_state
= {
116 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
117 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
118 .primitiveRestartEnable
= false,
121 const VkPipelineColorBlendStateCreateInfo blend_state
= {
122 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
123 .logicOpEnable
= false,
124 .attachmentCount
= 1,
125 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
127 .colorWriteMask
= VK_COLOR_COMPONENT_R_BIT
|
128 VK_COLOR_COMPONENT_G_BIT
|
129 VK_COLOR_COMPONENT_B_BIT
|
130 VK_COLOR_COMPONENT_A_BIT
,
134 const VkPipelineRasterizationStateCreateInfo rs_state
= {
135 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
136 .depthClampEnable
= false,
137 .rasterizerDiscardEnable
= false,
138 .polygonMode
= VK_POLYGON_MODE_FILL
,
139 .cullMode
= VK_CULL_MODE_NONE
,
140 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
,
143 result
= radv_graphics_pipeline_create(device_h
,
144 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
145 &(VkGraphicsPipelineCreateInfo
) {
146 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
150 .pVertexInputState
= &vi_state
,
151 .pInputAssemblyState
= &ia_state
,
153 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
154 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
158 .pRasterizationState
= &rs_state
,
159 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
160 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
161 .rasterizationSamples
= 1,
162 .sampleShadingEnable
= false,
164 .alphaToCoverageEnable
= false,
165 .alphaToOneEnable
= false,
167 .pColorBlendState
= &blend_state
,
168 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
169 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
170 .dynamicStateCount
= 2,
171 .pDynamicStates
= (VkDynamicState
[]) {
172 VK_DYNAMIC_STATE_VIEWPORT
,
173 VK_DYNAMIC_STATE_SCISSOR
,
176 .renderPass
= device
->meta_state
.fast_clear_flush
.pass
,
179 &(struct radv_graphics_pipeline_create_info
) {
180 .use_rectlist
= true,
181 .custom_blend_mode
= V_028808_CB_ELIMINATE_FAST_CLEAR
,
183 &device
->meta_state
.alloc
,
184 &device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
);
185 if (result
!= VK_SUCCESS
)
188 result
= radv_graphics_pipeline_create(device_h
,
189 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
190 &(VkGraphicsPipelineCreateInfo
) {
191 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
195 .pVertexInputState
= &vi_state
,
196 .pInputAssemblyState
= &ia_state
,
198 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
199 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
203 .pRasterizationState
= &rs_state
,
204 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
205 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
206 .rasterizationSamples
= 1,
207 .sampleShadingEnable
= false,
209 .alphaToCoverageEnable
= false,
210 .alphaToOneEnable
= false,
212 .pColorBlendState
= &blend_state
,
213 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
214 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
215 .dynamicStateCount
= 2,
216 .pDynamicStates
= (VkDynamicState
[]) {
217 VK_DYNAMIC_STATE_VIEWPORT
,
218 VK_DYNAMIC_STATE_SCISSOR
,
221 .renderPass
= device
->meta_state
.fast_clear_flush
.pass
,
224 &(struct radv_graphics_pipeline_create_info
) {
225 .use_rectlist
= true,
226 .custom_blend_mode
= V_028808_CB_FMASK_DECOMPRESS
,
228 &device
->meta_state
.alloc
,
229 &device
->meta_state
.fast_clear_flush
.fmask_decompress_pipeline
);
230 if (result
!= VK_SUCCESS
)
235 radv_DestroyPipeline(device_h
, device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
, &device
->meta_state
.alloc
);
237 ralloc_free(fs_module
.nir
);
242 radv_device_finish_meta_fast_clear_flush_state(struct radv_device
*device
)
244 struct radv_meta_state
*state
= &device
->meta_state
;
246 radv_DestroyRenderPass(radv_device_to_handle(device
),
247 state
->fast_clear_flush
.pass
, &state
->alloc
);
248 radv_DestroyPipeline(radv_device_to_handle(device
),
249 state
->fast_clear_flush
.cmask_eliminate_pipeline
,
251 radv_DestroyPipeline(radv_device_to_handle(device
),
252 state
->fast_clear_flush
.fmask_decompress_pipeline
,
257 radv_device_init_meta_fast_clear_flush_state(struct radv_device
*device
)
259 VkResult res
= VK_SUCCESS
;
261 struct radv_shader_module vs_module
= { .nir
= radv_meta_build_nir_vs_generate_vertices() };
262 if (!vs_module
.nir
) {
263 /* XXX: Need more accurate error */
264 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
268 res
= create_pass(device
);
269 if (res
!= VK_SUCCESS
)
272 VkShaderModule vs_module_h
= radv_shader_module_to_handle(&vs_module
);
273 res
= create_pipeline(device
, vs_module_h
);
274 if (res
!= VK_SUCCESS
)
280 radv_device_finish_meta_fast_clear_flush_state(device
);
283 ralloc_free(vs_module
.nir
);
289 emit_fast_clear_flush(struct radv_cmd_buffer
*cmd_buffer
,
290 const VkExtent2D
*resolve_extent
,
293 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
295 radv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
298 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
301 .width
= resolve_extent
->width
,
302 .height
= resolve_extent
->height
,
307 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
308 .offset
= (VkOffset2D
) { 0, 0 },
309 .extent
= (VkExtent2D
) { resolve_extent
->width
, resolve_extent
->height
},
312 radv_CmdDraw(cmd_buffer_h
, 3, 1, 0, 0);
313 cmd_buffer
->state
.flush_bits
|= (RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
314 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
);
318 radv_emit_set_predication_state_from_image(struct radv_cmd_buffer
*cmd_buffer
,
319 struct radv_image
*image
, bool value
)
324 va
= radv_buffer_get_va(image
->bo
) + image
->offset
;
325 va
+= image
->dcc_pred_offset
;
328 si_emit_set_predication_state(cmd_buffer
, va
);
334 radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer
*cmd_buffer
,
335 struct radv_image
*image
,
336 const VkImageSubresourceRange
*subresourceRange
)
338 struct radv_meta_saved_state saved_state
;
339 VkDevice device_h
= radv_device_to_handle(cmd_buffer
->device
);
340 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
341 uint32_t layer_count
= radv_get_layerCount(image
, subresourceRange
);
344 assert(cmd_buffer
->queue_family_index
== RADV_QUEUE_GENERAL
);
346 radv_meta_save(&saved_state
, cmd_buffer
,
347 RADV_META_SAVE_GRAPHICS_PIPELINE
|
348 RADV_META_SAVE_PASS
);
350 if (image
->fmask
.size
> 0) {
351 pipeline
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.fmask_decompress_pipeline
;
353 pipeline
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
;
356 if (image
->surface
.dcc_size
) {
357 radv_emit_set_predication_state_from_image(cmd_buffer
, image
, true);
358 cmd_buffer
->state
.predicating
= true;
360 for (uint32_t layer
= 0; layer
< layer_count
; ++layer
) {
361 struct radv_image_view iview
;
363 radv_image_view_init(&iview
, cmd_buffer
->device
,
364 &(VkImageViewCreateInfo
) {
365 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
366 .image
= radv_image_to_handle(image
),
367 .viewType
= radv_meta_get_view_type(image
),
368 .format
= image
->vk_format
,
369 .subresourceRange
= {
370 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
373 .baseArrayLayer
= subresourceRange
->baseArrayLayer
+ layer
,
379 radv_CreateFramebuffer(device_h
,
380 &(VkFramebufferCreateInfo
) {
381 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
382 .attachmentCount
= 1,
383 .pAttachments
= (VkImageView
[]) {
384 radv_image_view_to_handle(&iview
)
386 .width
= image
->info
.width
,
387 .height
= image
->info
.height
,
390 &cmd_buffer
->pool
->alloc
,
393 radv_CmdBeginRenderPass(cmd_buffer_h
,
394 &(VkRenderPassBeginInfo
) {
395 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
396 .renderPass
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.pass
,
408 .clearValueCount
= 0,
409 .pClearValues
= NULL
,
411 VK_SUBPASS_CONTENTS_INLINE
);
413 emit_fast_clear_flush(cmd_buffer
,
414 &(VkExtent2D
) { image
->info
.width
, image
->info
.height
},
416 radv_CmdEndRenderPass(cmd_buffer_h
);
418 radv_DestroyFramebuffer(device_h
, fb_h
,
419 &cmd_buffer
->pool
->alloc
);
422 if (image
->surface
.dcc_size
) {
423 cmd_buffer
->state
.predicating
= false;
424 radv_emit_set_predication_state_from_image(cmd_buffer
, image
, false);
426 radv_meta_restore(&saved_state
, cmd_buffer
);