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

Consistently return HassleError and remove unneeded check macros #30

Merged
merged 1 commit into from
Jan 25, 2022

Conversation

MarijnS95
Copy link
Member

Depends on #29

Our public API becomes a lot cleaner when returning HassleError everywhere, helped by the fact that HRESULTs from the low-level COM API is a newtype with support for functions to convert to Result<> easily. These can be short-circuit-returned in a more Rust'y way through the questionmark operator instead of wrapping everything in large macro calls. This change is based on a similar approach in the Ash crate: https://github.com/MaikKlein/ash/pull/339/files

src/wrapper.rs Outdated
Comment on lines 293 to 298
let mut compile_error = 0u32;
unsafe {
result.get_status(&mut compile_error);
}
let status_hr = unsafe { result.get_status(&mut compile_error) };

if result_hr == 0 && compile_error == 0 {
if !result_hr.is_err() && !status_hr.is_err() && compile_error == 0 {
Ok(DxcOperationResult::new(result))
} else {
Err((DxcOperationResult::new(result), result_hr))
Copy link
Member Author

Choose a reason for hiding this comment

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

The functions with a DxcOperationResult are up for a rework next: they're tricky to get right and even https://asawicki.info/news_1719_two_shader_compilers_of_direct3d_12 from my notes doesn't explain very clearly what to do, but #29 and #30 are going to make it easier to implement said refactor at least.

@MarijnS95 MarijnS95 force-pushed the consistent-result-api branch 2 times, most recently from 29ae848 to ab1c125 Compare January 25, 2022 17:40
Our public API becomes a lot cleaner when returning `HassleError`
everywhere, helped by the fact that `HRESULT`s from the low-level COM
API is a newtype with support for functions to convert to `Result<>`
easily.  These can be short-circuit-returned in a more Rust'y way
through the questionmark operator instead of wrapping everything in
large macro calls.  This change is based on a similar approach in the
Ash crate: https://github.com/MaikKlein/ash/pull/339/files
@MarijnS95 MarijnS95 merged commit 518eb2d into main Jan 25, 2022
@MarijnS95 MarijnS95 deleted the consistent-result-api branch January 25, 2022 19:24
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