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

Remove Unsafe in macro.rs #43

Merged
merged 12 commits into from
Nov 20, 2019
Merged

Remove Unsafe in macro.rs #43

merged 12 commits into from
Nov 20, 2019

Conversation

Huanzo
Copy link
Contributor

@Huanzo Huanzo commented Nov 7, 2019

This is my take on removing the unsafe block in macro.rs.

This will definitely be slower than the unsafe version but I don't think that it matters too much as it will not be called very often.

I could not get it work with the Deref impl so I changed that to a normal function.

this should be a way to remove the unsafe code in the Spirv Deref impl.
Not sure how it affects performance yet.
I will take a look at the bytecode and see if maybe the compiler is
smart enough to optimize that away.
Let the deref return a `Vec<u32>` instead of a slice reference. This
should not hurt performance too much as this will be done a finite
amount of times att startup.
@Huanzo Huanzo mentioned this pull request Nov 7, 2019
src/macros.rs Outdated Show resolved Hide resolved
@Huanzo
Copy link
Contributor Author

Huanzo commented Nov 7, 2019 via email

src/macros.rs Outdated Show resolved Hide resolved
@parasyte
Copy link
Owner

parasyte commented Nov 8, 2019

In addition, we can also add #![forbid(unsafe_code)] to lib.rs with the last bit of unsafe removed.

@Huanzo
Copy link
Contributor Author

Huanzo commented Nov 8, 2019

Ah ok I did not see that.

Why did you choose to go the unsafe route then? Performance?

@parasyte
Copy link
Owner

parasyte commented Nov 9, 2019

No, it was contributed by Ralith in their PR for ash: ash-rs/ash#245

@Huanzo
Copy link
Contributor Author

Huanzo commented Nov 12, 2019

Ok i now have used u32::from_ne_bytes() to repect the target endianness.

Do we want/need to throw that output Vec into wgpu::read_spirv or can we assume that the resulting bytecode is valid? Thing is that wgpu::read_spirv takes something that is Read and Seek which limits our options quite a bit. So will this suffice for now?

@parasyte
Copy link
Owner

wgpu::read_spirv handles endianness correctly regardless of endianness of the SPIRV and endianness of the host. See https://github.com/gfx-rs/gfx/blob/ca53a530843c8b3f76928b42753113f1a785b101/src/hal/src/pso/mod.rs#L299-L304

The Read and Seek trait bounds aren't a problem, since std::io::Cursor takes care of that.

src/macros.rs Outdated Show resolved Hide resolved
Copy link
Owner

@parasyte parasyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@parasyte
Copy link
Owner

Closes #40

@parasyte parasyte merged commit c5718cc into parasyte:master Nov 20, 2019
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

Successfully merging this pull request may close these issues.

3 participants