diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2017-12-31 07:12:27 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2017-12-31 07:12:27 +0000 |
commit | 051645c92924bf915d82bf219f2ed67309b5577a (patch) | |
tree | 4aae126dd8e5a18c6a9926a5468d1561e6038a07 /lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c | |
parent | 2dae6fe6f74cf7fb9fd65285302c0331d9786b00 (diff) |
Merge Mesa 17.2.8
Diffstat (limited to 'lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c')
-rw-r--r-- | lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c | 244 |
1 files changed, 99 insertions, 145 deletions
diff --git a/lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c b/lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c index 15c9bbcb1..27f8c160c 100644 --- a/lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c +++ b/lib/mesa/src/amd/vulkan/radv_meta_fast_clear.c @@ -26,53 +26,7 @@ #include "radv_meta.h" #include "radv_private.h" -#include "nir/nir_builder.h" #include "sid.h" -/** - * Vertex attributes used by all pipelines. - */ -struct vertex_attrs { - float position[2]; /**< 3DPRIM_RECTLIST */ -}; - -/* passthrough vertex shader */ -static nir_shader * -build_nir_vs(void) -{ - const struct glsl_type *vec4 = glsl_vec4_type(); - - nir_builder b; - nir_variable *a_position; - nir_variable *v_position; - - nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_VERTEX, NULL); - b.shader->info.name = ralloc_strdup(b.shader, "meta_fast_clear_vs"); - - a_position = nir_variable_create(b.shader, nir_var_shader_in, vec4, - "a_position"); - a_position->data.location = VERT_ATTRIB_GENERIC0; - - v_position = nir_variable_create(b.shader, nir_var_shader_out, vec4, - "gl_Position"); - v_position->data.location = VARYING_SLOT_POS; - - nir_copy_var(&b, v_position, a_position); - - return b.shader; -} - -/* simple passthrough shader */ -static nir_shader * -build_nir_fs(void) -{ - nir_builder b; - - nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL); - b.shader->info.name = ralloc_asprintf(b.shader, - "meta_fast_clear_noop_fs"); - - return b.shader; -} static VkResult create_pass(struct radv_device *device) @@ -128,7 +82,7 @@ create_pipeline(struct radv_device *device, VkDevice device_h = radv_device_to_handle(device); struct radv_shader_module fs_module = { - .nir = build_nir_fs(), + .nir = radv_meta_build_nir_fs_noop(), }; if (!fs_module.nir) { @@ -154,24 +108,8 @@ create_pipeline(struct radv_device *device, const VkPipelineVertexInputStateCreateInfo vi_state = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .vertexBindingDescriptionCount = 1, - .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) { - { - .binding = 0, - .stride = sizeof(struct vertex_attrs), - .inputRate = VK_VERTEX_INPUT_RATE_VERTEX - }, - }, - .vertexAttributeDescriptionCount = 1, - .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) { - { - /* Position */ - .location = 0, - .binding = 0, - .format = VK_FORMAT_R32G32_SFLOAT, - .offset = offsetof(struct vertex_attrs, position), - }, - } + .vertexBindingDescriptionCount = 0, + .vertexAttributeDescriptionCount = 0, }; const VkPipelineInputAssemblyStateCreateInfo ia_state = { @@ -214,8 +152,8 @@ create_pipeline(struct radv_device *device, .pViewportState = &(VkPipelineViewportStateCreateInfo) { .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .viewportCount = 0, - .scissorCount = 0, + .viewportCount = 1, + .scissorCount = 1, }, .pRasterizationState = &rs_state, .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) { @@ -227,7 +165,14 @@ create_pipeline(struct radv_device *device, .alphaToOneEnable = false, }, .pColorBlendState = &blend_state, - .pDynamicState = NULL, + .pDynamicState = &(VkPipelineDynamicStateCreateInfo) { + .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = 2, + .pDynamicStates = (VkDynamicState[]) { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR, + }, + }, .renderPass = device->meta_state.fast_clear_flush.pass, .subpass = 0, }, @@ -252,8 +197,8 @@ create_pipeline(struct radv_device *device, .pViewportState = &(VkPipelineViewportStateCreateInfo) { .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .viewportCount = 0, - .scissorCount = 0, + .viewportCount = 1, + .scissorCount = 1, }, .pRasterizationState = &rs_state, .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) { @@ -265,7 +210,14 @@ create_pipeline(struct radv_device *device, .alphaToOneEnable = false, }, .pColorBlendState = &blend_state, - .pDynamicState = NULL, + .pDynamicState = &(VkPipelineDynamicStateCreateInfo) { + .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = 2, + .pDynamicStates = (VkDynamicState[]) { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR, + }, + }, .renderPass = device->meta_state.fast_clear_flush.pass, .subpass = 0, }, @@ -316,7 +268,7 @@ radv_device_init_meta_fast_clear_flush_state(struct radv_device *device) zero(device->meta_state.fast_clear_flush); - struct radv_shader_module vs_module = { .nir = build_nir_vs() }; + struct radv_shader_module vs_module = { .nir = radv_meta_build_nir_vs_generate_vertices() }; if (!vs_module.nir) { /* XXX: Need more accurate error */ res = VK_ERROR_OUT_OF_HOST_MEMORY; @@ -350,45 +302,6 @@ emit_fast_clear_flush(struct radv_cmd_buffer *cmd_buffer, { struct radv_device *device = cmd_buffer->device; VkCommandBuffer cmd_buffer_h = radv_cmd_buffer_to_handle(cmd_buffer); - uint32_t offset; - const struct vertex_attrs vertex_data[3] = { - { - .position = { - 0, - 0, - }, - }, - { - .position = { - 0, - resolve_extent->height, - }, - }, - { - .position = { - resolve_extent->width, - 0, - }, - }, - }; - - cmd_buffer->state.flush_bits |= (RADV_CMD_FLAG_FLUSH_AND_INV_CB | - RADV_CMD_FLAG_FLUSH_AND_INV_CB_META); - radv_cmd_buffer_upload_data(cmd_buffer, sizeof(vertex_data), 16, vertex_data, &offset); - struct radv_buffer vertex_buffer = { - .device = device, - .size = sizeof(vertex_data), - .bo = cmd_buffer->upload.upload_bo, - .offset = offset, - }; - - VkBuffer vertex_buffer_h = radv_buffer_to_handle(&vertex_buffer); - - radv_CmdBindVertexBuffers(cmd_buffer_h, - /*firstBinding*/ 0, - /*bindingCount*/ 1, - (VkBuffer[]) { vertex_buffer_h }, - (VkDeviceSize[]) { 0 }); VkPipeline pipeline_h; if (fmask_decompress) @@ -402,58 +315,94 @@ emit_fast_clear_flush(struct radv_cmd_buffer *cmd_buffer, pipeline_h); } + radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer), 0, 1, &(VkViewport) { + .x = 0, + .y = 0, + .width = resolve_extent->width, + .height = resolve_extent->height, + .minDepth = 0.0f, + .maxDepth = 1.0f + }); + + radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer), 0, 1, &(VkRect2D) { + .offset = (VkOffset2D) { 0, 0 }, + .extent = (VkExtent2D) { resolve_extent->width, resolve_extent->height }, + }); + radv_CmdDraw(cmd_buffer_h, 3, 1, 0, 0); cmd_buffer->state.flush_bits |= (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_CB_META); - si_emit_cache_flush(cmd_buffer); +} + +static void +radv_emit_set_predication_state_from_image(struct radv_cmd_buffer *cmd_buffer, + struct radv_image *image, bool value) +{ + uint64_t va = 0; + + if (value) { + va = cmd_buffer->device->ws->buffer_get_va(image->bo) + image->offset; + va += image->dcc_pred_offset; + } + + si_emit_set_predication_state(cmd_buffer, va); } /** */ void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer, - struct radv_image *image) + struct radv_image *image, + const VkImageSubresourceRange *subresourceRange) { struct radv_meta_saved_state saved_state; struct radv_meta_saved_pass_state saved_pass_state; VkDevice device_h = radv_device_to_handle(cmd_buffer->device); VkCommandBuffer cmd_buffer_h = radv_cmd_buffer_to_handle(cmd_buffer); + uint32_t layer_count = radv_get_layerCount(image, subresourceRange); + assert(cmd_buffer->queue_family_index == RADV_QUEUE_GENERAL); radv_meta_save_pass(&saved_pass_state, cmd_buffer); - radv_meta_save_graphics_reset_vport_scissor(&saved_state, cmd_buffer); + radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer); - struct radv_image_view iview; - radv_image_view_init(&iview, cmd_buffer->device, - &(VkImageViewCreateInfo) { - .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + if (image->surface.dcc_size) { + radv_emit_set_predication_state_from_image(cmd_buffer, image, true); + cmd_buffer->state.predicating = true; + } + for (uint32_t layer = 0; layer < layer_count; ++layer) { + struct radv_image_view iview; + + radv_image_view_init(&iview, cmd_buffer->device, + &(VkImageViewCreateInfo) { + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .image = radv_image_to_handle(image), + .viewType = radv_meta_get_view_type(image), .format = image->vk_format, .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .baseMipLevel = 0, .levelCount = 1, - .baseArrayLayer = 0, + .baseArrayLayer = subresourceRange->baseArrayLayer + layer, .layerCount = 1, - }, - }, - cmd_buffer, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - - VkFramebuffer fb_h; - radv_CreateFramebuffer(device_h, - &(VkFramebufferCreateInfo) { - .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, - .attachmentCount = 1, - .pAttachments = (VkImageView[]) { - radv_image_view_to_handle(&iview) - }, - .width = image->extent.width, - .height = image->extent.height, + }, + }); + + VkFramebuffer fb_h; + radv_CreateFramebuffer(device_h, + &(VkFramebufferCreateInfo) { + .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, + .attachmentCount = 1, + .pAttachments = (VkImageView[]) { + radv_image_view_to_handle(&iview) + }, + .width = image->info.width, + .height = image->info.height, .layers = 1 - }, - &cmd_buffer->pool->alloc, - &fb_h); + }, + &cmd_buffer->pool->alloc, + &fb_h); - radv_CmdBeginRenderPass(cmd_buffer_h, + radv_CmdBeginRenderPass(cmd_buffer_h, &(VkRenderPassBeginInfo) { .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = cmd_buffer->device->meta_state.fast_clear_flush.pass, @@ -464,8 +413,8 @@ radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer, 0, }, .extent = { - image->extent.width, - image->extent.height, + image->info.width, + image->info.height, } }, .clearValueCount = 0, @@ -473,14 +422,19 @@ radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer, }, VK_SUBPASS_CONTENTS_INLINE); - emit_fast_clear_flush(cmd_buffer, - &(VkExtent2D) { image->extent.width, image->extent.height }, - image->fmask.size > 0); - radv_CmdEndRenderPass(cmd_buffer_h); + emit_fast_clear_flush(cmd_buffer, + &(VkExtent2D) { image->info.width, image->info.height }, + image->fmask.size > 0); + radv_CmdEndRenderPass(cmd_buffer_h); - radv_DestroyFramebuffer(device_h, fb_h, - &cmd_buffer->pool->alloc); + radv_DestroyFramebuffer(device_h, fb_h, + &cmd_buffer->pool->alloc); + } + if (image->surface.dcc_size) { + cmd_buffer->state.predicating = false; + radv_emit_set_predication_state_from_image(cmd_buffer, image, false); + } radv_meta_restore(&saved_state, cmd_buffer); radv_meta_restore_pass(&saved_pass_state, cmd_buffer); } |