Skip to content

Commit

Permalink
Update headers (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 authored Jul 18, 2024
1 parent a1ede11 commit 4f85e22
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 130 deletions.
24 changes: 12 additions & 12 deletions examples/enumerate_adapters/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ int main(int argc, char *argv[]) {
WGPUAdapter adapter = adapters[i];
assert(adapter);

WGPUAdapterProperties props;
wgpuAdapterGetProperties(adapter, &props);
WGPUAdapterInfo info = {0};
wgpuAdapterGetInfo(adapter, &info);
printf("WGPUAdapter: %d\n", i);
printf("WGPUAdapterProperties {\n"
"\tvendorID: %" PRIu32 "\n"
"\tvendorName: %s\n"
printf("WGPUAdapterInfo {\n"
"\tvendor: %s\n"
"\tarchitecture: %s\n"
"\tdeviceID: %" PRIu32 "\n"
"\tname: %s\n"
"\tdriverDescription: %s\n"
"\tadapterType: %#.8x\n"
"\tdevice: %s\n"
"\tdescription: %s\n"
"\tbackendType: %#.8x\n"
"\tadapterType: %#.8x\n"
"\tvendorID: %" PRIu32 "\n"
"\tdeviceID: %" PRIu32 "\n"
"}\n",
props.vendorID, props.vendorName, props.architecture, props.deviceID,
props.name, props.driverDescription, props.adapterType,
props.backendType);
info.vendor, info.architecture, info.device, info.description,
info.backendType, info.adapterType, info.vendorID, info.deviceID);

wgpuAdapterInfoFreeMembers(info);
wgpuAdapterRelease(adapter);
}

Expand Down
14 changes: 14 additions & 0 deletions examples/framework/framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,17 @@ void frmwrk_print_global_report(WGPUGlobalReport report) {
}
printf("}\n");
}

void frmwrk_print_adapter_info(WGPUAdapter adapter) {
struct WGPUAdapterInfo info = {0};
wgpuAdapterGetInfo(adapter, &info);
printf("description: %s\n", info.description);
printf("vendor: %s\n", info.vendor);
printf("architecture: %s\n", info.architecture);
printf("device: %s\n", info.device);
printf("backend type: %u\n", info.backendType);
printf("adapter type: %u\n", info.adapterType);
printf("vendorID: %x\n", info.vendorID);
printf("deviceID: %x\n", info.deviceID);
wgpuAdapterInfoFreeMembers(info);
}
1 change: 1 addition & 0 deletions examples/framework/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ WGPUShaderModule frmwrk_load_shader_module(WGPUDevice device, const char *name);
void frmwrk_print_global_report(WGPUGlobalReport report);
WGPUBuffer frmwrk_device_create_buffer_init(
WGPUDevice device, const frmwrk_buffer_init_descriptor *descriptor);
void frmwrk_print_adapter_info(WGPUAdapter adapter);

#endif // FRAMEWORK_H
2 changes: 2 additions & 0 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ int main(int argc, char *argv[]) {
handle_request_adapter, &demo);
assert(demo.adapter);

frmwrk_print_adapter_info(demo.adapter);

wgpuAdapterRequestDevice(demo.adapter, NULL, handle_request_device, &demo);
assert(demo.device);

Expand Down
2 changes: 1 addition & 1 deletion ffi/webgpu-headers
51 changes: 49 additions & 2 deletions src/conv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::native;
use crate::utils::{make_slice, ptr_into_label, ptr_into_pathbuf};
use crate::{follow_chain, map_enum};
use crate::{native, UncapturedErrorCallback};
use std::num::{NonZeroIsize, NonZeroU32, NonZeroU64};
use std::ptr::NonNull;
use std::{borrow::Cow, ffi::CStr};
Expand Down Expand Up @@ -302,13 +302,14 @@ pub fn map_instance_descriptor(
}

#[inline]
pub fn map_device_descriptor<'a>(
pub(crate) fn map_device_descriptor<'a>(
des: &native::WGPUDeviceDescriptor,
base_limits: wgt::Limits,
extras: Option<&native::WGPUDeviceExtras>,
) -> (
wgt::DeviceDescriptor<wgc::Label<'a>>,
*const std::ffi::c_char,
Option<UncapturedErrorCallback>,
) {
(
wgt::DeviceDescriptor {
Expand All @@ -331,6 +332,13 @@ pub fn map_device_descriptor<'a>(
Some(extras) => extras.tracePath,
None => std::ptr::null(),
},
match des.uncapturedErrorCallbackInfo.callback {
None => None,
callback => Some(UncapturedErrorCallback {
callback,
userdata: des.uncapturedErrorCallbackInfo.userdata,
}),
},
)
}

Expand Down Expand Up @@ -1523,6 +1531,24 @@ pub fn map_texture_usage_flags(flags: native::WGPUTextureUsage) -> wgt::TextureU
temp
}

#[inline]
pub fn to_native_texture_usage_flags(flags: wgt::TextureUsages) -> native::WGPUTextureUsage {
let mut flag = 0;
if flags.contains(wgt::TextureUsages::COPY_SRC) {
flag |= native::WGPUTextureUsage_CopySrc;
}
if flags.contains(wgt::TextureUsages::COPY_DST) {
flag |= native::WGPUTextureUsage_CopySrc;
}
if flags.contains(wgt::TextureUsages::TEXTURE_BINDING) {
flag |= native::WGPUTextureUsage_TextureBinding;
}
if flags.contains(wgt::TextureUsages::RENDER_ATTACHMENT) {
flag |= native::WGPUTextureUsage_RenderAttachment;
}
flag
}

pub enum CreateSurfaceParams {
Raw(
(
Expand Down Expand Up @@ -1633,3 +1659,24 @@ pub fn map_surface_configuration(
},
}
}

pub fn map_backend_type(backend: wgt::Backend) -> native::WGPUBackendType {
match backend {
wgt::Backend::Empty => native::WGPUBackendType_Null,
wgt::Backend::Vulkan => native::WGPUBackendType_Vulkan,
wgt::Backend::Metal => native::WGPUBackendType_Metal,
wgt::Backend::Dx12 => native::WGPUBackendType_D3D12,
wgt::Backend::Gl => native::WGPUBackendType_OpenGL,
wgt::Backend::BrowserWebGpu => native::WGPUBackendType_WebGPU,
}
}

pub fn map_adapter_type(device_type: wgt::DeviceType) -> native::WGPUAdapterType {
match device_type {
wgt::DeviceType::Other => native::WGPUAdapterType_Unknown,
wgt::DeviceType::IntegratedGpu => native::WGPUAdapterType_IntegratedGPU,
wgt::DeviceType::DiscreteGpu => native::WGPUAdapterType_DiscreteGPU,
wgt::DeviceType::VirtualGpu => native::WGPUAdapterType_CPU, // close enough?
wgt::DeviceType::Cpu => native::WGPUAdapterType_CPU,
}
}
Loading

0 comments on commit 4f85e22

Please sign in to comment.