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

Storable instances have incorrect alignment #12

Open
expipiplus1 opened this issue Nov 28, 2020 · 5 comments
Open

Storable instances have incorrect alignment #12

expipiplus1 opened this issue Nov 28, 2020 · 5 comments

Comments

@expipiplus1
Copy link

Seems to always be 1!

@mgsloan
Copy link
Collaborator

mgsloan commented Nov 29, 2020

Good point! It should be documented that these instances only work with processors that support unaligned memory access (nearly all, and modern processors have nearly 0 overhead for unaligned access). Leaving this issue open to track the documentation concern.

The alignment value is correct.

@expipiplus1
Copy link
Author

One of the primary purposes of Storable instances is in interop with languages such as C which do respect alignment though.

There are are still many platforms where alignment is important (for instance GPU programming).

I think if it's going to stick with 1 then this has to be spelled out very loudly in the documentation, and also that in addition to the alignment of these instances being 1, the alignment of the components types is ignored (against the direction of the Storable documentation for portable code).

expipiplus1 added a commit to expipiplus1/vulkan that referenced this issue Nov 30, 2020
th-utilities does not respect alignment: fpco/th-utilities#12
@dpwiz
Copy link

dpwiz commented Jun 10, 2022

Wouldn't it be possible to use "deriving via" wrappers with alignment as a phantom argument?

deriving GStorable via Aligned 4 MyStuff

(I know next to nothing about about deriving-via magic.)

@dpwiz
Copy link

dpwiz commented Dec 9, 2022

FTR, it should be possible to reconstruct Haskell record from SPIR-V reflection of its struct (glsl or otherwise) and make an exact Storable instance for it.

@goertzenator
Copy link

Member alignment is also not respected. For example, the Storable instance of ...

data MyStruct = MyStruct
  { p1 :: Int32
  , p2 :: Int64
  }

... will not leave padding after p1 to keep p2 aligned.

Please document that this does not create C compatible Storable instances.

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

4 participants