diff --git a/src/freedreno/vulkan/tu_cmd_buffer.cc b/src/freedreno/vulkan/tu_cmd_buffer.cc index 8f990af21db..5d62f2e2038 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.cc +++ b/src/freedreno/vulkan/tu_cmd_buffer.cc @@ -2015,6 +2015,8 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer, tu_fill_render_pass_state(&cmd_buffer->state.vk_rp, cmd_buffer->state.pass, cmd_buffer->state.subpass); + vk_cmd_set_cb_attachment_count(&cmd_buffer->vk, + cmd_buffer->state.subpass->color_count); cmd_buffer->state.dirty |= TU_CMD_DIRTY_SUBPASS; cmd_buffer->patchpoints_ctx = ralloc_parent(NULL); @@ -3649,6 +3651,8 @@ tu_emit_subpass_begin(struct tu_cmd_buffer *cmd) tu_set_input_attachments(cmd, cmd->state.subpass); + vk_cmd_set_cb_attachment_count(&cmd->vk, cmd->state.subpass->color_count); + cmd->state.dirty |= TU_CMD_DIRTY_SUBPASS; } diff --git a/src/vulkan/runtime/vk_graphics_state.c b/src/vulkan/runtime/vk_graphics_state.c index 0a7b07288f5..e217e5ddd53 100644 --- a/src/vulkan/runtime/vk_graphics_state.c +++ b/src/vulkan/runtime/vk_graphics_state.c @@ -275,6 +275,15 @@ vk_get_dynamic_graphics_states(BITSET_WORD *dynamic, unreachable("Unsupported dynamic graphics state"); } } + + /* attachmentCount is ignored if all of the states using it are dyanmic. + * + * TODO: Handle advanced blending here when supported. + */ + if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_ENABLES) && + BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS) && + BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_WRITE_MASKS)) + BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_ATTACHMENT_COUNT); } #define IS_DYNAMIC(STATE) \ @@ -2806,6 +2815,15 @@ vk_common_CmdSetColorBlendAdvancedEXT(VkCommandBuffer commandBuffer, unreachable("VK_EXT_blend_operation_advanced unsupported"); } +void +vk_cmd_set_cb_attachment_count(struct vk_command_buffer *cmd, + uint32_t attachment_count) +{ + struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state; + + SET_DYN_VALUE(dyn, CB_ATTACHMENT_COUNT, cb.attachment_count, attachment_count); +} + VKAPI_ATTR void VKAPI_CALL vk_common_CmdSetDiscardRectangleEnableEXT(VkCommandBuffer commandBuffer, VkBool32 discardRectangleEnable) diff --git a/src/vulkan/runtime/vk_graphics_state.h b/src/vulkan/runtime/vk_graphics_state.h index 196c3c4d9fe..049a4f95914 100644 --- a/src/vulkan/runtime/vk_graphics_state.h +++ b/src/vulkan/runtime/vk_graphics_state.h @@ -1110,6 +1110,15 @@ vk_cmd_set_vertex_binding_strides(struct vk_command_buffer *cmd, uint32_t binding_count, const VkDeviceSize *strides); +/* Set color attachment count for blending on a command buffer. + * + * This is an implicit part of starting a subpass or a secondary command + * buffer in a subpass. + */ +void +vk_cmd_set_cb_attachment_count(struct vk_command_buffer *cmd, + uint32_t attachment_count); + #ifdef __cplusplus } #endif