Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jun 24, 2024
1 parent 09bbfc6 commit 11fed80
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 14 deletions.
29 changes: 28 additions & 1 deletion crates/canvas-c/src/webgpu/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,6 @@ impl From<wgpu_types::TextureAspect> for CanvasTextureAspect {
}
}


impl Into<wgpu_types::TextureAspect> for CanvasTextureAspect {
fn into(self) -> wgpu_types::TextureAspect {
match self {
Expand All @@ -797,3 +796,31 @@ impl Into<wgpu_types::TextureAspect> for CanvasTextureAspect {
}
}
}

#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
pub enum CanvasIndexFormat {
/// Indices are 16 bit unsigned integers.
Uint16 = 0,
/// Indices are 32 bit unsigned integers.
#[default]
Uint32 = 1,
}

impl From<wgpu_types::IndexFormat> for CanvasIndexFormat {
fn from(value: wgpu_types::IndexFormat) -> Self {
match value {
wgpu_types::IndexFormat::Uint16 => Self::Uint16,
wgpu_types::IndexFormat::Uint32 => Self::Uint32,
}
}
}

impl Into<wgpu_types::IndexFormat> for CanvasIndexFormat {
fn into(self) -> wgpu_types::IndexFormat {
match self {
CanvasIndexFormat::Uint16 => wgpu_types::IndexFormat::Uint16,
CanvasIndexFormat::Uint32 => wgpu_types::IndexFormat::Uint32,
}
}
}
6 changes: 4 additions & 2 deletions crates/canvas-c/src/webgpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod gpu_query_set;
pub mod gpu_queue;
pub mod gpu_supported_limits;
pub mod prelude;
pub mod gpu_render_pass_encoder;
pub mod gpu_render_pass;
pub mod gpu_shader_module;
pub mod gpu_canvas_context;
pub mod enums;
Expand All @@ -51,4 +51,6 @@ pub mod gpu_texture_view;
pub mod gpu_bind_group;
pub mod gpu_bind_group_layout;
pub mod gpu_command_buffer;
pub mod structs;
pub mod structs;
pub mod gpu_render_bundle;
pub mod gpu_render_pipeline;
144 changes: 133 additions & 11 deletions crates/canvas-c/src/webgpu/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ impl Into<wgpu_types::Origin2d> for CanvasOrigin2d {
}
}



#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct CanvasExtent3d {
Expand All @@ -68,19 +66,143 @@ pub struct CanvasExtent3d {
pub depth_or_array_layers: u32,
}

impl Into<wgpu_types::Extent3d> for CanvasExtent3d{
impl Into<wgpu_types::Extent3d> for CanvasExtent3d {
fn into(self) -> wgpu_types::Extent3d {
wgpu_types::Extent3d { width: self.width, height: self.height, depth_or_array_layers: self.depth_or_array_layers }
wgpu_types::Extent3d {
width: self.width,
height: self.height,
depth_or_array_layers: self.depth_or_array_layers,
}
}
}


impl From<wgpu_types::Extent3d> for CanvasExtent3d{
impl From<wgpu_types::Extent3d> for CanvasExtent3d {
fn from(value: wgpu_types::Extent3d) -> Self {
Self {
width: value.width,
height: value.height,
depth_or_array_layers: value.depth_or_array_layers,
Self {
width: value.width,
height: value.height,
depth_or_array_layers: value.depth_or_array_layers,
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct CanvasColor {
pub r: f64,
pub g: f64,
pub b: f64,
pub a: f64,
}

impl CanvasColor {
pub const TRANSPARENT: Self = Self {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.0,
};
pub const BLACK: Self = Self {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub const WHITE: Self = Self {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
};
pub const RED: Self = Self {
r: 1.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub const GREEN: Self = Self {
r: 0.0,
g: 1.0,
b: 0.0,
a: 1.0,
};
pub const BLUE: Self = Self {
r: 0.0,
g: 0.0,
b: 1.0,
a: 1.0,
};
}

impl Into<wgpu_types::Color> for CanvasColor {
fn into(self) -> wgpu_types::Color {
wgpu_types::Color {
r: self.r,
g: self.g,
b: self.b,
a: self.a,
}
}
}

impl From<wgpu_types::Color> for CanvasColor {
fn from(value: wgpu_types::Color) -> Self {
Self::Color {
r: value.r,
g: value.g,
b: value.b,
a: value.a,
}
}
}
}

#[derive(Debug, Clone, Copy)]
pub struct CanvasImageDataLayout {
offset: u64,
bytes_per_row: Option<u32>,
rows_per_image: Option<u32>,
}

impl From<wgpu_types::ImageDataLayout> for CanvasImageDataLayout {
fn from(value: wgpu_types::ImageDataLayout) -> Self {
Self {
offset: value.offset,
bytes_per_row: value.bytes_per_row,
rows_per_image: value.rows_per_image,
}
}
}

impl Into<wgpu_types::ImageDataLayout> for CanvasImageDataLayout {
fn into(self) -> wgpu_types::ImageDataLayout {
wgpu_types::ImageDataLayout {
offset: self.offset,
bytes_per_row: self.bytes_per_row,
rows_per_image: self.rows_per_image,
}
}
}

#[repr(C)]
#[derive(Debug)]
pub struct CanvasImageCopyExternalImage {
/// The texture to be copied from. The copy source data is captured at the moment
/// the copy is issued.
pub source: *const u8,
pub source_size: usize,
/// The base texel used for copying from the external image. Together
/// with the `copy_size` argument to copy functions, defines the
/// sub-region of the image to copy.
///
/// Relative to the top left of the image.
///
/// Must be [`Origin2d::ZERO`] if [`DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES`] is not supported.
pub origin: CanvasOrigin2d,
/// If the Y coordinate of the image should be flipped. Even if this is
/// true, `origin` is still relative to the top left.
pub flip_y: bool,

pub width: u32,

pub height: u32,
}
5 changes: 5 additions & 0 deletions packages/canvas/WebGPU/GPUBindGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { native_ } from './Constants';

export class GPUBindGroup {
[native_];
}
21 changes: 21 additions & 0 deletions packages/canvas/WebGPU/GPURenderPass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { native_ } from './Constants';
import { GPUBindGroup } from './GPUBindGroup';

export class GPURenderPass {
[native_];

setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsetsData?: number[] | Uint8Array, dynamicOffsetsDataStart?: number, dynamicOffsetsDataLength?: number) {
const group = bindGroup?.[native_];
if (!group) {
return;
}
if (Array.isArray(dynamicOffsetsData)) {
const data = new Uint8Array(dynamicOffsetsData);
this[native_].setBindGroup(index, group, data, 0, data.length);
} else if (dynamicOffsetsData instanceof Uint8Array) {
this[native_].setBindGroup(index, group, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
} else {
this[native_].setBindGroup(index, group);
}
}
}

0 comments on commit 11fed80

Please sign in to comment.