Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jun 23, 2024
1 parent 4bc0c6b commit 9c11b71
Show file tree
Hide file tree
Showing 56 changed files with 6,170 additions and 3,817 deletions.
282 changes: 265 additions & 17 deletions crates/canvas-c/src/webgpu/enums.rs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions crates/canvas-c/src/webgpu/gpu_adapter_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ pub extern "C" fn canvas_native_webgpu_adapter_info_description(
let info = unsafe { &*info };
CString::new(info.0.name.clone()).unwrap().into_raw()
}


#[no_mangle]
pub unsafe extern "C" fn canvas_native_webgpu_adapter_info_destroy(
info: *mut CanvasGPUAdapterInfo,
) {
if info.is_null() {
return;
}

let _ = Box::from_raw(info);
}
6 changes: 6 additions & 0 deletions crates/canvas-c/src/webgpu/gpu_bind_group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::gpu::CanvasWebGPUInstance;

pub struct CanvasGPUBindGroup {
pub(crate) instance: CanvasWebGPUInstance,
pub(crate) group: wgpu_core::id::BindGroupId,
}
6 changes: 6 additions & 0 deletions crates/canvas-c/src/webgpu/gpu_bind_group_layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::gpu::CanvasWebGPUInstance;

pub struct CanvasGPUBindGroupLayout {
pub(crate) instance: CanvasWebGPUInstance,
pub(crate) group_layout: wgpu_core::id::BindGroupLayoutId,
}
46 changes: 22 additions & 24 deletions crates/canvas-c/src/webgpu/gpu_canvas_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ pub extern "C" fn canvas_native_webgpu_context_configure(

let config = unsafe { &*config };

println!("config {:?}", config);

let view_formats = if !config.view_formats.is_null() && config.view_formats_size > 0 {
unsafe {
std::slice::from_raw_parts(config.view_formats, config.view_formats_size)
Expand All @@ -165,8 +163,6 @@ pub extern "C" fn canvas_native_webgpu_context_configure(
vec![]
};

print!("view_formats {:?}", view_formats.as_slice());

let config = wgpu_types::SurfaceConfiguration::<Vec<wgpu_types::TextureFormat>> {
desired_maximum_frame_latency: 2,
usage: wgpu_types::TextureUsages::from_bits_truncate(config.usage),
Expand All @@ -178,10 +174,8 @@ pub extern "C" fn canvas_native_webgpu_context_configure(
view_formats: view_formats,
};

print!("SurfaceConfiguration {:?}", &config);

// todo handle error
if let Some(_) =
if let Some(err) =
gfx_select!(device_id => global.surface_configure(surface_id, device_id, &config))
{}
}
Expand Down Expand Up @@ -210,30 +204,34 @@ pub extern "C" fn canvas_native_webgpu_context_get_current_texture(
if context.is_null() {
return std::ptr::null_mut();
}


let context = unsafe { &*context };
let surface_id = context.surface;
let global = &context.instance.0;

match gfx_select!(surface_id => global.surface_get_current_texture(surface_id, None)) {
Ok(texture) => match texture.status {
wgpu_types::SurfaceStatus::Good | wgpu_types::SurfaceStatus::Suboptimal => {
Box::into_raw(Box::new(CanvasGPUTexture {
instance: context.instance.clone(),
texture: texture.texture_id.unwrap(),
owned: false,
depth_or_array_layers: 1,
dimension: super::enums::CanvasTextureDimension::D2,
format: context.format.into(),
mipLevelCount: 1,
sampleCount: 1,
width: context.width,
height: context.height,
usage: context.usage,
}))
Ok(texture) => {
match texture.status {
wgpu_types::SurfaceStatus::Good | wgpu_types::SurfaceStatus::Suboptimal => {
Box::into_raw(Box::new(CanvasGPUTexture {
instance: context.instance.clone(),
texture: texture.texture_id.unwrap(),
owned: false,
depth_or_array_layers: 1,
dimension: super::enums::CanvasTextureDimension::D2,
format: context.format.into(),
mipLevelCount: 1,
sampleCount: 1,
width: context.width,
height: context.height,
usage: context.usage,
}))
}
_ => std::ptr::null_mut(),
}
_ => std::ptr::null_mut(),
},
Err(_) => {
Err(error) => {
// todo handle error
std::ptr::null_mut()
}
Expand Down
6 changes: 6 additions & 0 deletions crates/canvas-c/src/webgpu/gpu_command_buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::gpu::CanvasWebGPUInstance;

pub struct CanvasGPUCommandBuffer {
pub(crate) instance: CanvasWebGPUInstance,
pub(crate) command_buffer: wgpu_core::id::CommandBufferId,
}
Loading

0 comments on commit 9c11b71

Please sign in to comment.