vulkan-tutorial/src/Util.hs

69 lines
1.7 KiB
Haskell
Raw Permalink Normal View History

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)
2023-04-12 11:41:00 +00:00
import Debug.Trace
2023-04-02 08:46:02 +00:00
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
2023-04-12 11:41:00 +00:00
result =
if minUBOAlignment > 0
then (origSize + minUBOAlignment - 1) .&. complement (minUBOAlignment - 1)
else origSize
2023-04-02 08:46:02 +00:00
in
2023-04-12 11:41:00 +00:00
-- trace ("padding result: " <> show result) result
result
2023-04-02 08:46:02 +00:00
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
}