dzn: Properly support static blend constants

The current code was assuming blend constants to be passed dynamically,
which is wrong. Let's handle both the dynamic and static cases.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15608>
This commit is contained in:
Boris Brezillon 2022-03-28 09:39:20 +02:00 committed by Marge Bot
parent f16a7aa9d6
commit 23bd889541
3 changed files with 33 additions and 1 deletions

View File

@ -2473,6 +2473,13 @@ dzn_cmd_buffer_update_zsa(dzn_cmd_buffer *cmdbuf)
}
}
static void
dzn_cmd_buffer_update_blend_constants(dzn_cmd_buffer *cmdbuf)
{
if (cmdbuf->state.dirty & DZN_CMD_DIRTY_BLEND_CONSTANTS)
cmdbuf->cmdlist->OMSetBlendFactor(cmdbuf->state.blend.constants);
}
static VkResult
dzn_cmd_buffer_triangle_fan_create_index(dzn_cmd_buffer *cmdbuf, uint32_t *vertex_count)
{
@ -2614,6 +2621,7 @@ dzn_cmd_buffer_prepare_draw(dzn_cmd_buffer *cmdbuf, bool indexed)
dzn_cmd_buffer_update_vbviews(cmdbuf);
dzn_cmd_buffer_update_push_constants(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS);
dzn_cmd_buffer_update_zsa(cmdbuf);
dzn_cmd_buffer_update_blend_constants(cmdbuf);
if (indexed)
dzn_cmd_buffer_update_ibview(cmdbuf);
@ -3366,6 +3374,12 @@ dzn_CmdBindPipeline(VkCommandBuffer commandBuffer,
cmdbuf->state.dirty |= DZN_CMD_DIRTY_STENCIL_REF;
}
if (!gfx->blend.dynamic_constants) {
memcpy(cmdbuf->state.blend.constants, gfx->blend.constants,
sizeof(cmdbuf->state.blend.constants));
cmdbuf->state.dirty |= DZN_CMD_DIRTY_BLEND_CONSTANTS;
}
for (uint32_t vb = 0; vb < gfx->vb.count; vb++)
cmdbuf->state.vb.views[vb].StrideInBytes = gfx->vb.strides[vb];
@ -4057,7 +4071,9 @@ dzn_CmdSetBlendConstants(VkCommandBuffer commandBuffer,
{
VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
cmdbuf->cmdlist->OMSetBlendFactor(blendConstants);
memcpy(cmdbuf->state.blend.constants, blendConstants,
sizeof(cmdbuf->state.blend.constants));
cmdbuf->state.dirty |= DZN_CMD_DIRTY_BLEND_CONSTANTS;
}
VKAPI_ATTR void VKAPI_CALL

View File

@ -681,6 +681,9 @@ dzn_graphics_pipeline_translate_blend(dzn_graphics_pipeline *pipeline,
in_blend->logicOpEnable ?
translate_logic_op(in_blend->logicOp) : D3D12_LOGIC_OP_NOOP;
out->BlendState.AlphaToCoverageEnable = in_ms->alphaToCoverageEnable;
memcpy(pipeline->blend.constants, in_blend->blendConstants,
sizeof(pipeline->blend.constants));
for (uint32_t i = 0; i < in_blend->attachmentCount; i++) {
if (i > 0 &&
!memcmp(&in_blend->pAttachments[i - 1], &in_blend->pAttachments[i],
@ -692,6 +695,7 @@ dzn_graphics_pipeline_translate_blend(dzn_graphics_pipeline *pipeline,
in_blend->logicOpEnable;
out->BlendState.RenderTarget[i].RenderTargetWriteMask =
in_blend->pAttachments[i].colorWriteMask;
if (in_blend->logicOpEnable) {
out->BlendState.RenderTarget[i].LogicOpEnable = true;
out->BlendState.RenderTarget[i].LogicOp = logicop;
@ -814,6 +818,9 @@ dzn_graphics_pipeline_create(dzn_device *device,
case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
pipeline->zsa.stencil_test.dynamic_write_mask = true;
break;
case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
pipeline->blend.dynamic_constants = true;
break;
default: unreachable("Unsupported dynamic state");
}
}

View File

@ -307,6 +307,7 @@ enum dzn_cmd_dirty {
DZN_CMD_DIRTY_STENCIL_REF = 1 << 3,
DZN_CMD_DIRTY_STENCIL_COMPARE_MASK = 1 << 4,
DZN_CMD_DIRTY_STENCIL_WRITE_MASK = 1 << 5,
DZN_CMD_DIRTY_BLEND_CONSTANTS = 1 << 6,
};
#define MAX_VBS 16
@ -485,6 +486,9 @@ struct dzn_cmd_buffer_state {
} front, back;
} stencil_test;
} zsa;
struct {
float constants[4];
} blend;
D3D12_VIEWPORT viewports[MAX_VP];
D3D12_RECT scissors[MAX_SCISSOR];
struct {
@ -759,6 +763,11 @@ struct dzn_graphics_pipeline {
} stencil_test;
} zsa;
struct {
bool dynamic_constants;
float constants[4];
} blend;
ID3D12CommandSignature *indirect_cmd_sigs[DZN_NUM_INDIRECT_DRAW_CMD_SIGS];
};