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

Update library to latest webgpu-native headers #427

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

PJB3005
Copy link
Contributor

@PJB3005 PJB3005 commented Sep 19, 2024

This goes up to webgpu-native/webgpu-headers@a41b613

Things I didn't do:

  • I didn't update the library to make sure "instance dropped" callback error codes are guaranteed to happen, like they seem to be in Dawn.

List of changes (roughly in order of header commits):

  • Various enum and struct renames
  • Updated callbacks to use the new *CallbackInfo structs and 2-userdata system. Also updated functions to return WGPUFuture, though the WGPUFuture thing is just stubbed out at the moment as I don't think wgpu-core has the necessary functionality for it. wgpuInstanceWaitAny is unimplemented!()
  • DepthClipControl merged into PrimitiveState, related code simplified.
  • Updated depthWriteEnabled to use an optional bool, mostly matters due to added validation.
  • Add TODOs for missing features (sliced 3D compressed textures)
  • *Reference() became *AddRef()
  • Added unorm10-10-10-2 vertex format
  • Usage field in TextureViewDescriptor, just used for validation as wgpu-core doesn't allow specifying it anyways.
  • Removed maxInterStageShaderComponents
  • Added clang_macro_fallback() to bindgen config, since the headers switched to using UINT32_MAX etc. UINT64_MAX still doesn't work so I had to manually define those.
  • Renamed flags enums. Added a conversion helper function to convert them from u64 -> u32 for mapping. (means added direct dependency on bitflags crate)
  • Removed device argument from (unimplemented) wgpuGetProcAddress
  • Suboptimal surface texture acquisition moved to enum return value, was easy since wgpu-core already returns it like that.
  • "Undefined" present mode added, it just selects FIFO.
  • *EnumerateFeatures() has been replaced with *GetFeatures().
  • All strings are now passed as WGPUStringView.

This goes up to webgpu-native/webgpu-headers@2b59747

Things I *didn't* do:

* I didn't update the library to make sure "instance dropped" callback
  error codes are guaranteed to happen, like they seem to be in Dawn.

List of changes (roughly in order of header commits):

Various enum and struct renames

Updated callbacks to use the new *CallbackInfo structs and 2-userdata system. Also updated functions to return WGPUFuture, though the WGPUFuture thing is just stubbed out at the moment as I don't think wgpu-core has the necessary functionality for it. wgpuInstanceWaitAny is unimplemented!()

DepthClipControl merged into PrimitiveState, related code simplified.

Updated depthWriteEnabled to use an optional bool, mostly matters due to added validation.

Add TODOs for missing features (sliced 3D compressed textures)

*Reference() became *AddRef()

Added unorm10-10-10-2 vertex format

Usage field in TextureViewDescriptor, just used for validation as wgpu-core doesn't allow specifying it anyways.

Removed maxInterStageShaderComponents

Added clang_macro_fallback to bindgen config, since the headers switched to using UINT32_MAX etc. UINT64_MAX still doesn't work so I had to manually define those.

Renamed flags enums. Added a conversion helper function to convert them from u64 -> u32 for mapping. (means added direct dependency on bitflags crate)

Removed device argument from (unimplemented) wgpuGetProcAddress

Suboptimal surface texture acquisition moved to enum return value, was easy since wgpu-core already returns it like that.

"Undefined" present mode added, it just selects FIFO.
This enum was replaced with WGPUMapAsyncStatus, but I didn't quite notice. The error codes map different.
@PJB3005
Copy link
Contributor Author

PJB3005 commented Sep 19, 2024

Remaining Windows CI failure is caused by webgpu-native/webgpu-headers#339

Replaces *EnumerateFeatures with *GetFeatures.

Also fixes CI due to fix in headers.
Copy link
Collaborator

@almarklein almarklein left a comment

Choose a reason for hiding this comment

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

LGTM but maybe @rajveermalviya can have a look at the Rust code.

Upstream removed the "Flags" suffix from flags types and moved them to no longer be C enums. This matches that change. WGPUInstanceFlag still has "Flag" in the name because, well, there'd be nothing left to distinguish it from WGPUInstance, and it makes sense for it.
Copy link
Contributor

@eliemichel eliemichel left a comment

Choose a reason for hiding this comment

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

Nice job! I started looking at how to implement futures in wgpu a couple of days ago, nothing obvious but I'll share if I figure sth out!

let present_mode = match config.presentMode {
native::WGPUPresentMode_Undefined => wgt::PresentMode::Fifo,
_ => map_present_mode(config.presentMode),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this match should be part of map_present_mode rather than being added on top of it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this here because I wasn't sure if I could cleanly add that to map_present_mode, as it's defined with a map_enum! macro.

@@ -1701,3 +1694,11 @@ pub fn map_adapter_type(device_type: wgt::DeviceType) -> native::WGPUAdapterType
wgt::DeviceType::Cpu => native::WGPUAdapterType_CPU,
}
}

pub fn from_u64_bits<T: bitflags::Flags<Bits = u32>>(value: u64) -> Option<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

(Note: Ideally bitfields would switch to u64 in upstream wgpu instead of needing a conversion here)

Cargo.toml Outdated
@@ -157,6 +157,7 @@ log = "0.4"
thiserror = "1"
parking_lot = "0.12"
smallvec = "1"
bitflags = "2.6.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to be able to refer to bitflags types for the from_u64_bits helper.

@eliemichel
Copy link
Contributor

eliemichel commented Oct 3, 2024

For WGPUFuture, we need to have access to submission index (and return that in the future's id). Here is the beginning of an attempt at adding this upstream: gfx-rs/wgpu#6360

_ => make_slice(string_view.data as *const u8, string_view.length),
};

Some(std::str::from_utf8_unchecked(bytes))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Important to note: this doesn't check whether strings passed into the library are valid UTF-8. I previously many locations did, but I figured this wasn't necessary.

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