nvk: Add a nvk_min_cbuf_alignment() helper and use it

We want to be able to use cbufs for UBOs and descriptor buffers going
forward.  This also cleans up alignments all over the code-base where
just kinda did whatever seemed like a good idea at the time.  The result
is a lot more flexible and accurate.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26617>
This commit is contained in:
Faith Ekstrand
2023-12-08 22:00:21 -06:00
committed by Marge Bot
parent bc236acff5
commit b7f8a9e648
7 changed files with 23 additions and 7 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ nvk_get_buffer_alignment(UNUSED const struct nv_device_info *info,
uint32_t alignment = 16;
if (usage_flags & VK_BUFFER_USAGE_2_UNIFORM_BUFFER_BIT_KHR)
alignment = MAX2(alignment, NVK_MIN_UBO_ALIGNMENT);
alignment = MAX2(alignment, nvk_min_cbuf_alignment(info));
if (usage_flags & VK_BUFFER_USAGE_2_STORAGE_BUFFER_BIT_KHR)
alignment = MAX2(alignment, NVK_MIN_SSBO_ALIGNMENT);
+4 -1
View File
@@ -682,6 +682,9 @@ void
nvk_cmd_buffer_flush_push_descriptors(struct nvk_cmd_buffer *cmd,
struct nvk_descriptor_state *desc)
{
struct nvk_device *dev = nvk_cmd_buffer_device(cmd);
struct nvk_physical_device *pdev = nvk_device_physical(dev);
const uint32_t min_cbuf_alignment = nvk_min_cbuf_alignment(&pdev->info);
VkResult result;
if (!desc->push_dirty)
@@ -692,7 +695,7 @@ nvk_cmd_buffer_flush_push_descriptors(struct nvk_cmd_buffer *cmd,
uint64_t push_set_addr;
result = nvk_cmd_buffer_upload_data(cmd, push_set->data,
sizeof(push_set->data),
NVK_MIN_UBO_ALIGNMENT,
min_cbuf_alignment,
&push_set_addr);
if (unlikely(result != VK_SUCCESS)) {
vk_command_buffer_set_error(&cmd->vk, result);
+7 -2
View File
@@ -379,6 +379,7 @@ nvk_CreateDescriptorPool(VkDevice _device,
VkDescriptorPool *pDescriptorPool)
{
VK_FROM_HANDLE(nvk_device, dev, _device);
struct nvk_physical_device *pdev = nvk_device_physical(dev);
struct nvk_descriptor_pool *pool;
uint64_t size = sizeof(struct nvk_descriptor_pool);
uint64_t bo_size = 0;
@@ -423,7 +424,7 @@ nvk_CreateDescriptorPool(VkDevice _device,
* conservative here.) Allocate enough extra space that we can chop it
* into maxSets pieces and align each one of them to 32B.
*/
bo_size += NVK_MIN_UBO_ALIGNMENT * pCreateInfo->maxSets;
bo_size += nvk_min_cbuf_alignment(&pdev->info) * pCreateInfo->maxSets;
uint64_t entries_size = sizeof(struct nvk_descriptor_pool_entry) *
pCreateInfo->maxSets;
@@ -462,6 +463,7 @@ nvk_descriptor_set_create(struct nvk_device *dev,
uint32_t variable_count,
struct nvk_descriptor_set **out_set)
{
struct nvk_physical_device *pdev = nvk_device_physical(dev);
struct nvk_descriptor_set *set;
uint32_t mem_size = sizeof(struct nvk_descriptor_set) +
@@ -484,6 +486,8 @@ nvk_descriptor_set_create(struct nvk_device *dev,
set->size += stride * variable_count;
}
set->size = align64(set->size, nvk_min_cbuf_alignment(&pdev->info));
if (set->size > 0) {
if (pool->current_offset + set->size > pool->size)
return VK_ERROR_OUT_OF_POOL_MEMORY;
@@ -492,10 +496,11 @@ nvk_descriptor_set_create(struct nvk_device *dev,
set->addr = pool->bo->offset + pool->current_offset;
}
assert(pool->current_offset % nvk_min_cbuf_alignment(&pdev->info) == 0);
pool->entries[pool->entry_count].offset = pool->current_offset;
pool->entries[pool->entry_count].size = set->size;
pool->entries[pool->entry_count].set = set;
pool->current_offset += ALIGN(set->size, NVK_MIN_UBO_ALIGNMENT);
pool->current_offset += set->size;
pool->entry_count++;
vk_descriptor_set_layout_ref(&layout->vk);
@@ -57,7 +57,7 @@ nvk_descriptor_stride_align_for_type(const struct nvk_physical_device *pdev,
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
*stride = 1; /* Array size is bytes */
*align = NVK_MIN_UBO_ALIGNMENT;
*align = nvk_min_cbuf_alignment(&pdev->info);
break;
case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
+7 -1
View File
@@ -485,6 +485,12 @@ nvk_get_device_features(const struct nv_device_info *info,
};
}
uint32_t
nvk_min_cbuf_alignment(const struct nv_device_info *info)
{
return 256;
}
static void
nvk_get_device_properties(const struct nvk_instance *instance,
const struct nv_device_info *info,
@@ -747,7 +753,7 @@ nvk_get_device_properties(const struct nvk_instance *instance,
/* VK_EXT_robustness2 */
.robustStorageBufferAccessSizeAlignment = NVK_SSBO_BOUNDS_CHECK_ALIGNMENT,
.robustUniformBufferAccessSizeAlignment = NVK_MIN_UBO_ALIGNMENT,
.robustUniformBufferAccessSizeAlignment = nvk_min_cbuf_alignment(info),
/* VK_EXT_sample_locations */
.sampleLocationSampleCounts = sample_counts,
+2
View File
@@ -40,6 +40,8 @@ struct nvk_physical_device {
const struct vk_sync_type *sync_types[2];
};
uint32_t nvk_min_cbuf_alignment(const struct nv_device_info *info);
VK_DEFINE_HANDLE_CASTS(nvk_physical_device,
vk.base,
VkPhysicalDevice,
+1 -1
View File
@@ -152,7 +152,7 @@ nvk_physical_device_spirv_options(const struct nvk_physical_device *pdev,
.ubo_addr_format = nvk_buffer_addr_format(rs->uniform_buffers),
.shared_addr_format = nir_address_format_32bit_offset,
.min_ssbo_alignment = NVK_MIN_SSBO_ALIGNMENT,
.min_ubo_alignment = NVK_MIN_UBO_ALIGNMENT,
.min_ubo_alignment = nvk_min_cbuf_alignment(&pdev->info),
};
}