Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update deno and spec #4143

Merged
merged 10 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
301 changes: 244 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ wasm-bindgen-test = "0.3"
web-sys = "0.3.64"

# deno dependencies
deno_console = "0.106.0"
deno_core = "0.188.0"
deno_url = "0.106.0"
deno_web = "0.137.0"
deno_webidl = "0.106.0"
deno_console = "0.118.0"
deno_core = "0.213.0"
deno_url = "0.118.0"
deno_web = "0.149.0"
deno_webidl = "0.118.0"
deno_webgpu = { path = "./deno_webgpu" }
tokio = "1.32.0"
termcolor = "1.2.0"
Expand Down
31 changes: 17 additions & 14 deletions cts_runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(not(target_arch = "wasm32"))]
mod native {
use std::sync::Arc;
use std::{
env, fmt,
io::{Read, Write},
Expand All @@ -8,13 +9,12 @@ mod native {

use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::op;
use deno_core::op2;
use deno_core::resolve_url_or_path;
use deno_core::serde_json::json;
use deno_core::v8;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;
use deno_core::ZeroCopyBuf;
use deno_web::BlobStore;
use termcolor::Ansi;
use termcolor::Color::Red;
Expand All @@ -36,7 +36,10 @@ mod native {
deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<Permissions>(BlobStore::default(), None),
deno_web::deno_web::init_ops_and_esm::<Permissions>(
Arc::new(BlobStore::default()),
None,
),
deno_webgpu::deno_webgpu::init_ops_and_esm(true),
cts_runner::init_ops_and_esm(),
],
Expand All @@ -47,7 +50,7 @@ mod native {
let cfg = json!({"args": args, "cwd": env::current_dir().unwrap().to_string_lossy() });

{
let context = isolate.global_context();
let context = isolate.main_context();
let scope = &mut isolate.handle_scope();
let context_local = v8::Local::new(scope, context);
let global_obj = context_local.global(scope);
Expand All @@ -56,7 +59,6 @@ mod native {
let bootstrap_fn = v8::Local::<v8::Function>::try_from(bootstrap_fn).unwrap();

let options_v8 = deno_core::serde_v8::to_v8(scope, cfg).unwrap();
let bootstrap_fn = v8::Local::new(scope, bootstrap_fn);
let undefined = v8::undefined(scope);
bootstrap_fn
.call(scope, undefined.into(), &[options_v8])
Expand Down Expand Up @@ -86,26 +88,27 @@ mod native {
deps = [deno_webidl, deno_web],
ops = [op_exit, op_read_file_sync, op_write_file_sync],
esm_entry_point = "ext:cts_runner/bootstrap.js",
esm = ["bootstrap.js"],
esm = ["src/bootstrap.js"],
);

#[op]
#[op2(fast)]
fn op_exit(code: i32) -> Result<(), AnyError> {
std::process::exit(code)
}

#[op]
fn op_read_file_sync(path: String) -> Result<ZeroCopyBuf, AnyError> {
let path = std::path::Path::new(&path);
#[op2]
#[buffer]
fn op_read_file_sync(#[string] path: &str) -> Result<Vec<u8>, AnyError> {
let path = std::path::Path::new(path);
let mut file = std::fs::File::open(path)?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
Ok(ZeroCopyBuf::from(buf))
Ok(buf)
}

#[op]
fn op_write_file_sync(path: String, buf: ZeroCopyBuf) -> Result<(), AnyError> {
let path = std::path::Path::new(&path);
#[op2(fast)]
fn op_write_file_sync(#[string] path: &str, #[buffer] buf: &[u8]) -> Result<(), AnyError> {
let path = std::path::Path::new(path);
let mut file = std::fs::File::create(path)?;
file.write_all(&buf)?;
Ok(())
Expand Down
31 changes: 17 additions & 14 deletions deno_webgpu/binding.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

use deno_core::error::AnyError;
use deno_core::op;
use deno_core::op2;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
Expand Down Expand Up @@ -176,12 +176,13 @@ impl From<GpuBindingType> for wgpu_types::BindingType {
}
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_create_bind_group_layout(
state: &mut OpState,
device_rid: ResourceId,
label: Option<String>,
entries: Vec<GpuBindGroupLayoutEntry>,
#[smi] device_rid: ResourceId,
#[string] label: Option<String>,
#[serde] entries: Vec<GpuBindGroupLayoutEntry>,
) -> Result<WebGpuResult, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
Expand Down Expand Up @@ -213,12 +214,13 @@ pub fn op_webgpu_create_bind_group_layout(
) => state, WebGpuBindGroupLayout)
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_create_pipeline_layout(
state: &mut OpState,
device_rid: ResourceId,
label: Option<String>,
bind_group_layouts: Vec<u32>,
#[smi] device_rid: ResourceId,
#[string] label: Option<String>,
#[serde] bind_group_layouts: Vec<u32>,
) -> Result<WebGpuResult, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
Expand Down Expand Up @@ -257,13 +259,14 @@ pub struct GpuBindGroupEntry {
size: Option<u64>,
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_create_bind_group(
state: &mut OpState,
device_rid: ResourceId,
label: Option<String>,
layout: ResourceId,
entries: Vec<GpuBindGroupEntry>,
#[smi] device_rid: ResourceId,
#[string] label: Option<String>,
#[smi] layout: ResourceId,
#[serde] entries: Vec<GpuBindGroupEntry>,
) -> Result<WebGpuResult, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
Expand Down
46 changes: 24 additions & 22 deletions deno_webgpu/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::futures::channel::oneshot;
use deno_core::op;
use deno_core::op2;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
use std::borrow::Cow;
use std::cell::RefCell;
use std::convert::TryFrom;
use std::rc::Rc;
use std::time::Duration;
use wgpu_core::resource::BufferAccessResult;
Expand Down Expand Up @@ -40,12 +38,13 @@ impl Resource for WebGpuBufferMapped {
}
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_create_buffer(
state: &mut OpState,
device_rid: ResourceId,
label: Option<String>,
size: u64,
#[smi] device_rid: ResourceId,
#[string] label: Option<String>,
#[number] size: u64,
usage: u32,
mapped_at_creation: bool,
) -> Result<WebGpuResult, AnyError> {
Expand All @@ -70,14 +69,15 @@ pub fn op_webgpu_create_buffer(
) => state, WebGpuBuffer)
}

#[op]
#[op2(async)]
#[serde]
pub async fn op_webgpu_buffer_get_map_async(
state: Rc<RefCell<OpState>>,
buffer_rid: ResourceId,
device_rid: ResourceId,
#[smi] buffer_rid: ResourceId,
#[smi] device_rid: ResourceId,
mode: u32,
offset: u64,
size: u64,
#[number] offset: u64,
#[number] size: u64,
) -> Result<WebGpuResult, AnyError> {
let (sender, receiver) = oneshot::channel::<BufferAccessResult>();

Expand Down Expand Up @@ -143,13 +143,14 @@ pub async fn op_webgpu_buffer_get_map_async(
Ok(WebGpuResult::empty())
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_buffer_get_mapped_range(
state: &mut OpState,
buffer_rid: ResourceId,
offset: u64,
size: Option<u64>,
mut buf: ZeroCopyBuf,
#[smi] buffer_rid: ResourceId,
#[number] offset: u64,
#[number] size: Option<u64>,
#[buffer] buf: &mut [u8],
) -> Result<WebGpuResult, AnyError> {
let instance = state.borrow::<super::Instance>();
let buffer_resource = state.resource_table.get::<WebGpuBuffer>(buffer_rid)?;
Expand All @@ -172,12 +173,13 @@ pub fn op_webgpu_buffer_get_mapped_range(
Ok(WebGpuResult::rid(rid))
}

#[op]
#[op2]
#[serde]
pub fn op_webgpu_buffer_unmap(
state: &mut OpState,
buffer_rid: ResourceId,
mapped_rid: ResourceId,
buf: Option<ZeroCopyBuf>,
#[smi] buffer_rid: ResourceId,
#[smi] mapped_rid: ResourceId,
#[buffer] buf: Option<&[u8]>,
) -> Result<WebGpuResult, AnyError> {
let mapped_resource = state
.resource_table
Expand All @@ -188,7 +190,7 @@ pub fn op_webgpu_buffer_unmap(

if let Some(buf) = buf {
let slice = unsafe { std::slice::from_raw_parts_mut(mapped_resource.0, mapped_resource.1) };
slice.copy_from_slice(&buf);
slice.copy_from_slice(buf);
}

gfx_ok!(buffer => instance.buffer_unmap(buffer))
Expand Down
Loading