| 1 |
/* |
| 2 |
* Copyright © 2021 Collabora Ltd. |
| 3 |
* |
| 4 |
* Derived from tu_image.c which is: |
| 5 |
* Copyright © 2016 Red Hat. |
| 6 |
* Copyright © 2016 Bas Nieuwenhuizen |
| 7 |
* Copyright © 2015 Intel Corporation |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: MIT |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "genxml/gen_macros.h" |
| 13 |
|
| 14 |
#include "panvk_buffer.h" |
| 15 |
#include "panvk_buffer_view.h" |
| 16 |
#include "panvk_device.h" |
| 17 |
#include "panvk_entrypoints.h" |
| 18 |
#include "panvk_priv_bo.h" |
| 19 |
|
| 20 |
#include "pan_afbc.h" |
| 21 |
#include "pan_buffer.h" |
| 22 |
#include "pan_desc.h" |
| 23 |
#include "pan_props.h" |
| 24 |
|
| 25 |
#include "vk_format.h" |
| 26 |
#include "vk_log.h" |
| 27 |
|
| 28 |
VKAPI_ATTR VkResult VKAPI_CALL |
| 29 |
panvk_per_arch(CreateBufferView)(VkDevice _device, |
| 30 |
const VkBufferViewCreateInfo *pCreateInfo, |
| 31 |
const VkAllocationCallbacks *pAllocator, |
| 32 |
VkBufferView *pView) |
| 33 |
{ |
| 34 |
VK_FROM_HANDLE(panvk_device, device, _device); |
| 35 |
VK_FROM_HANDLE(panvk_buffer, buffer, pCreateInfo->buffer); |
| 36 |
|
| 37 |
struct panvk_buffer_view *view = vk_object_zalloc( |
| 38 |
&device->vk, pAllocator, sizeof(*view), VK_OBJECT_TYPE_BUFFER_VIEW); |
| 39 |
|
| 40 |
if (!view) |
| 41 |
return panvk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 42 |
|
| 43 |
vk_buffer_view_init(&device->vk, &view->vk, pCreateInfo); |
| 44 |
|
| 45 |
enum pipe_format pfmt = vk_format_to_pipe_format(view->vk.format); |
| 46 |
|
| 47 |
VkBufferUsageFlags tex_usage_mask = |
| 48 |
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | |
| 49 |
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; |
| 50 |
|
| 51 |
if (buffer->vk.usage & tex_usage_mask) { |
| 52 |
struct pan_buffer_view bview = { |
| 53 |
.format = pfmt, |
| 54 |
.width_el = view->vk.elements, |
| 55 |
.base = panvk_buffer_gpu_ptr(buffer, pCreateInfo->offset), |
| 56 |
}; |
| 57 |
#if PAN_ARCH >= 9 |
| 58 |
GENX(pan_buffer_texture_emit)(&bview, &view->descs.buf); |
| 59 |
#else |
| 60 |
GENX(pan_buffer_texture_emit)(&bview, &view->descs.attrib_buf, |
| 61 |
&view->descs.attrib); |
| 62 |
#endif |
| 63 |
} |
| 64 |
|
| 65 |
*pView = panvk_buffer_view_to_handle(view); |
| 66 |
return VK_SUCCESS; |
| 67 |
} |
| 68 |
|
| 69 |
VKAPI_ATTR void VKAPI_CALL |
| 70 |
panvk_per_arch(DestroyBufferView)(VkDevice _device, VkBufferView bufferView, |
| 71 |
const VkAllocationCallbacks *pAllocator) |
| 72 |
{ |
| 73 |
VK_FROM_HANDLE(panvk_device, device, _device); |
| 74 |
VK_FROM_HANDLE(panvk_buffer_view, view, bufferView); |
| 75 |
|
| 76 |
if (!view) |
| 77 |
return; |
| 78 |
|
| 79 |
vk_buffer_view_destroy(&device->vk, pAllocator, &view->vk); |
| 80 |
} |