About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/freedreno/vulkan/tu_buffer_view.cc
blob: 9c3f881fa99f43fa1f183a73027ac0eaafd3aaad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright © 2024 Valentine Burley
 * SPDX-License-Identifier: MIT
 */

#include "tu_buffer_view.h"

#include "tu_buffer.h"
#include "tu_device.h"
#include "tu_formats.h"

VKAPI_ATTR VkResult VKAPI_CALL
tu_CreateBufferView(VkDevice _device,
                    const VkBufferViewCreateInfo *pCreateInfo,
                    const VkAllocationCallbacks *pAllocator,
                    VkBufferView *pView)
{
   VK_FROM_HANDLE(tu_device, device, _device);
   VK_FROM_HANDLE(tu_buffer, buffer, pCreateInfo->buffer);
   struct tu_buffer_view *view;

   view = (struct tu_buffer_view *) vk_buffer_view_create(
      &device->vk, pCreateInfo, pAllocator, sizeof(*view));

   if (!view)
      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);

   uint8_t swiz[4] = { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z,
                       PIPE_SWIZZLE_W };

   TU_CALLX(device, fdl6_buffer_view_init)(
      view->descriptor, vk_format_to_pipe_format(view->vk.format),
      swiz, vk_buffer_address(&buffer->vk, view->vk.offset), view->vk.range);

   *pView = tu_buffer_view_to_handle(view);

   return VK_SUCCESS;
}

VKAPI_ATTR void VKAPI_CALL
tu_DestroyBufferView(VkDevice _device,
                     VkBufferView bufferView,
                     const VkAllocationCallbacks *pAllocator)
{
   VK_FROM_HANDLE(tu_device, device, _device);
   VK_FROM_HANDLE(tu_buffer_view, view, bufferView);

   if (!view)
      return;

   vk_buffer_view_destroy(&device->vk, pAllocator, &view->vk);
}