nvk: Implement VkPipelineLayout
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Tue, 31 Jan 2023 02:11:47 +0000 (20:11 -0600)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:53 +0000 (21:31 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/meson.build
src/nouveau/vulkan/nvk_pipeline_layout.c [new file with mode: 0644]
src/nouveau/vulkan/nvk_pipeline_layout.h [new file with mode: 0644]
src/nouveau/vulkan/nvk_private.h

index 2cd2358..6035e5d 100644 (file)
@@ -20,6 +20,8 @@ nvk_files = files(
   'nvk_instance.h',
   'nvk_physical_device.c',
   'nvk_physical_device.h',
+  'nvk_pipeline_layout.c',
+  'nvk_pipeline_layout.h',
   'nvk_private.h',
   'nvk_sampler.c',
   'nvk_sampler.h',
diff --git a/src/nouveau/vulkan/nvk_pipeline_layout.c b/src/nouveau/vulkan/nvk_pipeline_layout.c
new file mode 100644 (file)
index 0000000..d943e5a
--- /dev/null
@@ -0,0 +1,55 @@
+#include "nvk_pipeline_layout.h"
+
+#include "nvk_descriptor_set_layout.h"
+#include "nvk_device.h"
+
+#include "util/mesa-sha1.h"
+
+VKAPI_ATTR VkResult VKAPI_CALL nvk_CreatePipelineLayout(
+    VkDevice _device, const VkPipelineLayoutCreateInfo *pCreateInfo,
+    const VkAllocationCallbacks *pAllocator,
+    VkPipelineLayout *pPipelineLayout) {
+  VK_FROM_HANDLE(nvk_device, device, _device);
+  struct nvk_pipeline_layout *layout;
+
+  layout = vk_object_alloc(&device->vk, pAllocator, sizeof(*layout),
+                           VK_OBJECT_TYPE_PIPELINE_LAYOUT);
+  if (layout == NULL)
+    return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+  layout->num_sets = pCreateInfo->setLayoutCount;
+
+  for (uint32_t s = 0; s < pCreateInfo->setLayoutCount; s++) {
+    VK_FROM_HANDLE(nvk_descriptor_set_layout, set_layout,
+                   pCreateInfo->pSetLayouts[s]);
+    layout->set[s].layout = nvk_descriptor_set_layout_ref(set_layout);
+  }
+
+  struct mesa_sha1 sha1_ctx;
+  _mesa_sha1_init(&sha1_ctx);
+  _mesa_sha1_update(&sha1_ctx, &layout->num_sets, sizeof(layout->num_sets));
+  for (uint32_t s = 0; s < pCreateInfo->setLayoutCount; s++) {
+    _mesa_sha1_update(&sha1_ctx, layout->set[s].layout->sha1,
+                      sizeof(layout->set[s].layout->sha1));
+  }
+  _mesa_sha1_final(&sha1_ctx, layout->sha1);
+
+  *pPipelineLayout = nvk_pipeline_layout_to_handle(layout);
+
+  return VK_SUCCESS;
+}
+
+VKAPI_ATTR void VKAPI_CALL
+nvk_DestroyPipelineLayout(VkDevice _device, VkPipelineLayout pipelineLayout,
+                          const VkAllocationCallbacks *pAllocator) {
+  VK_FROM_HANDLE(nvk_device, device, _device);
+  VK_FROM_HANDLE(nvk_pipeline_layout, layout, pipelineLayout);
+
+  if (!layout)
+    return;
+
+  for (uint32_t s = 0; s < layout->num_sets; s++)
+    nvk_descriptor_set_layout_unref(device, layout->set[s].layout);
+
+  vk_object_free(&device->vk, pAllocator, layout);
+}
diff --git a/src/nouveau/vulkan/nvk_pipeline_layout.h b/src/nouveau/vulkan/nvk_pipeline_layout.h
new file mode 100644 (file)
index 0000000..5b148ce
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef NVK_PIPELINE_LAYOUT
+#define NVK_PIPELINE_LAYOUT 1
+
+#include "nvk_private.h"
+
+#include "vulkan/runtime/vk_object.h"
+
+struct nvk_descriptor_set_layout;
+
+struct nvk_pipeline_layout {
+  struct vk_object_base base;
+
+  unsigned char sha1[20];
+
+  uint32_t num_sets;
+
+  struct {
+    struct nvk_descriptor_set_layout *layout;
+  } set[NVK_MAX_SETS];
+};
+
+VK_DEFINE_HANDLE_CASTS(nvk_pipeline_layout, base, VkPipelineLayout,
+                       VK_OBJECT_TYPE_PIPELINE_LAYOUT)
+
+#endif
index d0fa48f..6224192 100644 (file)
@@ -12,6 +12,7 @@
 #include <fcntl.h>
 #include <xf86drm.h>
 
+#define NVK_MAX_SETS 8
 #define NVK_MIN_UBO_ALIGNMENT 16
 
 /**