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

refactor(dx12): remove unsafe ops in Adapter::texture_format_capabilities #3194

Merged

Conversation

ErichDonGubler
Copy link
Member

@ErichDonGubler ErichDonGubler commented Nov 8, 2022

Checklist

  • Run cargo clippy.
  • Run 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 and as 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.

@ErichDonGubler ErichDonGubler marked this pull request as ready for review November 8, 2022 17:37
&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>())
Copy link
Member

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

Copy link
Member Author

@ErichDonGubler ErichDonGubler Nov 14, 2022

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:

  1. RE: pointer slinging:
    1. We can definitely omit the explicit ::<c_void>. I've done so with 7c46b4b.
    2. 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.
  2. RE: size_of: I've seen folks like @retep998 make utility crates for Windows specifically to convert size_of's usizes to DWORDs. Maybe adding something like an extension trait for this (in a separate PR) would be good?

Thoughts?

Copy link
Member

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.

@ErichDonGubler ErichDonGubler force-pushed the d3d12-format-support-safety branch from 7669de0 to 7c46b4b Compare November 14, 2022 16:42
@ErichDonGubler ErichDonGubler changed the title refactor(hlsl-out): remove unsafe ops in Adapter::texture_format_capabilities refactor(dx12): remove unsafe ops in Adapter::texture_format_capabilities Nov 14, 2022
@ErichDonGubler ErichDonGubler force-pushed the d3d12-format-support-safety branch 2 times, most recently from c11fb89 to 9181af2 Compare November 14, 2022 17:37
@ErichDonGubler ErichDonGubler force-pushed the d3d12-format-support-safety branch from 9181af2 to 4d91332 Compare November 28, 2022 19:14
@ErichDonGubler
Copy link
Member Author

The wgpu::example/hello-compute tests::test_multithreaded_compute test in Linux CI is currently failing with:

[2022-11-28T19:23:18Z ERROR wgpu_hal::gles::egl] EGL 'eglInitialize' code 0x3001: DRI2: failed to load driver
corrupted double-linked list

...where 0x3001 == EGL_NOT_INITIALIZED.

I don't think that this failure is related to this change, but I'm not positive. Do you know, @cwfitzgerald?

@cwfitzgerald
Copy link
Member

Yeah, llvmpipe has been crapping the bed on the multi-threaded test of late.

@cwfitzgerald cwfitzgerald merged commit 46b1216 into gfx-rs:master Nov 30, 2022
@ErichDonGubler ErichDonGubler deleted the d3d12-format-support-safety branch December 16, 2022 22:26
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.

2 participants