From 935f316eb0c889a485756f79c459b9284807be20 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 10 Jun 2022 16:13:36 -0500 Subject: [PATCH] nvk: Basic descriptor binding Part-of: --- src/nouveau/vulkan/nvk_cmd_buffer.c | 30 ++++++++++++++++++++++++++++++ src/nouveau/vulkan/nvk_cmd_buffer.h | 25 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.c b/src/nouveau/vulkan/nvk_cmd_buffer.c index ce44cb7..2ce7596 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.c +++ b/src/nouveau/vulkan/nvk_cmd_buffer.c @@ -1,5 +1,6 @@ #include "nvk_cmd_buffer.h" +#include "nvk_descriptor_set.h" #include "nvk_device.h" #include "nvk_physical_device.h" @@ -49,6 +50,7 @@ nvk_reset_cmd_buffer(struct nvk_cmd_buffer *cmd_buffer) vk_command_buffer_reset(&cmd_buffer->vk); nouveau_ws_push_reset(cmd_buffer->push); + memset(&cmd_buffer->state, 0, sizeof(cmd_buffer->state)); return VK_SUCCESS; } @@ -241,3 +243,31 @@ VKAPI_ATTR void VKAPI_CALL nvk_CmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { } + + +VKAPI_ATTR void VKAPI_CALL +nvk_CmdBindDescriptorSets(VkCommandBuffer commandBuffer, + VkPipelineBindPoint pipelineBindPoint, + VkPipelineLayout _layout, + uint32_t firstSet, + uint32_t descriptorSetCount, + const VkDescriptorSet *pDescriptorSets, + uint32_t dynamicOffsetCount, + const uint32_t *pDynamicOffsets) +{ + VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer); + struct nvk_descriptor_state *desc = + nvk_get_descriptors_state(cmd, pipelineBindPoint); + + for (unsigned i = 0; i < descriptorSetCount; ++i) { + unsigned set_idx = i + firstSet; + VK_FROM_HANDLE(nvk_descriptor_set, set, pDescriptorSets[i]); + + if (desc->sets[set_idx] != set) { + desc->sets[set_idx] = set; + desc->sets_dirty |= BITFIELD_BIT(set_idx); + } + + /* TODO: Dynamic buffers */ + } +} diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.h b/src/nouveau/vulkan/nvk_cmd_buffer.h index b1361e5..7dd34ed 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.h +++ b/src/nouveau/vulkan/nvk_cmd_buffer.h @@ -19,12 +19,25 @@ struct nvk_cmd_pool { VK_DEFINE_NONDISP_HANDLE_CASTS(nvk_cmd_pool, vk.base, VkCommandPool, VK_OBJECT_TYPE_COMMAND_POOL) +struct nvk_descriptor_state { + struct nvk_descriptor_set *sets[NVK_MAX_SETS]; + uint32_t sets_dirty; +}; + +struct nvk_compute_state { + struct nvk_descriptor_state descriptors; +}; + struct nvk_cmd_buffer { struct vk_command_buffer vk; struct nvk_cmd_pool *pool; struct list_head pool_link; + struct { + struct nvk_compute_state cs; + } state; + struct nouveau_ws_push *push; bool reset_on_submit; }; @@ -34,4 +47,16 @@ VkResult nvk_reset_cmd_buffer(struct nvk_cmd_buffer *cmd_buffer); VK_DEFINE_HANDLE_CASTS(nvk_cmd_buffer, vk.base, VkCommandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER) +static inline struct nvk_descriptor_state * +nvk_get_descriptors_state(struct nvk_cmd_buffer *cmd, + VkPipelineBindPoint bind_point) +{ + switch (bind_point) { + case VK_PIPELINE_BIND_POINT_COMPUTE: + return &cmd->state.cs.descriptors; + default: + unreachable("Unhandled bind point"); + } +}; + #endif -- 2.7.4