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>
This commit is contained in:
Iago Toral Quiroga 2020-05-13 10:35:30 +02:00 committed by Marge Bot
parent 88a59437d2
commit 9aaf07e5be
5 changed files with 121 additions and 4 deletions

View file

@ -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;
}
@ -2538,6 +2550,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)
{
@ -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);
@ -3375,6 +3415,19 @@ v3dv_CmdSetStencilReference(VkCommandBuffer commandBuffer,
cmd_buffer->state.dirty |= V3DV_CMD_DIRTY_STENCIL_REFERENCE;
}
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,

View file

@ -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
},

View file

@ -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
},

View file

@ -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;
}
@ -1930,6 +1942,44 @@ stencil_op_is_no_op(const VkStencilOpState *stencil)
stencil->compareOp == VK_COMPARE_OP_ALWAYS;
}
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;

View file

@ -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)];