diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index bf298f28f0e..124ba544280 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -369,18 +369,18 @@ si_translate_blend_factor(enum amd_gfx_level gfx_level, VkBlendFactor factor) } static uint32_t -si_translate_blend_opt_function(unsigned op) +si_translate_blend_opt_function(VkBlendOp op) { switch (op) { - case V_028780_COMB_DST_PLUS_SRC: + case VK_BLEND_OP_ADD: return V_028760_OPT_COMB_ADD; - case V_028780_COMB_SRC_MINUS_DST: + case VK_BLEND_OP_SUBTRACT: return V_028760_OPT_COMB_SUBTRACT; - case V_028780_COMB_DST_MINUS_SRC: + case VK_BLEND_OP_REVERSE_SUBTRACT: return V_028760_OPT_COMB_REVSUBTRACT; - case V_028780_COMB_MIN_DST_SRC: + case VK_BLEND_OP_MIN: return V_028760_OPT_COMB_MIN; - case V_028780_COMB_MAX_DST_SRC: + case VK_BLEND_OP_MAX: return V_028760_OPT_COMB_MAX; default: return V_028760_OPT_COMB_BLEND_DISABLED; @@ -388,24 +388,24 @@ si_translate_blend_opt_function(unsigned op) } static uint32_t -si_translate_blend_opt_factor(unsigned factor, bool is_alpha) +si_translate_blend_opt_factor(VkBlendFactor factor, bool is_alpha) { switch (factor) { - case V_028780_BLEND_ZERO: + case VK_BLEND_FACTOR_ZERO: return V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_ALL; - case V_028780_BLEND_ONE: + case VK_BLEND_FACTOR_ONE: return V_028760_BLEND_OPT_PRESERVE_ALL_IGNORE_NONE; - case V_028780_BLEND_SRC_COLOR: + case VK_BLEND_FACTOR_SRC_COLOR: return is_alpha ? V_028760_BLEND_OPT_PRESERVE_A1_IGNORE_A0 : V_028760_BLEND_OPT_PRESERVE_C1_IGNORE_C0; - case V_028780_BLEND_ONE_MINUS_SRC_COLOR: + case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR: return is_alpha ? V_028760_BLEND_OPT_PRESERVE_A0_IGNORE_A1 : V_028760_BLEND_OPT_PRESERVE_C0_IGNORE_C1; - case V_028780_BLEND_SRC_ALPHA: + case VK_BLEND_FACTOR_SRC_ALPHA: return V_028760_BLEND_OPT_PRESERVE_A1_IGNORE_A0; - case V_028780_BLEND_ONE_MINUS_SRC_ALPHA: + case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA: return V_028760_BLEND_OPT_PRESERVE_A0_IGNORE_A1; - case V_028780_BLEND_SRC_ALPHA_SATURATE: + case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE: return is_alpha ? V_028760_BLEND_OPT_PRESERVE_ALL_IGNORE_NONE : V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_A0; default: @@ -418,54 +418,41 @@ si_translate_blend_opt_factor(unsigned factor, bool is_alpha) * func(src * DST, dst * 0) ---> func(src * 0, dst * SRC) */ static void -si_blend_remove_dst(unsigned *func, unsigned *src_factor, unsigned *dst_factor, - unsigned expected_dst, unsigned replacement_src) +si_blend_remove_dst(VkBlendOp *func, VkBlendFactor *src_factor, VkBlendFactor *dst_factor, + VkBlendFactor expected_dst, VkBlendFactor replacement_src) { - if (*src_factor == expected_dst && *dst_factor == V_028780_BLEND_ZERO) { - *src_factor = V_028780_BLEND_ZERO; + if (*src_factor == expected_dst && *dst_factor == VK_BLEND_FACTOR_ZERO) { + *src_factor = VK_BLEND_FACTOR_ZERO; *dst_factor = replacement_src; /* Commuting the operands requires reversing subtractions. */ - if (*func == V_028780_COMB_SRC_MINUS_DST) - *func = V_028780_COMB_DST_MINUS_SRC; - else if (*func == V_028780_COMB_DST_MINUS_SRC) - *func = V_028780_COMB_SRC_MINUS_DST; + if (*func == VK_BLEND_OP_SUBTRACT) + *func = VK_BLEND_OP_REVERSE_SUBTRACT; + else if (*func == VK_BLEND_OP_REVERSE_SUBTRACT) + *func = VK_BLEND_OP_SUBTRACT; } } static bool -si_blend_factor_uses_dst(unsigned factor) +si_blend_factor_uses_dst(VkBlendFactor factor) { - return factor == V_028780_BLEND_DST_COLOR || - factor == V_028780_BLEND_DST_ALPHA || - factor == V_028780_BLEND_SRC_ALPHA_SATURATE || - factor == V_028780_BLEND_ONE_MINUS_DST_ALPHA || - factor == V_028780_BLEND_ONE_MINUS_DST_COLOR; + return factor == VK_BLEND_FACTOR_DST_COLOR || factor == VK_BLEND_FACTOR_DST_ALPHA || + factor == VK_BLEND_FACTOR_SRC_ALPHA_SATURATE || + factor == VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA || + factor == VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; } static bool -is_dual_src(enum amd_gfx_level gfx_level, unsigned factor) +is_dual_src(VkBlendFactor factor) { - if (gfx_level >= GFX11) { - switch (factor) { - case V_028780_BLEND_SRC1_COLOR_GFX11: - case V_028780_BLEND_INV_SRC1_COLOR_GFX11: - case V_028780_BLEND_SRC1_ALPHA_GFX11: - case V_028780_BLEND_INV_SRC1_ALPHA_GFX11: - return true; - default: - return false; - } - } else { - switch (factor) { - case V_028780_BLEND_SRC1_COLOR_GFX6: - case V_028780_BLEND_INV_SRC1_COLOR_GFX6: - case V_028780_BLEND_SRC1_ALPHA_GFX6: - case V_028780_BLEND_INV_SRC1_ALPHA_GFX6: - return true; - default: - return false; - } + switch (factor) { + case VK_BLEND_FACTOR_SRC1_COLOR: + case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR: + case VK_BLEND_FACTOR_SRC1_ALPHA: + case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA: + return true; + default: + return false; } } @@ -639,52 +626,27 @@ radv_format_meta_fs_key(struct radv_device *device, VkFormat format) } static void -radv_blend_check_commutativity(enum amd_gfx_level gfx_level, struct radv_blend_state *blend, - unsigned op, unsigned src, unsigned dst, unsigned chanmask) +radv_blend_check_commutativity(struct radv_blend_state *blend, VkBlendOp op, VkBlendFactor src, + VkBlendFactor dst, unsigned chanmask) { - bool is_src_allowed = false; - /* Src factor is allowed when it does not depend on Dst. */ - if (src == V_028780_BLEND_ZERO || - src == V_028780_BLEND_ONE || - src == V_028780_BLEND_SRC_COLOR || - src == V_028780_BLEND_SRC_ALPHA || - src == V_028780_BLEND_SRC_ALPHA_SATURATE || - src == V_028780_BLEND_ONE_MINUS_SRC_COLOR || - src == V_028780_BLEND_ONE_MINUS_SRC_ALPHA) { - is_src_allowed = true; - } + static const uint32_t src_allowed = + (1u << VK_BLEND_FACTOR_ONE) | (1u << VK_BLEND_FACTOR_SRC_COLOR) | + (1u << VK_BLEND_FACTOR_SRC_ALPHA) | (1u << VK_BLEND_FACTOR_SRC_ALPHA_SATURATE) | + (1u << VK_BLEND_FACTOR_CONSTANT_COLOR) | (1u << VK_BLEND_FACTOR_CONSTANT_ALPHA) | + (1u << VK_BLEND_FACTOR_SRC1_COLOR) | (1u << VK_BLEND_FACTOR_SRC1_ALPHA) | + (1u << VK_BLEND_FACTOR_ZERO) | (1u << VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR) | + (1u << VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA) | + (1u << VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR) | + (1u << VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA) | + (1u << VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR) | (1u << VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA); - if (gfx_level >= GFX11) { - if (src == V_028780_BLEND_CONSTANT_COLOR_GFX11 || - src == V_028780_BLEND_CONSTANT_ALPHA_GFX11 || - src == V_028780_BLEND_SRC1_COLOR_GFX11 || - src == V_028780_BLEND_SRC1_ALPHA_GFX11 || - src == V_028780_BLEND_ONE_MINUS_CONSTANT_COLOR_GFX11 || - src == V_028780_BLEND_ONE_MINUS_CONSTANT_ALPHA_GFX11 || - src == V_028780_BLEND_INV_SRC1_COLOR_GFX11 || - src == V_028780_BLEND_INV_SRC1_ALPHA_GFX11) { - is_src_allowed = true; - } - } else { - if (src == V_028780_BLEND_CONSTANT_COLOR_GFX6 || - src == V_028780_BLEND_CONSTANT_ALPHA_GFX6 || - src == V_028780_BLEND_SRC1_COLOR_GFX6 || - src == V_028780_BLEND_SRC1_ALPHA_GFX6 || - src == V_028780_BLEND_ONE_MINUS_CONSTANT_COLOR_GFX6 || - src == V_028780_BLEND_ONE_MINUS_CONSTANT_ALPHA_GFX6 || - src == V_028780_BLEND_INV_SRC1_COLOR_GFX6 || - src == V_028780_BLEND_INV_SRC1_ALPHA_GFX6) { - is_src_allowed = true; - } - } - - if (dst == V_028780_BLEND_ONE && is_src_allowed) { + if (dst == VK_BLEND_FACTOR_ONE && (src_allowed & (1u << src))) { /* Addition is commutative, but floating point addition isn't * associative: subtle changes can be introduced via different * rounding. Be conservative, only enable for min and max. */ - if (op == V_028780_COMB_MAX_DST_SRC || op == V_028780_COMB_MIN_DST_SRC) + if (op == VK_BLEND_OP_MAX || op == VK_BLEND_OP_MIN) blend->commutative_4bit |= chanmask; } } @@ -727,12 +689,12 @@ radv_pipeline_init_blend_state(struct radv_graphics_pipeline *pipeline, for (i = 0; i < info->cb.att_count; i++) { unsigned blend_cntl = 0; unsigned srcRGB_opt, dstRGB_opt, srcA_opt, dstA_opt; - unsigned eqRGB = info->cb.att[i].color_blend_op; - unsigned srcRGB = info->cb.att[i].src_color_blend_factor; - unsigned dstRGB = info->cb.att[i].dst_color_blend_factor; - unsigned eqA = info->cb.att[i].alpha_blend_op; - unsigned srcA = info->cb.att[i].src_alpha_blend_factor; - unsigned dstA = info->cb.att[i].dst_alpha_blend_factor; + VkBlendOp eqRGB = info->cb.att[i].color_blend_op; + VkBlendFactor srcRGB = info->cb.att[i].src_color_blend_factor; + VkBlendFactor dstRGB = info->cb.att[i].dst_color_blend_factor; + VkBlendOp eqA = info->cb.att[i].alpha_blend_op; + VkBlendFactor srcA = info->cb.att[i].src_alpha_blend_factor; + VkBlendFactor dstA = info->cb.att[i].dst_alpha_blend_factor; blend.sx_mrt_blend_opt[i] = S_028760_COLOR_COMB_FCN(V_028760_OPT_COMB_BLEND_DISABLED) | S_028760_ALPHA_COMB_FCN(V_028760_OPT_COMB_BLEND_DISABLED); @@ -753,23 +715,21 @@ radv_pipeline_init_blend_state(struct radv_graphics_pipeline *pipeline, continue; } - if (is_dual_src(gfx_level, srcRGB) || is_dual_src(gfx_level, dstRGB) || - is_dual_src(gfx_level, srcA) || is_dual_src(gfx_level, dstA)) + if (is_dual_src(srcRGB) || is_dual_src(dstRGB) || is_dual_src(srcA) || is_dual_src(dstA)) if (i == 0) blend.mrt0_is_dual_src = true; - - if (eqRGB == V_028780_COMB_MIN_DST_SRC || eqRGB == V_028780_COMB_MAX_DST_SRC) { - srcRGB = V_028780_BLEND_ONE; - dstRGB = V_028780_BLEND_ONE; + if (eqRGB == VK_BLEND_OP_MIN || eqRGB == VK_BLEND_OP_MAX) { + srcRGB = VK_BLEND_FACTOR_ONE; + dstRGB = VK_BLEND_FACTOR_ONE; } - if (eqA == V_028780_COMB_MIN_DST_SRC || eqA == V_028780_COMB_MAX_DST_SRC) { - srcA = V_028780_BLEND_ONE; - dstA = V_028780_BLEND_ONE; + if (eqA == VK_BLEND_OP_MIN || eqA == VK_BLEND_OP_MAX) { + srcA = VK_BLEND_FACTOR_ONE; + dstA = VK_BLEND_FACTOR_ONE; } - radv_blend_check_commutativity(gfx_level, &blend, eqRGB, srcRGB, dstRGB, 0x7u << (4 * i)); - radv_blend_check_commutativity(gfx_level, &blend, eqA, srcA, dstA, 0x8u << (4 * i)); + radv_blend_check_commutativity(&blend, eqRGB, srcRGB, dstRGB, 0x7u << (4 * i)); + radv_blend_check_commutativity(&blend, eqA, srcA, dstA, 0x8u << (4 * i)); /* Blending optimizations for RB+. * These transformations don't change the behavior. @@ -777,14 +737,14 @@ radv_pipeline_init_blend_state(struct radv_graphics_pipeline *pipeline, * First, get rid of DST in the blend factors: * func(src * DST, dst * 0) ---> func(src * 0, dst * SRC) */ - si_blend_remove_dst(&eqRGB, &srcRGB, &dstRGB, V_028780_BLEND_DST_COLOR, - V_028780_BLEND_SRC_COLOR); + si_blend_remove_dst(&eqRGB, &srcRGB, &dstRGB, VK_BLEND_FACTOR_DST_COLOR, + VK_BLEND_FACTOR_SRC_COLOR); - si_blend_remove_dst(&eqA, &srcA, &dstA, V_028780_BLEND_DST_COLOR, - V_028780_BLEND_SRC_COLOR); + si_blend_remove_dst(&eqA, &srcA, &dstA, VK_BLEND_FACTOR_DST_COLOR, + VK_BLEND_FACTOR_SRC_COLOR); - si_blend_remove_dst(&eqA, &srcA, &dstA, V_028780_BLEND_DST_ALPHA, - V_028780_BLEND_SRC_ALPHA); + si_blend_remove_dst(&eqA, &srcA, &dstA, VK_BLEND_FACTOR_DST_ALPHA, + VK_BLEND_FACTOR_SRC_ALPHA); /* Look up the ideal settings from tables. */ srcRGB_opt = si_translate_blend_opt_factor(srcRGB, false); @@ -798,9 +758,9 @@ radv_pipeline_init_blend_state(struct radv_graphics_pipeline *pipeline, if (si_blend_factor_uses_dst(srcA)) dstA_opt = V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_NONE; - if (srcRGB == V_028780_BLEND_SRC_ALPHA_SATURATE && - (dstRGB == V_028780_BLEND_ZERO || dstRGB == V_028780_BLEND_SRC_ALPHA || - dstRGB == V_028780_BLEND_SRC_ALPHA_SATURATE)) + if (srcRGB == VK_BLEND_FACTOR_SRC_ALPHA_SATURATE && + (dstRGB == VK_BLEND_FACTOR_ZERO || dstRGB == VK_BLEND_FACTOR_SRC_ALPHA || + dstRGB == VK_BLEND_FACTOR_SRC_ALPHA_SATURATE)) dstRGB_opt = V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_A0; /* Set the final value. */ @@ -811,24 +771,24 @@ radv_pipeline_init_blend_state(struct radv_graphics_pipeline *pipeline, S_028760_ALPHA_COMB_FCN(si_translate_blend_opt_function(eqA)); blend_cntl |= S_028780_ENABLE(1); - blend_cntl |= S_028780_COLOR_COMB_FCN(eqRGB); - blend_cntl |= S_028780_COLOR_SRCBLEND(srcRGB); - blend_cntl |= S_028780_COLOR_DESTBLEND(dstRGB); + blend_cntl |= S_028780_COLOR_COMB_FCN(si_translate_blend_function(eqRGB)); + blend_cntl |= S_028780_COLOR_SRCBLEND(si_translate_blend_factor(gfx_level, srcRGB)); + blend_cntl |= S_028780_COLOR_DESTBLEND(si_translate_blend_factor(gfx_level, dstRGB)); if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) { blend_cntl |= S_028780_SEPARATE_ALPHA_BLEND(1); - blend_cntl |= S_028780_ALPHA_COMB_FCN(eqA); - blend_cntl |= S_028780_ALPHA_SRCBLEND(srcA); - blend_cntl |= S_028780_ALPHA_DESTBLEND(dstA); + blend_cntl |= S_028780_ALPHA_COMB_FCN(si_translate_blend_function(eqA)); + blend_cntl |= S_028780_ALPHA_SRCBLEND(si_translate_blend_factor(gfx_level, srcA)); + blend_cntl |= S_028780_ALPHA_DESTBLEND(si_translate_blend_factor(gfx_level, dstA)); } blend.cb_blend_control[i] = blend_cntl; blend.blend_enable_4bit |= 0xfu << (i * 4); - if (srcRGB == V_028780_BLEND_SRC_ALPHA || dstRGB == V_028780_BLEND_SRC_ALPHA || - srcRGB == V_028780_BLEND_SRC_ALPHA_SATURATE || - dstRGB == V_028780_BLEND_SRC_ALPHA_SATURATE || - srcRGB == V_028780_BLEND_ONE_MINUS_SRC_ALPHA || - dstRGB == V_028780_BLEND_ONE_MINUS_SRC_ALPHA) + if (srcRGB == VK_BLEND_FACTOR_SRC_ALPHA || dstRGB == VK_BLEND_FACTOR_SRC_ALPHA || + srcRGB == VK_BLEND_FACTOR_SRC_ALPHA_SATURATE || + dstRGB == VK_BLEND_FACTOR_SRC_ALPHA_SATURATE || + srcRGB == VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA || + dstRGB == VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA) blend.need_src_alpha |= 1 << i; } for (i = info->cb.att_count; i < 8; i++) { @@ -1879,7 +1839,6 @@ static struct radv_color_blend_info radv_pipeline_init_color_blend_info(struct radv_graphics_pipeline *pipeline, const VkGraphicsPipelineCreateInfo *pCreateInfo) { - const struct radv_physical_device *pdevice = pipeline->base.device->physical_device; const VkPipelineColorBlendStateCreateInfo *cb = pCreateInfo->pColorBlendState; const VkPipelineRenderingCreateInfo *ri = vk_find_struct_const(pCreateInfo->pNext, PIPELINE_RENDERING_CREATE_INFO); @@ -1899,16 +1858,12 @@ radv_pipeline_init_color_blend_info(struct radv_graphics_pipeline *pipeline, info.att[i].color_write_mask = att->colorWriteMask; info.att[i].blend_enable = att->blendEnable; - info.att[i].color_blend_op = si_translate_blend_function(att->colorBlendOp); - info.att[i].alpha_blend_op = si_translate_blend_function(att->alphaBlendOp); - info.att[i].src_color_blend_factor = - si_translate_blend_factor(pdevice->rad_info.gfx_level, att->srcColorBlendFactor); - info.att[i].dst_color_blend_factor = - si_translate_blend_factor(pdevice->rad_info.gfx_level, att->dstColorBlendFactor); - info.att[i].src_alpha_blend_factor = - si_translate_blend_factor(pdevice->rad_info.gfx_level, att->srcAlphaBlendFactor); - info.att[i].dst_alpha_blend_factor = - si_translate_blend_factor(pdevice->rad_info.gfx_level, att->dstAlphaBlendFactor); + info.att[i].color_blend_op = att->colorBlendOp; + info.att[i].alpha_blend_op = att->alphaBlendOp; + info.att[i].src_color_blend_factor = att->srcColorBlendFactor; + info.att[i].dst_color_blend_factor = att->dstColorBlendFactor; + info.att[i].src_alpha_blend_factor = att->srcAlphaBlendFactor; + info.att[i].dst_alpha_blend_factor = att->dstAlphaBlendFactor; } info.att_count = cb->attachmentCount; diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 4707b257798..48bc36f29da 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -2061,12 +2061,12 @@ struct radv_color_blend_info { struct { uint8_t color_write_mask; bool blend_enable; - uint16_t color_blend_op; - uint16_t alpha_blend_op; - uint16_t src_color_blend_factor; - uint16_t dst_color_blend_factor; - uint16_t src_alpha_blend_factor; - uint16_t dst_alpha_blend_factor; + VkBlendOp color_blend_op; + VkBlendOp alpha_blend_op; + VkBlendFactor src_color_blend_factor; + VkBlendFactor dst_color_blend_factor; + VkBlendFactor src_alpha_blend_factor; + VkBlendFactor dst_alpha_blend_factor; } att[MAX_RTS]; };