nvk: Add stub implementations of VkImage and VkImageView
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Tue, 31 Jan 2023 02:11:46 +0000 (20:11 -0600)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:52 +0000 (21:31 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

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

index 63e0e33..edbd971 100644 (file)
@@ -1,6 +1,10 @@
 nvk_files = files(
   'nvk_device.c',
   'nvk_device.h',
+  'nvk_image.c',
+  'nvk_image.h',
+  'nvk_image_view.c',
+  'nvk_image_view.h',
   'nvk_instance.c',
   'nvk_instance.h',
   'nvk_physical_device.c',
diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c
new file mode 100644 (file)
index 0000000..b1aaf2a
--- /dev/null
@@ -0,0 +1,55 @@
+#include "nvk_image.h"
+
+#include "nvk_device.h"
+
+static VkResult nvk_image_init(struct nvk_device *device,
+   struct nvk_image *image,
+   const VkImageCreateInfo *pCreateInfo)
+{
+   vk_image_init(&device->vk, &image->vk, pCreateInfo);
+   return VK_SUCCESS;
+}
+
+static void nvk_image_finish(struct nvk_image *image)
+{
+   vk_image_finish(&image->vk);
+}
+
+VKAPI_ATTR VkResult VKAPI_CALL nvk_CreateImage(VkDevice _device,
+   const VkImageCreateInfo *pCreateInfo,
+   const VkAllocationCallbacks *pAllocator,
+   VkImage *pImage)
+{
+   VK_FROM_HANDLE(nvk_device, device, _device);
+   struct nvk_image *image;
+   VkResult result;
+
+   image = vk_zalloc2(
+      &device->vk.alloc, pAllocator, sizeof(*image), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   if (!image)
+      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   result = nvk_image_init(device, image, pCreateInfo);
+   if (result != VK_SUCCESS) {
+      vk_free2(&device->vk.alloc, pAllocator, image);
+      return result;
+   }
+
+   *pImage = nvk_image_to_handle(image);
+
+   return VK_SUCCESS;
+}
+
+VKAPI_ATTR void VKAPI_CALL nvk_DestroyImage(VkDevice _device,
+   VkImage _image,
+   const VkAllocationCallbacks *pAllocator)
+{
+   VK_FROM_HANDLE(nvk_device, device, _device);
+   VK_FROM_HANDLE(nvk_image, image, _image);
+
+   if (!image)
+      return;
+
+   nvk_image_finish(image);
+   vk_free2(&device->vk.alloc, pAllocator, image);
+}
diff --git a/src/nouveau/vulkan/nvk_image.h b/src/nouveau/vulkan/nvk_image.h
new file mode 100644 (file)
index 0000000..8139b2c
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef NVK_IMAGE
+#define NVK_IMAGE 1
+
+#include "nvk_private.h"
+
+#include "vulkan/runtime/vk_image.h"
+
+struct nvk_image {
+   struct vk_image vk;
+};
+
+VK_DEFINE_HANDLE_CASTS(nvk_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
+
+#endif
diff --git a/src/nouveau/vulkan/nvk_image_view.c b/src/nouveau/vulkan/nvk_image_view.c
new file mode 100644 (file)
index 0000000..0399a7c
--- /dev/null
@@ -0,0 +1,41 @@
+#include "nvk_image_view.h"
+
+#include "nvk_device.h"
+#include "nvk_image.h"
+
+static VkResult nvk_image_view_init(struct nvk_device *device,
+   struct nvk_image_view *view,
+   const VkImageViewCreateInfo *pCreateInfo)
+{
+   return VK_SUCCESS;
+}
+
+VKAPI_ATTR VkResult VKAPI_CALL nvk_CreateImageView(VkDevice _device,
+   const VkImageViewCreateInfo *pCreateInfo,
+   const VkAllocationCallbacks *pAllocator,
+   VkImageView *pView)
+{
+   VK_FROM_HANDLE(nvk_device, device, _device);
+   struct nvk_image_view *view;
+
+   view = vk_image_view_create(&device->vk, false, pCreateInfo, pAllocator, sizeof(*view));
+   if (view == NULL)
+      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   *pView = nvk_image_view_to_handle(view);
+
+   return VK_SUCCESS;
+}
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice _device,
+   VkImageView imageView,
+   const VkAllocationCallbacks *pAllocator)
+{
+   VK_FROM_HANDLE(nvk_device, device, _device);
+   VK_FROM_HANDLE(nvk_image_view, view, imageView);
+
+   if (!view)
+      return;
+
+   vk_image_view_destroy(&device->vk, pAllocator, &view->vk);
+}
diff --git a/src/nouveau/vulkan/nvk_image_view.h b/src/nouveau/vulkan/nvk_image_view.h
new file mode 100644 (file)
index 0000000..0b90812
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef NVK_IMAGE_VIEW
+#define NVK_IMAGE_VIEW 1
+
+#include "nvk_private.h"
+
+#include "vulkan/runtime/vk_image.h"
+
+struct nvk_image_view {
+   struct vk_image_view vk;
+
+   /** Index in the image descriptor table */
+   uint32_t desc_idx;
+};
+
+VK_DEFINE_HANDLE_CASTS(nvk_image_view, vk.base, VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW)
+
+#endif