next chapter, but broken

This commit is contained in:
nek0 2023-05-12 13:30:00 +02:00
parent fdc86a3c03
commit 526b9ba281
5 changed files with 47 additions and 20 deletions

View file

@ -110,7 +110,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
let cameraInfo = Vk.zero let cameraInfo = Vk.zero
{ Vk.buffer = allocatedBuffer cameraBuffer { Vk.buffer = allocatedBuffer cameraBuffer
, Vk.offset = 0 , Vk.offset = 0
, Vk.range = fromIntegral $ sizeOf (GPUCameraData identity identity identity) , Vk.range = fromIntegral $ sizeOf (undefined :: GPUCameraData)
} :: Vk.DescriptorBufferInfo } :: Vk.DescriptorBufferInfo
sceneInfo = Vk.zero sceneInfo = Vk.zero
{ Vk.buffer = allocatedBuffer sceneBuffer { Vk.buffer = allocatedBuffer sceneBuffer
@ -129,7 +129,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
cameraInfo cameraInfo
0 0
sceneWrite = writeDescriptorBuffer sceneWrite = writeDescriptorBuffer
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER
(V.head globalDescriptor) (V.head globalDescriptor)
sceneInfo sceneInfo
1 1
@ -301,14 +301,18 @@ prepareRecording (V2 width height) commandBuffer graphicsPipeline = do
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor) Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
pokeData pokeData
:: FrameData :: (MonadResource m, MonadReader ReadState m, MonadIO m)
=> FrameData
-> Int -> Int
-> GPUSceneData -> GPUSceneData
-> GPUCameraData -> GPUCameraData
-> IO () -> m ()
pokeData frame frameNumber sceneParameters cameraParameters = do pokeData frame frameNumber sceneParameters cameraParameters = do
renderObjects <- (liftIO . STM.atomically . STM.readTMVar) =<< asks renderables
let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame) let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame)
memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame) memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame)
objectPointer = VMA.mappedData (bufferInfo $ frameObjectBuffer frame)
framed = fromIntegral frameNumber / 120 framed = fromIntegral frameNumber / 120
ambient = normalize $ V4 (sin framed) 0 (cos framed) 1 ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
-- ambient = V4 1 0 1 1 -- ambient = V4 1 0 1 1
@ -316,8 +320,25 @@ pokeData frame frameNumber sceneParameters cameraParameters = do
{ ambientColor = ambient { ambientColor = ambient
} }
V.mapM_
(\(index, obj) -> do
let modelMatrix = GPUObjectData (objectMatrix obj)
liftIO $ poke
(objectPointer `plusPtr` (index * sizeOf (undefined :: GPUObjectData)))
modelMatrix
)
(V.zip
(V.fromList [0 ..])
renderObjects
)
liftIO $ do
poke poke
(castPtr scenePointer) (castPtr scenePointer)
ambientParams ambientParams
poke (castPtr memoryPointer) cameraParameters poke
(castPtr memoryPointer)
cameraParameters

View file

@ -9,7 +9,7 @@ import Control.Monad.Trans.Resource
import qualified Data.Vector as V import qualified Data.Vector as V
import Data.Maybe (fromMaybe, isNothing) import Data.Maybe (fromMaybe, isNothing)
import Data.Bits import Data.Bits
import Data.Word (Word32) import Foreign
import Foreign.C.Types (CInt) import Foreign.C.Types (CInt)
import Linear import Linear
import qualified Vulkan as Vk import qualified Vulkan as Vk
@ -105,9 +105,16 @@ createLogicalDevice physDevice surface = do
{ Vk.queueCreateInfos = V.singleton (Vk.SomeStruct queueCreateInfo) { Vk.queueCreateInfos = V.singleton (Vk.SomeStruct queueCreateInfo)
, Vk.enabledExtensionNames = extensionNames , Vk.enabledExtensionNames = extensionNames
} }
shaderDrawParametersFeatures = Vk.zero
{ Vk.shaderDrawParameters = True
} :: Vk.PhysicalDeviceShaderDrawParametersFeatures
(_, logDevice) <- (_, logDevice) <-
Vk.withDevice physDevice deviceCreateInfo Nothing allocate Vk.withDevice
physDevice
(deviceCreateInfo Vk.::& shaderDrawParametersFeatures Vk.:& ())
Nothing
allocate
(result, formats) <- Vk.getPhysicalDeviceSurfaceFormatsKHR physDevice surface (result, formats) <- Vk.getPhysicalDeviceSurfaceFormatsKHR physDevice surface
unless (result == Vk.SUCCESS) $ unless (result == Vk.SUCCESS) $

View file

@ -73,7 +73,6 @@ drawFrame engineData frameNumber = do
, viewProjection = transpose $ camProjection !*! camView , viewProjection = transpose $ camProjection !*! camView
} }
liftIO $
pokeData pokeData
frame frame
frameNumber frameNumber

View file

@ -97,7 +97,7 @@ initVulkan window = do
(swapchain, surfaceFormat, depthImageView, depthAllocatedImage) <- (swapchain, surfaceFormat, depthImageView, depthAllocatedImage) <-
createSwapchain vulkanSurface surfaceFormats dimensions vulkanLogicalDevice allocator createSwapchain vulkanSurface surfaceFormats dimensions vulkanLogicalDevice allocator
imageViews <- getImageViewHandles swapchain surfaceFormat vulkanLogicalDevice imageViews <- getImageViewHandles swapchain surfaceFormat vulkanLogicalDevice
meshVertexShader <- loadShader vulkanLogicalDevice "shadersrc/mesh.vert" "vert" meshVertexShader <- loadShader vulkanLogicalDevice "shadersrc/tri_mesh.vert" "vert"
meshFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow_lit.frag" "frag" meshFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow_lit.frag" "frag"
renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat) Vk.FORMAT_D32_SFLOAT renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat) Vk.FORMAT_D32_SFLOAT
meshLayout <- createMeshPipelineLayout meshLayout <- createMeshPipelineLayout
@ -219,7 +219,7 @@ initDescriptors device = do
, Vk.descriptorCount = 10 , Vk.descriptorCount = 10
} }
, Vk.zero , Vk.zero
{ Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC { Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
, Vk.descriptorCount = 10 , Vk.descriptorCount = 10
} }
, Vk.zero , Vk.zero

View file

@ -230,8 +230,8 @@ data GPUCameraData = GPUCameraData
instance Storable GPUCameraData where instance Storable GPUCameraData where
sizeOf (GPUCameraData pview pprojection pviewProjection) = sizeOf _ =
sizeOf pview + sizeOf pprojection + sizeOf pviewProjection 3* sizeOf (undefined :: M44 Float)
alignment _ = 0 alignment _ = 0