tu: Move buffer related code to tu_buffer.cc/h
More code isolation. Match the structure of the common Vulkan runtime, NVK and RADV. Signed-off-by: Valentine Burley <valentine.burley@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29854>
This commit is contained in:

committed by
Marge Bot

parent
c0a9b0f8d6
commit
d882198fc3
@@ -21,6 +21,7 @@ tu_entrypoints = custom_target(
|
||||
libtu_files = files(
|
||||
'layers/tu_rmv_layer.cc',
|
||||
'tu_autotune.cc',
|
||||
'tu_buffer.cc',
|
||||
'tu_clear_blit.cc',
|
||||
'tu_cmd_buffer.cc',
|
||||
'tu_cs_breadcrumbs.cc',
|
||||
|
173
src/freedreno/vulkan/tu_buffer.cc
Normal file
173
src/freedreno/vulkan/tu_buffer.cc
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright © 2016 Red Hat.
|
||||
* Copyright © 2016 Bas Nieuwenhuizen
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* based in part on anv driver which is:
|
||||
* Copyright © 2015 Intel Corporation
|
||||
*/
|
||||
|
||||
#include "tu_buffer.h"
|
||||
|
||||
#include "tu_device.h"
|
||||
#include "tu_rmv.h"
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_CreateBuffer(VkDevice _device,
|
||||
const VkBufferCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkBuffer *pBuffer)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
struct tu_buffer *buffer;
|
||||
|
||||
buffer = (struct tu_buffer *) vk_buffer_create(
|
||||
&device->vk, pCreateInfo, pAllocator, sizeof(*buffer));
|
||||
if (buffer == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
TU_RMV(buffer_create, device, buffer);
|
||||
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_create_buffer(device, buffer);
|
||||
#endif
|
||||
|
||||
*pBuffer = tu_buffer_to_handle(buffer);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_DestroyBuffer(VkDevice _device,
|
||||
VkBuffer _buffer,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, _buffer);
|
||||
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
TU_RMV(buffer_destroy, device, buffer);
|
||||
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_destroy_buffer(device, buffer);
|
||||
#endif
|
||||
|
||||
vk_buffer_destroy(&device->vk, pAllocator, &buffer->vk);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_GetDeviceBufferMemoryRequirements(
|
||||
VkDevice _device,
|
||||
const VkDeviceBufferMemoryRequirements *pInfo,
|
||||
VkMemoryRequirements2 *pMemoryRequirements)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
|
||||
uint64_t size = pInfo->pCreateInfo->size;
|
||||
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
||||
.size = MAX2(align64(size, 64), size),
|
||||
.alignment = 64,
|
||||
.memoryTypeBits = (1 << device->physical_device->memory.type_count) - 1,
|
||||
};
|
||||
|
||||
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
||||
switch (ext->sType) {
|
||||
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
|
||||
VkMemoryDedicatedRequirements *req =
|
||||
(VkMemoryDedicatedRequirements *) ext;
|
||||
req->requiresDedicatedAllocation = false;
|
||||
req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_GetPhysicalDeviceExternalBufferProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
|
||||
VkExternalBufferProperties *pExternalBufferProperties)
|
||||
{
|
||||
BITMASK_ENUM(VkExternalMemoryFeatureFlagBits) flags = 0;
|
||||
VkExternalMemoryHandleTypeFlags export_flags = 0;
|
||||
VkExternalMemoryHandleTypeFlags compat_flags = 0;
|
||||
switch (pExternalBufferInfo->handleType) {
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
|
||||
flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
|
||||
VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
|
||||
compat_flags = export_flags =
|
||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
|
||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
|
||||
break;
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
|
||||
flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
|
||||
compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pExternalBufferProperties->externalMemoryProperties =
|
||||
(VkExternalMemoryProperties) {
|
||||
.externalMemoryFeatures = flags,
|
||||
.exportFromImportedHandleTypes = export_flags,
|
||||
.compatibleHandleTypes = compat_flags,
|
||||
};
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_BindBufferMemory2(VkDevice device,
|
||||
uint32_t bindInfoCount,
|
||||
const VkBindBufferMemoryInfo *pBindInfos)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, dev, device);
|
||||
|
||||
for (uint32_t i = 0; i < bindInfoCount; ++i) {
|
||||
VK_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory);
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, pBindInfos[i].buffer);
|
||||
|
||||
const VkBindMemoryStatusKHR *status =
|
||||
vk_find_struct_const(pBindInfos[i].pNext, BIND_MEMORY_STATUS_KHR);
|
||||
if (status)
|
||||
*status->pResult = VK_SUCCESS;
|
||||
|
||||
if (mem) {
|
||||
buffer->bo = mem->bo;
|
||||
buffer->iova = mem->bo->iova + pBindInfos[i].memoryOffset;
|
||||
if (buffer->vk.usage &
|
||||
(VK_BUFFER_USAGE_2_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT |
|
||||
VK_BUFFER_USAGE_2_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT))
|
||||
tu_bo_allow_dump(dev, mem->bo);
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_bind_buffer(dev, buffer);
|
||||
#endif
|
||||
} else {
|
||||
buffer->bo = NULL;
|
||||
}
|
||||
|
||||
TU_RMV(buffer_bind, dev, buffer);
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkDeviceAddress
|
||||
tu_GetBufferDeviceAddress(VkDevice _device,
|
||||
const VkBufferDeviceAddressInfo* pInfo)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, pInfo->buffer);
|
||||
|
||||
return buffer->iova;
|
||||
}
|
||||
|
||||
uint64_t tu_GetBufferOpaqueCaptureAddress(
|
||||
VkDevice _device,
|
||||
const VkBufferDeviceAddressInfo* pInfo)
|
||||
{
|
||||
/* We care only about memory allocation opaque addresses */
|
||||
return 0;
|
||||
}
|
28
src/freedreno/vulkan/tu_buffer.h
Normal file
28
src/freedreno/vulkan/tu_buffer.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright © 2016 Red Hat.
|
||||
* Copyright © 2016 Bas Nieuwenhuizen
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* based in part on anv driver which is:
|
||||
* Copyright © 2015 Intel Corporation
|
||||
*/
|
||||
|
||||
#ifndef TU_BUFFER_H
|
||||
#define TU_BUFFER_H
|
||||
|
||||
#include "tu_common.h"
|
||||
|
||||
#include "vk_buffer.h"
|
||||
|
||||
struct tu_buffer
|
||||
{
|
||||
struct vk_buffer vk;
|
||||
|
||||
struct tu_bo *bo;
|
||||
uint64_t iova;
|
||||
};
|
||||
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer, vk.base, VkBuffer,
|
||||
VK_OBJECT_TYPE_BUFFER)
|
||||
|
||||
#endif /* TU_BUFFER_H */
|
@@ -16,6 +16,7 @@
|
||||
#include "util/half_float.h"
|
||||
#include "compiler/nir/nir_builder.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_cmd_buffer.h"
|
||||
#include "tu_cs.h"
|
||||
#include "tu_formats.h"
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "vk_render_pass.h"
|
||||
#include "vk_util.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_clear_blit.h"
|
||||
#include "tu_cs.h"
|
||||
#include "tu_event.h"
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "vk_descriptors.h"
|
||||
#include "vk_util.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_device.h"
|
||||
#include "tu_image.h"
|
||||
#include "tu_formats.h"
|
||||
|
@@ -2948,36 +2948,6 @@ tu_UnmapMemory2KHR(VkDevice _device, const VkMemoryUnmapInfoKHR *pMemoryUnmapInf
|
||||
return tu_bo_unmap(device, mem->bo, pMemoryUnmapInfo->flags & VK_MEMORY_UNMAP_RESERVE_BIT_EXT);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_GetDeviceBufferMemoryRequirements(
|
||||
VkDevice _device,
|
||||
const VkDeviceBufferMemoryRequirements *pInfo,
|
||||
VkMemoryRequirements2 *pMemoryRequirements)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
|
||||
uint64_t size = pInfo->pCreateInfo->size;
|
||||
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
||||
.size = MAX2(align64(size, 64), size),
|
||||
.alignment = 64,
|
||||
.memoryTypeBits = (1 << dev->physical_device->memory.type_count) - 1,
|
||||
};
|
||||
|
||||
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
||||
switch (ext->sType) {
|
||||
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
|
||||
VkMemoryDedicatedRequirements *req =
|
||||
(VkMemoryDedicatedRequirements *) ext;
|
||||
req->requiresDedicatedAllocation = false;
|
||||
req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_GetDeviceMemoryCommitment(VkDevice device,
|
||||
VkDeviceMemory memory,
|
||||
@@ -2986,41 +2956,6 @@ tu_GetDeviceMemoryCommitment(VkDevice device,
|
||||
*pCommittedMemoryInBytes = 0;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_BindBufferMemory2(VkDevice device,
|
||||
uint32_t bindInfoCount,
|
||||
const VkBindBufferMemoryInfo *pBindInfos)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, dev, device);
|
||||
|
||||
for (uint32_t i = 0; i < bindInfoCount; ++i) {
|
||||
VK_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory);
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, pBindInfos[i].buffer);
|
||||
|
||||
const VkBindMemoryStatusKHR *status =
|
||||
vk_find_struct_const(pBindInfos[i].pNext, BIND_MEMORY_STATUS_KHR);
|
||||
if (status)
|
||||
*status->pResult = VK_SUCCESS;
|
||||
|
||||
if (mem) {
|
||||
buffer->bo = mem->bo;
|
||||
buffer->iova = mem->bo->iova + pBindInfos[i].memoryOffset;
|
||||
if (buffer->vk.usage &
|
||||
(VK_BUFFER_USAGE_2_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT |
|
||||
VK_BUFFER_USAGE_2_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT))
|
||||
tu_bo_allow_dump(dev, mem->bo);
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_bind_buffer(dev, buffer);
|
||||
#endif
|
||||
} else {
|
||||
buffer->bo = NULL;
|
||||
}
|
||||
|
||||
TU_RMV(buffer_bind, dev, buffer);
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_QueueBindSparse(VkQueue _queue,
|
||||
uint32_t bindInfoCount,
|
||||
@@ -3030,51 +2965,6 @@ tu_QueueBindSparse(VkQueue _queue,
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_CreateBuffer(VkDevice _device,
|
||||
const VkBufferCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkBuffer *pBuffer)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
struct tu_buffer *buffer;
|
||||
|
||||
buffer = (struct tu_buffer *) vk_buffer_create(
|
||||
&device->vk, pCreateInfo, pAllocator, sizeof(*buffer));
|
||||
if (buffer == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
TU_RMV(buffer_create, device, buffer);
|
||||
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_create_buffer(device, buffer);
|
||||
#endif
|
||||
|
||||
*pBuffer = tu_buffer_to_handle(buffer);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_DestroyBuffer(VkDevice _device,
|
||||
VkBuffer _buffer,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_device, device, _device);
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, _buffer);
|
||||
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
TU_RMV(buffer_destroy, device, buffer);
|
||||
|
||||
#ifdef HAVE_PERFETTO
|
||||
tu_perfetto_log_destroy_buffer(device, buffer);
|
||||
#endif
|
||||
|
||||
vk_buffer_destroy(&device->vk, pAllocator, &buffer->vk);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
tu_CreateFramebuffer(VkDevice _device,
|
||||
const VkFramebufferCreateInfo *pCreateInfo,
|
||||
@@ -3229,23 +3119,6 @@ tu_GetPhysicalDeviceMultisamplePropertiesEXT(
|
||||
pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){ 0, 0 };
|
||||
}
|
||||
|
||||
VkDeviceAddress
|
||||
tu_GetBufferDeviceAddress(VkDevice _device,
|
||||
const VkBufferDeviceAddressInfo* pInfo)
|
||||
{
|
||||
VK_FROM_HANDLE(tu_buffer, buffer, pInfo->buffer);
|
||||
|
||||
return buffer->iova;
|
||||
}
|
||||
|
||||
uint64_t tu_GetBufferOpaqueCaptureAddress(
|
||||
VkDevice device,
|
||||
const VkBufferDeviceAddressInfo* pInfo)
|
||||
{
|
||||
/* We care only about memory allocation opaque addresses */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t tu_GetDeviceMemoryOpaqueCaptureAddress(
|
||||
VkDevice device,
|
||||
const VkDeviceMemoryOpaqueCaptureAddressInfo* pInfo)
|
||||
|
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "tu_common.h"
|
||||
|
||||
#include "vk_buffer.h"
|
||||
#include "vk_device_memory.h"
|
||||
|
||||
#include "tu_autotune.h"
|
||||
@@ -420,16 +419,6 @@ struct tu_device_memory
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory, vk.base, VkDeviceMemory,
|
||||
VK_OBJECT_TYPE_DEVICE_MEMORY)
|
||||
|
||||
struct tu_buffer
|
||||
{
|
||||
struct vk_buffer vk;
|
||||
|
||||
struct tu_bo *bo;
|
||||
uint64_t iova;
|
||||
};
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer, vk.base, VkBuffer,
|
||||
VK_OBJECT_TYPE_BUFFER)
|
||||
|
||||
struct tu_attachment_info
|
||||
{
|
||||
struct tu_image_view *attachment;
|
||||
|
@@ -872,36 +872,3 @@ tu_GetPhysicalDeviceSparseImageFormatProperties2(
|
||||
/* Sparse images are not yet supported. */
|
||||
*pPropertyCount = 0;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
tu_GetPhysicalDeviceExternalBufferProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
|
||||
VkExternalBufferProperties *pExternalBufferProperties)
|
||||
{
|
||||
BITMASK_ENUM(VkExternalMemoryFeatureFlagBits) flags = 0;
|
||||
VkExternalMemoryHandleTypeFlags export_flags = 0;
|
||||
VkExternalMemoryHandleTypeFlags compat_flags = 0;
|
||||
switch (pExternalBufferInfo->handleType) {
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
|
||||
flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
|
||||
VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
|
||||
compat_flags = export_flags =
|
||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
|
||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
|
||||
break;
|
||||
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
|
||||
flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
|
||||
compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pExternalBufferProperties->externalMemoryProperties =
|
||||
(VkExternalMemoryProperties) {
|
||||
.externalMemoryFeatures = flags,
|
||||
.exportFromImportedHandleTypes = export_flags,
|
||||
.compatibleHandleTypes = compat_flags,
|
||||
};
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "drm-uapi/drm_fourcc.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_cs.h"
|
||||
#include "tu_descriptor_set.h"
|
||||
#include "tu_device.h"
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <perfetto.h>
|
||||
|
||||
#include "tu_perfetto.h"
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_device.h"
|
||||
#include "tu_image.h"
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "vk_util.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_cmd_buffer.h"
|
||||
#include "tu_cs.h"
|
||||
#include "tu_device.h"
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "tu_rmv.h"
|
||||
|
||||
#include "tu_buffer.h"
|
||||
#include "tu_cmd_buffer.h"
|
||||
#include "tu_cs.h"
|
||||
#include "tu_device.h"
|
||||
|
Reference in New Issue
Block a user