From b6e473cd5859268bdc18429f00630edca5a13196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Mon, 25 Mar 2024 14:56:20 +0100 Subject: [PATCH] v3dv: move depth CFG bits setting to cmd buffer emission As it depends on values that could be dynamic now. Technically we could try to keep pre-emitting, just in case that info is provided statically. But for the dynamic case, we would still need to compute that bits, and we would need to discard all the pre-emitted CFG set, and recompute it completely (as right now cl_emit_with_prepacked doesn't allow to override values). It is also gets a simpler code by setting those flags in only one codepath. As we are here, we also move z_updates_enable from the pipeline to the cmd_buffer. This values doesn't require a complex compute, so it is easier to just keep it on one place. Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/vulkan/v3dv_private.h | 6 +++--- src/broadcom/vulkan/v3dvx_cmd_buffer.c | 24 +++++++++++++++++------- src/broadcom/vulkan/v3dvx_pipeline.c | 10 ---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 60a680b6492..c5813d67521 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -1603,6 +1603,9 @@ struct v3dv_cmd_buffer_state { struct v3dv_perf_query *perf; } active_query; } query; + + /* This is dynamic state since VK_EXT_extended_dynamic_state. */ + bool z_updates_enable; }; void @@ -2260,9 +2263,6 @@ struct v3dv_pipeline { struct v3dv_pipeline_layout *layout; - /* Whether this pipeline enables depth writes */ - bool z_updates_enable; - enum v3dv_ez_state ez_state; /* If ez_state is V3D_EZ_DISABLED, if the reason for disabling is that the diff --git a/src/broadcom/vulkan/v3dvx_cmd_buffer.c b/src/broadcom/vulkan/v3dvx_cmd_buffer.c index 77e0af05ad9..7394b0b297b 100644 --- a/src/broadcom/vulkan/v3dvx_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dvx_cmd_buffer.c @@ -1783,6 +1783,7 @@ v3dX(cmd_buffer_emit_varyings_state)(struct v3dv_cmd_buffer *cmd_buffer) } } +#if V3D_VERSION == 42 /* Updates job early Z state tracking. Returns False if EZ must be disabled * for the current draw call. */ @@ -1920,10 +1921,10 @@ job_update_ez_state(struct v3dv_job *job, } /* If we had to disable EZ because of an incompatible test direction and - * and the pipeline writes depth then we need to disable EZ for the rest of - * the frame. + * and the cmd buffer writes depth then we need to disable EZ for the rest + * of the frame. */ - if (incompatible_test && pipeline->z_updates_enable) { + if (incompatible_test && cmd_buffer->state.z_updates_enable) { assert(disable_ez); job->ez_state = V3D_EZ_DISABLED; } @@ -1933,6 +1934,7 @@ job_update_ez_state(struct v3dv_job *job, return !disable_ez; } +#endif void v3dX(cmd_buffer_emit_configuration_bits)(struct v3dv_cmd_buffer *cmd_buffer) @@ -1949,12 +1951,23 @@ v3dX(cmd_buffer_emit_configuration_bits)(struct v3dv_cmd_buffer *cmd_buffer) struct vk_dynamic_graphics_state *dyn = &cmd_buffer->vk.dynamic_graphics_state; + bool has_depth = + pipeline->rendering_info.depth_attachment_format != VK_FORMAT_UNDEFINED; + cl_emit_with_prepacked(&job->bcl, CFG_BITS, pipeline->cfg_bits, config) { + if (dyn->ds.depth.test_enable && has_depth) { + config.z_updates_enable = dyn->ds.depth.write_enable; + config.depth_test_function = dyn->ds.depth.compare_op; + } else { + config.depth_test_function = VK_COMPARE_OP_ALWAYS; + } + + cmd_buffer->state.z_updates_enable = config.z_updates_enable; #if V3D_VERSION == 42 bool enable_ez = job_update_ez_state(job, pipeline, cmd_buffer); config.early_z_enable = enable_ez; config.early_z_updates_enable = config.early_z_enable && - pipeline->z_updates_enable; + cmd_buffer->state.z_updates_enable; #endif if (pipeline->rasterization_enabled) { @@ -1972,9 +1985,6 @@ v3dX(cmd_buffer_emit_configuration_bits)(struct v3dv_cmd_buffer *cmd_buffer) assert(cmd_buffer->device->devinfo.ver >= 71 || !dyn->ds.depth.bounds_test.enable); #if V3D_VERSION >= 71 - bool has_depth = - pipeline->rendering_info.depth_attachment_format != VK_FORMAT_UNDEFINED; - config.depth_bounds_test_enable = dyn->ds.depth.bounds_test.enable && has_depth; #endif diff --git a/src/broadcom/vulkan/v3dvx_pipeline.c b/src/broadcom/vulkan/v3dvx_pipeline.c index 38e640deefc..c944eee57a5 100644 --- a/src/broadcom/vulkan/v3dvx_pipeline.c +++ b/src/broadcom/vulkan/v3dvx_pipeline.c @@ -201,21 +201,11 @@ pack_cfg_bits(struct v3dv_pipeline *pipeline, /* Disable depth/stencil if we don't have a D/S attachment */ const struct vk_render_pass_state *ri = &pipeline->rendering_info; - bool has_depth = ri->depth_attachment_format != VK_FORMAT_UNDEFINED; bool has_stencil = ri->stencil_attachment_format != VK_FORMAT_UNDEFINED; - if (ds_info && ds_info->depthTestEnable && has_depth) { - config.z_updates_enable = ds_info->depthWriteEnable; - config.depth_test_function = ds_info->depthCompareOp; - } else { - config.depth_test_function = VK_COMPARE_OP_ALWAYS; - } - config.stencil_enable = ds_info ? ds_info->stencilTestEnable && has_stencil: false; - pipeline->z_updates_enable = config.z_updates_enable; - #if V3D_VERSION >= 71 /* From the Vulkan spec: *