From 13bd4ac3f183c858a6057f541f8ad15d5aea4ae0 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 19 Apr 2023 15:20:44 +0200 Subject: [PATCH] first little steps --- src/CommandBuffer.hs | 48 +++++++++++++++++++++++++------------------- src/Init.hs | 2 +- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/CommandBuffer.hs b/src/CommandBuffer.hs index 0dc8fbc..7b126ce 100644 --- a/src/CommandBuffer.hs +++ b/src/CommandBuffer.hs @@ -25,6 +25,7 @@ import Devices import Types import Memory import Util +import Control.Exception (bracket, bracket_) frameOverlap :: Int frameOverlap = 2 @@ -275,30 +276,31 @@ recordCommandBuffer deviceProps - scenePointer <- VMA.mapMemory allocator (bufferAllocation sceneParameterBuffer) + liftIO $ VMA.withMappedMemory allocator (bufferAllocation sceneParameterBuffer) bracket $ + \scenePointer -> - -- dataPointer <- liftIO $ new scenePointer + -- dataPointer <- liftIO $ new scenePointer - -- paramsPtr <- liftIO (new ambientParams) + -- paramsPtr <- liftIO (new ambientParams) - -- liftIO $ copyBytes - -- (scenePointer `plusPtr` (fromIntegral sceneDataOffset * fromIntegral frameIndex)) - -- paramsPtr - -- (sizeOf undefinedGPUSceneData) + -- liftIO $ copyBytes + -- (scenePointer `plusPtr` (fromIntegral sceneDataOffset * fromIntegral frameIndex)) + -- paramsPtr + -- (sizeOf undefinedGPUSceneData) - liftIO $ poke - (castPtr scenePointer `plusPtr` (fromIntegral sceneDataOffset * frameIndex)) - -- (castPtr scenePointer `plusPtr` - -- (fromIntegral $ - -- padUniformBufferSize (fromIntegral $ sizeOf (undefinedGPUSceneData)) deviceProps))-- * - -- -- fromIntegral frameIndex)) - ambientParams + liftIO $ poke + (castPtr scenePointer `plusPtr` (fromIntegral sceneDataOffset * frameIndex)) + -- (castPtr scenePointer `plusPtr` + -- (fromIntegral $ + -- padUniformBufferSize (fromIntegral $ sizeOf (undefinedGPUSceneData)) deviceProps))-- * + -- -- fromIntegral frameIndex)) + ambientParams - -- liftIO $ do - -- test <- peek (castPtr scenePointer :: Ptr GPUSceneData) - -- print test + -- liftIO $ do + -- test <- peek (castPtr scenePointer :: Ptr GPUSceneData) + -- print test - VMA.unmapMemory allocator (bufferAllocation sceneParameterBuffer) + -- VMA.unmapMemory allocator (bufferAllocation sceneParameterBuffer) renderObjects <- (liftIO . STM.atomically . STM.readTMVar) =<< asks renderables meshMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks meshLibrary @@ -330,11 +332,15 @@ recordCommandBuffer mesh = meshMap M.! meshID material = materialMap M.! materialID - memoryPointer <- VMA.mapMemory allocator (bufferAllocation $ frameCameraBuffer frame) + liftIO $ VMA.withMappedMemory + allocator + (bufferAllocation $ frameCameraBuffer frame) + bracket + $ \memoryPointer -> - liftIO $ poke (castPtr memoryPointer) cameraData + liftIO $ poke (castPtr memoryPointer) cameraData - VMA.unmapMemory allocator (bufferAllocation $ frameCameraBuffer frame) + -- VMA.unmapMemory allocator (bufferAllocation $ frameCameraBuffer frame) Vk.cmdBindPipeline commandBuffer Vk.PIPELINE_BIND_POINT_GRAPHICS (materialPipeline material) diff --git a/src/Init.hs b/src/Init.hs index 6e74c23..4022386 100644 --- a/src/Init.hs +++ b/src/Init.hs @@ -203,7 +203,7 @@ initDescriptors device = do 0 sceneBind = descriptorsetLayoutBinding Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC - (Vk.SHADER_STAGE_VERTEX_BIT .|. Vk.SHADER_STAGE_FRAGMENT_BIT) + Vk.SHADER_STAGE_FRAGMENT_BIT 1 objectBind = descriptorsetLayoutBinding Vk.DESCRIPTOR_TYPE_STORAGE_BUFFER