achirkin / vulkan

Low-level low-overhead haskell bindings to vulkan API
BSD 3-Clause "New" or "Revised" License
63 stars 12 forks source link

gltf interop #18

Open o1lo01ol1o opened 5 years ago

o1lo01ol1o commented 5 years ago

Hi,

I recently started a library to load assets from the gltf spec (here) with the aim of being able to efficiently get assets and animations to the vulkan api (using this c++ project as a reference).

I wondered if you could provide some advice: If I have a buffer or raw binary vertex data (ie, a Mesh) parsed as a little endian ByteString, some accessors telling me what components this buffer represents, the number of bytes per component, the stride, etc, what's the best way to get that geometry into a form that I can get to vkVertexBuffer efficiently?

I've looked at the DataFrame PrimBytes instance but I'm not exactly sure where to start as the easytensor vulkan-api design goals are not totally clear to me.

Thanks!

achirkin commented 5 years ago

In the simplest case, if you have raw bytes packed in a vector or a bytestring and a description of the attributes layout, you don't even need to process the content of the data. Just specify the layout similar to Lib/Vulkan/Vertex.hs way and copy the content of the vector as in Lib/Vulkan/VertexBuffer.hs. You just need a pointer to the raw data; for example, if you use vanilla bytestrings, then Data.ByteString.Unsafe.unsafeUseAsCStringLen is a way to go.

The easytensor-vulkan library is totally optional. I want to use easytensor for all matrix math in my future vulkan projects, so this library serves for compatibility. PrimBytes is an interface for fast packing of data; in vulkan-triangles, I use it to store arrays of plain haskell Vertex data types as interleaved vulkan buffers. Next months I will be intensely working on easytensor to make it more user-friendly and, in particular, automate things like creating VkVertexInputAttributeDescription for a data type. Beware, I will change the interface of PrimBytes soon, maybe even spit it into a separate package.

o1lo01ol1o commented 5 years ago

Great, that's helpful, thanks. I'll forgo easytensor integration until it stablizes.

I want to use easytensor for all matrix math in my future vulkan projects

I'm more than a little familiar with the state of (tensor-based) numerics for the Haskell ecosystem, so I have a few answers to this question, but why not something that's backed by BLAS for linear algebra?

achirkin commented 5 years ago

Because I want to implement a Proper pure haskell tensor library in the end :) And in easytensor, I care most of all about a specific performance thing: to implement type family-based overloading of generic data frames with SIMD vectors for graphics-specific cases, such as 4D float vectors and matrices.

o1lo01ol1o commented 5 years ago

I'm interested in how you'll handle the SIMD operations, but that's for another thread, I think.

I look forward to its development. :)