-
Notifications
You must be signed in to change notification settings - Fork 249
Convert to use glam
for math types
#149
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
Conversation
|
This asserting that padding bytes of contained types is def is a bug, but, I'm really surprised that padding bytes are not required to be undef. Why was that decision made? (And just as a frustrated aside, it sucks that this whole thing even exists, it'd be so nice if I didn't have to reimplement rustc's understanding of interpreting semantics from bytes...) edit: just debugged this, looks like the failure is indeed due to the bug of asserting that padding of contained types is def. @repi, feel free to delete the |
Currently all values allow defined padding bytes. I think there is work being done to refactor the representation of constants such that padding bytes are always undefined in the result of const eval. This only applies to direct references. This won't apply to raw pointers, as those are defined to not care about the pointee. For example it is perfectly valid to have a
|
This is in the context of const eval, though?... edit: to be specific, all bytes being interpreted here are the result of const eval, even those through pointers. Can non-const-eval bytes somehow leak through here? Where even would those come from? |
I don't think anyone ever proposed to force them to be undef. That would be a bunch of extra work (and it would require us to precisely define "padding byte" which is not easy for What is the benefit to forcing them |
I was refering to value trees, which I think would omit padding bytes. |
Ah yes, those would not preserve padding. But they would also not be used to represent normal |
I don't know what value trees are, but guessing from the name, it sounds exactly like what we want here. The problem is that spir-v doesn't allow untyped byte array constants to be reinterpreted as typed values (as the LLVM backend does), so we need to walk the byte array with the expected constant type and extract a "typed" constant value (tree) out of it. Is there some way for us to get a value tree from rustc, which I'm guessing is what this is? |
Value trees are not implemented yet. See rust-lang/compiler-team#323 for some further information. Also, value trees can only represent
That sounds then like it is impossible to write a correct rustc backend, I am afraid. Being able to reinterpret data at the byte level is a key ability of Rust. How does the spir-v backend implement raw pointer casts, |
Raw pointer casts for the
#153 improves this error. transmute seems to be unimplemented. (or cg_ssa is responsible for the impl) Unions are represented as raw byte arrays with padding initialized to zero. rust-gpu/rustc_codegen_spirv/src/abi.rs Lines 556 to 566 in b32c04b
|
Yes, we know, it's crappy to not have the full power of rust available on the GPU, but that's expected, and the benefits of using sort-of-kinda-Rust outweigh being banned from using some parts of the language. (RLSL was called "rust like shading language" for a reason, and this is kind of the spiritual successor to that)
Because we restrict the abilities of Rust, it's probably not observable. Considering this is a two-month-old project that extremely recently moved out of the "one person hacking on it prototype phase", I'm not going to say it definitely isn't observable, but I imagine we'll tighten up and formalize some language restrictions as time goes on. |
But then what happens when I store things into a union at one type and read it at another type?
That makes sense, thanks. I was lacking this context when being summoned into this thread. ;) If you anyway forbid all forms of transmuting (whether they be through unions, raw pointers, and That said, not all If padding bytes are not observable, then why do you need to assert that they are undefined? That is not something rustc guarantees (and for the reasons discussed above it likely would be incoherent to try to make rustc guarantee this), but if padding bytes are not observable with your backend, you can just ignore them. In fact, "assert that this is undef" is a really strange thing to do -- the entire point of "undef" is that you can replace it by an arbitrary value and everything will still work the same. The assert breaks that key property. |
Unions are really sketchily implemented right now and probably don't even work in shader mode (rather than kernel mode), very much an untested prototype thing.
Because I thought it was a reasonable, sane assumption that padding bytes are undefined, and asserting they're undefined helps validate that I'm doing the rather complicated walk over the bytes correctly (especially considering the original |
Why is that inaccessible? MIR should contain the type of the const/static you are accessing, and then you could in principle use our type-based value visitor to traverse that allocation in a type-directed way. But I am not very familiar with the interface codegen backends work against. Maybe there is some place where more type information could be preserved for backends that need it. (Allocations are entirely untyped, but the places where they are referenced in the MIR should be typed.) |
Because there's just literally no |
Wherever that |
|
It's behind a pointer, no? So the ABI is a |
Not sure why you are concerned with the ABI here. This is what I mean: const V: Vec<i32> = Vec::new();
fn main() {
let v = V;
} has MIR (looking only at the assignment)
Note that |
In the code, for example here you have the layout but do not pass it on:
And here you have a
|
the ABI ( What about the callsite that I linked earlier? I don't see any way to grab a Ty from there. Sure, there's a Ty for the pointer, but not the pointee. Also, would it be possible for you to join the discord, instead of discussing on this issue? Totally fine if not, just figured it might be a little easier. |
I'm not a big fan of discord, but I am on the Rust Zulip (at least on week-ends). :)
If you do a type-based traversal the way this code does (or find a way to use that code), you will have a type here. It is true that See for example this code for a visitor that handles references in a type-driven way. |
Removed And now the shader builds and runs, though is just black in the GPU version :) So must be some miss-compilation or incorrect feature implementation. The CPU version But very nice to get to a buildable and runnable state! |
this is a weird clippy error on the glam shader:
https://github.com/EmbarkStudios/rust-gpu/pull/149/checks?check_run_id=1326417262 it is from our codegen |
With some additional glam fixes and workarounds, got this compiling and running correctly on both GPU and CPU now! 🎉 Remaining thing to figure out though before merging is clippy on the shader and why that is failing. Or disable clippy on the shaders for now |
@khyperia @Jasper-Bekkers have a look at this now, passes CI now when I disabled clippy on the shader (for now), and think should be good to get in! |
Removes the temporary math types in
spirv-std
and uses our experimental spirv fork ofglam
(bitshifter/glam-rs#85) for our example shader! 🎉Todo:
assert_uninit
error: constant runtime array value
- CI clippy on shader disabled for now, tracked in Investigate clippy failure on example-shader with glam #186Fix #134