#include "libresoc_private.h"
#include "vk_util.h"
+#include "vk_alloc.h"
VkResult
libresoc_EnumerateInstanceExtensionProperties(const char *pLayerName,
return vk_outarray_status(&out);
}
+static void *
+default_alloc_func(void *pUserData, size_t size, size_t align,
+ VkSystemAllocationScope allocationScope)
+{
+ return malloc(size);
+}
+
+static void *
+default_realloc_func(void *pUserData, void *pOriginal, size_t size,
+ size_t align, VkSystemAllocationScope allocationScope)
+{
+ return realloc(pOriginal, size);
+}
+
+static void
+default_free_func(void *pUserData, void *pMemory)
+{
+ free(pMemory);
+}
+
+static const VkAllocationCallbacks default_alloc = {
+ .pUserData = NULL,
+ .pfnAllocation = default_alloc_func,
+ .pfnReallocation = default_realloc_func,
+ .pfnFree = default_free_func,
+};
+
VkResult
libresoc_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
if (getenv("LIBRESOC_TRACE")) {
fprintf(stderr, "CreateInstance called. \n");
}
- /* FIXME: stub */
- return VK_SUCCESS;
+ struct libresoc_instance *instance;
+
+ instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ if (!instance)
+ return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE);
+
+ if (pAllocator)
+ instance->alloc = *pAllocator;
+ else
+ instance->alloc = default_alloc;
+ /*TODO : enable extensions*/
+ *pInstance = libresoc_instance_to_handle(instance);
+
+ return VK_SUCCESS;
}
void
/* FIXME: stub */
}
+static VkResult
+libresoc_physical_device_try_create(struct libresoc_instance *instance,
+ struct libresoc_physical_device **device_out)
+{
+ VkResult result;
+
+ struct libresoc_physical_device *device =
+ vk_zalloc2(&instance->alloc, NULL, sizeof(*device), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ if (!device) {
+ result = vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+ return result;
+ }
+
+ device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
+ device->instance = instance;
+
+ *device_out = device;
+
+ return VK_SUCCESS;
+
+}
+static VkResult
+libresoc_enumerate_physical_devices(struct libresoc_instance *instance)
+{
+
+ VkResult result = VK_SUCCESS;
+ /* the driver creates a null
+ * device that allows to test the compiler without having a physical device
+ */
+ struct libresoc_physical_device *pdevice;
+
+ result = libresoc_physical_device_try_create(instance, &pdevice);
+ return result;
+
+}
+
VkResult
libresoc_EnumeratePhysicalDevices(VkInstance _instance,
uint32_t *pPhysicalDeviceCount,
if (getenv("LIBRESOC_TRACE")) {
fprintf(stderr, "EnumeratePhysicalDevices called\n");
}
+ LIBRESOC_FROM_HANDLE(libresoc_instance, instance, _instance);
+ VK_OUTARRAY_MAKE(out, pPhysicalDevices, pPhysicalDeviceCount);
+
+ VkResult result = libresoc_enumerate_physical_devices(instance);
+ if (result != VK_SUCCESS)
+ return result;
+
+ vk_outarray_append(&out, i) {
+ *i = libresoc_physical_device_to_handle(&instance->physical_device);
+ }
+
+ return vk_outarray_status(&out);
/* FIXME: stub */
return VK_SUCCESS;
}
idx = libresoc_get_physical_device_entrypoint_index(pName);
if (idx >= 0)
- return instance->physicalDevice.dispatch.entrypoints[idx];
+ return instance->physical_device.dispatch.entrypoints[idx];
idx = libresoc_get_device_entrypoint_index(pName);
if (idx >= 0)
if (idx < 0)
return NULL;
- return instance->physicalDevice.dispatch.entrypoints[idx];
+ return instance->physical_device.dispatch.entrypoints[idx];
}
VkResult