anv: Add helpers for getting the surface state from an image view

Gets rid of some duplicated logic.

Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23523>
This commit is contained in:
Faith Ekstrand 2023-03-29 09:47:20 -05:00 committed by Marge Bot
parent 16391645ef
commit bd285a6ad5
3 changed files with 23 additions and 8 deletions

View file

@ -2030,9 +2030,8 @@ anv_descriptor_set_write_image_view(struct anv_device *device,
if (image_view) {
for (unsigned p = 0; p < image_view->n_planes; p++) {
const struct anv_surface_state *sstate =
(desc->layout == VK_IMAGE_LAYOUT_GENERAL) ?
&image_view->planes[p].general_sampler :
&image_view->planes[p].optimal_sampler;
anv_image_view_texture_surface_state(image_view, p,
desc->layout);
desc_data[p].image =
anv_surface_state_to_handle(device->physical, sstate->state);
}
@ -2057,7 +2056,7 @@ anv_descriptor_set_write_image_view(struct anv_device *device,
struct anv_storage_image_descriptor desc_data = {
.vanilla = anv_surface_state_to_handle(
device->physical,
image_view->planes[0].storage.state),
anv_image_view_storage_surface_state(image_view)->state),
.image_depth = image_view->vk.storage.z_slice_count,
};
memcpy(desc_surface_map, &desc_data, sizeof(desc_data));

View file

@ -5329,6 +5329,22 @@ void anv_image_fill_surface_state(struct anv_device *device,
enum anv_image_view_state_flags flags,
struct anv_surface_state *state_inout);
static inline const struct anv_surface_state *
anv_image_view_texture_surface_state(const struct anv_image_view *iview,
uint32_t plane, VkImageLayout layout)
{
return layout == VK_IMAGE_LAYOUT_GENERAL ?
&iview->planes[plane].general_sampler :
&iview->planes[plane].optimal_sampler;
}
static inline const struct anv_surface_state *
anv_image_view_storage_surface_state(const struct anv_image_view *iview)
{
return &iview->planes[0].storage;
}
static inline bool
anv_cmd_graphics_state_has_image_as_attachment(const struct anv_cmd_graphics_state *state,
const struct anv_image *image)

View file

@ -1879,9 +1879,9 @@ emit_indirect_descriptor_binding_table_entry(struct anv_cmd_buffer *cmd_buffer,
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
if (desc->image_view) {
const struct anv_surface_state *sstate =
(desc->layout == VK_IMAGE_LAYOUT_GENERAL) ?
&desc->image_view->planes[binding->plane].general_sampler :
&desc->image_view->planes[binding->plane].optimal_sampler;
anv_image_view_texture_surface_state(desc->image_view,
binding->plane,
desc->layout);
surface_state = desc->image_view->use_surface_state_stream ?
sstate->state :
anv_bindless_state_for_binding_table(device, sstate->state);
@ -1895,7 +1895,7 @@ emit_indirect_descriptor_binding_table_entry(struct anv_cmd_buffer *cmd_buffer,
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
if (desc->image_view) {
const struct anv_surface_state *sstate =
&desc->image_view->planes[binding->plane].storage;
anv_image_view_storage_surface_state(desc->image_view);
surface_state = desc->image_view->use_surface_state_stream ?
sstate->state :
anv_bindless_state_for_binding_table(device, sstate->state);