diff options
Diffstat (limited to 'src/broadcom/vulkan/v3dv_meta_clear.c')
-rw-r--r-- | src/broadcom/vulkan/v3dv_meta_clear.c | 127 |
1 files changed, 56 insertions, 71 deletions
diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c index 5555c690bb3..8eeb03e57e2 100644 --- a/src/broadcom/vulkan/v3dv_meta_clear.c +++ b/src/broadcom/vulkan/v3dv_meta_clear.c @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Raspberry Pi + * Copyright © 2020 Raspberry Pi Ltd * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -25,7 +25,6 @@ #include "v3dv_meta_common.h" #include "compiler/nir/nir_builder.h" -#include "vk_format_info.h" #include "util/u_pack_color.h" static void @@ -68,7 +67,13 @@ clear_image_tlb(struct v3dv_cmd_buffer *cmd_buffer, { const VkOffset3D origin = { 0, 0, 0 }; VkFormat fb_format; - if (!v3dv_meta_can_use_tlb(image, &origin, &fb_format)) + + /* From vkCmdClearColorImage spec: + * "image must not use any of the formats that require a sampler YCBCR + * conversion" + */ + assert(image->plane_count == 1); + if (!v3dv_meta_can_use_tlb(image, 0, 0, &origin, NULL, &fb_format)) return false; uint32_t internal_type, internal_bpp; @@ -120,8 +125,9 @@ clear_image_tlb(struct v3dv_cmd_buffer *cmd_buffer, if (!job) return true; - v3dv_job_start_frame(job, width, height, max_layer, false, - 1, internal_bpp, + v3dv_job_start_frame(job, width, height, max_layer, + false, true, 1, internal_bpp, + 4 * v3d_internal_bpp_words(internal_bpp), image->vk.samples > VK_SAMPLE_COUNT_1_BIT); struct v3dv_meta_framebuffer framebuffer; @@ -161,11 +167,15 @@ v3dv_CmdClearColorImage(VkCommandBuffer commandBuffer, .color = *pColor, }; + cmd_buffer->state.is_transfer = true; + for (uint32_t i = 0; i < rangeCount; i++) { if (clear_image_tlb(cmd_buffer, image, &clear_value, &pRanges[i])) continue; unreachable("Unsupported color clear."); } + + cmd_buffer->state.is_transfer = false; } VKAPI_ATTR void VKAPI_CALL @@ -183,11 +193,15 @@ v3dv_CmdClearDepthStencilImage(VkCommandBuffer commandBuffer, .depthStencil = *pDepthStencil, }; + cmd_buffer->state.is_transfer = true; + for (uint32_t i = 0; i < rangeCount; i++) { if (clear_image_tlb(cmd_buffer, image, &clear_value, &pRanges[i])) continue; unreachable("Unsupported depth/stencil clear."); } + + cmd_buffer->state.is_transfer = false; } static void @@ -304,39 +318,6 @@ v3dv_meta_clear_finish(struct v3dv_device *device) } } -static nir_ssa_def * -gen_rect_vertices(nir_builder *b) -{ - nir_ssa_def *vertex_id = nir_load_vertex_id(b); - - /* vertex 0: -1.0, -1.0 - * vertex 1: -1.0, 1.0 - * vertex 2: 1.0, -1.0 - * vertex 3: 1.0, 1.0 - * - * so: - * - * channel 0 is vertex_id < 2 ? -1.0 : 1.0 - * channel 1 is vertex id & 1 ? 1.0 : -1.0 - */ - - nir_ssa_def *one = nir_imm_int(b, 1); - nir_ssa_def *c0cmp = nir_ilt(b, vertex_id, nir_imm_int(b, 2)); - nir_ssa_def *c1cmp = nir_ieq(b, nir_iand(b, vertex_id, one), one); - - nir_ssa_def *comp[4]; - comp[0] = nir_bcsel(b, c0cmp, - nir_imm_float(b, -1.0f), - nir_imm_float(b, 1.0f)); - - comp[1] = nir_bcsel(b, c1cmp, - nir_imm_float(b, 1.0f), - nir_imm_float(b, -1.0f)); - comp[2] = nir_imm_float(b, 0.0f); - comp[3] = nir_imm_float(b, 1.0f); - return nir_vec(b, comp, 4); -} - static nir_shader * get_clear_rect_vs() { @@ -349,7 +330,7 @@ get_clear_rect_vs() nir_variable_create(b.shader, nir_var_shader_out, vec4, "gl_Position"); vs_out_pos->data.location = VARYING_SLOT_POS; - nir_ssa_def *pos = gen_rect_vertices(&b); + nir_def *pos = nir_gen_rect_vertices(&b, NULL, NULL); nir_store_var(&b, vs_out_pos, pos, 0xf); return b.shader; @@ -372,8 +353,8 @@ get_clear_rect_gs(uint32_t push_constant_layer_base) nir->info.inputs_read = 1ull << VARYING_SLOT_POS; nir->info.outputs_written = (1ull << VARYING_SLOT_POS) | (1ull << VARYING_SLOT_LAYER); - nir->info.gs.input_primitive = GL_TRIANGLES; - nir->info.gs.output_primitive = GL_TRIANGLE_STRIP; + nir->info.gs.input_primitive = MESA_PRIM_TRIANGLES; + nir->info.gs.output_primitive = MESA_PRIM_TRIANGLE_STRIP; nir->info.gs.vertices_in = 3; nir->info.gs.vertices_out = 3; nir->info.gs.invocations = 1; @@ -406,7 +387,7 @@ get_clear_rect_gs(uint32_t push_constant_layer_base) nir_copy_deref(&b, nir_build_deref_var(&b, gs_out_pos), in_pos_i); /* gl_Layer from push constants */ - nir_ssa_def *layer = + nir_def *layer = nir_load_push_constant(&b, 1, 32, nir_imm_int(&b, 0), .base = push_constant_layer_base, .range = 4); nir_store_var(&b, gs_out_layer, layer, 0x1); @@ -434,7 +415,7 @@ get_color_clear_rect_fs(uint32_t rt_idx, VkFormat format) nir_variable_create(b.shader, nir_var_shader_out, fs_out_type, "out_color"); fs_out_color->data.location = FRAG_RESULT_DATA0 + rt_idx; - nir_ssa_def *color_load = nir_load_push_constant(&b, 4, 32, nir_imm_int(&b, 0), .base = 0, .range = 16); + nir_def *color_load = nir_load_push_constant(&b, 4, 32, nir_imm_int(&b, 0), .base = 0, .range = 16); nir_store_var(&b, fs_out_color, color_load, 0xf); return b.shader; @@ -452,7 +433,7 @@ get_depth_clear_rect_fs() "out_depth"); fs_out_depth->data.location = FRAG_RESULT_DEPTH; - nir_ssa_def *depth_load = + nir_def *depth_load = nir_load_push_constant(&b, 1, 32, nir_imm_int(&b, 0), .base = 0, .range = 4); nir_store_var(&b, fs_out_depth, depth_load, 0x1); @@ -475,12 +456,11 @@ create_pipeline(struct v3dv_device *device, VkPipeline *pipeline) { VkPipelineShaderStageCreateInfo stages[3] = { 0 }; - struct vk_shader_module vs_m; + struct vk_shader_module vs_m = vk_shader_module_from_nir(vs_nir); struct vk_shader_module gs_m; struct vk_shader_module fs_m; uint32_t stage_count = 0; - v3dv_shader_module_internal_init(device, &vs_m, vs_nir); stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stages[stage_count].stage = VK_SHADER_STAGE_VERTEX_BIT; stages[stage_count].module = vk_shader_module_to_handle(&vs_m); @@ -488,7 +468,7 @@ create_pipeline(struct v3dv_device *device, stage_count++; if (gs_nir) { - v3dv_shader_module_internal_init(device, &gs_m, gs_nir); + gs_m = vk_shader_module_from_nir(gs_nir); stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stages[stage_count].stage = VK_SHADER_STAGE_GEOMETRY_BIT; stages[stage_count].module = vk_shader_module_to_handle(&gs_m); @@ -497,7 +477,7 @@ create_pipeline(struct v3dv_device *device, } if (fs_nir) { - v3dv_shader_module_internal_init(device, &fs_m, fs_nir); + fs_m = vk_shader_module_from_nir(fs_nir); stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stages[stage_count].stage = VK_SHADER_STAGE_FRAGMENT_BIT; stages[stage_count].module = vk_shader_module_to_handle(&fs_m); @@ -581,6 +561,7 @@ create_pipeline(struct v3dv_device *device, pipeline); ralloc_free(vs_nir); + ralloc_free(gs_nir); ralloc_free(fs_nir); return result; @@ -592,7 +573,7 @@ create_color_clear_pipeline(struct v3dv_device *device, uint32_t subpass_idx, uint32_t rt_idx, VkFormat format, - uint32_t samples, + VkSampleCountFlagBits samples, uint32_t components, bool is_layered, VkPipelineLayout pipeline_layout, @@ -709,10 +690,11 @@ static VkResult create_color_clear_render_pass(struct v3dv_device *device, uint32_t rt_idx, VkFormat format, - uint32_t samples, + VkSampleCountFlagBits samples, VkRenderPass *pass) { - VkAttachmentDescription att = { + VkAttachmentDescription2 att = { + .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, .format = format, .samples = samples, .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, @@ -721,12 +703,14 @@ create_color_clear_render_pass(struct v3dv_device *device, .finalLayout = VK_IMAGE_LAYOUT_GENERAL, }; - VkAttachmentReference att_ref = { + VkAttachmentReference2 att_ref = { + .sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, .attachment = rt_idx, .layout = VK_IMAGE_LAYOUT_GENERAL, }; - VkSubpassDescription subpass = { + VkSubpassDescription2 subpass = { + .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2, .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .inputAttachmentCount = 0, .colorAttachmentCount = 1, @@ -737,8 +721,8 @@ create_color_clear_render_pass(struct v3dv_device *device, .pPreserveAttachments = NULL, }; - VkRenderPassCreateInfo info = { - .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, + VkRenderPassCreateInfo2 info = { + .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2, .attachmentCount = 1, .pAttachments = &att, .subpassCount = 1, @@ -747,14 +731,14 @@ create_color_clear_render_pass(struct v3dv_device *device, .pDependencies = NULL, }; - return v3dv_CreateRenderPass(v3dv_device_to_handle(device), - &info, &device->vk.alloc, pass); + return v3dv_CreateRenderPass2(v3dv_device_to_handle(device), + &info, &device->vk.alloc, pass); } static inline uint64_t get_color_clear_pipeline_cache_key(uint32_t rt_idx, VkFormat format, - uint32_t samples, + VkSampleCountFlagBits samples, uint32_t components, bool is_layered) { @@ -764,7 +748,7 @@ get_color_clear_pipeline_cache_key(uint32_t rt_idx, uint32_t bit_offset = 0; key |= rt_idx; - bit_offset += 2; + bit_offset += 3; key |= ((uint64_t) format) << bit_offset; bit_offset += 32; @@ -819,7 +803,7 @@ get_color_clear_pipeline(struct v3dv_device *device, uint32_t rt_idx, uint32_t attachment_idx, VkFormat format, - uint32_t samples, + VkSampleCountFlagBits samples, uint32_t components, bool is_layered, struct v3dv_meta_color_clear_pipeline **pipeline) @@ -1012,7 +996,7 @@ emit_subpass_color_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, assert(attachment_idx < cmd_buffer->state.pass->attachment_count); const VkFormat format = cmd_buffer->state.pass->attachments[attachment_idx].desc.format; - const VkFormat samples = + const VkSampleCountFlagBits samples = cmd_buffer->state.pass->attachments[attachment_idx].desc.samples; const uint32_t components = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | @@ -1049,8 +1033,6 @@ emit_subpass_color_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); - uint32_t dynamic_states = V3DV_CMD_DIRTY_VIEWPORT | V3DV_CMD_DIRTY_SCISSOR; - for (uint32_t i = 0; i < rect_count; i++) { const VkViewport viewport = { .x = rects[i].rect.offset.x, @@ -1087,7 +1069,7 @@ emit_subpass_color_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, cmd_buffer, (uintptr_t)pipeline, (v3dv_cmd_buffer_private_obj_destroy_cb) destroy_color_clear_pipeline); - v3dv_cmd_buffer_meta_state_pop(cmd_buffer, dynamic_states, false); + v3dv_cmd_buffer_meta_state_pop(cmd_buffer, false); } /* Emits a scissored quad, clearing the depth aspect by writing to gl_FragDepth @@ -1139,7 +1121,6 @@ emit_subpass_ds_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); - uint32_t dynamic_states = V3DV_CMD_DIRTY_VIEWPORT | V3DV_CMD_DIRTY_SCISSOR; if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) { v3dv_CmdSetStencilReference(cmd_buffer_handle, VK_STENCIL_FACE_FRONT_AND_BACK, @@ -1148,9 +1129,6 @@ emit_subpass_ds_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, VK_STENCIL_FACE_FRONT_AND_BACK, 0xff); v3dv_CmdSetStencilCompareMask(cmd_buffer_handle, VK_STENCIL_FACE_FRONT_AND_BACK, 0xff); - dynamic_states |= VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK | - VK_DYNAMIC_STATE_STENCIL_WRITE_MASK | - VK_DYNAMIC_STATE_STENCIL_REFERENCE; } for (uint32_t i = 0; i < rect_count; i++) { @@ -1179,7 +1157,7 @@ emit_subpass_ds_clear_rects(struct v3dv_cmd_buffer *cmd_buffer, } } - v3dv_cmd_buffer_meta_state_pop(cmd_buffer, dynamic_states, false); + v3dv_cmd_buffer_meta_state_pop(cmd_buffer, false); } static void @@ -1212,9 +1190,11 @@ v3dv_CmdClearAttachments(VkCommandBuffer commandBuffer, { V3DV_FROM_HANDLE(v3dv_cmd_buffer, cmd_buffer, commandBuffer); - /* We can only clear attachments in the current subpass */ - assert(attachmentCount <= 5); /* 4 color + D/S */ + /* We can have at most max_color_RTs + 1 D/S attachments */ + assert(attachmentCount <= + V3D_MAX_RENDER_TARGETS(cmd_buffer->device->devinfo.ver) + 1); + /* We can only clear attachments in the current subpass */ struct v3dv_render_pass *pass = cmd_buffer->state.pass; assert(cmd_buffer->state.subpass_idx < pass->subpass_count); @@ -1225,6 +1205,9 @@ v3dv_CmdClearAttachments(VkCommandBuffer commandBuffer, * framebuffers, we use a geometry shader to redirect clears to the * appropriate layers. */ + + v3dv_cmd_buffer_pause_occlusion_query(cmd_buffer); + bool is_layered, all_rects_same_layers; gather_layering_info(rectCount, pRects, &is_layered, &all_rects_same_layers); for (uint32_t i = 0; i < attachmentCount; i++) { @@ -1242,4 +1225,6 @@ v3dv_CmdClearAttachments(VkCommandBuffer commandBuffer, rectCount, pRects); } } + + v3dv_cmd_buffer_resume_occlusion_query(cmd_buffer); } |