Mercurial > games > semicongine
diff src/vulkan_helpers.nim @ 462:0bc8643cfe25
add: more steps in setup
author | Sam <sam@basx.dev> |
---|---|
date | Fri, 16 Dec 2022 00:05:41 +0700 |
parents | 59d861a6a5c4 |
children | 213fdf8d31dd |
line wrap: on
line diff
--- a/src/vulkan_helpers.nim Wed Dec 14 00:49:35 2022 +0700 +++ b/src/vulkan_helpers.nim Fri Dec 16 00:05:41 2022 +0700 @@ -1,6 +1,9 @@ +import std/tables import std/strutils -import std/enumerate -import vulkan + +import ./glslang/glslang +import ./vulkan + when defined(release): const ENABLEVULKANVALIDATIONLAYERS = false @@ -17,6 +20,7 @@ proc VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = (variant shl 29) or (major shl 22) or (minor shl 12) or patch + proc getInstanceExtensions*(): seq[string] = var extensionCount: uint32 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), nil) @@ -167,3 +171,24 @@ ) checkVkResult vkCreateDevice(physicalDevice, addr(deviceCreateInfo), nil, addr(result[0])) vkGetDeviceQueue(result[0], selectedQueueFamily, 0'u32, addr(result[1])); + +proc createShaderStage*(device: VkDevice, stage: VkShaderStageFlagBits, shader: string): VkPipelineShaderStageCreateInfo = + const VK_GLSL_MAP = { + VK_SHADER_STAGE_VERTEX_BIT: GLSLANG_STAGE_VERTEX, + VK_SHADER_STAGE_FRAGMENT_BIT: GLSLANG_STAGE_FRAGMENT, + }.toTable() + var code = compileGLSLToSPIRV(VK_GLSL_MAP[stage], shader, "<memory-shader>") + var createInfo = VkShaderModuleCreateInfo( + sType: VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, + codeSize: code.len.uint, + pCode: addr(code[0]), + ) + var shaderModule: VkShaderModule + checkVkResult vkCreateShaderModule(device, addr(createInfo), nil, addr(shaderModule)) + + var vertShaderStageInfo = VkPipelineShaderStageCreateInfo( + sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + stage: stage, + module: shaderModule, + pName: "main", # entry point for shader + )