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"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"lastModified": 1692799911,
|
||||
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -20,11 +20,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1699181587,
|
||||
"narHash": "sha256-v35mUUgVU2ituIHPNHifpjl5uiYQYyLrpaMtz8X8Ums=",
|
||||
"lastModified": 1692885195,
|
||||
"narHash": "sha256-zo/6ItD2ITIOsYmpQZ3sOcuDPhIh71flCj6TkF10nKM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "197629b470f184a47b2a5716312d25b09454bbf8",
|
||||
"rev": "27c6502cb974e6ad610baaeeba162acd3536ec45",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
haskell-language-server
|
||||
ghcid
|
||||
cabal-install
|
||||
(jailbreakUnbreak wavefront)
|
||||
]) ++ (with pkgs; [
|
||||
shaderc
|
||||
vulkan-loader
|
||||
|
|
|
@ -19,6 +19,8 @@ layout(set = 2, binding = 0) uniform sampler2D tex1;
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
|
@ -181,8 +182,7 @@ createFrames
|
|||
|
||||
recordCommandBuffer
|
||||
:: (MonadResource m, MonadReader ReadState m, MonadIO m)
|
||||
=> VMA.Allocator
|
||||
-> Vk.CommandBuffer
|
||||
=> Vk.CommandBuffer
|
||||
-> Vk.RenderPass
|
||||
-> Vk.Framebuffer
|
||||
-> V2 CInt
|
||||
|
@ -190,7 +190,6 @@ recordCommandBuffer
|
|||
-> FrameData
|
||||
-> m ()
|
||||
recordCommandBuffer
|
||||
allocator
|
||||
commandBuffer
|
||||
renderPass
|
||||
frameBuffer
|
||||
|
@ -235,8 +234,9 @@ recordCommandBuffer
|
|||
materialMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks materialLibrary
|
||||
|
||||
let draws = compactDraws meshMap materialMap renderObjects
|
||||
drawCommands = V.map
|
||||
(\(i, RenderObject mesh _ _) ->
|
||||
|
||||
let drawCommands = V.map
|
||||
(\(i, RenderObject mesh matrix material) ->
|
||||
Vk.DrawIndirectCommand
|
||||
{ vertexCount = fromIntegral (V.length $ meshVertices $ meshMap M.! mesh)
|
||||
, firstVertex = 0
|
||||
|
@ -249,24 +249,6 @@ recordCommandBuffer
|
|||
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_
|
||||
(\(IndirectBatch mesh material first count) -> do
|
||||
|
||||
|
@ -318,6 +300,50 @@ recordCommandBuffer
|
|||
)
|
||||
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
|
||||
:: V2 CInt
|
||||
-> Vk.CommandBuffer
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
module Draw where
|
||||
|
||||
import qualified Control.Concurrent.STM as STM
|
||||
|
@ -81,7 +80,6 @@ drawFrame engineData frameNumber = do
|
|||
cameraData
|
||||
|
||||
recordCommandBuffer
|
||||
(engineData.engineAllocator)
|
||||
(frameMainCommandBuffer frame)
|
||||
(engineRenderPass engineData)
|
||||
(engineFramebuffers engineData V.! fromIntegral index)
|
||||
|
|
25
src/Main.hs
25
src/Main.hs
|
@ -1,5 +1,4 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
|
@ -11,12 +10,9 @@ import Control.Monad.Loops
|
|||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Trans.Resource
|
||||
import Data.Bits
|
||||
import Data.ByteString.Char8
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Time.Clock
|
||||
import qualified Data.Vector as V
|
||||
import qualified SDL hiding (V2)
|
||||
import System.IO (stdout)
|
||||
import System.Mem
|
||||
import qualified Vulkan as Vk
|
||||
import qualified Vulkan.Zero as Vk
|
||||
|
@ -47,8 +43,6 @@ main = do
|
|||
|
||||
-- create abort condition for upcoming lop
|
||||
quit <- liftIO $ STM.newTMVarIO True
|
||||
time <- liftIO $ STM.newTMVarIO =<< getCurrentTime
|
||||
average <- liftIO $ STM.newTMVarIO 0
|
||||
|
||||
-- main loop
|
||||
whileM_
|
||||
|
@ -56,24 +50,11 @@ main = do
|
|||
)
|
||||
( do
|
||||
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 <- 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)
|
||||
return number
|
||||
-- draw
|
||||
-- liftIO $ putStr $ show (recip $ nominalDiffTimeToSeconds timeDiff) <> "\r"
|
||||
drawFrame engineData number
|
||||
-- poll events
|
||||
evs <- liftIO SDL.pollEvents
|
||||
|
@ -87,12 +68,6 @@ main = do
|
|||
evs
|
||||
)
|
||||
|
||||
fps <- liftIO $ STM.atomically $ STM.readTMVar average
|
||||
|
||||
liftIO $ hPutStr stdout $
|
||||
"\n" <>
|
||||
"Average FPS: " <> pack (show fps) <> "\n"
|
||||
|
||||
Vk.deviceWaitIdle $ engineLogicalDevice engineData
|
||||
|
||||
createBufferView
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
|
||||
module Memory where
|
||||
|
||||
import Control.Monad.IO.Class
|
||||
|
|
|
@ -188,8 +188,7 @@ loadFromObj filepath vma uploadContext queue device = do
|
|||
texCoords V.!
|
||||
(fromMaybe (error "no UV coordinates present") (faceTexCoordIndex index) - 1)
|
||||
in
|
||||
-- flip V coordinate of UVs to fix display
|
||||
V2 r (-s)
|
||||
V2 r s
|
||||
|
||||
compactDraws
|
||||
:: M.Map String Mesh
|
||||
|
|
|
@ -50,7 +50,6 @@ executable vulkan-tutorial
|
|||
, linear
|
||||
, monad-loops
|
||||
, stm
|
||||
, time
|
||||
, bytestring
|
||||
, text
|
||||
, vector
|
||||
|
|
Loading…
Reference in a new issue