diff --git a/src/vulkan/runtime/vk_graphics_state.c b/src/vulkan/runtime/vk_graphics_state.c index 9bc4f21493b..db2bd178e7b 100644 --- a/src/vulkan/runtime/vk_graphics_state.c +++ b/src/vulkan/runtime/vk_graphics_state.c @@ -23,8 +23,9 @@ enum mesa_vk_graphics_state_groups { MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT = (1 << 7), MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT = (1 << 8), MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT = (1 << 9), - MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT = (1 << 10), - MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT = (1 << 11), + MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT = (1 << 10), + MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT = (1 << 11), + MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT = (1 << 12), }; static void @@ -129,6 +130,9 @@ get_dynamic_state_groups(BITSET_WORD *dynamic, if (groups & MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT) BITSET_SET(dynamic, MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP); + if (groups & MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT) + BITSET_SET(dynamic, MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP); + if (groups & MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT) BITSET_SET(dynamic, MESA_VK_DYNAMIC_ATTACHMENT_FEEDBACK_LOOP_ENABLE); } @@ -175,6 +179,9 @@ fully_dynamic_state_groups(const BITSET_WORD *dynamic) if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP)) groups |= MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT; + if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP)) + groups |= MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT; + return groups; } @@ -1020,21 +1027,46 @@ vk_color_blend_state_init(struct vk_color_blend_state *cb, } static void -vk_rendering_attachment_location_state_init(struct vk_rendering_attachment_location_state *ral, - const BITSET_WORD *dynamic, - const VkRenderingAttachmentLocationInfoKHR *ral_info) +vk_input_attachment_location_state_init(struct vk_input_attachment_location_state *ial, + const BITSET_WORD *dynamic, + const VkRenderingInputAttachmentIndexInfoKHR *ial_info) { - *ral = (struct vk_rendering_attachment_location_state) { + *ial = (struct vk_input_attachment_location_state) { .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, + .depth_att = MESA_VK_ATTACHMENT_UNUSED, + .stencil_att = MESA_VK_ATTACHMENT_UNUSED, }; - if (!ral_info) + if (!ial_info) return; - for (uint32_t a = 0; a < MIN2(ral_info->colorAttachmentCount, + for (uint32_t a = 0; a < MIN2(ial_info->colorAttachmentCount, MESA_VK_MAX_COLOR_ATTACHMENTS); a++) { - ral->color_map[a] = - ral_info->pColorAttachmentLocations[a] == VK_ATTACHMENT_UNUSED ? - MESA_VK_ATTACHMENT_UNUSED : ral_info->pColorAttachmentLocations[a]; + ial->color_map[a] = + ial_info->pColorAttachmentInputIndices[a] == VK_ATTACHMENT_UNUSED ? + MESA_VK_ATTACHMENT_UNUSED : ial_info->pColorAttachmentInputIndices[a]; + } + ial->depth_att = ial_info->pDepthInputAttachmentIndex != NULL ? + *ial_info->pDepthInputAttachmentIndex : MESA_VK_ATTACHMENT_UNUSED; + ial->stencil_att = ial_info->pStencilInputAttachmentIndex != NULL ? + *ial_info->pStencilInputAttachmentIndex : MESA_VK_ATTACHMENT_UNUSED; +} + +static void +vk_color_attachment_location_state_init(struct vk_color_attachment_location_state *cal, + const BITSET_WORD *dynamic, + const VkRenderingAttachmentLocationInfoKHR *cal_info) +{ + *cal = (struct vk_color_attachment_location_state) { + .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, + }; + if (!cal_info) + return; + + for (uint32_t a = 0; a < MIN2(cal_info->colorAttachmentCount, + MESA_VK_MAX_COLOR_ATTACHMENTS); a++) { + cal->color_map[a] = + cal_info->pColorAttachmentLocations[a] == VK_ATTACHMENT_UNUSED ? + MESA_VK_ATTACHMENT_UNUSED : cal_info->pColorAttachmentLocations[a]; } } @@ -1059,12 +1091,24 @@ vk_dynamic_graphics_state_init_cb(struct vk_dynamic_graphics_state *dst, } static void -vk_dynamic_graphics_state_init_ral(struct vk_dynamic_graphics_state *dst, +vk_dynamic_graphics_state_init_ial(struct vk_dynamic_graphics_state *dst, const BITSET_WORD *needed, - const struct vk_rendering_attachment_location_state *ral) + const struct vk_input_attachment_location_state *ial) +{ + if (IS_NEEDED(INPUT_ATTACHMENT_MAP)) { + typed_memcpy(dst->ial.color_map, ial->color_map, MESA_VK_MAX_COLOR_ATTACHMENTS); + dst->ial.depth_att = ial->depth_att; + dst->ial.stencil_att = ial->stencil_att; + } +} + +static void +vk_dynamic_graphics_state_init_cal(struct vk_dynamic_graphics_state *dst, + const BITSET_WORD *needed, + const struct vk_color_attachment_location_state *cal) { if (IS_NEEDED(COLOR_ATTACHMENT_MAP)) - typed_memcpy(dst->ral.color_map, ral->color_map, MESA_VK_MAX_COLOR_ATTACHMENTS); + typed_memcpy(dst->cal.color_map, cal->color_map, MESA_VK_MAX_COLOR_ATTACHMENTS); } static bool @@ -1232,8 +1276,10 @@ vk_dynamic_graphics_state_init_rp(struct vk_dynamic_graphics_state *dst, vk_depth_stencil_state, ds); \ f(MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT, \ vk_color_blend_state, cb); \ + f(MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT, \ + vk_input_attachment_location_state, ial); \ f(MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT, \ - vk_rendering_attachment_location_state, ral); \ + vk_color_attachment_location_state, cal); \ f(MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT, \ vk_render_pass_state, rp); @@ -1467,7 +1513,6 @@ vk_graphics_pipeline_state_fill(const struct vk_device *device, if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) { needs |= MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT; - needs |= MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT; /* From the Vulkan 1.3.218 spec: * @@ -1526,15 +1571,18 @@ vk_graphics_pipeline_state_fill(const struct vk_device *device, VK_IMAGE_ASPECT_STENCIL_BIT)) || !vk_render_pass_state_is_complete(&rp)) needs |= MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT; + + needs |= MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT; } if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT) { if (rp.attachment_aspects & (VK_IMAGE_ASPECT_COLOR_BIT)) { - needs |= MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT | - MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT; + needs |= MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT; } needs |= MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT; + + needs |= MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT; } /* @@ -1659,7 +1707,9 @@ vk_graphics_pipeline_state_fill(const struct vk_device *device, const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_info = vk_find_struct_const(info->pNext, PIPELINE_FRAGMENT_SHADING_RATE_STATE_CREATE_INFO_KHR); - const VkRenderingAttachmentLocationInfoKHR *ral_info = + const VkRenderingInputAttachmentIndexInfoKHR *ial_info = + vk_find_struct_const(info->pNext, RENDERING_INPUT_ATTACHMENT_INDEX_INFO_KHR); + const VkRenderingAttachmentLocationInfoKHR *cal_info = vk_find_struct_const(info->pNext, RENDERING_ATTACHMENT_LOCATION_INFO_KHR); /* @@ -1840,7 +1890,12 @@ const struct vk_dynamic_graphics_state vk_default_dynamic_graphics_state = { .color_write_enables = 0xffu, .attachment_count = MESA_VK_MAX_COLOR_ATTACHMENTS, }, - .ral = { + .ial = { + .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, + .depth_att = MESA_VK_ATTACHMENT_UNUSED, + .stencil_att = MESA_VK_ATTACHMENT_UNUSED, + }, + .cal = { .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 }, }, }; @@ -2141,7 +2196,7 @@ vk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state *dst, COPY_ARRAY(CB_BLEND_CONSTANTS, cb.blend_constants, 4); if (IS_SET_IN_SRC(COLOR_ATTACHMENT_MAP)) { - COPY_ARRAY(COLOR_ATTACHMENT_MAP, ral.color_map, + COPY_ARRAY(COLOR_ATTACHMENT_MAP, cal.color_map, MESA_VK_MAX_COLOR_ATTACHMENTS); } @@ -3035,7 +3090,7 @@ vk_common_CmdSetRenderingAttachmentLocationsKHR( uint8_t val = pLocationInfo->pColorAttachmentLocations[i] == VK_ATTACHMENT_UNUSED ? MESA_VK_ATTACHMENT_UNUSED : pLocationInfo->pColorAttachmentLocations[i]; - SET_DYN_VALUE(dyn, COLOR_ATTACHMENT_MAP, ral.color_map[i], val); + SET_DYN_VALUE(dyn, COLOR_ATTACHMENT_MAP, cal.color_map[i], val); } } @@ -3053,15 +3108,19 @@ vk_common_CmdSetRenderingInputAttachmentIndicesKHR( pLocationInfo->pColorAttachmentInputIndices[i] == VK_ATTACHMENT_UNUSED ? MESA_VK_ATTACHMENT_UNUSED : pLocationInfo->pColorAttachmentInputIndices[i]; SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, - color_input_attachment_map[i], val); + ial.color_map[i], val); } - SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, - depth_input_attachment_unused, - pLocationInfo->pDepthInputAttachmentIndex == NULL); - SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, - stencil_input_attachment_unused, - pLocationInfo->pStencilInputAttachmentIndex == NULL); + uint8_t depth_att = + (pLocationInfo->pDepthInputAttachmentIndex == NULL || + *pLocationInfo->pDepthInputAttachmentIndex == VK_ATTACHMENT_UNUSED) ? + MESA_VK_ATTACHMENT_UNUSED : *pLocationInfo->pDepthInputAttachmentIndex; + uint8_t stencil_att = + (pLocationInfo->pStencilInputAttachmentIndex == NULL || + *pLocationInfo->pStencilInputAttachmentIndex == VK_ATTACHMENT_UNUSED) ? + MESA_VK_ATTACHMENT_UNUSED : *pLocationInfo->pStencilInputAttachmentIndex; + SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, ial.depth_att, depth_att); + SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, ial.stencil_att, stencil_att); } const char * diff --git a/src/vulkan/runtime/vk_graphics_state.h b/src/vulkan/runtime/vk_graphics_state.h index cc62c8cc7c8..d18b4d5eb84 100644 --- a/src/vulkan/runtime/vk_graphics_state.h +++ b/src/vulkan/runtime/vk_graphics_state.h @@ -668,7 +668,28 @@ struct vk_color_blend_state { }; /***/ -struct vk_rendering_attachment_location_state { +struct vk_input_attachment_location_state { + /** VkRenderingInputAttachmentIndexInfoKHR::pColorAttachmentLocations + * + * MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP + */ + uint8_t color_map[MESA_VK_MAX_COLOR_ATTACHMENTS]; + + /** VkRenderingInputAttachmentIndexInfoKHR::pDepthInputAttachmentIndex + * + * MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP + */ + uint8_t depth_att; + + /** VkRenderingInputAttachmentIndexInfoKHR::pStencilInputAttachmentIndex + * + * MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP + */ + uint8_t stencil_att; +}; + +/***/ +struct vk_color_attachment_location_state { /** VkRenderingAttachmentLocationInfoKHR::pColorAttachmentLocations * * MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP @@ -847,17 +868,11 @@ struct vk_dynamic_graphics_state { /** MESA_VK_DYNAMIC_ATTACHMENT_FEEDBACK_LOOP_ENABLE */ VkImageAspectFlags feedback_loops; + /** MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP */ + struct vk_input_attachment_location_state ial; + /** MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP */ - struct vk_rendering_attachment_location_state ral; - - /** MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP */ - uint8_t color_input_attachment_map[MESA_VK_MAX_COLOR_ATTACHMENTS]; - - /** MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP */ - bool depth_input_attachment_unused; - - /** MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP */ - bool stencil_input_attachment_unused; + struct vk_color_attachment_location_state cal; /** For pipelines, which bits of dynamic state are set */ BITSET_DECLARE(set, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX); @@ -879,7 +894,8 @@ struct vk_graphics_pipeline_all_state { struct vk_sample_locations_state ms_sample_locations; struct vk_depth_stencil_state ds; struct vk_color_blend_state cb; - struct vk_rendering_attachment_location_state ral; + struct vk_input_attachment_location_state ial; + struct vk_color_attachment_location_state cal; struct vk_render_pass_state rp; }; @@ -937,8 +953,11 @@ struct vk_graphics_pipeline_state { /** Color blend state */ const struct vk_color_blend_state *cb; + /** Input attachment mapping state */ + const struct vk_input_attachment_location_state *ial; + /** Color attachment mapping state */ - const struct vk_rendering_attachment_location_state *ral; + const struct vk_color_attachment_location_state *cal; /** Render pass state */ const struct vk_render_pass_state *rp; @@ -1189,6 +1208,21 @@ vk_cmd_set_cb_attachment_count(struct vk_command_buffer *cmd, const char * vk_dynamic_graphic_state_to_str(enum mesa_vk_dynamic_graphics_state state); +/** Check whether the color attachment location map is the identity + * + * :param cal: |in| Color attachment location state + */ +static inline bool +vk_color_attachment_location_state_is_identity( + const struct vk_color_attachment_location_state *cal) +{ + for (unsigned i = 0; i < ARRAY_SIZE(cal->color_map); i++) { + if (cal->color_map[i] != i) + return false; + } + return true; +} + #ifdef __cplusplus } #endif