Compare commits
18 commits
main
...
indirect_d
Author | SHA1 | Date | |
---|---|---|---|
73cb22a1f0 | |||
1cae4b0d65 | |||
8aab6e9bbb | |||
d75e0e1eeb | |||
06e3d5c2ec | |||
6d625cabf6 | |||
b4c74b4c0c | |||
7497a4c557 | |||
283d1be22d | |||
ddea01c005 | |||
88b2516976 | |||
b416f83eec | |||
acd8fe16c6 | |||
4dcf5ba486 | |||
302f7a6d83 | |||
02501ce1a1 | |||
9ed1391f5f | |||
4ee6c368df |
9 changed files with 59 additions and 62 deletions
12
flake.lock
12
flake.lock
|
@ -5,11 +5,11 @@
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1694529238,
|
"lastModified": 1692799911,
|
||||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1699181587,
|
"lastModified": 1692885195,
|
||||||
"narHash": "sha256-v35mUUgVU2ituIHPNHifpjl5uiYQYyLrpaMtz8X8Ums=",
|
"narHash": "sha256-zo/6ItD2ITIOsYmpQZ3sOcuDPhIh71flCj6TkF10nKM=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "197629b470f184a47b2a5716312d25b09454bbf8",
|
"rev": "27c6502cb974e6ad610baaeeba162acd3536ec45",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
haskell-language-server
|
haskell-language-server
|
||||||
ghcid
|
ghcid
|
||||||
cabal-install
|
cabal-install
|
||||||
(jailbreakUnbreak wavefront)
|
|
||||||
]) ++ (with pkgs; [
|
]) ++ (with pkgs; [
|
||||||
shaderc
|
shaderc
|
||||||
vulkan-loader
|
vulkan-loader
|
||||||
|
|
|
@ -19,6 +19,8 @@ layout(set = 2, binding = 0) uniform sampler2D tex1;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 color = texture(tex1, texCoord).xyz;
|
// Flip y coordinate of UVs to fix display
|
||||||
|
float y = texCoord.y * -1;
|
||||||
|
vec3 color = texture(tex1, vec2(texCoord.x ,y)).xyz;
|
||||||
outFragColor = vec4(color, inColor.w);
|
outFragColor = vec4(color, inColor.w);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
@ -181,8 +182,7 @@ createFrames
|
||||||
|
|
||||||
recordCommandBuffer
|
recordCommandBuffer
|
||||||
:: (MonadResource m, MonadReader ReadState m, MonadIO m)
|
:: (MonadResource m, MonadReader ReadState m, MonadIO m)
|
||||||
=> VMA.Allocator
|
=> Vk.CommandBuffer
|
||||||
-> Vk.CommandBuffer
|
|
||||||
-> Vk.RenderPass
|
-> Vk.RenderPass
|
||||||
-> Vk.Framebuffer
|
-> Vk.Framebuffer
|
||||||
-> V2 CInt
|
-> V2 CInt
|
||||||
|
@ -190,7 +190,6 @@ recordCommandBuffer
|
||||||
-> FrameData
|
-> FrameData
|
||||||
-> m ()
|
-> m ()
|
||||||
recordCommandBuffer
|
recordCommandBuffer
|
||||||
allocator
|
|
||||||
commandBuffer
|
commandBuffer
|
||||||
renderPass
|
renderPass
|
||||||
frameBuffer
|
frameBuffer
|
||||||
|
@ -235,8 +234,9 @@ recordCommandBuffer
|
||||||
materialMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks materialLibrary
|
materialMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks materialLibrary
|
||||||
|
|
||||||
let draws = compactDraws meshMap materialMap renderObjects
|
let draws = compactDraws meshMap materialMap renderObjects
|
||||||
drawCommands = V.map
|
|
||||||
(\(i, RenderObject mesh _ _) ->
|
let drawCommands = V.map
|
||||||
|
(\(i, RenderObject mesh matrix material) ->
|
||||||
Vk.DrawIndirectCommand
|
Vk.DrawIndirectCommand
|
||||||
{ vertexCount = fromIntegral (V.length $ meshVertices $ meshMap M.! mesh)
|
{ vertexCount = fromIntegral (V.length $ meshVertices $ meshMap M.! mesh)
|
||||||
, firstVertex = 0
|
, firstVertex = 0
|
||||||
|
@ -249,24 +249,6 @@ recordCommandBuffer
|
||||||
renderObjects
|
renderObjects
|
||||||
)
|
)
|
||||||
|
|
||||||
(memRelease, memPtr) <- VMA.withMappedMemory
|
|
||||||
allocator
|
|
||||||
(bufferAllocation $ frameIndirectBuffer frame)
|
|
||||||
allocate
|
|
||||||
|
|
||||||
V.mapM_
|
|
||||||
(\(idx, command) -> liftIO $
|
|
||||||
poke
|
|
||||||
(castPtr memPtr `plusPtr` (idx * sizeOf command))
|
|
||||||
command
|
|
||||||
)
|
|
||||||
(V.zip
|
|
||||||
(V.fromList [0 ..])
|
|
||||||
drawCommands
|
|
||||||
)
|
|
||||||
|
|
||||||
release memRelease
|
|
||||||
|
|
||||||
V.mapM_
|
V.mapM_
|
||||||
(\(IndirectBatch mesh material first count) -> do
|
(\(IndirectBatch mesh material first count) -> do
|
||||||
|
|
||||||
|
@ -318,6 +300,50 @@ recordCommandBuffer
|
||||||
)
|
)
|
||||||
draws
|
draws
|
||||||
|
|
||||||
|
-- V.mapM_
|
||||||
|
-- (\(IndirectBatch mesh material first count) -> do
|
||||||
|
|
||||||
|
-- when
|
||||||
|
-- (materialTextureSet material /= Vk.NULL_HANDLE)
|
||||||
|
-- (Vk.cmdBindDescriptorSets
|
||||||
|
-- commandBuffer
|
||||||
|
-- Vk.PIPELINE_BIND_POINT_GRAPHICS
|
||||||
|
-- (materialPipelineLayout material)
|
||||||
|
-- 2
|
||||||
|
-- (V.singleton $ materialTextureSet material)
|
||||||
|
-- V.empty
|
||||||
|
-- )
|
||||||
|
|
||||||
|
-- Vk.cmdBindPipeline commandBuffer Vk.PIPELINE_BIND_POINT_GRAPHICS (materialPipeline material)
|
||||||
|
|
||||||
|
-- Vk.cmdBindDescriptorSets
|
||||||
|
-- commandBuffer
|
||||||
|
-- Vk.PIPELINE_BIND_POINT_GRAPHICS
|
||||||
|
-- (materialPipelineLayout material)
|
||||||
|
-- 0
|
||||||
|
-- (V.singleton $ frameGlobalDescriptor frame)
|
||||||
|
-- V.empty
|
||||||
|
|
||||||
|
-- Vk.cmdBindDescriptorSets
|
||||||
|
-- commandBuffer
|
||||||
|
-- Vk.PIPELINE_BIND_POINT_GRAPHICS
|
||||||
|
-- (materialPipelineLayout material)
|
||||||
|
-- 1
|
||||||
|
-- (V.singleton $ frameObjectDescriptor frame)
|
||||||
|
-- V.empty
|
||||||
|
|
||||||
|
-- Vk.cmdBindVertexBuffers
|
||||||
|
-- commandBuffer
|
||||||
|
-- 0
|
||||||
|
-- (V.fromList [ allocatedBuffer $ meshBuffer mesh ])
|
||||||
|
-- (V.fromList [ 0 ])
|
||||||
|
|
||||||
|
-- mapM_
|
||||||
|
-- (Vk.cmdDraw commandBuffer (fromIntegral $ V.length $ meshVertices mesh) 1 0)
|
||||||
|
-- [first .. (count - 1)]
|
||||||
|
-- )
|
||||||
|
-- draws
|
||||||
|
|
||||||
prepareRecording
|
prepareRecording
|
||||||
:: V2 CInt
|
:: V2 CInt
|
||||||
-> Vk.CommandBuffer
|
-> Vk.CommandBuffer
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
|
||||||
module Draw where
|
module Draw where
|
||||||
|
|
||||||
import qualified Control.Concurrent.STM as STM
|
import qualified Control.Concurrent.STM as STM
|
||||||
|
@ -81,7 +80,6 @@ drawFrame engineData frameNumber = do
|
||||||
cameraData
|
cameraData
|
||||||
|
|
||||||
recordCommandBuffer
|
recordCommandBuffer
|
||||||
(engineData.engineAllocator)
|
|
||||||
(frameMainCommandBuffer frame)
|
(frameMainCommandBuffer frame)
|
||||||
(engineRenderPass engineData)
|
(engineRenderPass engineData)
|
||||||
(engineFramebuffers engineData V.! fromIntegral index)
|
(engineFramebuffers engineData V.! fromIntegral index)
|
||||||
|
|
25
src/Main.hs
25
src/Main.hs
|
@ -1,5 +1,4 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
{-# LANGUAGE OverloadedRecordDot #-}
|
||||||
|
@ -11,12 +10,9 @@ import Control.Monad.Loops
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.Trans.Resource
|
import Control.Monad.Trans.Resource
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
import Data.ByteString.Char8
|
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import Data.Time.Clock
|
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import qualified SDL hiding (V2)
|
import qualified SDL hiding (V2)
|
||||||
import System.IO (stdout)
|
|
||||||
import System.Mem
|
import System.Mem
|
||||||
import qualified Vulkan as Vk
|
import qualified Vulkan as Vk
|
||||||
import qualified Vulkan.Zero as Vk
|
import qualified Vulkan.Zero as Vk
|
||||||
|
@ -47,8 +43,6 @@ main = do
|
||||||
|
|
||||||
-- create abort condition for upcoming lop
|
-- create abort condition for upcoming lop
|
||||||
quit <- liftIO $ STM.newTMVarIO True
|
quit <- liftIO $ STM.newTMVarIO True
|
||||||
time <- liftIO $ STM.newTMVarIO =<< getCurrentTime
|
|
||||||
average <- liftIO $ STM.newTMVarIO 0
|
|
||||||
|
|
||||||
-- main loop
|
-- main loop
|
||||||
whileM_
|
whileM_
|
||||||
|
@ -56,24 +50,11 @@ main = do
|
||||||
)
|
)
|
||||||
( do
|
( do
|
||||||
liftIO performMajorGC
|
liftIO performMajorGC
|
||||||
now <- liftIO getCurrentTime
|
|
||||||
before <- liftIO $ STM.atomically $ STM.swapTMVar time now
|
|
||||||
let timeDiff = diffUTCTime now before
|
|
||||||
fps = recip $ nominalDiffTimeToSeconds timeDiff
|
|
||||||
liftIO $ hPutStr stdout $ pack $ "Current FPS: " <> show (floor fps) <> " \r"
|
|
||||||
number <- liftIO $ STM.atomically $ do
|
number <- liftIO $ STM.atomically $ do
|
||||||
number <- STM.readTMVar frameNumber
|
number <- STM.readTMVar frameNumber
|
||||||
if number == 0 then
|
|
||||||
void $ STM.swapTMVar average fps
|
|
||||||
else do
|
|
||||||
oldAverage <- STM.readTMVar average
|
|
||||||
let newAverage = (oldAverage * fromIntegral number + fps) / frameCount
|
|
||||||
frameCount = fromIntegral number + 1
|
|
||||||
void $ STM.swapTMVar average newAverage
|
|
||||||
void $ STM.swapTMVar frameNumber (succ number)
|
void $ STM.swapTMVar frameNumber (succ number)
|
||||||
return number
|
return number
|
||||||
-- draw
|
-- draw
|
||||||
-- liftIO $ putStr $ show (recip $ nominalDiffTimeToSeconds timeDiff) <> "\r"
|
|
||||||
drawFrame engineData number
|
drawFrame engineData number
|
||||||
-- poll events
|
-- poll events
|
||||||
evs <- liftIO SDL.pollEvents
|
evs <- liftIO SDL.pollEvents
|
||||||
|
@ -87,12 +68,6 @@ main = do
|
||||||
evs
|
evs
|
||||||
)
|
)
|
||||||
|
|
||||||
fps <- liftIO $ STM.atomically $ STM.readTMVar average
|
|
||||||
|
|
||||||
liftIO $ hPutStr stdout $
|
|
||||||
"\n" <>
|
|
||||||
"Average FPS: " <> pack (show fps) <> "\n"
|
|
||||||
|
|
||||||
Vk.deviceWaitIdle $ engineLogicalDevice engineData
|
Vk.deviceWaitIdle $ engineLogicalDevice engineData
|
||||||
|
|
||||||
createBufferView
|
createBufferView
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
{-# LANGUAGE OverloadedRecordDot #-}
|
||||||
|
|
||||||
module Memory where
|
module Memory where
|
||||||
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
|
|
|
@ -188,8 +188,7 @@ loadFromObj filepath vma uploadContext queue device = do
|
||||||
texCoords V.!
|
texCoords V.!
|
||||||
(fromMaybe (error "no UV coordinates present") (faceTexCoordIndex index) - 1)
|
(fromMaybe (error "no UV coordinates present") (faceTexCoordIndex index) - 1)
|
||||||
in
|
in
|
||||||
-- flip V coordinate of UVs to fix display
|
V2 r s
|
||||||
V2 r (-s)
|
|
||||||
|
|
||||||
compactDraws
|
compactDraws
|
||||||
:: M.Map String Mesh
|
:: M.Map String Mesh
|
||||||
|
|
|
@ -50,7 +50,6 @@ executable vulkan-tutorial
|
||||||
, linear
|
, linear
|
||||||
, monad-loops
|
, monad-loops
|
||||||
, stm
|
, stm
|
||||||
, time
|
|
||||||
, bytestring
|
, bytestring
|
||||||
, text
|
, text
|
||||||
, vector
|
, vector
|
||||||
|
|
Loading…
Reference in a new issue