Skip to content

Commit d35b766

Browse files
committed
Revert "Use deriving via Packed (Vertex ...) for Vertex Data"
This reverts commit 26dc573. Actually, that didn't go so well.
1 parent 26dc573 commit d35b766

File tree

3 files changed

+13
-10
lines changed
  • ghengin-core

3 files changed

+13
-10
lines changed

ghengin-core/ghengin-core-indep/Ghengin/Core/Mesh/Vertex.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ instance (Block (Vertex (y:ys)), Block x) => Block (Vertex (x:y:ys)) where
101101
writePacked p (Diff o) (Sin a)
102102
writePacked p (Diff $ o + sizeOfPacked (Proxy @(Vertex '[x]))) b
103103

104-
-- NB: We use Packed for Storable Vertex
104+
-- NB: We use Std140 for Storable Vertex, which isn't quite right since
105+
-- vertices need to abide by the location/component layout, but is fine for now.
106+
--
105107
-- A good explanation is in https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
106-
-- See also https://github.com/alt-romes/ghengin/pull/16#issuecomment-3563044060
107-
deriving via (Graphics.Gl.Block.Packed (Vertex '[x])) instance Block x => Storable (Vertex '[x])
108-
deriving via (Graphics.Gl.Block.Packed (Vertex (x:y:ys))) instance (Block x, Block (Vertex (y:ys))) => Storable (Vertex (x:y:ys))
108+
deriving via (Std140 (Vertex '[x])) instance Block x => Storable (Vertex '[x])
109+
deriving via (Std140 (Vertex (x:y:ys))) instance (Block x, Block (Vertex (y:ys))) => Storable (Vertex (x:y:ys))
109110

110111
instance Show x => Show (Vertex '[x]) where
111112
show (Sin x) = show x

ghengin-core/ghengin-core/Ghengin/Core/Renderer/Buffer.hsig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Data.Word (Word, Word32)
44
import Data.Int (Int32)
55
import qualified Data.Vector.Storable as SV
66
-- TODO:Exchange Vk specific types to renderer agnostic enumerations
7-
import qualified Vulkan as Vk (BufferUsageFlags)
7+
import qualified Vulkan as Vk (DescriptorType, BufferUsageFlags)
88

99
import Ghengin.Core.Mesh.Vertex
1010
import Ghengin.Core.Renderer.Kernel
@@ -35,7 +35,8 @@ writing into mapped buffers we know what layout to use (std140).
3535

3636
However, for `DeviceLocalBuffer`s, at the moment, we don't know its use, so we
3737
delegate the decision of what standard to use to the definition site of the
38-
`Storable` instance which should in theory be derived via `Packed` from `gl-block`.
38+
`Storable` instance which should in theory be derived via `Std140` or `Std430`
39+
or `Packed` from `gl-block`.
3940

4041
Furthermore, for Vertex buffers, given that (1) we use device local buffers and
4142
(2) when copying data from CPU to the device buffers it's useful to have

ghengin-core/ghengin-vulkan/Ghengin/Vulkan/Renderer/Buffer.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ data VertexBuffer where
4949
VertexBuffer :: !DeviceLocalBuffer
5050
Word32 -- ^ N vertices
5151
-> VertexBuffer
52+
-- NB: We use Std140 throughout this module for Vertex, which isn't quite
53+
-- right since vertices need to abide by the location/component layout
54+
-- specification... but since Std140 gives some padding this should work fine
55+
-- if you are using Vertices with Vector attributes only.
56+
-- Ghengin.Core.Mesh.Vertex also defines a Storable instance for vertices based on Std140
5257

53-
-- | Create vertex buffer. Vertices are laid out in packed memory in the given vector.
54-
--
55-
-- If your type instances @'Block'@, you can get a correct Storable instance by
56-
-- @deriving via Packed MyTy instance Storable MyTy@
5758
createVertexBuffer :: αs. Storable (Vertex αs) => SV.Vector (Vertex αs) -> Renderer VertexBuffer
5859
createVertexBuffer vv =
5960
flip VertexBuffer (fromIntegral $ SV.length vv) <$>

0 commit comments

Comments
 (0)