Skip to content

Commit 3209697

Browse files
committed
testing github action
1 parent 096f404 commit 3209697

File tree

6 files changed

+53
-84
lines changed

6 files changed

+53
-84
lines changed

src/main/kotlin/vkk/_10/structs/DeviceCreateInfo.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package vkk._10.structs
22

33
import kool.Adr
44
import kool.PointerAdr
5-
import kool.Ptr
65
import org.lwjgl.system.MemoryStack
76
import org.lwjgl.system.MemoryUtil.NULL
87
import org.lwjgl.system.MemoryUtil.memPutAddress
98
import org.lwjgl.vulkan.*
109
import org.lwjgl.vulkan.VkDeviceCreateInfo.*
10+
import vkk.VkStructure
1111
import vkk.VkDeviceCreateFlags
1212
import vkk.VkStructureType
1313

@@ -77,8 +77,7 @@ class DeviceCreateInfo(
7777
var queueCreateInfos: Collection<DeviceQueueCreateInfo>,
7878
var enabledExtensionNames: Collection<String>? = null,
7979
var enabledFeatures: PhysicalDeviceFeatures? = null,
80-
var next: Ptr = NULL
81-
) {
80+
var next: VkStructure? = null) {
8281

8382
val type get() = VkStructureType.DEVICE_CREATE_INFO
8483

@@ -87,18 +86,18 @@ class DeviceCreateInfo(
8786
queueCreateInfo: DeviceQueueCreateInfo,
8887
enabledExtensionNames: Collection<String>? = null,
8988
enabledFeatures: PhysicalDeviceFeatures? = null,
90-
next: Ptr = NULL
89+
next: VkStructure? = null
9190
) : this(flags, listOf(queueCreateInfo), enabledExtensionNames, enabledFeatures, next)
9291

9392
infix fun write(stack: MemoryStack): Adr {
9493
val adr = stack.ncalloc(ALIGNOF, 1, SIZEOF)
9594
nsType(adr, type.i)
96-
npNext(adr, next)
95+
npNext(adr, next?.write(stack) ?: NULL)
9796
nflags(adr, flags)
9897
run {
9998
nqueueCreateInfoCount(adr, queueCreateInfos.size)
10099
val pQueueCreateInfos = stack.ncalloc(VkDeviceQueueCreateInfo.ALIGNOF, queueCreateInfos.size, VkDeviceQueueCreateInfo.SIZEOF)
101-
for(i in queueCreateInfos.indices)
100+
for (i in queueCreateInfos.indices)
102101
queueCreateInfos.elementAt(i).write(pQueueCreateInfos + i * VkDeviceQueueCreateInfo.SIZEOF, stack)
103102
memPutAddress(adr + PQUEUECREATEINFOS, pQueueCreateInfos)
104103
}

src/main/kotlin/vkk/_10/structs/InstanceCreateInfo.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package vkk._10.structs
22

33
import kool.Adr
44
import kool.PointerAdr
5-
import kool.Ptr
65
import org.lwjgl.system.MemoryStack
76
import org.lwjgl.system.MemoryUtil.*
87
import org.lwjgl.vulkan.*
98
import org.lwjgl.vulkan.VkInstanceCreateInfo.*
10-
import vkk.Structure
9+
import vkk.VkStructure
1110
import vkk.StructureChain
1211
import vkk.VkStructureType
1312

@@ -62,8 +61,8 @@ class InstanceCreateInfo(
6261
var applicationInfo: ApplicationInfo? = null,
6362
var enabledLayerNames: List<String>? = null,
6463
var enabledExtensionNames: List<String>? = null,
65-
override var next: Structure? = null
66-
) : Structure, StructureChain {
64+
override var next: VkStructure? = null
65+
) : VkStructure, StructureChain {
6766

6867
val type get() = VkStructureType.INSTANCE_CREATE_INFO
6968

src/main/kotlin/vkk/util.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ inline fun <R> MemoryStack.framed(block: () -> R): R {
4949
}
5050
}
5151

52-
interface Structure {
52+
interface VkStructure {
5353
infix fun write(stack: MemoryStack): Adr
5454
}
5555

5656
interface StructureChain {
57-
var next: Structure?
57+
var next: VkStructure?
5858
}

src/main/kotlin/vkk/vu.kt

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package vkk
22

3-
import kool.set
4-
import org.lwjgl.system.MemoryStack
53
import org.lwjgl.vulkan.EXTDebugUtils.VK_EXT_DEBUG_UTILS_EXTENSION_NAME
64
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
148
import vkk.identifiers.UniqueInstance
159

1610
object vu {
@@ -283,7 +277,15 @@ object vu {
283277
// vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes);
284278
// vk::UniqueDescriptorSetLayout createDescriptorSetLayout(vk::UniqueDevice const& device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const& bindingData,
285279
// 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+
287289
// 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);
288290
// vk::UniquePipeline createGraphicsPipeline(vk::UniqueDevice const& device, vk::UniquePipelineCache const& pipelineCache,
289291
// std::pair<vk::ShaderModule, vk::SpecializationInfo const*> const& vertexShaderData,
@@ -343,72 +345,17 @@ object vu {
343345
return UniqueInstance(instanceCreateInfo)
344346
}
345347

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*/);
381350

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)
401355

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
407357
}
408358

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);
412359
// std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const& surface);
413360
// uint32_t findMemoryType(vk::PhysicalDeviceMemoryProperties const& memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask);
414361
// std::vector<std::string> getDeviceExtensions();

src/test/kotlin/tests/02 enumerateDevices.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import io.kotlintest.specs.StringSpec
44
import main.isNotGithubAction
5+
import org.lwjgl.system.Configuration
56
import vkk.vu
67

78
class `02 enumerateDevices` : StringSpec() {
@@ -10,6 +11,7 @@ class `02 enumerateDevices` : StringSpec() {
1011
val engineName = "Vulkan.hpp"
1112

1213
init {
14+
Configuration.DEBUG_LOADER.set(true)
1315
if (isNotGithubAction)
1416
"02 enumerateDevices" {
1517

src/test/kotlin/tests/04 initCommandBuffer.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@ package tests
22

33
import io.kotlintest.specs.StringSpec
44
import main.isNotGithubAction
5+
import vkk.DEBUG
6+
import vkk.vu
57

68
class `04 initCommandBuffer` : StringSpec() {
9+
10+
val appName = "04_InitCommandBuffer"
11+
val engineName = "Vulkan.hpp"
12+
713
init {
814
if (isNotGithubAction)
915
"04 initCommandBuffer" {
1016

17+
val instance = vu.createInstance(appName, engineName)
18+
// if(DEBUG)
19+
// vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
20+
21+
val physicalDevice = instance.enumeratePhysicalDevices[0]
22+
23+
val graphicsQueueFamilyIndex = vu.findGraphicsQueueFamilyIndex(physicalDevice.queueFamilyProperties)
24+
val device = vu.createDevice(physicalDevice, graphicsQueueFamilyIndex)
25+
26+
/* VULKAN_HPP_KEY_START */
27+
28+
// create a UniqueCommandPool to allocate a CommandBuffer from
29+
val commandPool = device.createCommandPoolUnique(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex))
30+
31+
// allocate a CommandBuffer from the CommandPool
32+
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front())
1133
}
1234
}
1335
}

0 commit comments

Comments
 (0)