vulkan icon indicating copy to clipboard operation
vulkan copied to clipboard

need example or documentaion for reading from an array with a count field

Open redfish64 opened this issue 6 years ago • 1 comments

Admittedly I don't know very much about haskell, so I apologize if the solution is obvious, but I can't seem to figure out how to read from an array which has a variable length.

The best I could come up with is this (for reading the memoryTypes from the "vkGetPhysicalDeviceMemoryProperties" function)

      memTypes <- case memTypeIndex of
        0 -> Just <$> readFieldArray @"memoryTypes" @0 memPropPtr
        1 -> Just <$> readFieldArray @"memoryTypes" @1 memPropPtr
        2 -> Just <$> readFieldArray @"memoryTypes" @2 memPropPtr
        3 -> Just <$> readFieldArray @"memoryTypes" @3 memPropPtr
        4 -> Just <$> readFieldArray @"memoryTypes" @4 memPropPtr
        5 -> Just <$> readFieldArray @"memoryTypes" @5 memPropPtr
        6 -> Just <$> readFieldArray @"memoryTypes" @6 memPropPtr
        7 -> Just <$> readFieldArray @"memoryTypes" @7 memPropPtr
...

I can't find any example or code anywhere that uses readFieldArray with a variable length, so with my limited knowledge of Haskell, I'm not sure if there is a better way.

Would it be possible to describe how this is done in some documentation somewhere or in an example?

redfish64 avatar Mar 21 '19 02:03 redfish64

In your case (since you check the length anyway), the best way is to use readFieldArrayUnsafe (which takes Int index), which I added just couple days ago (soon will be on hackage).

But probably I should add a tutorial on how to use type-level Nats with vulkan-api. Thanks for reporting! Let's keep this issue open for now.

achirkin avatar Mar 21 '19 05:03 achirkin