view src/semicongine/vulkan/buffer.nim @ 558:affa6571a2c9

add: swapchain, images, fix some destroctors
author Sam <sam@basx.dev>
date Thu, 02 Mar 2023 23:16:45 +0700
parents 7c44f714bd03
children cc7ba46fe3c4
line wrap: on
line source

import ./api
import ./device

type
  Buffer = object
    device: Device
    vk: VkBuffer
    size: uint64

# currently no support for extended structure and concurrent/shared use
# (shardingMode = VK_SHARING_MODE_CONCURRENT not supported)
proc createBuffer(device: Device, size: uint64, flags: openArray[VkBufferCreateFlagBits], usage: openArray[VkBufferUsageFlagBits]): Buffer =
  result.device = device
  result.size = size
  var createInfo = VkBufferCreateInfo(
    sType: VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
    flags: toBits(flags),
    size: size,
    usage: toBits(usage),
    sharingMode: VK_SHARING_MODE_EXCLUSIVE,
  )

  checkVkResult vkCreateBuffer(
    device=device.vk,
    pCreateInfo=addr createInfo,
    pAllocator=nil,
    pBuffer=addr result.vk
  )

proc destroy(buffer: var Buffer) =
  assert buffer.device.vk.valid
  assert buffer.vk.valid
  buffer.device.vk.vkDestroyBuffer(buffer.vk, nil)
  buffer.vk.reset()