mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 17:30:12 +01:00
nvk: Rework side-band data upload
Instead of doing magic alignments, it now takes an explicit alignment parameter. Also, we now have a version of the helper which does the memcpy. This should encourage users to avoid reading reading upload maps in case they're ever write-combine in the future. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
parent
56843707c1
commit
87686a2220
5 changed files with 38 additions and 29 deletions
|
|
@ -152,19 +152,15 @@ nvk_cmd_buffer_resize_upload_buf(struct nvk_cmd_buffer *cmd,
|
|||
}
|
||||
|
||||
VkResult
|
||||
nvk_cmd_buffer_upload_alloc(struct nvk_cmd_buffer *cmd, uint32_t size,
|
||||
nvk_cmd_buffer_upload_alloc(struct nvk_cmd_buffer *cmd,
|
||||
uint32_t size, uint32_t alignment,
|
||||
uint64_t *addr, void **ptr)
|
||||
{
|
||||
assert(size % 4 == 0);
|
||||
|
||||
/* Align to the scalar cache line size if it results in this allocation
|
||||
* being placed in less of them.
|
||||
*/
|
||||
uint32_t offset = cmd->upload.offset;
|
||||
uint32_t line_size = 256;//for compute dispatches
|
||||
uint32_t gap = align(offset, line_size) - offset;
|
||||
if ((size & ~(line_size - 1)) > gap)
|
||||
offset = align(offset, line_size);
|
||||
if (align > 0)
|
||||
offset = align(offset, alignment);
|
||||
|
||||
if (offset + size > cmd->upload.size) {
|
||||
if (!nvk_cmd_buffer_resize_upload_buf(cmd, size))
|
||||
|
|
@ -180,6 +176,23 @@ nvk_cmd_buffer_upload_alloc(struct nvk_cmd_buffer *cmd, uint32_t size,
|
|||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
nvk_cmd_buffer_upload_data(struct nvk_cmd_buffer *cmd,
|
||||
const void *data, uint32_t size,
|
||||
uint32_t alignment, uint64_t *addr)
|
||||
{
|
||||
VkResult result;
|
||||
void *map;
|
||||
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, size, alignment, addr, &map);
|
||||
if (unlikely(result != VK_SUCCESS))
|
||||
return result;
|
||||
|
||||
memcpy(map, data, size);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
nvk_BeginCommandBuffer(VkCommandBuffer commandBuffer,
|
||||
const VkCommandBufferBeginInfo *pBeginInfo)
|
||||
|
|
|
|||
|
|
@ -144,7 +144,11 @@ nvk_get_descriptors_state(struct nvk_cmd_buffer *cmd,
|
|||
};
|
||||
|
||||
VkResult nvk_cmd_buffer_upload_alloc(struct nvk_cmd_buffer *cmd,
|
||||
uint32_t size,
|
||||
uint32_t size, uint32_t alignment,
|
||||
uint64_t *addr, void **ptr);
|
||||
|
||||
VkResult nvk_cmd_buffer_upload_data(struct nvk_cmd_buffer *cmd,
|
||||
const void *data, uint32_t size,
|
||||
uint32_t alignment, uint64_t *addr);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -76,37 +76,31 @@ nvk_CmdDispatch(VkCommandBuffer commandBuffer,
|
|||
desc->root.cs.grid_size[1] = groupCountY;
|
||||
desc->root.cs.grid_size[2] = groupCountZ;
|
||||
|
||||
uint32_t root_table_size = sizeof(desc->root);
|
||||
void *root_table_map;
|
||||
uint64_t root_table_addr;
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, root_table_size,
|
||||
&root_table_addr, &root_table_map);
|
||||
result = nvk_cmd_buffer_upload_data(cmd, &desc->root, sizeof(desc->root),
|
||||
NVK_MIN_UBO_ALIGNMENT,
|
||||
&root_table_addr);
|
||||
if (unlikely(result != VK_SUCCESS)) {
|
||||
vk_command_buffer_set_error(&cmd->vk, result);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(root_table_map, &desc->root, sizeof(desc->root));
|
||||
|
||||
uint32_t qmd[128];
|
||||
memset(qmd, 0, sizeof(qmd));
|
||||
memcpy(qmd, pipeline->qmd_template, sizeof(pipeline->qmd_template));
|
||||
|
||||
gv100_compute_setup_launch_desc(qmd, groupCountX, groupCountY, groupCountZ);
|
||||
|
||||
gp100_cp_launch_desc_set_cb(qmd, 0, root_table_size, root_table_addr);
|
||||
gp100_cp_launch_desc_set_cb(qmd, 1, root_table_size, root_table_addr);
|
||||
gp100_cp_launch_desc_set_cb(qmd, 0, sizeof(desc->root), root_table_addr);
|
||||
gp100_cp_launch_desc_set_cb(qmd, 1, sizeof(desc->root), root_table_addr);
|
||||
|
||||
uint64_t qmd_addr;
|
||||
void *qmd_map;
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, sizeof(qmd), &qmd_addr,&qmd_map);
|
||||
result = nvk_cmd_buffer_upload_data(cmd, qmd, sizeof(qmd), 256, &qmd_addr);
|
||||
if (unlikely(result != VK_SUCCESS)) {
|
||||
vk_command_buffer_set_error(&cmd->vk, result);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(qmd_map, qmd, sizeof(qmd));
|
||||
|
||||
struct nv_push *p = P_SPACE(cmd->push, 6);
|
||||
|
||||
P_MTHD(p, NVA0C0, INVALIDATE_SHADER_CACHES_NO_WFI);
|
||||
|
|
|
|||
|
|
@ -1037,22 +1037,19 @@ nvk_flush_descriptors(struct nvk_cmd_buffer *cmd)
|
|||
const struct nvk_descriptor_state *desc = &cmd->state.gfx.descriptors;
|
||||
VkResult result;
|
||||
|
||||
uint32_t root_table_size = sizeof(desc->root);
|
||||
void *root_table_map;
|
||||
uint64_t root_table_addr;
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, root_table_size,
|
||||
&root_table_addr, &root_table_map);
|
||||
result = nvk_cmd_buffer_upload_data(cmd, &desc->root, sizeof(desc->root),
|
||||
NVK_MIN_UBO_ALIGNMENT,
|
||||
&root_table_addr);
|
||||
if (unlikely(result != VK_SUCCESS)) {
|
||||
vk_command_buffer_set_error(&cmd->vk, result);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(root_table_map, &desc->root, sizeof(desc->root));
|
||||
|
||||
struct nv_push *p = P_SPACE(cmd->push, 26);
|
||||
|
||||
P_MTHD(p, NV9097, SET_CONSTANT_BUFFER_SELECTOR_A);
|
||||
P_NV9097_SET_CONSTANT_BUFFER_SELECTOR_A(p, root_table_size);
|
||||
P_NV9097_SET_CONSTANT_BUFFER_SELECTOR_A(p, sizeof(desc->root));
|
||||
P_NV9097_SET_CONSTANT_BUFFER_SELECTOR_B(p, root_table_addr >> 32);
|
||||
P_NV9097_SET_CONSTANT_BUFFER_SELECTOR_C(p, root_table_addr);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ nvk_cmd_bind_map_buffer(struct vk_command_buffer *vk_cmd,
|
|||
|
||||
uint64_t addr;
|
||||
assert(buffer->vk.size < UINT_MAX);
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, buffer->vk.size, &addr, map_out);
|
||||
result = nvk_cmd_buffer_upload_alloc(cmd, buffer->vk.size, 16,
|
||||
&addr, map_out);
|
||||
if (unlikely(result != VK_SUCCESS))
|
||||
return result;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue