Skip to content

Commit

Permalink
chore: bump wgpu-core
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jul 19, 2024
1 parent c11f2d7 commit 5ed05a5
Show file tree
Hide file tree
Showing 83 changed files with 6,013 additions and 4,605 deletions.
18 changes: 9 additions & 9 deletions apps/demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ Application.on('uncaughtError', (args) => {
Application.on('launch', (args) => {
//require('@nativescript/canvas-polyfill');
if (global.isAndroid) {
jp.wasabeef.takt.Takt.stock(Utils.android.getApplicationContext()).seat(jp.wasabeef.takt.Seat.TOP_CENTER).color(-65536);
// jp.wasabeef.takt.Takt.stock(Utils.android.getApplicationContext()).seat(jp.wasabeef.takt.Seat.TOP_CENTER).color(-65536);
} else {
monitor = GDPerformanceMonitor.new();
monitor.startMonitoringWithConfiguration((label) => {
label.backgroundColor = UIColor.blackColor;
label.textColor = UIColor.whiteColor;
label.layer.borderColor = UIColor.redColor;
});
monitor.appVersionHidden = true;
monitor.deviceVersionHidden = true;
// monitor = GDPerformanceMonitor.new();
// monitor.startMonitoringWithConfiguration((label) => {
// label.backgroundColor = UIColor.blackColor;
// label.textColor = UIColor.whiteColor;
// label.layer.borderColor = UIColor.redColor;
// });
// monitor.appVersionHidden = true;
// monitor.deviceVersionHidden = true;
}
});
Application.run({ moduleName: 'app-root' });
2 changes: 1 addition & 1 deletion apps/demo/src/plugin-demos/canvas.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Page xmlns:canvas="@nativescript/canvas" xmlns:ui="@nativescript/canvas/dom/index" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<Page.actionBar>
<ActionBar title="canvas 2.0" icon="" class="action-bar">
<ActionBar title="canvas 2.0 WebGPU" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>

Expand Down
16 changes: 8 additions & 8 deletions crates/canvas-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ canvas-webgl = { path = "../canvas-webgl", optional = true }
parking_lot = "0.12.0"
ureq = { version = "2.9.6", features = ["gzip"] }
bytes = "1.5.0"
log = { version = "0.4.20"}
wgpu-types = "0.20.0"
log = { version = "0.4.20" }
wgpu-types = { version = "22.0.0" }
futures = "0.3"
raw-window-handle = "0.6.2"
wgpu-core = {version = "0.21.0", features = ["wgsl","vulkan","metal","raw-window-handle"]}
wgpu-core = { version = "22.0.0", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }

[target.'cfg(target_os="ios")'.dependencies]
display-link = {version = "0.2.0"}
wgpu-core = {version = "0.21.0", features = ["wgsl", "metal","raw-window-handle"]}
wgpu-core = {version = "22.0.0", features = ["wgsl", "metal","raw-window-handle"]}


# [target.'cfg(target_os="macos")'.dependencies]
# display-link = { git = "https://github.com/servo/display-link", branch = "no-transmute" }
# wgpu-core = {version = "0.21.0", features = ["wgsl", "metal","raw-window-handle"]}
#[target.'cfg(target_os="macos")'.dependencies]
#display-link = { git = "https://github.com/servo/display-link", branch = "no-transmute" }
#wgpu-core = { version = "22.0.0", features = ["wgsl", "metal", "raw-window-handle"] }

[target.'cfg(target_os="android")'.dependencies]
ndk = { version = "0.7.0", features = ["bitmap"] }
once_cell = "1.14.0"
wgpu-core = {version = "0.21.0", features = ["wgsl","vulkan","raw-window-handle"]}
wgpu-core = { version = "22.0.0", features = ["wgsl", "vulkan", "raw-window-handle"] }
21 changes: 20 additions & 1 deletion crates/canvas-c/src/buffers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use bytes::BytesMut;
use std::ffi::{c_char, CString};

use bytes::BytesMut;

use crate::ImageAsset;

#[derive(Clone)]
enum U8BufferInner {
BytesMut(BytesMut),
Vec(Vec<u8>),
ImageAsset(ImageAsset),
}

#[derive(Clone)]
Expand All @@ -19,20 +23,29 @@ impl U8Buffer {
match &self.0 {
U8BufferInner::BytesMut(value) => value,
U8BufferInner::Vec(value) => value.as_slice(),
U8BufferInner::ImageAsset(value) => {
value.0.get_bytes().unwrap_or(&[])
}
}
}

pub fn get_buffer_mut(&mut self) -> &mut [u8] {
match &mut self.0 {
U8BufferInner::BytesMut(value) => value,
U8BufferInner::Vec(value) => value.as_mut_slice(),
U8BufferInner::ImageAsset(value) => {
value.0.get_bytes_mut().unwrap_or(&mut [])
}
}
}

pub fn length(&self) -> usize {
match &self.0 {
U8BufferInner::BytesMut(value) => value.len(),
U8BufferInner::Vec(value) => value.len(),
U8BufferInner::ImageAsset(value) => {
value.0.len()
}
}
}
}
Expand All @@ -55,6 +68,12 @@ impl From<BytesMut> for U8Buffer {
}
}

impl From<ImageAsset> for U8Buffer {
fn from(value: ImageAsset) -> Self {
U8Buffer(U8BufferInner::ImageAsset(value.clone()))
}
}

pub struct U16Buffer(Vec<u16>);

impl U16Buffer {
Expand Down
42 changes: 25 additions & 17 deletions crates/canvas-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
use std::borrow::Cow;
use std::ffi::{CStr, CString};
use std::io::{Read, Write};
use std::os::raw::{c_char, c_int, c_uint};
use std::os::raw::c_ulong;
use std::os::raw::c_void;
use std::os::raw::{c_char, c_int, c_uint};
use std::sync::Arc;

use parking_lot::{MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock};

use canvas_2d::context::{Context, ContextWrapper};
use canvas_2d::context::compositing::composite_operation_type::CompositeOperationType;
use canvas_2d::context::drawing_paths::fill_rule::FillRule;
use canvas_2d::context::fill_and_stroke_styles::paint::paint_style_set_color_with_string;
Expand All @@ -19,7 +20,6 @@ use canvas_2d::context::line_styles::line_cap::LineCap;
use canvas_2d::context::line_styles::line_join::LineJoin;
pub use canvas_2d::context::text_styles::text_align::TextAlign;
use canvas_2d::context::text_styles::text_direction::TextDirection;
use canvas_2d::context::{Context, ContextWrapper};
use canvas_2d::utils::color::{parse_color, to_parsed_color};
use canvas_2d::utils::image::{
from_backend_texture, from_bitmap_slice, from_image_slice, from_image_slice_encoded,
Expand All @@ -33,6 +33,7 @@ use canvas_webgl::utils::gl::bytes_per_pixel;
use once_cell::sync::OnceCell;

use crate::buffers::{F32Buffer, I32Buffer, StringBuffer, U32Buffer, U8Buffer};

pub mod webgpu;

#[repr(C)]
Expand Down Expand Up @@ -711,7 +712,7 @@ pub extern "C" fn canvas_native_context_create_gl_no_window(
width as i32,
height as i32,
)
.unwrap();
.unwrap();

gl_context.make_current();

Expand Down Expand Up @@ -1953,7 +1954,6 @@ pub extern "C" fn canvas_native_context_create_pattern_canvas2d(
source.make_current();



#[cfg(any(target_os = "ios", target_os = "macos"))] {
let snapshot = source_ctx.snapshot();
let info = snapshot.image_info();
Expand All @@ -1964,21 +1964,20 @@ pub extern "C" fn canvas_native_context_create_pattern_canvas2d(
if let Some(image) = from_backend_texture(&mut ctx, &image, origin, info) {
return Some(canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Pattern(
context.get_context().create_pattern(image, repetition),
))
));
}
}

return None;
}

#[cfg(target_os = "android")] {

let snapshot = source_ctx.raster_snapshot();

if let Some(image) = snapshot {
return Some(canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Pattern(
context.get_context().create_pattern(image, repetition),
))
));
}


Expand Down Expand Up @@ -4641,6 +4640,15 @@ pub extern "C" fn canvas_native_image_asset_has_error(asset: *mut ImageAsset) ->
true
}

#[no_mangle]
pub extern "C" fn canvas_native_image_asset_get_data(asset: *mut ImageAsset) -> *mut U8Buffer {
if asset.is_null() {
return std::ptr::null_mut();
}
let asset = unsafe { &*asset };
Box::into_raw(Box::new(U8Buffer::from(asset.clone())))
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
struct ThreadCallbackData {
Expand Down Expand Up @@ -5282,8 +5290,8 @@ pub extern "C" fn canvas_native_webgl_to_data_url(
format.as_ref(),
quality,
))
.unwrap()
.into_raw()
.unwrap()
.into_raw()
}

#[derive(Debug)]
Expand Down Expand Up @@ -7723,8 +7731,8 @@ pub extern "C" fn canvas_native_webgl_get_program_info_log(
state.get_inner_mut(),
),
)
.unwrap()
.into_raw()
.unwrap()
.into_raw()
}

#[no_mangle]
Expand Down Expand Up @@ -7766,8 +7774,8 @@ pub extern "C" fn canvas_native_webgl_get_shader_info_log(
CString::new(
canvas_webgl::webgl::canvas_native_webgl_get_shader_info_log(shader, state.get_inner_mut()),
)
.unwrap()
.into_raw()
.unwrap()
.into_raw()
}

#[no_mangle]
Expand Down Expand Up @@ -7812,8 +7820,8 @@ pub extern "C" fn canvas_native_webgl_get_shader_source(
shader,
state.get_inner_mut(),
))
.unwrap()
.into_raw()
.unwrap()
.into_raw()
}

#[no_mangle]
Expand Down Expand Up @@ -9698,8 +9706,8 @@ pub extern "C" fn canvas_native_webgl2_get_active_uniform_block_name(
state.get_inner_mut(),
),
)
.unwrap()
.into_raw()
.unwrap()
.into_raw()
}

#[no_mangle]
Expand Down
112 changes: 110 additions & 2 deletions crates/canvas-c/src/webgpu/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,10 @@ impl From<wgpu_types::TextureFormat> for CanvasGPUTextureFormat {
wgpu_types::TextureFormat::Rg16Unorm => CanvasGPUTextureFormat::Rg16Unorm,
wgpu_types::TextureFormat::Rg16Snorm => CanvasGPUTextureFormat::Rg16Snorm,
wgpu_types::TextureFormat::Rg16Float => CanvasGPUTextureFormat::Rg16Float,
wgpu_types::TextureFormat::Rgba8Unorm => CanvasGPUTextureFormat::Rgba8Unorm,
wgpu_types::TextureFormat::Rgba8UnormSrgb => CanvasGPUTextureFormat::Rgba8UnormSrgb,
wgpu_types::TextureFormat::Rgba8Snorm => CanvasGPUTextureFormat::Rgba8Snorm,
wgpu_types::TextureFormat::Rgba8Uint => CanvasGPUTextureFormat::Rgba8Uint,
wgpu_types::TextureFormat::Rgba8Sint => CanvasGPUTextureFormat::Rgba8Sint,
wgpu_types::TextureFormat::Bgra8Unorm => CanvasGPUTextureFormat::Bgra8Unorm,
wgpu_types::TextureFormat::Bgra8UnormSrgb => CanvasGPUTextureFormat::Bgra8UnormSrgb,
wgpu_types::TextureFormat::Rgb9e5Ufloat => CanvasGPUTextureFormat::Rgb9e5Ufloat,
wgpu_types::TextureFormat::Rgb10a2Uint => CanvasGPUTextureFormat::Rgb10a2Uint,
Expand Down Expand Up @@ -699,6 +697,116 @@ impl Into<Option<wgpu_types::TextureFormat>> for CanvasOptionsGPUTextureFormat {
}
}

impl Into<String> for CanvasGPUTextureFormat {
fn into(self) -> String {
let s: String;
let name = match self {
CanvasGPUTextureFormat::R8Unorm => "r8unorm",
CanvasGPUTextureFormat::R8Snorm => "r8snorm",
CanvasGPUTextureFormat::R8Uint => "r8uint",
CanvasGPUTextureFormat::R8Sint => "r8sint",
CanvasGPUTextureFormat::R16Uint => "r16uint",
CanvasGPUTextureFormat::R16Sint => "r16sint",
CanvasGPUTextureFormat::R16Unorm => "r16unorm",
CanvasGPUTextureFormat::R16Snorm => "r16snorm",
CanvasGPUTextureFormat::R16Float => "r16float",
CanvasGPUTextureFormat::Rg8Unorm => "rg8unorm",
CanvasGPUTextureFormat::Rg8Snorm => "rg8snorm",
CanvasGPUTextureFormat::Rg8Uint => "rg8uint",
CanvasGPUTextureFormat::Rg8Sint => "rg8sint",
CanvasGPUTextureFormat::R32Uint => "r32uint",
CanvasGPUTextureFormat::R32Sint => "r32sint",
CanvasGPUTextureFormat::R32Float => "r32float",
CanvasGPUTextureFormat::Rg16Uint => "rg16uint",
CanvasGPUTextureFormat::Rg16Sint => "rg16sint",
CanvasGPUTextureFormat::Rg16Unorm => "rg16unorm",
CanvasGPUTextureFormat::Rg16Snorm => "rg16snorm",
CanvasGPUTextureFormat::Rg16Float => "rg16float",
CanvasGPUTextureFormat::Rgba8Unorm => "rgba8unorm",
CanvasGPUTextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb",
CanvasGPUTextureFormat::Rgba8Snorm => "rgba8snorm",
CanvasGPUTextureFormat::Rgba8Uint => "rgba8uint",
CanvasGPUTextureFormat::Rgba8Sint => "rgba8sint",
CanvasGPUTextureFormat::Bgra8Unorm => "bgra8unorm",
CanvasGPUTextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb",
CanvasGPUTextureFormat::Rgb10a2Uint => "rgb10a2uint",
CanvasGPUTextureFormat::Rgb10a2Unorm => "rgb10a2unorm",
CanvasGPUTextureFormat::Rg11b10Float => "rg11b10ufloat",
CanvasGPUTextureFormat::Rg32Uint => "rg32uint",
CanvasGPUTextureFormat::Rg32Sint => "rg32sint",
CanvasGPUTextureFormat::Rg32Float => "rg32float",
CanvasGPUTextureFormat::Rgba16Uint => "rgba16uint",
CanvasGPUTextureFormat::Rgba16Sint => "rgba16sint",
CanvasGPUTextureFormat::Rgba16Unorm => "rgba16unorm",
CanvasGPUTextureFormat::Rgba16Snorm => "rgba16snorm",
CanvasGPUTextureFormat::Rgba16Float => "rgba16float",
CanvasGPUTextureFormat::Rgba32Uint => "rgba32uint",
CanvasGPUTextureFormat::Rgba32Sint => "rgba32sint",
CanvasGPUTextureFormat::Rgba32Float => "rgba32float",
CanvasGPUTextureFormat::Stencil8 => "stencil8",
CanvasGPUTextureFormat::Depth32Float => "depth32float",
CanvasGPUTextureFormat::Depth16Unorm => "depth16unorm",
CanvasGPUTextureFormat::Depth32FloatStencil8 => "depth32float-stencil8",
CanvasGPUTextureFormat::Depth24Plus => "depth24plus",
CanvasGPUTextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8",
CanvasGPUTextureFormat::NV12 => "nv12",
CanvasGPUTextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat",
CanvasGPUTextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm",
CanvasGPUTextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb",
CanvasGPUTextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm",
CanvasGPUTextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb",
CanvasGPUTextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm",
CanvasGPUTextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb",
CanvasGPUTextureFormat::Bc4RUnorm => "bc4-r-unorm",
CanvasGPUTextureFormat::Bc4RSnorm => "bc4-r-snorm",
CanvasGPUTextureFormat::Bc5RgUnorm => "bc5-rg-unorm",
CanvasGPUTextureFormat::Bc5RgSnorm => "bc5-rg-snorm",
CanvasGPUTextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat",
CanvasGPUTextureFormat::Bc6hRgbFloat => "bc6h-rgb-float",
CanvasGPUTextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm",
CanvasGPUTextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb",
CanvasGPUTextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm",
CanvasGPUTextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb",
CanvasGPUTextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm",
CanvasGPUTextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb",
CanvasGPUTextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm",
CanvasGPUTextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb",
CanvasGPUTextureFormat::EacR11Unorm => "eac-r11unorm",
CanvasGPUTextureFormat::EacR11Snorm => "eac-r11snorm",
CanvasGPUTextureFormat::EacRg11Unorm => "eac-rg11unorm",
CanvasGPUTextureFormat::EacRg11Snorm => "eac-rg11snorm",
CanvasGPUTextureFormat::Astc { block, channel } => {
let block = match block {
CanvasAstcBlock::B4x4 => "4x4",
CanvasAstcBlock::B5x4 => "5x4",
CanvasAstcBlock::B5x5 => "5x5",
CanvasAstcBlock::B6x5 => "6x5",
CanvasAstcBlock::B6x6 => "6x6",
CanvasAstcBlock::B8x5 => "8x5",
CanvasAstcBlock::B8x6 => "8x6",
CanvasAstcBlock::B8x8 => "8x8",
CanvasAstcBlock::B10x5 => "10x5",
CanvasAstcBlock::B10x6 => "10x6",
CanvasAstcBlock::B10x8 => "10x8",
CanvasAstcBlock::B10x10 => "10x10",
CanvasAstcBlock::B12x10 => "12x10",
CanvasAstcBlock::B12x12 => "12x12",
};

let channel = match channel {
CanvasAstcChannel::Unorm => "unorm",
CanvasAstcChannel::UnormSrgb => "unorm-srgb",
CanvasAstcChannel::Hdr => "hdr",
};

s = format!("astc-{block}-{channel}");
&s
}
};
name.to_string()
}
}

#[no_mangle]
pub extern "C" fn canvas_native_webgpu_enum_gpu_texture_to_string(
value: CanvasGPUTextureFormat,
Expand Down
Loading

0 comments on commit 5ed05a5

Please sign in to comment.