make it work!

This commit is contained in:
nek0 2023-04-19 17:26:33 +02:00
parent b8fbbc8050
commit e3bed9a2eb
6 changed files with 28 additions and 18 deletions

View file

@ -15,7 +15,7 @@ layout(set = 0, binding = 1) uniform SceneData{
} sceneData;
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;
}

View file

@ -150,7 +150,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
cameraInfo
0
sceneWrite = writeDescriptorBuffer
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
(V.head globalDescriptor)
sceneInfo
1
@ -175,6 +175,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
, frameCommandPool = commandPool
, frameMainCommandBuffer = V.head commandBuffer
, frameCameraBuffer = cameraBuffer
, frameSceneBuffer = sceneBuffer
, frameObjectBuffer = objectBuffer
, frameGlobalDescriptor = V.head globalDescriptor
, frameObjectDescriptor = V.head objectDescriptor
@ -265,8 +266,8 @@ recordCommandBuffer
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
let framed = fromIntegral frameNumber / 120
-- ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
ambient = V4 1 0 1 1
ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
-- ambient = V4 1 0 1 1
ambientParams = sceneParameters
{ ambientColor = ambient
}
@ -276,8 +277,10 @@ recordCommandBuffer
deviceProps
liftIO $ VMA.withMappedMemory allocator (bufferAllocation sceneParameterBuffer) bracket $
\scenePointer ->
liftIO $ do
-- VMA.withMappedMemory allocator (bufferAllocation (frameSceneBuffer frame)) bracket $
-- \scenePointer ->
let scenePointer = VMA.mappedData (bufferInfo (frameSceneBuffer frame))
-- dataPointer <- liftIO $ new scenePointer
@ -289,7 +292,7 @@ recordCommandBuffer
-- (sizeOf undefinedGPUSceneData)
liftIO $ poke
(castPtr scenePointer `plusPtr` (fromIntegral sceneDataOffset * frameIndex))
(castPtr scenePointer)
-- (castPtr scenePointer `plusPtr`
-- (fromIntegral $
-- padUniformBufferSize (fromIntegral $ sizeOf (undefinedGPUSceneData)) deviceProps))-- *
@ -356,7 +359,7 @@ recordCommandBuffer
(materialPipelineLayout material)
0
(V.singleton $ frameGlobalDescriptor frame)
(V.singleton $ fromIntegral uniformOffset)
V.empty -- (V.singleton $ fromIntegral uniformOffset)
Vk.cmdBindDescriptorSets
commandBuffer

View file

@ -156,9 +156,9 @@ initVulkan window = do
)
<*> createAllocatedBuffer
allocator
(sizeOf undefinedGPUSceneData)
(sizeOf undefinedGPUSceneData * frameOverlap)
Vk.BUFFER_USAGE_UNIFORM_BUFFER_BIT
VMA.MEMORY_USAGE_CPU_TO_GPU
VMA.MEMORY_USAGE_GPU_ONLY
initScene :: (MonadReader ReadState m, MonadIO m) => m ()
@ -202,7 +202,7 @@ initDescriptors device = do
Vk.SHADER_STAGE_VERTEX_BIT
0
sceneBind = descriptorsetLayoutBinding
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
Vk.SHADER_STAGE_FRAGMENT_BIT
1
objectBind = descriptorsetLayoutBinding
@ -229,7 +229,7 @@ initDescriptors device = do
, Vk.descriptorCount = 10
}
, Vk.zero
{ Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
{ Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
, Vk.descriptorCount = 10
}
, Vk.zero

View file

@ -6,6 +6,8 @@ module Memory where
import Control.Monad.IO.Class
import Control.Monad.Trans.Resource
import Data.Bits ((.|.))
import Foreign.Ptr
import qualified VulkanMemoryAllocator as VMA
@ -61,13 +63,16 @@ createAllocatedBuffer allocator allocationSize usage memoryUsage = do
}
vmaAllocationInfo = Vk.zero
{ 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
(_, (buffer, newAllocation, _)) <- allocate
(_, (buffer, newAllocation, info)) <- allocate
(VMA.createBuffer allocator bufferInfo vmaAllocationInfo)
(\(buffer, newAllocation, _) -> do
putStrLn "destroying buffer"
VMA.destroyBuffer allocator buffer newAllocation
)
return $ AllocatedBuffer buffer newAllocation
return $ AllocatedBuffer buffer newAllocation info

View file

@ -64,10 +64,10 @@ uploadMesh vertices allocator = do
} :: VMA.AllocationCreateInfo
(_, mesh) <- allocate
(do
(buffer, bAllocation, _) <- VMA.createBuffer allocator bufferCreateInfo allocationCreateInfo
return (Mesh vertices (AllocatedBuffer buffer bAllocation))
(buffer, bAllocation, bInfo) <- VMA.createBuffer allocator bufferCreateInfo allocationCreateInfo
return (Mesh vertices (AllocatedBuffer buffer bAllocation bInfo))
)
(\(Mesh _ (AllocatedBuffer buffer bAllocation)) -> do
(\(Mesh _ (AllocatedBuffer buffer bAllocation bInfo)) -> do
putStrLn "destroying mesh"
VMA.destroyBuffer allocator buffer bAllocation
)

View file

@ -51,6 +51,7 @@ data EngineData = EngineData
data AllocatedBuffer = AllocatedBuffer
{ allocatedBuffer :: Vk.Buffer
, bufferAllocation :: VMA.Allocation
, bufferInfo :: VMA.AllocationInfo
}
deriving (Show)
@ -198,6 +199,7 @@ data FrameData = FrameData
, frameCommandPool :: Vk.CommandPool
, frameMainCommandBuffer :: Vk.CommandBuffer
, frameCameraBuffer :: AllocatedBuffer
, frameSceneBuffer :: AllocatedBuffer
, frameObjectBuffer :: AllocatedBuffer
, frameGlobalDescriptor :: Vk.DescriptorSet
, frameObjectDescriptor :: Vk.DescriptorSet