anv: split buffer view from anv_image.c

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30285>
This commit is contained in:
Lionel Landwerlin 2024-07-21 11:53:00 +03:00 committed by Marge Bot
parent f5af56528b
commit eff01c46d8
4 changed files with 123 additions and 117 deletions

View file

@ -0,0 +1,106 @@
/* Copyright © 2024 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "anv_private.h"
static void
anv_fill_buffer_view_surface_state(struct anv_device *device,
struct anv_buffer_state *state,
enum isl_format format,
struct isl_swizzle swizzle,
isl_surf_usage_flags_t usage,
struct anv_address address,
uint32_t range, uint32_t stride)
{
anv_fill_buffer_surface_state(device,
state->state_data.data,
format, swizzle, usage,
address, range, stride);
if (state->state.map)
memcpy(state->state.map, state->state_data.data, ANV_SURFACE_STATE_SIZE);
}
VkResult
anv_CreateBufferView(VkDevice _device,
const VkBufferViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkBufferView *pView)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
struct anv_buffer_view *view;
view = vk_buffer_view_create(&device->vk, pCreateInfo,
pAllocator, sizeof(*view));
if (!view)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
const VkBufferUsageFlags2CreateInfoKHR *view_usage_info =
vk_find_struct_const(pCreateInfo->pNext, BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
const VkBufferUsageFlags buffer_usage =
view_usage_info != NULL ? view_usage_info->usage : buffer->vk.usage;
struct anv_format_plane format;
format = anv_get_format_plane(device->info, pCreateInfo->format,
0, VK_IMAGE_TILING_LINEAR);
const uint32_t format_bs = isl_format_get_layout(format.isl_format)->bpb / 8;
const uint32_t align_range =
align_down_npot_u32(view->vk.range, format_bs);
view->address = anv_address_add(buffer->address, pCreateInfo->offset);
if (buffer_usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
view->general.state = anv_device_maybe_alloc_surface_state(device, NULL);
anv_fill_buffer_view_surface_state(device,
&view->general,
format.isl_format,
format.swizzle,
ISL_SURF_USAGE_TEXTURE_BIT,
view->address, align_range, format_bs);
} else {
view->general.state = ANV_STATE_NULL;
}
if (buffer_usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) {
view->storage.state = anv_device_maybe_alloc_surface_state(device, NULL);
anv_fill_buffer_view_surface_state(device,
&view->storage,
format.isl_format, format.swizzle,
ISL_SURF_USAGE_STORAGE_BIT,
view->address, align_range, format_bs);
} else {
view->storage.state = ANV_STATE_NULL;
}
*pView = anv_buffer_view_to_handle(view);
return VK_SUCCESS;
}
void
anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
if (!view)
return;
if (view->general.state.alloc_size > 0) {
anv_state_pool_free(&device->bindless_surface_state_pool,
view->general.state);
}
if (view->storage.state.alloc_size > 0) {
anv_state_pool_free(&device->bindless_surface_state_pool,
view->storage.state);
}
vk_buffer_view_destroy(&device->vk, pAllocator, &view->vk);
}

View file

@ -3231,19 +3231,6 @@ anv_layout_has_untracked_aux_writes(const struct intel_device_info * const devin
return true;
}
static struct anv_state
maybe_alloc_surface_state(struct anv_device *device,
struct anv_state_stream *surface_state_stream)
{
if (device->physical->indirect_descriptors) {
if (surface_state_stream)
return anv_state_stream_alloc(surface_state_stream, 64, 64);
return anv_state_pool_alloc(&device->bindless_surface_state_pool, 64, 64);
} else {
return ANV_STATE_NULL;
}
}
static enum isl_channel_select
remap_swizzle(VkComponentSwizzle swizzle,
struct isl_swizzle format_swizzle)
@ -3649,9 +3636,9 @@ anv_image_view_init(struct anv_device *device,
if (iview->vk.usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
iview->planes[vplane].optimal_sampler.state =
maybe_alloc_surface_state(device, surface_state_stream);
anv_device_maybe_alloc_surface_state(device, surface_state_stream);
iview->planes[vplane].general_sampler.state =
maybe_alloc_surface_state(device, surface_state_stream);
anv_device_maybe_alloc_surface_state(device, surface_state_stream);
enum isl_aux_usage general_aux_usage =
anv_layout_to_aux_usage(device->info, image, 1UL << iaspect_bit,
@ -3699,7 +3686,7 @@ anv_image_view_init(struct anv_device *device,
VK_QUEUE_COMPUTE_BIT |
VK_QUEUE_TRANSFER_BIT);
iview->planes[vplane].storage.state =
maybe_alloc_surface_state(device, surface_state_stream);
anv_device_maybe_alloc_surface_state(device, surface_state_stream);
anv_image_fill_surface_state(device, image, 1ULL << iaspect_bit,
&storage_view,
@ -3773,107 +3760,6 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
vk_free2(&iview->vk.base.device->alloc, pAllocator, iview);
}
static void
anv_fill_buffer_view_surface_state(struct anv_device *device,
struct anv_buffer_state *state,
enum isl_format format,
struct isl_swizzle swizzle,
isl_surf_usage_flags_t usage,
struct anv_address address,
uint32_t range, uint32_t stride)
{
anv_fill_buffer_surface_state(device,
state->state_data.data,
format, swizzle, usage,
address, range, stride);
if (state->state.map)
memcpy(state->state.map, state->state_data.data, ANV_SURFACE_STATE_SIZE);
}
VkResult
anv_CreateBufferView(VkDevice _device,
const VkBufferViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkBufferView *pView)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
struct anv_buffer_view *view;
view = vk_buffer_view_create(&device->vk, pCreateInfo,
pAllocator, sizeof(*view));
if (!view)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
const VkBufferUsageFlags2CreateInfoKHR *view_usage_info =
vk_find_struct_const(pCreateInfo->pNext, BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
const VkBufferUsageFlags buffer_usage =
view_usage_info != NULL ? view_usage_info->usage : buffer->vk.usage;
struct anv_format_plane format;
format = anv_get_format_plane(device->info, pCreateInfo->format,
0, VK_IMAGE_TILING_LINEAR);
const uint32_t format_bs = isl_format_get_layout(format.isl_format)->bpb / 8;
const uint32_t align_range =
align_down_npot_u32(view->vk.range, format_bs);
view->address = anv_address_add(buffer->address, pCreateInfo->offset);
if (buffer_usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
view->general.state = maybe_alloc_surface_state(device, NULL);
anv_fill_buffer_view_surface_state(device,
&view->general,
format.isl_format,
format.swizzle,
ISL_SURF_USAGE_TEXTURE_BIT,
view->address, align_range, format_bs);
} else {
view->general.state = ANV_STATE_NULL;
}
if (buffer_usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) {
view->storage.state = maybe_alloc_surface_state(device, NULL);
anv_fill_buffer_view_surface_state(device,
&view->storage,
format.isl_format, format.swizzle,
ISL_SURF_USAGE_STORAGE_BIT,
view->address, align_range, format_bs);
} else {
view->storage.state = ANV_STATE_NULL;
}
*pView = anv_buffer_view_to_handle(view);
return VK_SUCCESS;
}
void
anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
if (!view)
return;
if (view->general.state.alloc_size > 0) {
anv_state_pool_free(&device->bindless_surface_state_pool,
view->general.state);
}
if (view->storage.state.alloc_size > 0) {
anv_state_pool_free(&device->bindless_surface_state_pool,
view->storage.state);
}
vk_buffer_view_destroy(&device->vk, pAllocator, &view->vk);
}
void anv_GetRenderingAreaGranularityKHR(
VkDevice _device,
const VkRenderingAreaInfoKHR* pRenderingAreaInfo,

View file

@ -2100,6 +2100,19 @@ anv_bindless_state_for_binding_table(struct anv_device *device,
return state;
}
static inline struct anv_state
anv_device_maybe_alloc_surface_state(struct anv_device *device,
struct anv_state_stream *surface_state_stream)
{
if (device->physical->indirect_descriptors) {
if (surface_state_stream)
return anv_state_stream_alloc(surface_state_stream, 64, 64);
return anv_state_pool_alloc(&device->bindless_surface_state_pool, 64, 64);
} else {
return ANV_STATE_NULL;
}
}
static inline uint32_t
anv_mocs(const struct anv_device *device,
const struct anv_bo *bo,

View file

@ -149,6 +149,7 @@ libanv_files = files(
'anv_blorp.c',
'anv_bo_sync.c',
'anv_buffer.c',
'anv_buffer_view.c',
'anv_cmd_buffer.c',
'anv_descriptor_set.c',
'anv_device.c',