-
Notifications
You must be signed in to change notification settings - Fork 960
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
refactor(dx12): remove unsafe
ops in Adapter::texture_format_capabilities
#3194
refactor(dx12): remove unsafe
ops in Adapter::texture_format_capabilities
#3194
Conversation
&mut data_no_depth as *mut _ as *mut _, | ||
mem::size_of::<d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT>() as _, | ||
ptr::addr_of_mut!(data_no_depth).cast::<c_void>(), | ||
DWORD::try_from(mem::size_of::<d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only hesitation is the verbosity of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this with a fresh brain:
- RE: pointer slinging:
- We can definitely omit the explicit
::<c_void>
. I've done so with 7c46b4b. - We could fully qualify the
addr_of_mut
symbol, which would make this shorter and, IMO, easier to follow. In general, I think a lot of this code would be smaller with no loss of clarity (and therefore more friendly to the mental cache) without path qualifications for most symbols.
- We can definitely omit the explicit
- RE:
size_of
: I've seen folks like @retep998 make utility crates for Windows specifically to convertsize_of
'susize
s toDWORD
s. Maybe adding something like an extension trait for this (in a separate PR) would be good?
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly now that I look at this, this seems fine.
7669de0
to
7c46b4b
Compare
unsafe
ops in Adapter::texture_format_capabilities
unsafe
ops in Adapter::texture_format_capabilities
c11fb89
to
9181af2
Compare
9181af2
to
4d91332
Compare
The
...where I don't think that this failure is related to this change, but I'm not positive. Do you know, @cwfitzgerald? |
Yeah, llvmpipe has been crapping the bed on the multi-threaded test of late. |
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Add change to CHANGELOG.md. See simple instructions inside file.I don't think that this is necessary.Connections
Link to the issues addressed by this PR, or dependent PRs in other repositories
Description
Describe what problem this is solving, and how it's solved.
The code being changed here used
unsafe
andas
casting unnecessarily. Both are unusually fraught parts of writing in Rust. So, where possible, we'd like to avoid them. In this case…we can!Testing
Explain how this change is tested.
It still compiles, and I feel confident that the changes are correct, but I haven't tested locally. I can test this locally, though, if you wish.