make it work!
This commit is contained in:
parent
fa984175b3
commit
2d1ac519c5
6 changed files with 28 additions and 18 deletions
|
@ -15,7 +15,7 @@ layout(set = 0, binding = 1) uniform SceneData{
|
||||||
} sceneData;
|
} sceneData;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
//outColor = vec4(fragColor.xyz + sceneData.ambientColor.xyz, 1.0f);
|
outColor = vec4(fragColor.xyz + sceneData.ambientColor.xyz, 1.0f);
|
||||||
|
//outColor = fragColor;
|
||||||
//outColor = sceneData.ambientColor;
|
//outColor = sceneData.ambientColor;
|
||||||
outColor = fragColor;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,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 -- _DYNAMIC
|
||||||
(V.head globalDescriptor)
|
(V.head globalDescriptor)
|
||||||
sceneInfo
|
sceneInfo
|
||||||
1
|
1
|
||||||
|
@ -175,6 +175,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
|
||||||
, frameCommandPool = commandPool
|
, frameCommandPool = commandPool
|
||||||
, frameMainCommandBuffer = V.head commandBuffer
|
, frameMainCommandBuffer = V.head commandBuffer
|
||||||
, frameCameraBuffer = cameraBuffer
|
, frameCameraBuffer = cameraBuffer
|
||||||
|
, frameSceneBuffer = sceneBuffer
|
||||||
, frameObjectBuffer = objectBuffer
|
, frameObjectBuffer = objectBuffer
|
||||||
, frameGlobalDescriptor = V.head globalDescriptor
|
, frameGlobalDescriptor = V.head globalDescriptor
|
||||||
, frameObjectDescriptor = V.head objectDescriptor
|
, frameObjectDescriptor = V.head objectDescriptor
|
||||||
|
@ -265,8 +266,8 @@ recordCommandBuffer
|
||||||
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
|
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
|
||||||
|
|
||||||
let framed = fromIntegral frameNumber / 120
|
let 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
|
||||||
ambientParams = sceneParameters
|
ambientParams = sceneParameters
|
||||||
{ ambientColor = ambient
|
{ ambientColor = ambient
|
||||||
}
|
}
|
||||||
|
@ -276,8 +277,10 @@ recordCommandBuffer
|
||||||
deviceProps
|
deviceProps
|
||||||
|
|
||||||
|
|
||||||
liftIO $ VMA.withMappedMemory allocator (bufferAllocation sceneParameterBuffer) bracket $
|
liftIO $ do
|
||||||
\scenePointer ->
|
-- VMA.withMappedMemory allocator (bufferAllocation (frameSceneBuffer frame)) bracket $
|
||||||
|
-- \scenePointer ->
|
||||||
|
let scenePointer = VMA.mappedData (bufferInfo (frameSceneBuffer frame))
|
||||||
|
|
||||||
-- dataPointer <- liftIO $ new scenePointer
|
-- dataPointer <- liftIO $ new scenePointer
|
||||||
|
|
||||||
|
@ -289,7 +292,7 @@ recordCommandBuffer
|
||||||
-- (sizeOf undefinedGPUSceneData)
|
-- (sizeOf undefinedGPUSceneData)
|
||||||
|
|
||||||
liftIO $ poke
|
liftIO $ poke
|
||||||
(castPtr scenePointer `plusPtr` (fromIntegral sceneDataOffset * frameIndex))
|
(castPtr scenePointer)
|
||||||
-- (castPtr scenePointer `plusPtr`
|
-- (castPtr scenePointer `plusPtr`
|
||||||
-- (fromIntegral $
|
-- (fromIntegral $
|
||||||
-- padUniformBufferSize (fromIntegral $ sizeOf (undefinedGPUSceneData)) deviceProps))-- *
|
-- padUniformBufferSize (fromIntegral $ sizeOf (undefinedGPUSceneData)) deviceProps))-- *
|
||||||
|
@ -356,7 +359,7 @@ recordCommandBuffer
|
||||||
(materialPipelineLayout material)
|
(materialPipelineLayout material)
|
||||||
0
|
0
|
||||||
(V.singleton $ frameGlobalDescriptor frame)
|
(V.singleton $ frameGlobalDescriptor frame)
|
||||||
(V.singleton $ fromIntegral uniformOffset)
|
V.empty -- (V.singleton $ fromIntegral uniformOffset)
|
||||||
|
|
||||||
Vk.cmdBindDescriptorSets
|
Vk.cmdBindDescriptorSets
|
||||||
commandBuffer
|
commandBuffer
|
||||||
|
|
|
@ -156,9 +156,9 @@ initVulkan window = do
|
||||||
)
|
)
|
||||||
<*> createAllocatedBuffer
|
<*> createAllocatedBuffer
|
||||||
allocator
|
allocator
|
||||||
(sizeOf undefinedGPUSceneData)
|
(sizeOf undefinedGPUSceneData * frameOverlap)
|
||||||
Vk.BUFFER_USAGE_UNIFORM_BUFFER_BIT
|
Vk.BUFFER_USAGE_UNIFORM_BUFFER_BIT
|
||||||
VMA.MEMORY_USAGE_CPU_TO_GPU
|
VMA.MEMORY_USAGE_GPU_ONLY
|
||||||
|
|
||||||
|
|
||||||
initScene :: (MonadReader ReadState m, MonadIO m) => m ()
|
initScene :: (MonadReader ReadState m, MonadIO m) => m ()
|
||||||
|
@ -202,7 +202,7 @@ initDescriptors device = do
|
||||||
Vk.SHADER_STAGE_VERTEX_BIT
|
Vk.SHADER_STAGE_VERTEX_BIT
|
||||||
0
|
0
|
||||||
sceneBind = descriptorsetLayoutBinding
|
sceneBind = descriptorsetLayoutBinding
|
||||||
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
|
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
|
||||||
Vk.SHADER_STAGE_FRAGMENT_BIT
|
Vk.SHADER_STAGE_FRAGMENT_BIT
|
||||||
1
|
1
|
||||||
objectBind = descriptorsetLayoutBinding
|
objectBind = descriptorsetLayoutBinding
|
||||||
|
@ -229,7 +229,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
|
||||||
|
|
|
@ -6,6 +6,8 @@ module Memory where
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.Trans.Resource
|
import Control.Monad.Trans.Resource
|
||||||
|
|
||||||
|
import Data.Bits ((.|.))
|
||||||
|
|
||||||
import Foreign.Ptr
|
import Foreign.Ptr
|
||||||
|
|
||||||
import qualified VulkanMemoryAllocator as VMA
|
import qualified VulkanMemoryAllocator as VMA
|
||||||
|
@ -61,13 +63,16 @@ createAllocatedBuffer allocator allocationSize usage memoryUsage = do
|
||||||
}
|
}
|
||||||
vmaAllocationInfo = Vk.zero
|
vmaAllocationInfo = Vk.zero
|
||||||
{ VMA.usage = memoryUsage
|
{ VMA.usage = memoryUsage
|
||||||
|
, VMA.flags = VMA.ALLOCATION_CREATE_MAPPED_BIT
|
||||||
|
, VMA.requiredFlags = Vk.MEMORY_PROPERTY_HOST_VISIBLE_BIT .|. Vk.MEMORY_PROPERTY_HOST_COHERENT_BIT
|
||||||
|
, VMA.preferredFlags = Vk.MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||||
} :: VMA.AllocationCreateInfo
|
} :: VMA.AllocationCreateInfo
|
||||||
|
|
||||||
(_, (buffer, newAllocation, _)) <- allocate
|
(_, (buffer, newAllocation, info)) <- allocate
|
||||||
(VMA.createBuffer allocator bufferInfo vmaAllocationInfo)
|
(VMA.createBuffer allocator bufferInfo vmaAllocationInfo)
|
||||||
(\(buffer, newAllocation, _) -> do
|
(\(buffer, newAllocation, _) -> do
|
||||||
putStrLn "destroying buffer"
|
putStrLn "destroying buffer"
|
||||||
VMA.destroyBuffer allocator buffer newAllocation
|
VMA.destroyBuffer allocator buffer newAllocation
|
||||||
)
|
)
|
||||||
|
|
||||||
return $ AllocatedBuffer buffer newAllocation
|
return $ AllocatedBuffer buffer newAllocation info
|
||||||
|
|
|
@ -64,10 +64,10 @@ uploadMesh vertices allocator = do
|
||||||
} :: VMA.AllocationCreateInfo
|
} :: VMA.AllocationCreateInfo
|
||||||
(_, mesh) <- allocate
|
(_, mesh) <- allocate
|
||||||
(do
|
(do
|
||||||
(buffer, bAllocation, _) <- VMA.createBuffer allocator bufferCreateInfo allocationCreateInfo
|
(buffer, bAllocation, bInfo) <- VMA.createBuffer allocator bufferCreateInfo allocationCreateInfo
|
||||||
return (Mesh vertices (AllocatedBuffer buffer bAllocation))
|
return (Mesh vertices (AllocatedBuffer buffer bAllocation bInfo))
|
||||||
)
|
)
|
||||||
(\(Mesh _ (AllocatedBuffer buffer bAllocation)) -> do
|
(\(Mesh _ (AllocatedBuffer buffer bAllocation bInfo)) -> do
|
||||||
putStrLn "destroying mesh"
|
putStrLn "destroying mesh"
|
||||||
VMA.destroyBuffer allocator buffer bAllocation
|
VMA.destroyBuffer allocator buffer bAllocation
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,6 +51,7 @@ data EngineData = EngineData
|
||||||
data AllocatedBuffer = AllocatedBuffer
|
data AllocatedBuffer = AllocatedBuffer
|
||||||
{ allocatedBuffer :: Vk.Buffer
|
{ allocatedBuffer :: Vk.Buffer
|
||||||
, bufferAllocation :: VMA.Allocation
|
, bufferAllocation :: VMA.Allocation
|
||||||
|
, bufferInfo :: VMA.AllocationInfo
|
||||||
}
|
}
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
@ -198,6 +199,7 @@ data FrameData = FrameData
|
||||||
, frameCommandPool :: Vk.CommandPool
|
, frameCommandPool :: Vk.CommandPool
|
||||||
, frameMainCommandBuffer :: Vk.CommandBuffer
|
, frameMainCommandBuffer :: Vk.CommandBuffer
|
||||||
, frameCameraBuffer :: AllocatedBuffer
|
, frameCameraBuffer :: AllocatedBuffer
|
||||||
|
, frameSceneBuffer :: AllocatedBuffer
|
||||||
, frameObjectBuffer :: AllocatedBuffer
|
, frameObjectBuffer :: AllocatedBuffer
|
||||||
, frameGlobalDescriptor :: Vk.DescriptorSet
|
, frameGlobalDescriptor :: Vk.DescriptorSet
|
||||||
, frameObjectDescriptor :: Vk.DescriptorSet
|
, frameObjectDescriptor :: Vk.DescriptorSet
|
||||||
|
|
Loading…
Reference in a new issue