nvk: Add a buffer alignment helper
This consolodates buffer alignment calculations into one place, including physical device queries, buffer creation, and buffer memory requirements queries. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:

committed by
Marge Bot

parent
6a0cc93bd4
commit
0498eeba32
@@ -4,6 +4,26 @@
|
||||
#include "nvk_device_memory.h"
|
||||
#include "nvk_physical_device.h"
|
||||
|
||||
uint32_t
|
||||
nvk_get_buffer_alignment(UNUSED const struct nvk_physical_device *pdev,
|
||||
VkBufferUsageFlags usage_flags,
|
||||
UNUSED VkBufferCreateFlags create_flags)
|
||||
{
|
||||
uint32_t alignment = 16;
|
||||
|
||||
if (usage_flags & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
|
||||
alignment = MAX2(alignment, NVK_MIN_UBO_ALIGNMENT);
|
||||
|
||||
if (usage_flags & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)
|
||||
alignment = MAX2(alignment, NVK_MIN_SSBO_ALIGNMENT);
|
||||
|
||||
if (usage_flags & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT))
|
||||
alignment = MAX2(alignment, NVK_MIN_UBO_ALIGNMENT);
|
||||
|
||||
return alignment;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
nvk_CreateBuffer(VkDevice device,
|
||||
const VkBufferCreateInfo *pCreateInfo,
|
||||
@@ -45,9 +65,14 @@ nvk_GetDeviceBufferMemoryRequirements(
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_device, dev, device);
|
||||
|
||||
const uint32_t alignment =
|
||||
nvk_get_buffer_alignment(nvk_device_physical(dev),
|
||||
pInfo->pCreateInfo->usage,
|
||||
pInfo->pCreateInfo->flags);
|
||||
|
||||
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
||||
.size = pInfo->pCreateInfo->size,
|
||||
.alignment = 64, /* TODO */
|
||||
.size = ALIGN_POT(pInfo->pCreateInfo->size, alignment),
|
||||
.alignment = alignment,
|
||||
.memoryTypeBits = BITFIELD_MASK(dev->pdev->mem_type_cnt),
|
||||
};
|
||||
|
||||
|
@@ -8,6 +8,12 @@
|
||||
#include "vulkan/runtime/vk_buffer.h"
|
||||
|
||||
struct nvk_device_memory;
|
||||
struct nvk_physical_device;
|
||||
|
||||
uint32_t ATTRIBUTE_PURE
|
||||
nvk_get_buffer_alignment(const struct nvk_physical_device *pdev,
|
||||
VkBufferUsageFlags usage_flags,
|
||||
VkBufferCreateFlags create_flags);
|
||||
|
||||
struct nvk_buffer {
|
||||
struct vk_buffer vk;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "nvk_physical_device.h"
|
||||
|
||||
#include "nvk_bo_sync.h"
|
||||
#include "nvk_buffer.h"
|
||||
#include "nvk_entrypoints.h"
|
||||
#include "nvk_format.h"
|
||||
#include "nvk_image.h"
|
||||
@@ -110,9 +111,14 @@ nvk_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
|
||||
.lineWidthGranularity = 0.0625,
|
||||
.nonCoherentAtomSize = 64,
|
||||
.minMemoryMapAlignment = 64,
|
||||
.minUniformBufferOffsetAlignment = NVK_MIN_UBO_ALIGNMENT,
|
||||
.minTexelBufferOffsetAlignment = NVK_MIN_UBO_ALIGNMENT,
|
||||
.minStorageBufferOffsetAlignment = NVK_MIN_SSBO_ALIGNMENT,
|
||||
.minUniformBufferOffsetAlignment =
|
||||
nvk_get_buffer_alignment(pdev, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 0),
|
||||
.minTexelBufferOffsetAlignment =
|
||||
nvk_get_buffer_alignment(pdev, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
|
||||
0),
|
||||
.minStorageBufferOffsetAlignment =
|
||||
nvk_get_buffer_alignment(pdev, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 0),
|
||||
.maxVertexInputAttributeOffset = 2047,
|
||||
.maxVertexInputAttributes = 32,
|
||||
.maxVertexInputBindingStride = 2048,
|
||||
|
Reference in New Issue
Block a user