Skip to content

Commit

Permalink
Update native headers to latest commit (#383)
Browse files Browse the repository at this point in the history
* Update native headers to latest commit

Everything is just marked as unimplemented for now, due to lacking support in main wgpu.

The biggest reason I did this is because the added depthSlice field in WGPURenderPassColorAttachment caused conflicts when trying to use up-to-date headers with wgpu-native.

* Review comment

Test against WGPU_DEPTH_SLICE_UNDEFINED instead, update examples

* log instead of panic

---------

Co-authored-by: rajveermalviya <[email protected]>
  • Loading branch information
PJB3005 and rajveermalviya authored May 7, 2024
1 parent 85563e5 commit 33133da
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/capture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int main(int argc, char *argv[]) {
.view = texture_view,
.loadOp = WGPULoadOp_Clear,
.storeOp = WGPUStoreOp_Store,
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
.clearValue =
(const WGPUColor){
.r = 1,
Expand Down
1 change: 1 addition & 0 deletions examples/texture_arrays/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ int main(int argc, char *argv[]) {
.view = frame,
.loadOp = WGPULoadOp_Clear,
.storeOp = WGPUStoreOp_Store,
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
.clearValue =
(const WGPUColor){
.r = 0.0,
Expand Down
1 change: 1 addition & 0 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ int main(int argc, char *argv[]) {
.view = frame,
.loadOp = WGPULoadOp_Clear,
.storeOp = WGPUStoreOp_Store,
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
.clearValue =
(const WGPUColor){
.r = 0.0,
Expand Down
2 changes: 1 addition & 1 deletion ffi/webgpu-headers
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ pub unsafe extern "C" fn wgpuAdapterHasFeature(
pub unsafe extern "C" fn wgpuAdapterRequestDevice(
adapter: native::WGPUAdapter,
descriptor: Option<&native::WGPUDeviceDescriptor>,
callback: native::WGPURequestDeviceCallback,
callback: native::WGPUAdapterRequestDeviceCallback,
userdata: *mut std::os::raw::c_void,
) {
let (adapter_id, context) = {
Expand Down Expand Up @@ -982,7 +982,7 @@ pub unsafe extern "C" fn wgpuBufferMapAsync(
mode: native::WGPUMapModeFlags,
offset: usize,
size: usize,
callback: native::WGPUBufferMapCallback,
callback: native::WGPUBufferMapAsyncCallback,
userdata: *mut std::ffi::c_void,
) {
let (buffer_id, context, error_sink) = {
Expand Down Expand Up @@ -1172,6 +1172,10 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
make_slice(descriptor.colorAttachments, descriptor.colorAttachmentCount)
.iter()
.map(|color_attachment| {
if color_attachment.depthSlice != native::WGPU_DEPTH_SLICE_UNDEFINED {
log::warn!("Depth slice on color attachments is not implemented");
}

color_attachment.view.as_ref().map(|view| {
wgc::command::RenderPassColorAttachment {
view: view.id,
Expand Down Expand Up @@ -2683,7 +2687,7 @@ pub unsafe extern "C" fn wgpuInstanceCreateSurface(
pub unsafe extern "C" fn wgpuInstanceRequestAdapter(
instance: native::WGPUInstance,
options: Option<&native::WGPURequestAdapterOptions>,
callback: native::WGPURequestAdapterCallback,
callback: native::WGPUInstanceRequestAdapterCallback,
userdata: *mut std::os::raw::c_void,
) {
let instance = instance.as_ref().expect("invalid instance");
Expand Down Expand Up @@ -2853,7 +2857,7 @@ pub unsafe extern "C" fn wgpuQuerySetRelease(query_set: native::WGPUQuerySet) {
#[no_mangle]
pub unsafe extern "C" fn wgpuQueueOnSubmittedWorkDone(
queue: native::WGPUQueue,
callback: native::WGPUQueueWorkDoneCallback,
callback: native::WGPUQueueOnSubmittedWorkDoneCallback,
userdata: *mut ::std::os::raw::c_void,
) {
let (queue_id, context) = {
Expand Down Expand Up @@ -3901,21 +3905,21 @@ pub unsafe extern "C" fn wgpuSurfaceCapabilitiesFreeMembers(
) {
if !capabilities.formats.is_null() && capabilities.formatCount > 0 {
drop(Vec::from_raw_parts(
capabilities.formats,
capabilities.formats as *mut native::WGPUTextureFormat,
capabilities.formatCount,
capabilities.formatCount,
));
}
if !capabilities.presentModes.is_null() && capabilities.presentModeCount > 0 {
drop(Vec::from_raw_parts(
capabilities.presentModes,
capabilities.presentModes as *mut native::WGPUPresentMode,
capabilities.presentModeCount,
capabilities.presentModeCount,
));
}
if !capabilities.alphaModes.is_null() && capabilities.alphaModeCount > 0 {
drop(Vec::from_raw_parts(
capabilities.alphaModes,
capabilities.alphaModes as *mut native::WGPUCompositeAlphaMode,
capabilities.alphaModeCount,
capabilities.alphaModeCount,
));
Expand Down
31 changes: 28 additions & 3 deletions src/unimplemented.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use crate::native;

#[no_mangle]
pub extern "C" fn wgpuAdapterRequestAdapterInfo(
_adapter: native::WGPUAdapter,
_callback: native::WGPUAdapterRequestAdapterInfoCallback,
_userdata: *mut ::std::os::raw::c_void,
) {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuGetProcAddress(
_device: native::WGPUDevice,
Expand Down Expand Up @@ -73,7 +82,7 @@ pub extern "C" fn wgpuComputePipelineSetLabel(
pub extern "C" fn wgpuDeviceCreateComputePipelineAsync(
_device: native::WGPUDevice,
_descriptor: *const native::WGPUComputePipelineDescriptor,
_callback: native::WGPUCreateComputePipelineAsyncCallback,
_callback: native::WGPUDeviceCreateComputePipelineAsyncCallback,
_userdata: *mut ::std::os::raw::c_void,
) {
unimplemented!();
Expand All @@ -83,7 +92,7 @@ pub extern "C" fn wgpuDeviceCreateComputePipelineAsync(
pub extern "C" fn wgpuDeviceCreateRenderPipelineAsync(
_device: native::WGPUDevice,
_descriptor: *const native::WGPURenderPipelineDescriptor,
_callback: native::WGPUCreateRenderPipelineAsyncCallback,
_callback: native::WGPUDeviceCreateRenderPipelineAsyncCallback,
_userdata: *mut ::std::os::raw::c_void,
) {
unimplemented!();
Expand All @@ -97,6 +106,14 @@ pub extern "C" fn wgpuDeviceSetLabel(
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuInstanceHasWGSLLanguageFeature(
_instance: native::WGPUInstance,
_feature: native::WGPUWGSLFeatureName,
) -> bool {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuInstanceProcessEvents(_instance: native::WGPUInstance) {
unimplemented!();
Expand Down Expand Up @@ -169,7 +186,7 @@ pub extern "C" fn wgpuSamplerSetLabel(
#[no_mangle]
pub extern "C" fn wgpuShaderModuleGetCompilationInfo(
_shader_module: native::WGPUShaderModule,
_callback: native::WGPUCompilationInfoCallback,
_callback: native::WGPUShaderModuleGetCompilationInfoCallback,
_userdata: *mut ::std::os::raw::c_void,
) {
unimplemented!();
Expand All @@ -183,6 +200,14 @@ pub extern "C" fn wgpuShaderModuleSetLabel(
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuSurfaceSetLabel(
_surface: native::WGPUSurface,
_label: *const ::std::os::raw::c_char,
) {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuTextureSetLabel(
_texture: native::WGPUTexture,
Expand Down

0 comments on commit 33133da

Please sign in to comment.