2023-04-02 08:46:02 +00:00
|
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
|
|
{-# LANGUAGE DataKinds #-}
|
2023-01-06 15:03:01 +00:00
|
|
|
module Util where
|
|
|
|
|
2023-04-02 08:46:02 +00:00
|
|
|
import Data.Bits
|
|
|
|
|
2023-01-06 15:03:01 +00:00
|
|
|
import qualified Data.Vector as V
|
|
|
|
|
2023-04-02 08:46:02 +00:00
|
|
|
import Data.Word (Word32)
|
|
|
|
|
|
|
|
import qualified Vulkan as Vk
|
|
|
|
import qualified Vulkan.CStruct.Extends as Vk
|
|
|
|
import qualified Vulkan.Zero as Vk
|
|
|
|
|
2023-01-06 15:03:01 +00:00
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
|
|
|
|
|
|
|
getFrame :: EngineData -> Int -> FrameData
|
|
|
|
getFrame engineData frame =
|
|
|
|
let frameVector = engineFrames engineData
|
|
|
|
in
|
|
|
|
frameVector V.! (frame `mod` V.length frameVector)
|
2023-04-02 08:46:02 +00:00
|
|
|
|
|
|
|
padUniformBufferSize
|
|
|
|
:: Vk.DeviceSize
|
|
|
|
-> Vk.PhysicalDeviceProperties
|
|
|
|
-> Vk.DeviceSize
|
|
|
|
padUniformBufferSize origSize gpuProperties =
|
|
|
|
let minUBOAlignment = Vk.minUniformBufferOffsetAlignment $ Vk.limits gpuProperties
|
|
|
|
in
|
|
|
|
if minUBOAlignment > 0
|
|
|
|
then (origSize + minUBOAlignment - 1) .&. complement (minUBOAlignment - 1)
|
|
|
|
else origSize
|
|
|
|
|
|
|
|
descriptorsetLayoutBinding
|
|
|
|
:: Vk.DescriptorType
|
|
|
|
-> Vk.ShaderStageFlags
|
|
|
|
-> Word32
|
|
|
|
-> Vk.DescriptorSetLayoutBinding
|
|
|
|
descriptorsetLayoutBinding type' stageFlags binding =
|
|
|
|
Vk.zero
|
|
|
|
{ Vk.binding = binding
|
|
|
|
, Vk.descriptorCount = 1
|
|
|
|
, Vk.descriptorType = type'
|
|
|
|
, Vk.immutableSamplers = V.empty
|
|
|
|
, Vk.stageFlags = stageFlags
|
|
|
|
}
|
|
|
|
|
|
|
|
writeDescriptorBuffer
|
|
|
|
:: Vk.DescriptorType
|
|
|
|
-> Vk.DescriptorSet
|
|
|
|
-> Vk.DescriptorBufferInfo
|
|
|
|
-> Word32
|
|
|
|
-> Vk.SomeStruct Vk.WriteDescriptorSet
|
|
|
|
writeDescriptorBuffer type' dstSet bufferInfo binding = Vk.SomeStruct $
|
|
|
|
Vk.zero
|
|
|
|
{ Vk.dstBinding = binding
|
|
|
|
, Vk.dstSet = dstSet
|
|
|
|
, Vk.descriptorCount = 1
|
|
|
|
, Vk.descriptorType = type'
|
|
|
|
, Vk.bufferInfo = V.singleton bufferInfo
|
|
|
|
}
|