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

Investigate custom repr for GPU memory #11

Closed
Jasper-Bekkers opened this issue Aug 19, 2020 · 6 comments
Closed

Investigate custom repr for GPU memory #11

Jasper-Bekkers opened this issue Aug 19, 2020 · 6 comments
Labels
t: design Design of our rust-gpu language and std

Comments

@Jasper-Bekkers
Copy link
Contributor

A few options here:

  • Hack the compiler to just output the data layout that we want
  • Add #[repr(std140)] and #[repr(std430)] to the language frontend (maybe have better names for when we want to support non-Vulkan backends with different layout requirements
  • Support #[repr(Rust)] and #[repr(C)] natively through Vulkan's Scalar Block Layout. (Note that this comes with a performance warning).
  • All / most of the above
@Jasper-Bekkers Jasper-Bekkers added the t: design Design of our rust-gpu language and std label Aug 19, 2020
@repi
Copy link
Contributor

repi commented Aug 19, 2020

* Support `#[repr(Rust)]` 

This is the richest one and most ideal one if/when we have Rust both on the CPU and GPU side.

But also this representation has explicitly no guarantees about ABI compatability or stability between compiler version, so to be safe one would have to have exactly the same rustc compiler for the CPU code and the GPU code to have this match, which is likely unfeasible for a long time.

Need a representation that has a stable ABI, do still hope that Rust in the future will have a subset that can give ABI stability guarantees.

repr(C) is likely the only choice on the Rust CPU side for now and until then.

@Jasper-Bekkers
Copy link
Contributor Author

From @h3r2tic #[repr(Rust)] would probably also make the SPIR-V code platform specific.

@khyperia
Copy link
Contributor

What exactly does this affect? Things that I can think of:

  1. Calling spir-v compiled by other languages from Rust
  2. Binding layout?
  3. Accessing binary buffer blobs passed into shader (e.g. array of structs)

1 is not on the roadmap. If 2, pointing out explicitly where and what cases it can happen would help. If 3, I wasn't aware that shaders could access binary buffer blobs (I don't think you can in glsl?) - I'd appreciate a pointer in the spec.

@h3r2tic
Copy link

h3r2tic commented Oct 14, 2020

If you mean repr(Rust), then it's not very compatible with anything; even two identical structs can be incompatible with each other: https://doc.rust-lang.org/nomicon/repr-rust.html

@khyperia
Copy link
Contributor

Yes, but does that actually affect anything? What ABI boundary are we going through where that will be a problem?

@h3r2tic
Copy link

h3r2tic commented Oct 22, 2020

It's probably something for @Jasper-Bekkers :P What was the intended use case? The issue lists possible options, but not motivations.

I was going under the assumption that this would be for buffers (constant, uniform) that want to share types between the CPU and GPU, and access them on the GPU via something similar to Shader Storage Buffer Objects, but with Rust idioms/semantics. On the codegen side, this could end up generating typed loads/stores, or map to simple DWORD fetches like Buffer Textures.

For example, here I have a shader that does a ton of manual unpacking of ray-tracing acceleration data and mesh geometry via bindless buffer textures. Automating that would be great -- but again, I'm not sure if this is the intended motivation behind this issue.

@repi repi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: design Design of our rust-gpu language and std
Projects
None yet
Development

No branches or pull requests

4 participants