|
1 | 1 | package vkk |
2 | 2 |
|
3 | | -import kool.set |
4 | | -import org.lwjgl.system.MemoryStack |
5 | 3 | import org.lwjgl.vulkan.EXTDebugUtils.VK_EXT_DEBUG_UTILS_EXTENSION_NAME |
6 | 4 | import org.lwjgl.vulkan.VK10.* |
7 | | -import org.lwjgl.vulkan.VkApplicationInfo |
8 | | -import org.lwjgl.vulkan.VkInstance |
9 | | -import org.lwjgl.vulkan.VkInstanceCreateInfo |
10 | | -import vkk._10.structs.ApplicationInfo |
11 | | -import vkk._10.structs.ExtensionProperties |
12 | | -import vkk._10.structs.InstanceCreateInfo |
13 | | -import vkk._10.structs.LayerProperties |
| 5 | +import vkk._10.structs.* |
| 6 | +import vkk.identifiers.PhysicalDevice |
| 7 | +import vkk.identifiers.UniqueDevice |
14 | 8 | import vkk.identifiers.UniqueInstance |
15 | 9 |
|
16 | 10 | object vu { |
@@ -283,7 +277,15 @@ object vu { |
283 | 277 | // vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes); |
284 | 278 | // vk::UniqueDescriptorSetLayout createDescriptorSetLayout(vk::UniqueDevice const& device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const& bindingData, |
285 | 279 | // vk::DescriptorSetLayoutCreateFlags flags = {}); |
286 | | -// vk::UniqueDevice createDevice(vk::PhysicalDevice physicalDevice, uint32_t queueFamilyIndex, std::vector<std::string> const& extensions = {}, vk::PhysicalDeviceFeatures const* physicalDeviceFeatures = nullptr, void const* pNext = nullptr); |
| 280 | + |
| 281 | + fun createDevice(physicalDevice: PhysicalDevice, queueFamilyIndex: Int, extensions: ArrayList<String> = ArrayList(), physicalDeviceFeatures: PhysicalDeviceFeatures? = null, next: VkStructure? = null): UniqueDevice { |
| 282 | + // create a UniqueDevice |
| 283 | + val deviceQueueCreateInfo = DeviceQueueCreateInfo(0, queueFamilyIndex, queuePriority = 0f) |
| 284 | + val deviceCreateInfo = DeviceCreateInfo(0, deviceQueueCreateInfo, extensions, physicalDeviceFeatures) |
| 285 | + deviceCreateInfo.next = next |
| 286 | + return physicalDevice.createDeviceUnique(deviceCreateInfo) |
| 287 | + } |
| 288 | + |
287 | 289 | // std::vector<vk::UniqueFramebuffer> createFramebuffers(vk::UniqueDevice &device, vk::UniqueRenderPass &renderPass, std::vector<vk::UniqueImageView> const& imageViews, vk::UniqueImageView const& depthImageView, vk::Extent2D const& extent); |
288 | 290 | // vk::UniquePipeline createGraphicsPipeline(vk::UniqueDevice const& device, vk::UniquePipelineCache const& pipelineCache, |
289 | 291 | // std::pair<vk::ShaderModule, vk::SpecializationInfo const*> const& vertexShaderData, |
@@ -343,72 +345,17 @@ object vu { |
343 | 345 | return UniqueInstance(instanceCreateInfo) |
344 | 346 | } |
345 | 347 |
|
346 | | - fun createInstanceLwjgl(appName: String, engineName: String, |
347 | | - layers: ArrayList<String> = ArrayList(), extensions: ArrayList<String> = ArrayList(), |
348 | | - apiVersion: Int = VK_API_VERSION_1_0): VkInstance { |
349 | | - |
350 | | - val layerProperties = ArrayList<LayerProperties>() |
351 | | - val extensionProperties = ArrayList<ExtensionProperties>() |
352 | | - |
353 | | - if (vk.DEBUG) { |
354 | | - layerProperties += vk.enumerateInstanceLayerProperties() |
355 | | - extensionProperties += vk.enumerateInstanceExtensionProperties() |
356 | | - } |
357 | | - val enabledLayers = ArrayList<String>(layers.size) |
358 | | - for (layer in layers) { |
359 | | - assert(layerProperties.find { layer == it.layerName } != null) |
360 | | - enabledLayers += layer |
361 | | - } |
362 | | - if (vk.DEBUG) { |
363 | | - val validation = "VK_LAYER_KHRONOS_validation" |
364 | | - // Enable standard validation layer to find as much errors as possible! |
365 | | - if (validation !in layers && layerProperties.find { validation == it.layerName } != null) |
366 | | - enabledLayers += validation |
367 | | - val lunar = "VK_LAYER_LUNARG_assistant_layer" |
368 | | - if (lunar !in layers && layerProperties.find { lunar == it.layerName } != null) |
369 | | - enabledLayers += lunar |
370 | | - } |
371 | | - |
372 | | - val enabledExtensions = ArrayList<String>(extensions.size) |
373 | | - for (ext in extensions) { |
374 | | - assert(extensionProperties.find { ext == it.extensionName } != null) |
375 | | - enabledExtensions += ext |
376 | | - } |
377 | | - if (vk.DEBUG) |
378 | | - if (VK_EXT_DEBUG_UTILS_EXTENSION_NAME !in extensions && |
379 | | - extensionProperties.find { VK_EXT_DEBUG_UTILS_EXTENSION_NAME == it.extensionName } != null) |
380 | | - enabledExtensions += VK_EXT_DEBUG_UTILS_EXTENSION_NAME |
| 348 | +// vk::UniqueRenderPass createRenderPass(vk::UniqueDevice &device, vk::Format colorFormat, vk::Format depthFormat, vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear, vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR); |
| 349 | +// VkBool32 debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/); |
381 | 350 |
|
382 | | - // create a UniqueInstance |
383 | | - val stack = MemoryStack.stackPush() |
384 | | - val pAppName = stack.UTF8(appName) |
385 | | - val pEngineName = stack.UTF8(engineName) |
386 | | - val applicationInfo = VkApplicationInfo.callocStack(stack) |
387 | | - .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO) |
388 | | - .pApplicationName(pAppName) |
389 | | - .pEngineName(pEngineName) |
390 | | - .apiVersion(apiVersion) |
391 | | - // in non-debug mode just use the InstanceCreateInfo for instance creation |
392 | | - val pEnableLayers = stack.callocPointer(enabledLayers.size) |
393 | | - enabledLayers.forEachIndexed { i, s -> pEnableLayers[i] = stack.ASCII(s) } |
394 | | - val pEnableExtensions = stack.callocPointer(enabledExtensions.size) |
395 | | - enabledExtensions.forEachIndexed { i, s -> pEnableExtensions[i] = stack.ASCII(s) } |
396 | | - val instanceCreateInfo = VkInstanceCreateInfo.mallocStack(stack) |
397 | | - .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO) |
398 | | - .pApplicationInfo(applicationInfo) |
399 | | - .ppEnabledLayerNames(pEnableLayers) |
400 | | - .ppEnabledExtensionNames(pEnableExtensions) |
| 351 | + fun findGraphicsQueueFamilyIndex(queueFamilyProperties: Array<QueueFamilyProperties>): Int { |
| 352 | + // get the first index into queueFamiliyProperties which supports graphics |
| 353 | + val graphicsQueueFamilyIndex = queueFamilyProperties.indexOfFirst { it.queueFlags has VkQueueFlag.GRAPHICS_BIT } |
| 354 | + assert(graphicsQueueFamilyIndex != -1) |
401 | 355 |
|
402 | | - val pp = stack.callocPointer(1) |
403 | | - VK_CHECK_RESULT(vkCreateInstance(instanceCreateInfo, null, pp)) |
404 | | - return VkInstance(pp[0], instanceCreateInfo).also { |
405 | | - stack.pop() |
406 | | - } |
| 356 | + return graphicsQueueFamilyIndex |
407 | 357 | } |
408 | 358 |
|
409 | | -// vk::UniqueRenderPass createRenderPass(vk::UniqueDevice &device, vk::Format colorFormat, vk::Format depthFormat, vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear, vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR); |
410 | | -// VkBool32 debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/); |
411 | | -// uint32_t findGraphicsQueueFamilyIndex(std::vector<vk::QueueFamilyProperties> const& queueFamilyProperties); |
412 | 359 | // std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const& surface); |
413 | 360 | // uint32_t findMemoryType(vk::PhysicalDeviceMemoryProperties const& memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask); |
414 | 361 | // std::vector<std::string> getDeviceExtensions(); |
|
0 commit comments