Compare commits

..

18 commits

Author SHA1 Message Date
73cb22a1f0 more twiddling 2023-08-25 01:10:38 +02:00
1cae4b0d65 try fixing 2023-08-25 00:59:36 +02:00
8aab6e9bbb explicitly enable multiIndirectDraw 2023-08-25 00:45:42 +02:00
d75e0e1eeb condense flake 2023-08-24 19:51:25 +02:00
06e3d5c2ec fix ambiguous record updates 2023-08-24 19:48:36 +02:00
6d625cabf6 final flake fix 2023-08-24 19:47:13 +02:00
b4c74b4c0c make shell 2023-08-24 17:03:24 +02:00
7497a4c557 move package 2023-08-24 17:02:12 +02:00
283d1be22d flake update 2023-08-24 16:04:09 +02:00
ddea01c005 fix flake 2023-08-24 16:00:27 +02:00
88b2516976 fix flake 2023-08-24 03:58:29 +02:00
b416f83eec small-ish fixes 2023-08-24 03:54:57 +02:00
acd8fe16c6 add test/debug VM capability 2023-08-24 03:54:23 +02:00
4dcf5ba486 flake update 2023-08-15 04:25:21 +02:00
302f7a6d83 using indirect draw, not working yet 2023-06-11 08:08:29 +02:00
02501ce1a1 fix double spaceships 2023-05-20 21:05:17 +02:00
9ed1391f5f remove lambda 2023-05-20 20:46:21 +02:00
4ee6c368df first little optimisation 2023-05-20 18:36:31 +02:00
9 changed files with 59 additions and 62 deletions

View file

@ -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": {

View file

@ -40,7 +40,6 @@
haskell-language-server
ghcid
cabal-install
(jailbreakUnbreak wavefront)
]) ++ (with pkgs; [
shaderc
vulkan-loader

View file

@ -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);
}

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -1,7 +1,6 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedRecordDot #-}
module Memory where
import Control.Monad.IO.Class

View file

@ -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

View file

@ -50,7 +50,6 @@ executable vulkan-tutorial
, linear
, monad-loops
, stm
, time
, bytestring
, text
, vector