Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
redfish64 opened this issue Mar 21, 2019 · 1 comment

Comments

@redfish64
Copy link

redfish64 commented Mar 21, 2019

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?

@achirkin
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants