changeset 1054:b101ea4d411e

del: do not use vulkan 1.3 functions to support older hardware
author sam <sam@basx.dev>
date Sat, 30 Mar 2024 21:52:17 +0700
parents 6377949df709
children 4bf4c029b880
files semicongine/vulkan/buffer.nim semicongine/vulkan/commandbuffer.nim semicongine/vulkan/device.nim semicongine/vulkan/image.nim
diffstat 4 files changed, 42 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/vulkan/buffer.nim	Sat Mar 30 20:45:59 2024 +0700
+++ b/semicongine/vulkan/buffer.nim	Sat Mar 30 21:52:17 2024 +0700
@@ -108,14 +108,16 @@
 
   var copyRegion = VkBufferCopy(size: VkDeviceSize(src.size), dstOffset: VkDeviceSize(dstOffset))
   withSingleUseCommandBuffer(src.device, queue, true, commandBuffer):
-    let barrier = VkMemoryBarrier2(
-      sType: VK_STRUCTURE_TYPE_MEMORY_BARRIER_2,
-      srcStageMask: [VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT].toBits,
-      srcAccessMask: [VK_ACCESS_2_MEMORY_WRITE_BIT].toBits,
-      dstStageMask: [VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT].toBits,
-      dstAccessMask: [VK_ACCESS_2_MEMORY_READ_BIT].toBits,
+    let barrier = VkMemoryBarrier(
+      sType: VK_STRUCTURE_TYPE_MEMORY_BARRIER,
+      srcAccessMask: [VK_ACCESS_MEMORY_WRITE_BIT].toBits,
+      dstAccessMask: [VK_ACCESS_MEMORY_READ_BIT].toBits,
     )
-    commandBuffer.pipelineBarrier(memoryBarriers = [barrier])
+    commandBuffer.pipelineBarrier(
+      [VK_PIPELINE_STAGE_TRANSFER_BIT],
+      [VK_PIPELINE_STAGE_VERTEX_INPUT_BIT],
+      memoryBarriers = [barrier]
+    )
     commandBuffer.vkCmdCopyBuffer(src.vk, dst.vk, 1, addr(copyRegion))
 
 proc destroy*(buffer: var Buffer) =
--- a/semicongine/vulkan/commandbuffer.nim	Sat Mar 30 20:45:59 2024 +0700
+++ b/semicongine/vulkan/commandbuffer.nim	Sat Mar 30 21:52:17 2024 +0700
@@ -33,23 +33,26 @@
 
 proc pipelineBarrier*(
   commandBuffer: VkCommandBuffer,
-  memoryBarriers: openArray[VkMemoryBarrier2] = [],
-  bufferMemoryBarriers: openArray[VkBufferMemoryBarrier2] = [],
-  imageBarriers: openArray[VkImageMemoryBarrier2] = [],
+  srcStages: openArray[VkPipelineStageFlagBits],
+  dstStages: openArray[VkPipelineStageFlagBits],
+  memoryBarriers: openArray[VkMemoryBarrier] = [],
+  bufferMemoryBarriers: openArray[VkBufferMemoryBarrier] = [],
+  imageBarriers: openArray[VkImageMemoryBarrier] = [],
 ) =
-  let dependencies = VkDependencyInfo(
-    sType: VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
-    dependencyFlags: VkDependencyFlags(0),
-    memoryBarrierCount: uint32(memoryBarriers.len),
-    pMemoryBarriers: memoryBarriers.toCPointer,
-    bufferMemoryBarrierCount: uint32(bufferMemoryBarriers.len),
-    pBufferMemoryBarriers: bufferMemoryBarriers.toCPointer,
-    imageMemoryBarrierCount: uint32(imageBarriers.len),
-    pImageMemoryBarriers: imageBarriers.toCPointer,
+
+  vkCmdPipelineBarrier(
+    commandBuffer,
+    srcStageMask = srcStages.toBits,
+    dstStageMask = dstStages.toBits,
+    dependencyFlags = VkDependencyFlags(0),
+    memoryBarrierCount = uint32(memoryBarriers.len),
+    pMemoryBarriers = memoryBarriers.toCPointer,
+    bufferMemoryBarrierCount = uint32(bufferMemoryBarriers.len),
+    pBufferMemoryBarriers = bufferMemoryBarriers.toCPointer,
+    imageMemoryBarrierCount = uint32(imageBarriers.len),
+    pImageMemoryBarriers = imageBarriers.toCPointer,
   )
 
-  vkCmdPipelineBarrier2(commandBuffer, addr dependencies)
-
 
 template withSingleUseCommandBuffer*(device: Device, queue: Queue, needsTransfer: bool, commandBuffer, body: untyped): untyped =
   assert device.vk.valid
--- a/semicongine/vulkan/device.nim	Sat Mar 30 20:45:59 2024 +0700
+++ b/semicongine/vulkan/device.nim	Sat Mar 30 21:52:17 2024 +0700
@@ -50,14 +50,9 @@
     )
   var queueList = deviceQueues.values.toSeq
 
-  var features13 = VkPhysicalDeviceVulkan13Features(
-    stype: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
-    synchronization2: true
-  )
   var features2 = VkPhysicalDeviceFeatures2(
     stype: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
     features: result.enabledFeatures,
-    pNext: addr features13,
   )
   var createInfo = VkDeviceCreateInfo(
     sType: VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
--- a/semicongine/vulkan/image.nim	Sat Mar 30 20:45:59 2024 +0700
+++ b/semicongine/vulkan/image.nim	Sat Mar 30 21:52:17 2024 +0700
@@ -80,8 +80,9 @@
   checkVkResult image.device.vk.vkBindImageMemory(image.vk, image.memory.vk, VkDeviceSize(0))
 
 proc transitionImageLayout(image: VulkanImage, queue: Queue, oldLayout, newLayout: VkImageLayout) =
-  var barrier = VkImageMemoryBarrier2(
-      sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
+  var
+    barrier = VkImageMemoryBarrier(
+      sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
       oldLayout: oldLayout,
       newLayout: newLayout,
       srcQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED,
@@ -93,23 +94,25 @@
         levelCount: 1,
         baseArrayLayer: 0,
         layerCount: 1,
-    ),
-  )
+      ),
+    )
+    srcStage: VkPipelineStageFlagBits
+    dstStage: VkPipelineStageFlagBits
   if oldLayout == VK_IMAGE_LAYOUT_UNDEFINED and newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
-    barrier.srcStageMask = [VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT].toBits
-    barrier.srcAccessMask = VkAccessFlags2(0)
-    barrier.dstStageMask = [VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT].toBits
-    barrier.dstAccessMask = [VK_ACCESS_2_TRANSFER_WRITE_BIT].toBits
+    srcStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
+    barrier.srcAccessMask = VkAccessFlags(0)
+    dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT
+    barrier.dstAccessMask = [VK_ACCESS_TRANSFER_WRITE_BIT].toBits
   elif oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL and newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
-    barrier.srcStageMask = [VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT].toBits
-    barrier.srcAccessMask = [VK_ACCESS_2_TRANSFER_WRITE_BIT].toBits
-    barrier.dstStageMask = [VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT].toBits
-    barrier.dstAccessMask = [VK_ACCESS_2_SHADER_READ_BIT].toBits
+    srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT
+    barrier.srcAccessMask = [VK_ACCESS_TRANSFER_WRITE_BIT].toBits
+    dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
+    barrier.dstAccessMask = [VK_ACCESS_SHADER_READ_BIT].toBits
   else:
     raise newException(Exception, "Unsupported layout transition!")
 
   withSingleUseCommandBuffer(image.device, queue, false, commandBuffer):
-    commandBuffer.pipelineBarrier(imageBarriers = [barrier])
+    commandBuffer.pipelineBarrier([srcStage], [dstStage], imageBarriers = [barrier])
 
 proc copy*(src: Buffer, dst: VulkanImage, queue: Queue) =
   assert src.device.vk.valid