diff options
author | Iago Toral Quiroga <itoral@igalia.com> | 2020-05-13 10:35:30 +0200 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2020-10-13 21:21:30 +0000 |
commit | 9aaf07e5be8260b28dd25ddbc3cbe974ebdf9b0f (patch) | |
tree | 4f51bc124cb54a4fe4516b1402ba1a38f43cd01c | |
parent | 88a59437d24bf8ad646230a67b50de85753e59e2 (diff) |
v3dv: implement depth bias
This doesn't implement depth bias clamp, which requires to support the
depth bias clamp feature, which we do not advertise as available at present.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
-rw-r--r-- | src/broadcom/vulkan/v3dv_cmd_buffer.c | 53 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_meta_clear.c | 2 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_meta_copy.c | 2 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_pipeline.c | 53 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_private.h | 15 |
5 files changed, 121 insertions, 4 deletions
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index 60865ccb2b8..e45ddc33bd1 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -49,6 +49,10 @@ const struct v3dv_dynamic_state default_dynamic_state = { .back = 0u, }, .blend_constants = { 0.0f, 0.0f, 0.0f, 0.0f }, + .depth_bias = { + .constant_factor = 0.0f, + .slope_factor = 0.0f, + }, }; void @@ -1990,6 +1994,14 @@ cmd_buffer_bind_pipeline_static_state(struct v3dv_cmd_buffer *cmd_buffer, } } + if (!(dynamic_mask & V3DV_DYNAMIC_DEPTH_BIAS)) { + if (memcmp(&dest->depth_bias, &src->depth_bias, + sizeof(src->depth_bias))) { + memcpy(&dest->depth_bias, &src->depth_bias, sizeof(src->depth_bias)); + dirty |= V3DV_CMD_DIRTY_DEPTH_BIAS; + } + } + cmd_buffer->state.dynamic.mask = dynamic_mask; cmd_buffer->state.dirty |= dirty; } @@ -2539,6 +2551,31 @@ emit_stencil(struct v3dv_cmd_buffer *cmd_buffer) } static void +emit_depth_bias(struct v3dv_cmd_buffer *cmd_buffer) +{ + struct v3dv_pipeline *pipeline = cmd_buffer->state.pipeline; + assert(pipeline); + + if (!pipeline->depth_bias.enabled) + return; + + struct v3dv_job *job = cmd_buffer->state.job; + assert(job); + + v3dv_cl_ensure_space_with_branch(&job->bcl, cl_packet_length(DEPTH_OFFSET)); + + struct v3dv_dynamic_state *dynamic = &cmd_buffer->state.dynamic; + cl_emit(&job->bcl, DEPTH_OFFSET, bias) { + bias.depth_offset_factor = dynamic->depth_bias.slope_factor; + bias.depth_offset_units = dynamic->depth_bias.constant_factor; + if (pipeline->depth_bias.is_z16) + bias.depth_offset_units *= 256.0f; + } + + cmd_buffer->state.dirty &= ~V3DV_CMD_DIRTY_DEPTH_BIAS; +} + +static void emit_blend(struct v3dv_cmd_buffer *cmd_buffer) { struct v3dv_job *job = cmd_buffer->state.job; @@ -3113,6 +3150,9 @@ cmd_buffer_emit_pre_draw(struct v3dv_cmd_buffer *cmd_buffer) if (*dirty & (V3DV_CMD_DIRTY_PIPELINE | dynamic_stencil_dirty_flags)) emit_stencil(cmd_buffer); + if (*dirty & (V3DV_CMD_DIRTY_PIPELINE | V3DV_CMD_DIRTY_DEPTH_BIAS)) + emit_depth_bias(cmd_buffer); + if (*dirty & (V3DV_CMD_DIRTY_PIPELINE | V3DV_CMD_DIRTY_BLEND_CONSTANTS)) emit_blend(cmd_buffer); @@ -3376,6 +3416,19 @@ v3dv_CmdSetStencilReference(VkCommandBuffer commandBuffer, } void +v3dv_CmdSetDepthBias(VkCommandBuffer commandBuffer, + float depthBiasConstantFactor, + float depthBiasClamp, + float depthBiasSlopeFactor) +{ + V3DV_FROM_HANDLE(v3dv_cmd_buffer, cmd_buffer, commandBuffer); + + cmd_buffer->state.dynamic.depth_bias.constant_factor = depthBiasConstantFactor; + cmd_buffer->state.dynamic.depth_bias.slope_factor = depthBiasSlopeFactor; + cmd_buffer->state.dirty |= V3DV_CMD_DIRTY_DEPTH_BIAS; +} + +void v3dv_CmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout _layout, diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c index 624964cf31b..e4d8c5cf800 100644 --- a/src/broadcom/vulkan/v3dv_meta_clear.c +++ b/src/broadcom/vulkan/v3dv_meta_clear.c @@ -226,9 +226,9 @@ create_pipeline(struct v3dv_device *device, VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, VK_DYNAMIC_STATE_STENCIL_REFERENCE, VK_DYNAMIC_STATE_BLEND_CONSTANTS, + VK_DYNAMIC_STATE_DEPTH_BIAS, #if 0 VK_DYNAMIC_STATE_LINE_WIDTH, - VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_DEPTH_BOUNDS, #endif }, diff --git a/src/broadcom/vulkan/v3dv_meta_copy.c b/src/broadcom/vulkan/v3dv_meta_copy.c index 08c632c8560..346e7f03f76 100644 --- a/src/broadcom/vulkan/v3dv_meta_copy.c +++ b/src/broadcom/vulkan/v3dv_meta_copy.c @@ -3046,9 +3046,9 @@ create_pipeline(struct v3dv_device *device, VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, VK_DYNAMIC_STATE_STENCIL_REFERENCE, VK_DYNAMIC_STATE_BLEND_CONSTANTS, + VK_DYNAMIC_STATE_DEPTH_BIAS, #if 0 VK_DYNAMIC_STATE_LINE_WIDTH, - VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_DEPTH_BOUNDS, #endif }, diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index facc3da7f74..bb015b3637c 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -1539,6 +1539,8 @@ v3dv_dynamic_state_mask(VkDynamicState state) return V3DV_DYNAMIC_STENCIL_REFERENCE; case VK_DYNAMIC_STATE_BLEND_CONSTANTS: return V3DV_DYNAMIC_BLEND_CONSTANTS; + case VK_DYNAMIC_STATE_DEPTH_BIAS: + return V3DV_DYNAMIC_DEPTH_BIAS; default: unreachable("Unhandled dynamic state"); } @@ -1590,7 +1592,6 @@ pipeline_init_dynamic_state(struct v3dv_pipeline *pipeline, } if (pCreateInfo->pDepthStencilState != NULL) { - if (!(dynamic_states & V3DV_DYNAMIC_STENCIL_COMPARE_MASK)) { dynamic->stencil_compare_mask.front = pCreateInfo->pDepthStencilState->front.compareMask; @@ -1620,6 +1621,17 @@ pipeline_init_dynamic_state(struct v3dv_pipeline *pipeline, sizeof(dynamic->blend_constants)); } + if (pCreateInfo->pRasterizationState && + !pCreateInfo->pRasterizationState->rasterizerDiscardEnable) { + if (pCreateInfo->pRasterizationState->depthBiasEnable && + !(dynamic_states & V3DV_DYNAMIC_DEPTH_BIAS)) { + dynamic->depth_bias.constant_factor = + pCreateInfo->pRasterizationState->depthBiasConstantFactor; + dynamic->depth_bias.slope_factor = + pCreateInfo->pRasterizationState->depthBiasSlopeFactor; + } + } + pipeline->dynamic_state.mask = dynamic_states; } @@ -1931,6 +1943,44 @@ stencil_op_is_no_op(const VkStencilOpState *stencil) } static void +enable_depth_bias(struct v3dv_pipeline *pipeline, + const VkGraphicsPipelineCreateInfo *pInfo) +{ + assert(pInfo); + + pipeline->depth_bias.enabled = false; + pipeline->depth_bias.is_z16 = false; + + if (!pInfo->pRasterizationState || + !pInfo->pRasterizationState->depthBiasEnable || + pInfo->pRasterizationState->rasterizerDiscardEnable) + return; + + /* Check the depth/stencil attachment description for the subpass used with + * this pipeline. + */ + struct v3dv_render_pass *pass = + v3dv_render_pass_from_handle(pInfo->renderPass); + assert(pass); + + assert(pInfo->subpass < pass->subpass_count); + struct v3dv_subpass *subpass = &pass->subpasses[pInfo->subpass]; + assert(subpass); + + if (subpass->ds_attachment.attachment == VK_ATTACHMENT_UNUSED) + return; + + assert(subpass->ds_attachment.attachment < pass->attachment_count); + struct v3dv_render_pass_attachment *att = + &pass->attachments[subpass->ds_attachment.attachment]; + + if (att->desc.format == VK_FORMAT_D16_UNORM) + pipeline->depth_bias.is_z16 = true; + + pipeline->depth_bias.enabled = true; +} + +static void pipeline_set_ez_state(struct v3dv_pipeline *pipeline, const VkPipelineDepthStencilStateCreateInfo *ds_info) { @@ -2267,6 +2317,7 @@ pipeline_init(struct v3dv_pipeline *pipeline, pack_cfg_bits(pipeline, ds_info, rs_info); pack_stencil_cfg(pipeline, ds_info); pipeline_set_ez_state(pipeline, ds_info); + enable_depth_bias(pipeline, pCreateInfo); pipeline->primitive_restart = pCreateInfo->pInputAssemblyState->primitiveRestartEnable; diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 14eb8b8ec89..feec14c31ac 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -542,7 +542,8 @@ enum v3dv_dynamic_state_bits { V3DV_DYNAMIC_STENCIL_WRITE_MASK = 1 << 3, V3DV_DYNAMIC_STENCIL_REFERENCE = 1 << 4, V3DV_DYNAMIC_BLEND_CONSTANTS = 1 << 5, - V3DV_DYNAMIC_ALL = (1 << 6) - 1, + V3DV_DYNAMIC_DEPTH_BIAS = 1 << 6, + V3DV_DYNAMIC_ALL = (1 << 7) - 1, }; /* Flags for dirty pipeline state. @@ -560,6 +561,7 @@ enum v3dv_cmd_dirty_bits { V3DV_CMD_DIRTY_BLEND_CONSTANTS = 1 << 9, V3DV_CMD_DIRTY_SHADER_VARIANTS = 1 << 10, V3DV_CMD_DIRTY_OCCLUSION_QUERY = 1 << 11, + V3DV_CMD_DIRTY_DEPTH_BIAS = 1 << 12, }; @@ -590,6 +592,11 @@ struct v3dv_dynamic_state { } stencil_reference; float blend_constants[4]; + + struct { + float constant_factor; + float slope_factor; + } depth_bias; }; extern const struct v3dv_dynamic_state default_dynamic_state; @@ -1297,6 +1304,12 @@ struct v3dv_pipeline { uint32_t color_write_masks; } blend; + /* Depth bias */ + struct { + bool enabled; + bool is_z16; + } depth_bias; + /* Packets prepacked during pipeline creation */ uint8_t cfg_bits[cl_packet_length(CFG_BITS)]; |