# HG changeset patch # User sam # Date 1711810337 -25200 # Node ID b65068f5f2464a2abbd4e4b1298321227edbe8bf # Parent b425111868583569e79d2d2885f7675948de96fd del: do not use vulkan 1.3 functions to support older hardware diff -r b42511186858 -r b65068f5f246 semicongine/vulkan/buffer.nim --- 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) = diff -r b42511186858 -r b65068f5f246 semicongine/vulkan/commandbuffer.nim --- 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 diff -r b42511186858 -r b65068f5f246 semicongine/vulkan/device.nim --- 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, diff -r b42511186858 -r b65068f5f246 semicongine/vulkan/image.nim --- 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