mirror of
https://github.com/denoland/deno
synced 2024-08-27 20:09:17 +00:00
upgrade: Rust 1.51.0 (#9895)
This commit is contained in:
parent
881e1e8164
commit
e7954413e1
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -74,7 +74,7 @@ jobs:
|
|||
- name: Install rust
|
||||
uses: hecrj/setup-rust-action@v1
|
||||
with:
|
||||
rust-version: 1.50.0
|
||||
rust-version: 1.51.0
|
||||
|
||||
- name: Install clippy and rustfmt
|
||||
if: matrix.kind == 'lint'
|
||||
|
|
24
cli/ast.rs
24
cli/ast.rs
|
@ -59,11 +59,11 @@ pub struct Location {
|
|||
pub col: usize,
|
||||
}
|
||||
|
||||
impl Into<Location> for swc_common::Loc {
|
||||
fn into(self) -> Location {
|
||||
impl From<swc_common::Loc> for Location {
|
||||
fn from(swc_loc: swc_common::Loc) -> Self {
|
||||
use swc_common::FileName::*;
|
||||
|
||||
let filename = match &self.file.name {
|
||||
let filename = match &swc_loc.file.name {
|
||||
Real(path_buf) => path_buf.to_string_lossy().to_string(),
|
||||
Custom(str_) => str_.to_string(),
|
||||
_ => panic!("invalid filename"),
|
||||
|
@ -71,15 +71,15 @@ impl Into<Location> for swc_common::Loc {
|
|||
|
||||
Location {
|
||||
filename,
|
||||
line: self.line,
|
||||
col: self.col_display,
|
||||
line: swc_loc.line,
|
||||
col: swc_loc.col_display,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<ModuleSpecifier> for Location {
|
||||
fn into(self) -> ModuleSpecifier {
|
||||
resolve_url_or_path(&self.filename).unwrap()
|
||||
impl From<Location> for ModuleSpecifier {
|
||||
fn from(loc: Location) -> Self {
|
||||
resolve_url_or_path(&loc.filename).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,10 +174,10 @@ fn get_ts_config(tsx: bool, dts: bool) -> TsConfig {
|
|||
pub fn get_syntax(media_type: &MediaType) -> Syntax {
|
||||
match media_type {
|
||||
MediaType::JavaScript => Syntax::Es(get_es_config(false)),
|
||||
MediaType::JSX => Syntax::Es(get_es_config(true)),
|
||||
MediaType::Jsx => Syntax::Es(get_es_config(true)),
|
||||
MediaType::TypeScript => Syntax::Typescript(get_ts_config(false, false)),
|
||||
MediaType::Dts => Syntax::Typescript(get_ts_config(false, true)),
|
||||
MediaType::TSX => Syntax::Typescript(get_ts_config(true, false)),
|
||||
MediaType::Tsx => Syntax::Typescript(get_ts_config(true, false)),
|
||||
_ => Syntax::Es(get_es_config(false)),
|
||||
}
|
||||
}
|
||||
|
@ -429,10 +429,10 @@ pub fn parse_with_source_map(
|
|||
comments.with_leading(module.span.lo, |comments| comments.to_vec());
|
||||
|
||||
Ok(ParsedModule {
|
||||
comments,
|
||||
leading_comments,
|
||||
module,
|
||||
source_map,
|
||||
comments,
|
||||
source_file,
|
||||
})
|
||||
}
|
||||
|
@ -711,7 +711,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
"#;
|
||||
let module = parse(specifier.as_str(), source, &MediaType::TSX)
|
||||
let module = parse(specifier.as_str(), source, &MediaType::Tsx)
|
||||
.expect("could not parse module");
|
||||
let (code, _) = module
|
||||
.transpile(&EmitOptions::default())
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::Result;
|
||||
use std::{
|
||||
collections::HashMap, path::PathBuf, process::Command, time::Duration,
|
||||
};
|
||||
use std::{collections::HashMap, path::Path, process::Command, time::Duration};
|
||||
pub use test_util::{parse_wrk_output, WrkOutput as HttpBenchmarkResult};
|
||||
|
||||
// Some of the benchmarks in this file have been renamed. In case the history
|
||||
|
@ -15,7 +13,7 @@ pub use test_util::{parse_wrk_output, WrkOutput as HttpBenchmarkResult};
|
|||
const DURATION: &str = "20s";
|
||||
|
||||
pub(crate) fn benchmark(
|
||||
target_path: &PathBuf,
|
||||
target_path: &Path,
|
||||
) -> Result<HashMap<String, HttpBenchmarkResult>> {
|
||||
let deno_exe = test_util::deno_exe_path();
|
||||
let deno_exe = deno_exe.to_str().unwrap();
|
||||
|
|
|
@ -14,7 +14,7 @@ use std::collections::HashMap;
|
|||
use std::io::BufRead;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use std::process::ChildStdin;
|
||||
use std::process::ChildStdout;
|
||||
use std::process::Command;
|
||||
|
@ -135,7 +135,7 @@ impl Drop for LspClient {
|
|||
}
|
||||
|
||||
impl LspClient {
|
||||
fn new(deno_exe: &PathBuf) -> Result<Self, AnyError> {
|
||||
fn new(deno_exe: &Path) -> Result<Self, AnyError> {
|
||||
let mut child = Command::new(deno_exe)
|
||||
.arg("lsp")
|
||||
.stdin(Stdio::piped())
|
||||
|
@ -244,7 +244,7 @@ impl LspClient {
|
|||
/// A benchmark that opens a 8000+ line TypeScript document, adds a function to
|
||||
/// the end of the document and does a level of hovering and gets quick fix
|
||||
/// code actions.
|
||||
fn bench_big_file_edits(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
|
||||
fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
|
||||
let mut client = LspClient::new(deno_exe)?;
|
||||
|
||||
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
|
||||
|
@ -302,7 +302,7 @@ fn bench_big_file_edits(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
|
|||
}
|
||||
|
||||
/// A test that starts up the LSP, opens a single line document, and exits.
|
||||
fn bench_startup_shutdown(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
|
||||
fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
|
||||
let mut client = LspClient::new(deno_exe)?;
|
||||
|
||||
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
|
||||
|
@ -338,7 +338,7 @@ fn bench_startup_shutdown(deno_exe: &PathBuf) -> Result<Duration, AnyError> {
|
|||
|
||||
/// Generate benchmarks for the LSP server.
|
||||
pub(crate) fn benchmarks(
|
||||
deno_exe: &PathBuf,
|
||||
deno_exe: &Path,
|
||||
) -> Result<HashMap<String, u64>, AnyError> {
|
||||
println!("-> Start benchmarking lsp");
|
||||
let mut exec_times = HashMap::new();
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::collections::HashMap;
|
|||
use std::convert::From;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
|
@ -126,8 +127,8 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
|
|||
const RESULT_KEYS: &[&str] =
|
||||
&["mean", "stddev", "user", "system", "min", "max"];
|
||||
fn run_exec_time(
|
||||
deno_exe: &PathBuf,
|
||||
target_dir: &PathBuf,
|
||||
deno_exe: &Path,
|
||||
target_dir: &Path,
|
||||
) -> Result<HashMap<String, HashMap<String, f64>>> {
|
||||
let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine");
|
||||
|
||||
|
@ -218,7 +219,7 @@ fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> u64 {
|
|||
|
||||
const BINARY_TARGET_FILES: &[&str] =
|
||||
&["CLI_SNAPSHOT.bin", "COMPILER_SNAPSHOT.bin"];
|
||||
fn get_binary_sizes(target_dir: &PathBuf) -> Result<HashMap<String, u64>> {
|
||||
fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> {
|
||||
let mut sizes = HashMap::<String, u64>::new();
|
||||
let mut mtimes = HashMap::<String, SystemTime>::new();
|
||||
|
||||
|
@ -276,7 +277,7 @@ const BUNDLES: &[(&str, &str)] = &[
|
|||
("file_server", "./test_util/std/http/file_server.ts"),
|
||||
("gist", "./test_util/std/examples/gist.ts"),
|
||||
];
|
||||
fn bundle_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
|
||||
fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
|
||||
let mut sizes = HashMap::<String, u64>::new();
|
||||
|
||||
for (name, url) in BUNDLES {
|
||||
|
@ -304,7 +305,7 @@ fn bundle_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
|
|||
Ok(sizes)
|
||||
}
|
||||
|
||||
fn run_throughput(deno_exe: &PathBuf) -> Result<HashMap<String, f64>> {
|
||||
fn run_throughput(deno_exe: &Path) -> Result<HashMap<String, f64>> {
|
||||
let mut m = HashMap::<String, f64>::new();
|
||||
|
||||
m.insert("100M_tcp".to_string(), throughput::tcp(deno_exe, 100)?);
|
||||
|
@ -315,7 +316,7 @@ fn run_throughput(deno_exe: &PathBuf) -> Result<HashMap<String, f64>> {
|
|||
Ok(m)
|
||||
}
|
||||
|
||||
fn run_http(target_dir: &PathBuf, new_data: &mut BenchResult) -> Result<()> {
|
||||
fn run_http(target_dir: &Path, new_data: &mut BenchResult) -> Result<()> {
|
||||
let stats = http::benchmark(target_dir)?;
|
||||
|
||||
new_data.req_per_sec = stats
|
||||
|
@ -332,7 +333,7 @@ fn run_http(target_dir: &PathBuf, new_data: &mut BenchResult) -> Result<()> {
|
|||
}
|
||||
|
||||
fn run_strace_benchmarks(
|
||||
deno_exe: &PathBuf,
|
||||
deno_exe: &Path,
|
||||
new_data: &mut BenchResult,
|
||||
) -> Result<()> {
|
||||
use std::io::Read;
|
||||
|
@ -372,7 +373,7 @@ fn run_strace_benchmarks(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn run_max_mem_benchmark(deno_exe: &PathBuf) -> Result<HashMap<String, u64>> {
|
||||
fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
|
||||
let mut results = HashMap::<String, u64>::new();
|
||||
|
||||
for (name, args, return_code) in EXEC_TIME_BENCHMARKS {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::Result;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
path::Path,
|
||||
process::Command,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ const MB: usize = 1024 * 1024;
|
|||
const SERVER_ADDR: &str = "0.0.0.0:4544";
|
||||
const CLIENT_ADDR: &str = "127.0.0.1 4544";
|
||||
|
||||
pub(crate) fn cat(deno_exe: &PathBuf, megs: usize) -> f64 {
|
||||
pub(crate) fn cat(deno_exe: &Path, megs: usize) -> f64 {
|
||||
let size = megs * MB;
|
||||
let shell_cmd = format!(
|
||||
"{} run --allow-read cli/tests/cat.ts /dev/zero | head -c {}",
|
||||
|
@ -28,7 +28,7 @@ pub(crate) fn cat(deno_exe: &PathBuf, megs: usize) -> f64 {
|
|||
(end - start).as_secs_f64()
|
||||
}
|
||||
|
||||
pub(crate) fn tcp(deno_exe: &PathBuf, megs: usize) -> Result<f64> {
|
||||
pub(crate) fn tcp(deno_exe: &Path, megs: usize) -> Result<f64> {
|
||||
let size = megs * MB;
|
||||
|
||||
// The GNU flavor of `nc` requires the `-N` flag to shutdown the network socket after EOF on stdin
|
||||
|
|
|
@ -223,8 +223,8 @@ pub fn map_content_type(
|
|||
| "application/node" => {
|
||||
map_js_like_extension(specifier, MediaType::JavaScript)
|
||||
}
|
||||
"text/jsx" => MediaType::JSX,
|
||||
"text/tsx" => MediaType::TSX,
|
||||
"text/jsx" => MediaType::Jsx,
|
||||
"text/tsx" => MediaType::Tsx,
|
||||
"application/json" | "text/json" => MediaType::Json,
|
||||
"application/wasm" => MediaType::Wasm,
|
||||
// Handle plain and possibly webassembly
|
||||
|
@ -264,8 +264,8 @@ fn map_js_like_extension(
|
|||
None => default,
|
||||
Some(os_str) => match os_str.to_str() {
|
||||
None => default,
|
||||
Some("jsx") => MediaType::JSX,
|
||||
Some("tsx") => MediaType::TSX,
|
||||
Some("jsx") => MediaType::Jsx,
|
||||
Some("tsx") => MediaType::Tsx,
|
||||
// Because DTS files do not have a separate media type, or a unique
|
||||
// extension, we have to "guess" at those things that we consider that
|
||||
// look like TypeScript, and end with `.d.ts` are DTS files.
|
||||
|
@ -685,8 +685,8 @@ mod tests {
|
|||
("data:text/plain,Hello%2C%20Deno!", true, MediaType::Unknown, "text/plain", "Hello, Deno!"),
|
||||
("data:,Hello%2C%20Deno!", true, MediaType::Unknown, "", "Hello, Deno!"),
|
||||
("data:application/javascript,console.log(\"Hello, Deno!\");%0A", true, MediaType::JavaScript, "application/javascript", "console.log(\"Hello, Deno!\");\n"),
|
||||
("data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::JSX, "text/jsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
|
||||
("data:text/tsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::TSX, "text/tsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
|
||||
("data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::Jsx, "text/jsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
|
||||
("data:text/tsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo=", true, MediaType::Tsx, "text/tsx;base64", "export default function() {\n return <div>Hello Deno!</div>\n}\n"),
|
||||
];
|
||||
|
||||
for (
|
||||
|
@ -744,10 +744,10 @@ mod tests {
|
|||
let fixtures = vec![
|
||||
// Extension only
|
||||
(file_url!("/foo/bar.ts"), None, MediaType::TypeScript, None),
|
||||
(file_url!("/foo/bar.tsx"), None, MediaType::TSX, None),
|
||||
(file_url!("/foo/bar.tsx"), None, MediaType::Tsx, None),
|
||||
(file_url!("/foo/bar.d.ts"), None, MediaType::Dts, None),
|
||||
(file_url!("/foo/bar.js"), None, MediaType::JavaScript, None),
|
||||
(file_url!("/foo/bar.jsx"), None, MediaType::JSX, None),
|
||||
(file_url!("/foo/bar.jsx"), None, MediaType::Jsx, None),
|
||||
(file_url!("/foo/bar.json"), None, MediaType::Json, None),
|
||||
(file_url!("/foo/bar.wasm"), None, MediaType::Wasm, None),
|
||||
(file_url!("/foo/bar.cjs"), None, MediaType::JavaScript, None),
|
||||
|
@ -823,13 +823,13 @@ mod tests {
|
|||
(
|
||||
"https://deno.land/x/mod",
|
||||
Some("text/jsx".to_string()),
|
||||
MediaType::JSX,
|
||||
MediaType::Jsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"https://deno.land/x/mod",
|
||||
Some("text/tsx".to_string()),
|
||||
MediaType::TSX,
|
||||
MediaType::Tsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
|
@ -860,25 +860,25 @@ mod tests {
|
|||
(
|
||||
"https://deno.land/x/mod.tsx",
|
||||
Some("application/typescript".to_string()),
|
||||
MediaType::TSX,
|
||||
MediaType::Tsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"https://deno.land/x/mod.tsx",
|
||||
Some("application/javascript".to_string()),
|
||||
MediaType::TSX,
|
||||
MediaType::Tsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"https://deno.land/x/mod.jsx",
|
||||
Some("application/javascript".to_string()),
|
||||
MediaType::JSX,
|
||||
MediaType::Jsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"https://deno.land/x/mod.jsx",
|
||||
Some("application/x-typescript".to_string()),
|
||||
MediaType::JSX,
|
||||
MediaType::Jsx,
|
||||
None,
|
||||
),
|
||||
(
|
||||
|
|
|
@ -248,7 +248,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_collect_files() {
|
||||
fn create_files(dir_path: &PathBuf, files: &[&str]) {
|
||||
fn create_files(dir_path: &Path, files: &[&str]) {
|
||||
std::fs::create_dir(dir_path).expect("Failed to create directory");
|
||||
for f in files {
|
||||
let path = dir_path.join(f);
|
||||
|
|
|
@ -274,7 +274,7 @@ pub fn analyze_dependencies(
|
|||
let resolved_import =
|
||||
resolve_import(&import, specifier, maybe_import_map);
|
||||
if media_type == &MediaType::JavaScript
|
||||
|| media_type == &MediaType::JSX
|
||||
|| media_type == &MediaType::Jsx
|
||||
{
|
||||
maybe_type = Some(resolved_import)
|
||||
} else {
|
||||
|
@ -297,11 +297,7 @@ pub fn analyze_dependencies(
|
|||
let maybe_resolved_type_dependency =
|
||||
// Check for `@deno-types` pragmas that affect the import
|
||||
if let Some(comment) = desc.leading_comments.last() {
|
||||
if let Some(deno_types) = parse_deno_types(&comment.text).as_ref() {
|
||||
Some(resolve_import(deno_types, specifier, maybe_import_map))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
parse_deno_types(&comment.text).as_ref().map(|deno_types| resolve_import(deno_types, specifier, maybe_import_map))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
@ -461,31 +461,27 @@ fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String {
|
|||
fn to_lsp_related_information(
|
||||
related_information: &Option<Vec<diagnostics::Diagnostic>>,
|
||||
) -> Option<Vec<lsp::DiagnosticRelatedInformation>> {
|
||||
if let Some(related) = related_information {
|
||||
Some(
|
||||
related
|
||||
.iter()
|
||||
.filter_map(|ri| {
|
||||
if let (Some(source), Some(start), Some(end)) =
|
||||
(&ri.source, &ri.start, &ri.end)
|
||||
{
|
||||
let uri = lsp::Url::parse(&source).unwrap();
|
||||
Some(lsp::DiagnosticRelatedInformation {
|
||||
location: lsp::Location {
|
||||
uri,
|
||||
range: to_lsp_range(start, end),
|
||||
},
|
||||
message: get_diagnostic_message(&ri),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
related_information.as_ref().map(|related| {
|
||||
related
|
||||
.iter()
|
||||
.filter_map(|ri| {
|
||||
if let (Some(source), Some(start), Some(end)) =
|
||||
(&ri.source, &ri.start, &ri.end)
|
||||
{
|
||||
let uri = lsp::Url::parse(&source).unwrap();
|
||||
Some(lsp::DiagnosticRelatedInformation {
|
||||
location: lsp::Location {
|
||||
uri,
|
||||
range: to_lsp_range(start, end),
|
||||
},
|
||||
message: get_diagnostic_message(&ri),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn ts_json_to_diagnostics(
|
||||
|
|
|
@ -154,7 +154,7 @@ impl DocumentCache {
|
|||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.docs.iter().count()
|
||||
self.docs.len()
|
||||
}
|
||||
|
||||
pub fn line_index(&self, specifier: &ModuleSpecifier) -> Option<LineIndex> {
|
||||
|
|
|
@ -166,11 +166,7 @@ pub async fn get_asset(
|
|||
.request(state_snapshot, RequestMethod::GetAsset(specifier.clone()))
|
||||
.await?;
|
||||
let maybe_text: Option<String> = serde_json::from_value(res)?;
|
||||
let maybe_asset = if let Some(text) = maybe_text {
|
||||
Some(AssetDocument::new(text))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let maybe_asset = maybe_text.map(AssetDocument::new);
|
||||
Ok(maybe_asset)
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +179,7 @@ fn display_parts_to_string(parts: &[SymbolDisplayPart]) -> String {
|
|||
.join("")
|
||||
}
|
||||
|
||||
fn get_tag_body_text(tag: &JSDocTagInfo) -> Option<String> {
|
||||
fn get_tag_body_text(tag: &JsDocTagInfo) -> Option<String> {
|
||||
tag.text.as_ref().map(|text| match tag.name.as_str() {
|
||||
"example" => {
|
||||
let caption_regex =
|
||||
|
@ -209,7 +205,7 @@ fn get_tag_body_text(tag: &JSDocTagInfo) -> Option<String> {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_tag_documentation(tag: &JSDocTagInfo) -> String {
|
||||
fn get_tag_documentation(tag: &JsDocTagInfo) -> String {
|
||||
match tag.name.as_str() {
|
||||
"augments" | "extends" | "param" | "template" => {
|
||||
if let Some(text) = &tag.text {
|
||||
|
@ -439,7 +435,7 @@ pub struct SymbolDisplayPart {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct JSDocTagInfo {
|
||||
pub struct JsDocTagInfo {
|
||||
name: String,
|
||||
text: Option<String>,
|
||||
}
|
||||
|
@ -452,7 +448,7 @@ pub struct QuickInfo {
|
|||
text_span: TextSpan,
|
||||
display_parts: Option<Vec<SymbolDisplayPart>>,
|
||||
documentation: Option<Vec<SymbolDisplayPart>>,
|
||||
tags: Option<Vec<JSDocTagInfo>>,
|
||||
tags: Option<Vec<JsDocTagInfo>>,
|
||||
}
|
||||
|
||||
impl QuickInfo {
|
||||
|
@ -536,10 +532,11 @@ impl DocumentSpan {
|
|||
let origin_selection_range =
|
||||
if let Some(original_context_span) = &self.original_context_span {
|
||||
Some(original_context_span.to_range(line_index))
|
||||
} else if let Some(original_text_span) = &self.original_text_span {
|
||||
Some(original_text_span.to_range(line_index))
|
||||
} else {
|
||||
None
|
||||
self
|
||||
.original_text_span
|
||||
.as_ref()
|
||||
.map(|original_text_span| original_text_span.to_range(line_index))
|
||||
};
|
||||
let link = lsp::LocationLink {
|
||||
origin_selection_range,
|
||||
|
@ -927,7 +924,7 @@ pub struct CompletionEntryDetails {
|
|||
kind_modifiers: String,
|
||||
display_parts: Vec<SymbolDisplayPart>,
|
||||
documentation: Option<Vec<SymbolDisplayPart>>,
|
||||
tags: Option<Vec<JSDocTagInfo>>,
|
||||
tags: Option<Vec<JsDocTagInfo>>,
|
||||
code_actions: Option<Vec<CodeAction>>,
|
||||
source: Option<Vec<SymbolDisplayPart>>,
|
||||
}
|
||||
|
@ -1261,7 +1258,7 @@ pub struct SignatureHelpItem {
|
|||
separator_display_parts: Vec<SymbolDisplayPart>,
|
||||
parameters: Vec<SignatureHelpParameter>,
|
||||
documentation: Vec<SymbolDisplayPart>,
|
||||
tags: Vec<JSDocTagInfo>,
|
||||
tags: Vec<JsDocTagInfo>,
|
||||
}
|
||||
|
||||
impl SignatureHelpItem {
|
||||
|
@ -1328,12 +1325,9 @@ impl SelectionRange {
|
|||
) -> lsp::SelectionRange {
|
||||
lsp::SelectionRange {
|
||||
range: self.text_span.to_range(line_index),
|
||||
parent: match &self.parent {
|
||||
Some(parent_selection) => {
|
||||
Some(Box::new(parent_selection.to_selection_range(line_index)))
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
parent: self.parent.as_ref().map(|parent_selection| {
|
||||
Box::new(parent_selection.to_selection_range(line_index))
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1345,6 +1339,7 @@ struct Response {
|
|||
}
|
||||
|
||||
struct State<'a> {
|
||||
#[allow(unused)]
|
||||
asset: Option<String>,
|
||||
last_id: usize,
|
||||
response: Option<Response>,
|
||||
|
|
|
@ -497,11 +497,11 @@ async fn eval_command(
|
|||
media_type: if ext.as_str() == "ts" {
|
||||
MediaType::TypeScript
|
||||
} else if ext.as_str() == "tsx" {
|
||||
MediaType::TSX
|
||||
MediaType::Tsx
|
||||
} else if ext.as_str() == "js" {
|
||||
MediaType::JavaScript
|
||||
} else {
|
||||
MediaType::JSX
|
||||
MediaType::Jsx
|
||||
},
|
||||
source: String::from_utf8(source_code)?,
|
||||
specifier: main_module.clone(),
|
||||
|
|
|
@ -14,10 +14,10 @@ use std::path::PathBuf;
|
|||
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||
pub enum MediaType {
|
||||
JavaScript = 0,
|
||||
JSX = 1,
|
||||
Jsx = 1,
|
||||
TypeScript = 2,
|
||||
Dts = 3,
|
||||
TSX = 4,
|
||||
Tsx = 4,
|
||||
Json = 5,
|
||||
Wasm = 6,
|
||||
TsBuildInfo = 7,
|
||||
|
@ -29,10 +29,10 @@ impl fmt::Display for MediaType {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let value = match self {
|
||||
MediaType::JavaScript => "JavaScript",
|
||||
MediaType::JSX => "JSX",
|
||||
MediaType::Jsx => "JSX",
|
||||
MediaType::TypeScript => "TypeScript",
|
||||
MediaType::Dts => "Dts",
|
||||
MediaType::TSX => "TSX",
|
||||
MediaType::Tsx => "TSX",
|
||||
MediaType::Json => "Json",
|
||||
MediaType::Wasm => "Wasm",
|
||||
MediaType::TsBuildInfo => "TsBuildInfo",
|
||||
|
@ -103,9 +103,9 @@ impl MediaType {
|
|||
}
|
||||
MediaType::TypeScript
|
||||
}
|
||||
Some("tsx") => MediaType::TSX,
|
||||
Some("tsx") => MediaType::Tsx,
|
||||
Some("js") => MediaType::JavaScript,
|
||||
Some("jsx") => MediaType::JSX,
|
||||
Some("jsx") => MediaType::Jsx,
|
||||
Some("mjs") => MediaType::JavaScript,
|
||||
Some("cjs") => MediaType::JavaScript,
|
||||
Some("json") => MediaType::Json,
|
||||
|
@ -124,10 +124,10 @@ impl MediaType {
|
|||
pub fn as_ts_extension(&self) -> &str {
|
||||
match self {
|
||||
MediaType::JavaScript => ".js",
|
||||
MediaType::JSX => ".jsx",
|
||||
MediaType::Jsx => ".jsx",
|
||||
MediaType::TypeScript => ".ts",
|
||||
MediaType::Dts => ".d.ts",
|
||||
MediaType::TSX => ".tsx",
|
||||
MediaType::Tsx => ".tsx",
|
||||
MediaType::Json => ".json",
|
||||
// TypeScript doesn't have an "unknown", so we will treat WASM as JS for
|
||||
// mapping purposes, though in reality, it is unlikely to ever be passed
|
||||
|
@ -149,10 +149,10 @@ impl MediaType {
|
|||
pub fn as_ts_script_kind(&self) -> i32 {
|
||||
match self {
|
||||
MediaType::JavaScript => 1,
|
||||
MediaType::JSX => 2,
|
||||
MediaType::Jsx => 2,
|
||||
MediaType::TypeScript => 3,
|
||||
MediaType::Dts => 3,
|
||||
MediaType::TSX => 4,
|
||||
MediaType::Tsx => 4,
|
||||
MediaType::Json => 5,
|
||||
_ => 0,
|
||||
}
|
||||
|
@ -166,10 +166,10 @@ impl Serialize for MediaType {
|
|||
{
|
||||
let value = match self {
|
||||
MediaType::JavaScript => 0_i32,
|
||||
MediaType::JSX => 1_i32,
|
||||
MediaType::Jsx => 1_i32,
|
||||
MediaType::TypeScript => 2_i32,
|
||||
MediaType::Dts => 3_i32,
|
||||
MediaType::TSX => 4_i32,
|
||||
MediaType::Tsx => 4_i32,
|
||||
MediaType::Json => 5_i32,
|
||||
MediaType::Wasm => 6_i32,
|
||||
MediaType::TsBuildInfo => 7_i32,
|
||||
|
@ -208,13 +208,13 @@ mod tests {
|
|||
MediaType::from(Path::new("foo/bar.ts")),
|
||||
MediaType::TypeScript
|
||||
);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.tsx")), MediaType::TSX);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.tsx")), MediaType::Tsx);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.d.ts")), MediaType::Dts);
|
||||
assert_eq!(
|
||||
MediaType::from(Path::new("foo/bar.js")),
|
||||
MediaType::JavaScript
|
||||
);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.jsx")), MediaType::JSX);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.jsx")), MediaType::Jsx);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.json")), MediaType::Json);
|
||||
assert_eq!(MediaType::from(Path::new("foo/bar.wasm")), MediaType::Wasm);
|
||||
assert_eq!(
|
||||
|
@ -256,10 +256,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_serialization() {
|
||||
assert_eq!(json!(MediaType::JavaScript), json!(0));
|
||||
assert_eq!(json!(MediaType::JSX), json!(1));
|
||||
assert_eq!(json!(MediaType::Jsx), json!(1));
|
||||
assert_eq!(json!(MediaType::TypeScript), json!(2));
|
||||
assert_eq!(json!(MediaType::Dts), json!(3));
|
||||
assert_eq!(json!(MediaType::TSX), json!(4));
|
||||
assert_eq!(json!(MediaType::Tsx), json!(4));
|
||||
assert_eq!(json!(MediaType::Json), json!(5));
|
||||
assert_eq!(json!(MediaType::Wasm), json!(6));
|
||||
assert_eq!(json!(MediaType::TsBuildInfo), json!(7));
|
||||
|
@ -270,10 +270,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_display() {
|
||||
assert_eq!(MediaType::JavaScript.to_string(), "JavaScript");
|
||||
assert_eq!(MediaType::JSX.to_string(), "JSX");
|
||||
assert_eq!(MediaType::Jsx.to_string(), "JSX");
|
||||
assert_eq!(MediaType::TypeScript.to_string(), "TypeScript");
|
||||
assert_eq!(MediaType::Dts.to_string(), "Dts");
|
||||
assert_eq!(MediaType::TSX.to_string(), "TSX");
|
||||
assert_eq!(MediaType::Tsx.to_string(), "TSX");
|
||||
assert_eq!(MediaType::Json.to_string(), "Json");
|
||||
assert_eq!(MediaType::Wasm.to_string(), "Wasm");
|
||||
assert_eq!(MediaType::TsBuildInfo.to_string(), "TsBuildInfo");
|
||||
|
|
|
@ -197,12 +197,10 @@ pub fn parse_ts_reference(comment: &str) -> Option<TypeScriptReference> {
|
|||
Some(TypeScriptReference::Path(
|
||||
captures.get(1).unwrap().as_str().to_string(),
|
||||
))
|
||||
} else if let Some(captures) = TYPES_REFERENCE_RE.captures(comment) {
|
||||
Some(TypeScriptReference::Types(
|
||||
captures.get(1).unwrap().as_str().to_string(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
TYPES_REFERENCE_RE.captures(comment).map(|captures| {
|
||||
TypeScriptReference::Types(captures.get(1).unwrap().as_str().to_string())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,17 +298,14 @@ impl Module {
|
|||
module.is_parsed = true;
|
||||
}
|
||||
}
|
||||
module.maybe_types = if let Some(ref specifier) = cached_module.maybe_types
|
||||
{
|
||||
Some((
|
||||
module.maybe_types = cached_module.maybe_types.map(|specifier| {
|
||||
(
|
||||
specifier.clone(),
|
||||
module
|
||||
.resolve_import(&specifier, None)
|
||||
.expect("could not resolve module"),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
)
|
||||
});
|
||||
module
|
||||
}
|
||||
|
||||
|
@ -348,7 +343,7 @@ impl Module {
|
|||
let specifier =
|
||||
self.resolve_import(&import, Some(location.clone()))?;
|
||||
if self.media_type == MediaType::JavaScript
|
||||
|| self.media_type == MediaType::JSX
|
||||
|| self.media_type == MediaType::Jsx
|
||||
{
|
||||
// TODO(kitsonk) we need to specifically update the cache when
|
||||
// this value changes
|
||||
|
@ -1073,8 +1068,8 @@ impl Graph {
|
|||
for (_, module_slot) in self.modules.iter_mut() {
|
||||
if let ModuleSlot::Module(module) = module_slot {
|
||||
if !(emit_options.check_js
|
||||
|| module.media_type == MediaType::JSX
|
||||
|| module.media_type == MediaType::TSX
|
||||
|| module.media_type == MediaType::Jsx
|
||||
|| module.media_type == MediaType::Tsx
|
||||
|| module.media_type == MediaType::TypeScript)
|
||||
{
|
||||
emitted_files
|
||||
|
@ -1274,9 +1269,9 @@ impl Graph {
|
|||
let mut specifiers = HashSet::<&ModuleSpecifier>::new();
|
||||
for (_, module_slot) in self.modules.iter() {
|
||||
if let ModuleSlot::Module(module) = module_slot {
|
||||
if module.media_type == MediaType::JSX
|
||||
if module.media_type == MediaType::Jsx
|
||||
|| module.media_type == MediaType::TypeScript
|
||||
|| module.media_type == MediaType::TSX
|
||||
|| module.media_type == MediaType::Tsx
|
||||
{
|
||||
specifiers.insert(&module.specifier);
|
||||
}
|
||||
|
@ -1418,7 +1413,7 @@ impl Graph {
|
|||
self.modules.iter().all(|(_, m)| {
|
||||
if let ModuleSlot::Module(m) = m {
|
||||
let needs_emit = match m.media_type {
|
||||
MediaType::TypeScript | MediaType::TSX | MediaType::JSX => true,
|
||||
MediaType::TypeScript | MediaType::Tsx | MediaType::Jsx => true,
|
||||
MediaType::JavaScript => check_js,
|
||||
_ => false,
|
||||
};
|
||||
|
@ -1462,7 +1457,7 @@ impl Graph {
|
|||
let check_js = config.get_check_js();
|
||||
self.modules.iter().any(|(_, m)| match m {
|
||||
ModuleSlot::Module(m) => match m.media_type {
|
||||
MediaType::TypeScript | MediaType::TSX | MediaType::JSX => true,
|
||||
MediaType::TypeScript | MediaType::Tsx | MediaType::Jsx => true,
|
||||
MediaType::JavaScript => check_js,
|
||||
_ => false,
|
||||
},
|
||||
|
@ -1618,8 +1613,8 @@ impl Graph {
|
|||
// if we don't have check_js enabled, we won't touch non TypeScript or JSX
|
||||
// modules
|
||||
if !(emit_options.check_js
|
||||
|| module.media_type == MediaType::JSX
|
||||
|| module.media_type == MediaType::TSX
|
||||
|| module.media_type == MediaType::Jsx
|
||||
|| module.media_type == MediaType::Tsx
|
||||
|| module.media_type == MediaType::TypeScript)
|
||||
{
|
||||
continue;
|
||||
|
@ -1734,11 +1729,8 @@ impl GraphBuilder {
|
|||
maybe_import_map: Option<ImportMap>,
|
||||
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
|
||||
) -> Self {
|
||||
let internal_import_map = if let Some(import_map) = maybe_import_map {
|
||||
Some(Arc::new(Mutex::new(import_map)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let internal_import_map =
|
||||
maybe_import_map.map(|import_map| Arc::new(Mutex::new(import_map)));
|
||||
GraphBuilder {
|
||||
graph: Graph::new(handler, maybe_lockfile),
|
||||
maybe_import_map: internal_import_map,
|
||||
|
@ -2069,8 +2061,8 @@ pub mod tests {
|
|||
let source = "console.log(42);".to_string();
|
||||
let maybe_version = Some(get_version(&source, &version::deno(), b""));
|
||||
let module = Module {
|
||||
source,
|
||||
maybe_version,
|
||||
source,
|
||||
..Module::default()
|
||||
};
|
||||
assert!(module.is_emit_valid(b""));
|
||||
|
@ -2079,8 +2071,8 @@ pub mod tests {
|
|||
let old_source = "console.log(43);";
|
||||
let maybe_version = Some(get_version(old_source, &version::deno(), b""));
|
||||
let module = Module {
|
||||
source,
|
||||
maybe_version,
|
||||
source,
|
||||
..Module::default()
|
||||
};
|
||||
assert!(!module.is_emit_valid(b""));
|
||||
|
@ -2088,8 +2080,8 @@ pub mod tests {
|
|||
let source = "console.log(42);".to_string();
|
||||
let maybe_version = Some(get_version(&source, "0.0.0", b""));
|
||||
let module = Module {
|
||||
source,
|
||||
maybe_version,
|
||||
source,
|
||||
..Module::default()
|
||||
};
|
||||
assert!(!module.is_emit_valid(b""));
|
||||
|
|
|
@ -110,13 +110,9 @@ impl ProgramState {
|
|||
};
|
||||
|
||||
let maybe_inspect_host = flags.inspect.or(flags.inspect_brk);
|
||||
let maybe_inspector_server = match maybe_inspect_host {
|
||||
Some(host) => Some(Arc::new(InspectorServer::new(
|
||||
host,
|
||||
version::get_user_agent(),
|
||||
))),
|
||||
None => None,
|
||||
};
|
||||
let maybe_inspector_server = maybe_inspect_host.map(|host| {
|
||||
Arc::new(InspectorServer::new(host, version::get_user_agent()))
|
||||
});
|
||||
|
||||
let coverage_dir = flags
|
||||
.coverage_dir
|
||||
|
|
|
@ -48,11 +48,7 @@ pub fn apply_source_map<G: SourceMapGetter>(
|
|||
// source file map.
|
||||
let end_column = match js_error.end_column {
|
||||
Some(ec) => {
|
||||
if let Some(sc) = start_column {
|
||||
Some(ec - (js_error.start_column.unwrap() - sc))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
start_column.map(|sc| ec - (js_error.start_column.unwrap() - sc))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
|
|
@ -157,11 +157,8 @@ impl CoverageReporter for LcovCoverageReporter {
|
|||
) {
|
||||
// TODO(caspervonb) cleanup and reduce duplication between reporters, pre-compute line coverage
|
||||
// elsewhere.
|
||||
let maybe_source_map = if let Some(source_map) = maybe_source_map {
|
||||
Some(SourceMap::from_slice(&source_map).unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let maybe_source_map = maybe_source_map
|
||||
.map(|source_map| SourceMap::from_slice(&source_map).unwrap());
|
||||
|
||||
let url = Url::parse(&script_coverage.url).unwrap();
|
||||
let file_path = url.to_file_path().unwrap();
|
||||
|
@ -374,11 +371,8 @@ impl CoverageReporter for PrettyCoverageReporter {
|
|||
maybe_source_map: Option<Vec<u8>>,
|
||||
maybe_original_source: Option<String>,
|
||||
) {
|
||||
let maybe_source_map = if let Some(source_map) = maybe_source_map {
|
||||
Some(SourceMap::from_slice(&source_map).unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let maybe_source_map = maybe_source_map
|
||||
.map(|source_map| SourceMap::from_slice(&source_map).unwrap());
|
||||
|
||||
let mut ignored_spans: Vec<Span> = Vec::new();
|
||||
for item in ast::lex("", script_source, &MediaType::JavaScript) {
|
||||
|
|
|
@ -14,6 +14,7 @@ use std::io;
|
|||
use std::io::Write;
|
||||
#[cfg(not(windows))]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -318,7 +319,7 @@ pub fn install(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn is_in_path(dir: &PathBuf) -> bool {
|
||||
fn is_in_path(dir: &Path) -> bool {
|
||||
if let Some(paths) = env::var_os("PATH") {
|
||||
for p in env::split_paths(&paths) {
|
||||
if *dir == p {
|
||||
|
|
|
@ -6,7 +6,6 @@ use deno_core::error::AnyError;
|
|||
use deno_core::serde_json::json;
|
||||
use deno_core::url::Url;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn is_supported(p: &Path) -> bool {
|
||||
use std::path::Component;
|
||||
|
@ -34,7 +33,7 @@ fn is_supported(p: &Path) -> bool {
|
|||
|
||||
pub fn prepare_test_modules_urls(
|
||||
include: Vec<String>,
|
||||
root_path: &PathBuf,
|
||||
root_path: &Path,
|
||||
) -> Result<Vec<Url>, AnyError> {
|
||||
let (include_paths, include_urls): (Vec<String>, Vec<String>) =
|
||||
include.into_iter().partition(|n| !is_remote_url(n));
|
||||
|
|
|
@ -134,9 +134,9 @@ fn get_tsc_media_type(specifier: &ModuleSpecifier) -> MediaType {
|
|||
}
|
||||
MediaType::TypeScript
|
||||
}
|
||||
Some("tsx") => MediaType::TSX,
|
||||
Some("tsx") => MediaType::Tsx,
|
||||
Some("js") => MediaType::JavaScript,
|
||||
Some("jsx") => MediaType::JSX,
|
||||
Some("jsx") => MediaType::Jsx,
|
||||
_ => MediaType::Unknown,
|
||||
},
|
||||
}
|
||||
|
@ -634,10 +634,10 @@ mod tests {
|
|||
fn test_get_tsc_media_type() {
|
||||
let fixtures = vec![
|
||||
("file:///a.ts", MediaType::TypeScript),
|
||||
("file:///a.tsx", MediaType::TSX),
|
||||
("file:///a.tsx", MediaType::Tsx),
|
||||
("file:///a.d.ts", MediaType::Dts),
|
||||
("file:///a.js", MediaType::JavaScript),
|
||||
("file:///a.jsx", MediaType::JSX),
|
||||
("file:///a.jsx", MediaType::Jsx),
|
||||
("file:///a.cjs", MediaType::Unknown),
|
||||
("file:///a.mjs", MediaType::Unknown),
|
||||
("file:///a.json", MediaType::Unknown),
|
||||
|
|
|
@ -175,7 +175,7 @@ fn jsonc_to_serde(j: JsonValue) -> Value {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct TSConfigJson {
|
||||
struct TsConfigJson {
|
||||
compiler_options: Option<HashMap<String, Value>>,
|
||||
exclude: Option<Vec<String>>,
|
||||
extends: Option<String>,
|
||||
|
@ -221,7 +221,7 @@ pub fn parse_config(
|
|||
) -> Result<(Value, Option<IgnoredCompilerOptions>), AnyError> {
|
||||
assert!(!config_text.is_empty());
|
||||
let jsonc = jsonc_parser::parse_to_value(config_text)?.unwrap();
|
||||
let config: TSConfigJson = serde_json::from_value(jsonc_to_serde(jsonc))?;
|
||||
let config: TsConfigJson = serde_json::from_value(jsonc_to_serde(jsonc))?;
|
||||
|
||||
if let Some(compiler_options) = config.compiler_options {
|
||||
parse_compiler_options(&compiler_options, Some(path.to_owned()), false)
|
||||
|
|
|
@ -39,12 +39,12 @@ pub struct ResponseHeader {
|
|||
pub result: u32,
|
||||
}
|
||||
|
||||
impl Into<[u8; 16]> for ResponseHeader {
|
||||
fn into(self) -> [u8; 16] {
|
||||
impl From<ResponseHeader> for [u8; 16] {
|
||||
fn from(r: ResponseHeader) -> Self {
|
||||
let mut resp_header = [0u8; 16];
|
||||
resp_header[0..8].copy_from_slice(&self.request_id.to_le_bytes());
|
||||
resp_header[8..12].copy_from_slice(&self.status.to_le_bytes());
|
||||
resp_header[12..16].copy_from_slice(&self.result.to_le_bytes());
|
||||
resp_header[0..8].copy_from_slice(&r.request_id.to_le_bytes());
|
||||
resp_header[8..12].copy_from_slice(&r.status.to_le_bytes());
|
||||
resp_header[12..16].copy_from_slice(&r.result.to_le_bytes());
|
||||
resp_header
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,8 +201,8 @@ impl JsRuntime {
|
|||
DENO_INIT.call_once(|| {
|
||||
// Include 10MB ICU data file.
|
||||
#[repr(C, align(16))]
|
||||
struct ICUData([u8; 10413584]);
|
||||
static ICU_DATA: ICUData = ICUData(*include_bytes!("icudtl.dat"));
|
||||
struct IcuData([u8; 10413584]);
|
||||
static ICU_DATA: IcuData = IcuData(*include_bytes!("icudtl.dat"));
|
||||
v8::icu::set_common_data(&ICU_DATA.0).unwrap();
|
||||
unsafe { v8_init() };
|
||||
});
|
||||
|
|
|
@ -10,19 +10,19 @@ use deno_core::{OpState, Resource};
|
|||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUBindGroupLayout(
|
||||
pub(crate) struct WebGpuBindGroupLayout(
|
||||
pub(crate) wgpu_core::id::BindGroupLayoutId,
|
||||
);
|
||||
impl Resource for WebGPUBindGroupLayout {
|
||||
impl Resource for WebGpuBindGroupLayout {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUBindGroupLayout".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPUBindGroup(pub(crate) wgpu_core::id::BindGroupId);
|
||||
impl Resource for WebGPUBindGroup {
|
||||
pub(crate) struct WebGpuBindGroup(pub(crate) wgpu_core::id::BindGroupId);
|
||||
impl Resource for WebGpuBindGroup {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUBindGroup".into()
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ impl Resource for WebGPUBindGroup {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUBufferBindingLayout {
|
||||
struct GpuBufferBindingLayout {
|
||||
#[serde(rename = "type")]
|
||||
kind: Option<String>,
|
||||
has_dynamic_offset: Option<bool>,
|
||||
|
@ -39,14 +39,14 @@ struct GPUBufferBindingLayout {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUSamplerBindingLayout {
|
||||
struct GpuSamplerBindingLayout {
|
||||
#[serde(rename = "type")]
|
||||
kind: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUTextureBindingLayout {
|
||||
struct GpuTextureBindingLayout {
|
||||
sample_type: Option<String>,
|
||||
view_dimension: Option<String>,
|
||||
multisampled: Option<bool>,
|
||||
|
@ -54,7 +54,7 @@ struct GPUTextureBindingLayout {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUStorageTextureBindingLayout {
|
||||
struct GpuStorageTextureBindingLayout {
|
||||
access: String,
|
||||
format: String,
|
||||
view_dimension: Option<String>,
|
||||
|
@ -62,13 +62,13 @@ struct GPUStorageTextureBindingLayout {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUBindGroupLayoutEntry {
|
||||
struct GpuBindGroupLayoutEntry {
|
||||
binding: u32,
|
||||
visibility: u32,
|
||||
buffer: Option<GPUBufferBindingLayout>,
|
||||
sampler: Option<GPUSamplerBindingLayout>,
|
||||
texture: Option<GPUTextureBindingLayout>,
|
||||
storage_texture: Option<GPUStorageTextureBindingLayout>,
|
||||
buffer: Option<GpuBufferBindingLayout>,
|
||||
sampler: Option<GpuSamplerBindingLayout>,
|
||||
texture: Option<GpuTextureBindingLayout>,
|
||||
storage_texture: Option<GpuStorageTextureBindingLayout>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -76,7 +76,7 @@ struct GPUBindGroupLayoutEntry {
|
|||
pub struct CreateBindGroupLayoutArgs {
|
||||
device_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
entries: Vec<GPUBindGroupLayoutEntry>,
|
||||
entries: Vec<GpuBindGroupLayoutEntry>,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_create_bind_group_layout(
|
||||
|
@ -87,7 +87,7 @@ pub fn op_webgpu_create_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -205,11 +205,11 @@ pub fn op_webgpu_create_bind_group_layout(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPUBindGroupLayout(bind_group_layout));
|
||||
.add(WebGpuBindGroupLayout(bind_group_layout));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ pub fn op_webgpu_create_pipeline_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -238,7 +238,7 @@ pub fn op_webgpu_create_pipeline_layout(
|
|||
for rid in &args.bind_group_layouts {
|
||||
let bind_group_layout = state
|
||||
.resource_table
|
||||
.get::<WebGPUBindGroupLayout>(*rid)
|
||||
.get::<WebGpuBindGroupLayout>(*rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
bind_group_layouts.push(bind_group_layout.0);
|
||||
}
|
||||
|
@ -257,17 +257,17 @@ pub fn op_webgpu_create_pipeline_layout(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(super::pipeline::WebGPUPipelineLayout(pipeline_layout));
|
||||
.add(super::pipeline::WebGpuPipelineLayout(pipeline_layout));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUBindGroupEntry {
|
||||
struct GpuBindGroupEntry {
|
||||
binding: u32,
|
||||
kind: String,
|
||||
resource: u32,
|
||||
|
@ -281,7 +281,7 @@ pub struct CreateBindGroupArgs {
|
|||
device_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
layout: u32,
|
||||
entries: Vec<GPUBindGroupEntry>,
|
||||
entries: Vec<GpuBindGroupEntry>,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_create_bind_group(
|
||||
|
@ -292,7 +292,7 @@ pub fn op_webgpu_create_bind_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -305,14 +305,14 @@ pub fn op_webgpu_create_bind_group(
|
|||
"GPUSampler" => {
|
||||
let sampler_resource = state
|
||||
.resource_table
|
||||
.get::<super::sampler::WebGPUSampler>(entry.resource)
|
||||
.get::<super::sampler::WebGpuSampler>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
wgpu_core::binding_model::BindingResource::Sampler(sampler_resource.0)
|
||||
}
|
||||
"GPUTextureView" => {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTextureView>(entry.resource)
|
||||
.get::<super::texture::WebGpuTextureView>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
wgpu_core::binding_model::BindingResource::TextureView(
|
||||
texture_view_resource.0,
|
||||
|
@ -321,7 +321,7 @@ pub fn op_webgpu_create_bind_group(
|
|||
"GPUBufferBinding" => {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(entry.resource)
|
||||
.get::<super::buffer::WebGpuBuffer>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
wgpu_core::binding_model::BindingResource::Buffer(
|
||||
wgpu_core::binding_model::BufferBinding {
|
||||
|
@ -339,7 +339,7 @@ pub fn op_webgpu_create_bind_group(
|
|||
|
||||
let bind_group_layout = state
|
||||
.resource_table
|
||||
.get::<WebGPUBindGroupLayout>(args.layout)
|
||||
.get::<WebGpuBindGroupLayout>(args.layout)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let descriptor = wgpu_core::binding_model::BindGroupDescriptor {
|
||||
|
@ -354,10 +354,10 @@ pub fn op_webgpu_create_bind_group(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUBindGroup(bind_group));
|
||||
let rid = state.resource_table.add(WebGpuBindGroup(bind_group));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -15,18 +15,18 @@ use std::cell::RefCell;
|
|||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::error::DOMExceptionOperationError;
|
||||
use super::error::WebGPUError;
|
||||
use super::error::DomExceptionOperationError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUBuffer(pub(crate) wgpu_core::id::BufferId);
|
||||
impl Resource for WebGPUBuffer {
|
||||
pub(crate) struct WebGpuBuffer(pub(crate) wgpu_core::id::BufferId);
|
||||
impl Resource for WebGpuBuffer {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUBuffer".into()
|
||||
}
|
||||
}
|
||||
|
||||
struct WebGPUBufferMapped(*mut u8, usize);
|
||||
impl Resource for WebGPUBufferMapped {
|
||||
struct WebGpuBufferMapped(*mut u8, usize);
|
||||
impl Resource for WebGpuBufferMapped {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUBufferMapped".into()
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ pub fn op_webgpu_create_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -67,11 +67,11 @@ pub fn op_webgpu_create_buffer(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUBuffer(buffer));
|
||||
let rid = state.resource_table.add(WebGpuBuffer(buffer));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -98,12 +98,12 @@ pub async fn op_webgpu_buffer_get_map_async(
|
|||
let instance = state_.borrow::<super::Instance>();
|
||||
let buffer_resource = state_
|
||||
.resource_table
|
||||
.get::<WebGPUBuffer>(args.buffer_rid)
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer = buffer_resource.0;
|
||||
let device_resource = state_
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
device = device_resource.0;
|
||||
|
||||
|
@ -182,7 +182,7 @@ pub fn op_webgpu_buffer_get_mapped_range(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUBuffer>(args.buffer_rid)
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer = buffer_resource.0;
|
||||
|
||||
|
@ -191,7 +191,7 @@ pub fn op_webgpu_buffer_get_mapped_range(
|
|||
args.offset,
|
||||
std::num::NonZeroU64::new(args.size)
|
||||
))
|
||||
.map_err(|e| DOMExceptionOperationError::new(&e.to_string()))?;
|
||||
.map_err(|e| DomExceptionOperationError::new(&e.to_string()))?;
|
||||
|
||||
let slice = unsafe {
|
||||
std::slice::from_raw_parts_mut(slice_pointer, args.size as usize)
|
||||
|
@ -200,7 +200,7 @@ pub fn op_webgpu_buffer_get_mapped_range(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPUBufferMapped(slice_pointer, args.size as usize));
|
||||
.add(WebGpuBufferMapped(slice_pointer, args.size as usize));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
|
@ -221,12 +221,12 @@ pub fn op_webgpu_buffer_unmap(
|
|||
) -> Result<Value, AnyError> {
|
||||
let mapped_resource = state
|
||||
.resource_table
|
||||
.take::<WebGPUBufferMapped>(args.mapped_rid)
|
||||
.take::<WebGpuBufferMapped>(args.mapped_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUBuffer>(args.buffer_rid)
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer = buffer_resource.0;
|
||||
|
||||
|
@ -240,5 +240,5 @@ pub fn op_webgpu_buffer_unmap(
|
|||
|
||||
let maybe_err = gfx_select!(buffer => instance.buffer_unmap(buffer)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
|
|
@ -12,20 +12,20 @@ use std::borrow::Cow;
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
use super::texture::serialize_texture_format;
|
||||
|
||||
struct WebGPURenderBundleEncoder(
|
||||
struct WebGpuRenderBundleEncoder(
|
||||
RefCell<wgpu_core::command::RenderBundleEncoder>,
|
||||
);
|
||||
impl Resource for WebGPURenderBundleEncoder {
|
||||
impl Resource for WebGpuRenderBundleEncoder {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPURenderBundleEncoder".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPURenderBundle(pub(crate) wgpu_core::id::RenderBundleId);
|
||||
impl Resource for WebGPURenderBundle {
|
||||
pub(crate) struct WebGpuRenderBundle(pub(crate) wgpu_core::id::RenderBundleId);
|
||||
impl Resource for WebGpuRenderBundle {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPURenderBundle".into()
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub fn op_webgpu_create_render_bundle_encoder(
|
|||
) -> Result<Value, AnyError> {
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -80,13 +80,13 @@ pub fn op_webgpu_create_render_bundle_encoder(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPURenderBundleEncoder(RefCell::new(
|
||||
.add(WebGpuRenderBundleEncoder(RefCell::new(
|
||||
render_bundle_encoder,
|
||||
)));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from),
|
||||
"err": maybe_err.map(WebGpuError::from),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub fn op_webgpu_render_bundle_encoder_finish(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.take::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.take::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder = Rc::try_unwrap(render_bundle_encoder_resource)
|
||||
.ok()
|
||||
|
@ -121,11 +121,11 @@ pub fn op_webgpu_render_bundle_encoder_finish(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPURenderBundle(render_bundle));
|
||||
let rid = state.resource_table.add(WebGpuRenderBundle(render_bundle));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -147,11 +147,11 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGPUBindGroup>(args.bind_group)
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
// I know this might look like it can be easily deduplicated, but it can not
|
||||
|
@ -202,7 +202,7 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -229,7 +229,7 @@ pub fn op_webgpu_render_bundle_encoder_pop_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -255,7 +255,7 @@ pub fn op_webgpu_render_bundle_encoder_insert_debug_marker(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -283,11 +283,11 @@ pub fn op_webgpu_render_bundle_encoder_set_pipeline(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGPURenderPipeline>(args.pipeline)
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_pipeline(
|
||||
|
@ -315,11 +315,11 @@ pub fn op_webgpu_render_bundle_encoder_set_index_buffer(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
render_bundle_encoder_resource
|
||||
|
@ -352,11 +352,11 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
|
||||
|
@ -387,7 +387,7 @@ pub fn op_webgpu_render_bundle_encoder_draw(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw(
|
||||
|
@ -419,7 +419,7 @@ pub fn op_webgpu_render_bundle_encoder_draw_indexed(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indexed(
|
||||
|
@ -449,11 +449,11 @@ pub fn op_webgpu_render_bundle_encoder_draw_indirect(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.indirect_buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indirect(
|
||||
|
|
|
@ -11,21 +11,21 @@ use serde::Deserialize;
|
|||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUCommandEncoder(
|
||||
pub(crate) struct WebGpuCommandEncoder(
|
||||
pub(crate) wgpu_core::id::CommandEncoderId,
|
||||
);
|
||||
impl Resource for WebGPUCommandEncoder {
|
||||
impl Resource for WebGpuCommandEncoder {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUCommandEncoder".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPUCommandBuffer(
|
||||
pub(crate) struct WebGpuCommandBuffer(
|
||||
pub(crate) wgpu_core::id::CommandBufferId,
|
||||
);
|
||||
impl Resource for WebGPUCommandBuffer {
|
||||
impl Resource for WebGpuCommandBuffer {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUCommandBuffer".into()
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ pub fn op_webgpu_create_command_encoder(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -71,27 +71,27 @@ pub fn op_webgpu_create_command_encoder(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPUCommandEncoder(command_encoder));
|
||||
.add(WebGpuCommandEncoder(command_encoder));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from),
|
||||
"err": maybe_err.map(WebGpuError::from),
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPURenderPassColorAttachment {
|
||||
pub struct GpuRenderPassColorAttachment {
|
||||
view: u32,
|
||||
resolve_target: Option<u32>,
|
||||
load_op: String,
|
||||
load_value: Option<super::render_pass::GPUColor>,
|
||||
load_value: Option<super::render_pass::GpuColor>,
|
||||
store_op: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPURenderPassDepthStencilAttachment {
|
||||
struct GpuRenderPassDepthStencilAttachment {
|
||||
view: u32,
|
||||
depth_load_op: String,
|
||||
depth_load_value: Option<f32>,
|
||||
|
@ -108,8 +108,8 @@ struct GPURenderPassDepthStencilAttachment {
|
|||
pub struct CommandEncoderBeginRenderPassArgs {
|
||||
command_encoder_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
color_attachments: Vec<GPURenderPassColorAttachment>,
|
||||
depth_stencil_attachment: Option<GPURenderPassDepthStencilAttachment>,
|
||||
color_attachments: Vec<GpuRenderPassColorAttachment>,
|
||||
depth_stencil_attachment: Option<GpuRenderPassDepthStencilAttachment>,
|
||||
_occlusion_query_set: Option<u32>, // not yet implemented
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
) -> Result<Value, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let mut color_attachments = vec![];
|
||||
|
@ -128,7 +128,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
for color_attachment in args.color_attachments {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTextureView>(color_attachment.view)
|
||||
.get::<super::texture::WebGpuTextureView>(color_attachment.view)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let attachment = wgpu_core::command::ColorAttachmentDescriptor {
|
||||
|
@ -138,7 +138,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
.map(|rid| {
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTextureView>(rid)
|
||||
.get::<super::texture::WebGpuTextureView>(rid)
|
||||
.ok_or_else(bad_resource_id)
|
||||
})
|
||||
.transpose()?
|
||||
|
@ -180,7 +180,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
if let Some(attachment) = args.depth_stencil_attachment {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTextureView>(attachment.view)
|
||||
.get::<super::texture::WebGpuTextureView>(attachment.view)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
depth_stencil_attachment =
|
||||
|
@ -232,7 +232,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(super::render_pass::WebGPURenderPass(RefCell::new(
|
||||
.add(super::render_pass::WebGpuRenderPass(RefCell::new(
|
||||
render_pass,
|
||||
)));
|
||||
|
||||
|
@ -255,7 +255,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
|
|||
) -> Result<Value, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let descriptor = wgpu_core::command::ComputePassDescriptor {
|
||||
|
@ -269,7 +269,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(super::compute_pass::WebGPUComputePass(RefCell::new(
|
||||
.add(super::compute_pass::WebGpuComputePass(RefCell::new(
|
||||
compute_pass,
|
||||
)));
|
||||
|
||||
|
@ -297,17 +297,17 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.source)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let source_buffer = source_buffer_resource.0;
|
||||
let destination_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.destination)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_buffer = destination_buffer_resource.0;
|
||||
|
||||
|
@ -320,12 +320,12 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
|
|||
args.size
|
||||
)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPUImageCopyBuffer {
|
||||
pub struct GpuImageCopyBuffer {
|
||||
buffer: u32,
|
||||
offset: Option<u64>,
|
||||
bytes_per_row: Option<u32>,
|
||||
|
@ -334,7 +334,7 @@ pub struct GPUImageCopyBuffer {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPUOrigin3D {
|
||||
pub struct GpuOrigin3D {
|
||||
pub x: Option<u32>,
|
||||
pub y: Option<u32>,
|
||||
pub z: Option<u32>,
|
||||
|
@ -342,10 +342,10 @@ pub struct GPUOrigin3D {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPUImageCopyTexture {
|
||||
pub struct GpuImageCopyTexture {
|
||||
pub texture: u32,
|
||||
pub mip_level: Option<u32>,
|
||||
pub origin: Option<GPUOrigin3D>,
|
||||
pub origin: Option<GpuOrigin3D>,
|
||||
pub _aspect: Option<String>, // not yet implemented
|
||||
}
|
||||
|
||||
|
@ -353,9 +353,9 @@ pub struct GPUImageCopyTexture {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommandEncoderCopyBufferToTextureArgs {
|
||||
command_encoder_rid: ResourceId,
|
||||
source: GPUImageCopyBuffer,
|
||||
destination: GPUImageCopyTexture,
|
||||
copy_size: super::texture::GPUExtent3D,
|
||||
source: GpuImageCopyBuffer,
|
||||
destination: GpuImageCopyTexture,
|
||||
copy_size: super::texture::GpuExtent3D,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
|
||||
|
@ -366,16 +366,16 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.source.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTexture>(args.destination.texture)
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let source = wgpu_core::command::BufferCopyView {
|
||||
|
@ -409,16 +409,16 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
|
|||
}
|
||||
)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommandEncoderCopyTextureToBufferArgs {
|
||||
command_encoder_rid: ResourceId,
|
||||
source: GPUImageCopyTexture,
|
||||
destination: GPUImageCopyBuffer,
|
||||
copy_size: super::texture::GPUExtent3D,
|
||||
source: GpuImageCopyTexture,
|
||||
destination: GpuImageCopyBuffer,
|
||||
copy_size: super::texture::GpuExtent3D,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
|
||||
|
@ -429,16 +429,16 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTexture>(args.source.texture)
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.destination.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let source = wgpu_core::command::TextureCopyView {
|
||||
|
@ -471,16 +471,16 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
|
|||
}
|
||||
)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommandEncoderCopyTextureToTextureArgs {
|
||||
command_encoder_rid: ResourceId,
|
||||
source: GPUImageCopyTexture,
|
||||
destination: GPUImageCopyTexture,
|
||||
copy_size: super::texture::GPUExtent3D,
|
||||
source: GpuImageCopyTexture,
|
||||
destination: GpuImageCopyTexture,
|
||||
copy_size: super::texture::GpuExtent3D,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_command_encoder_copy_texture_to_texture(
|
||||
|
@ -491,16 +491,16 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTexture>(args.source.texture)
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTexture>(args.destination.texture)
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let source = wgpu_core::command::TextureCopyView {
|
||||
|
@ -537,7 +537,7 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture(
|
|||
}
|
||||
)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -555,7 +555,7 @@ pub fn op_webgpu_command_encoder_push_debug_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
|
@ -563,7 +563,7 @@ pub fn op_webgpu_command_encoder_push_debug_group(
|
|||
.command_encoder_push_debug_group(command_encoder, &args.group_label))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -580,13 +580,13 @@ pub fn op_webgpu_command_encoder_pop_debug_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
let maybe_err = gfx_select!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -604,7 +604,7 @@ pub fn op_webgpu_command_encoder_insert_debug_marker(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
|
@ -613,7 +613,7 @@ pub fn op_webgpu_command_encoder_insert_debug_marker(
|
|||
&args.marker_label
|
||||
)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -632,12 +632,12 @@ pub fn op_webgpu_command_encoder_write_timestamp(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let maybe_err =
|
||||
|
@ -648,7 +648,7 @@ pub fn op_webgpu_command_encoder_write_timestamp(
|
|||
))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -670,16 +670,16 @@ pub fn op_webgpu_command_encoder_resolve_query_set(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.destination)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let maybe_err =
|
||||
|
@ -693,7 +693,7 @@ pub fn op_webgpu_command_encoder_resolve_query_set(
|
|||
))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -710,7 +710,7 @@ pub fn op_webgpu_command_encoder_finish(
|
|||
) -> Result<Value, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.take::<WebGPUCommandEncoder>(args.command_encoder_rid)
|
||||
.take::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
@ -726,10 +726,10 @@ pub fn op_webgpu_command_encoder_finish(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPUCommandBuffer(command_buffer));
|
||||
.add(WebGpuCommandBuffer(command_buffer));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ use serde::Deserialize;
|
|||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUComputePass(
|
||||
pub(crate) struct WebGpuComputePass(
|
||||
pub(crate) RefCell<wgpu_core::command::ComputePass>,
|
||||
);
|
||||
impl Resource for WebGPUComputePass {
|
||||
impl Resource for WebGpuComputePass {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUComputePass".into()
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ pub fn op_webgpu_compute_pass_set_pipeline(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGPUComputePipeline>(args.pipeline)
|
||||
.get::<super::pipeline::WebGpuComputePipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_set_pipeline(
|
||||
|
@ -67,7 +67,7 @@ pub fn op_webgpu_compute_pass_dispatch(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch(
|
||||
|
@ -95,11 +95,11 @@ pub fn op_webgpu_compute_pass_dispatch_indirect(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.indirect_buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch_indirect(
|
||||
|
@ -126,11 +126,11 @@ pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -157,7 +157,7 @@ pub fn op_webgpu_compute_pass_end_pipeline_statistics_query(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -184,11 +184,11 @@ pub fn op_webgpu_compute_pass_write_timestamp(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -216,14 +216,14 @@ pub fn op_webgpu_compute_pass_end_pass(
|
|||
) -> Result<Value, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGPUCommandEncoder>(
|
||||
.get::<super::command_encoder::WebGpuCommandEncoder>(
|
||||
args.command_encoder_rid,
|
||||
)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.take::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.take::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pass = &compute_pass_resource.0.borrow();
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
@ -235,7 +235,7 @@ pub fn op_webgpu_compute_pass_end_pass(
|
|||
))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -256,11 +256,11 @@ pub fn op_webgpu_compute_pass_set_bind_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGPUBindGroup>(args.bind_group)
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -298,7 +298,7 @@ pub fn op_webgpu_compute_pass_push_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -326,7 +326,7 @@ pub fn op_webgpu_compute_pass_pop_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_pop_debug_group(
|
||||
|
@ -350,7 +350,7 @@ pub fn op_webgpu_compute_pass_insert_debug_marker(
|
|||
) -> Result<Value, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePass>(args.compute_pass_rid)
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -29,81 +29,81 @@ use wgpu_core::resource::CreateTextureViewError;
|
|||
#[derive(Serialize)]
|
||||
#[serde(tag = "type", content = "value")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum WebGPUError {
|
||||
pub enum WebGpuError {
|
||||
Lost,
|
||||
OutOfMemory,
|
||||
Validation(String),
|
||||
}
|
||||
|
||||
impl From<CreateBufferError> for WebGPUError {
|
||||
impl From<CreateBufferError> for WebGpuError {
|
||||
fn from(err: CreateBufferError) -> Self {
|
||||
match err {
|
||||
CreateBufferError::Device(err) => err.into(),
|
||||
CreateBufferError::AccessError(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DeviceError> for WebGPUError {
|
||||
impl From<DeviceError> for WebGpuError {
|
||||
fn from(err: DeviceError) -> Self {
|
||||
match err {
|
||||
DeviceError::Lost => WebGPUError::Lost,
|
||||
DeviceError::OutOfMemory => WebGPUError::OutOfMemory,
|
||||
DeviceError::Invalid => WebGPUError::Validation(err.to_string()),
|
||||
DeviceError::Lost => WebGpuError::Lost,
|
||||
DeviceError::OutOfMemory => WebGpuError::OutOfMemory,
|
||||
DeviceError::Invalid => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BufferAccessError> for WebGPUError {
|
||||
impl From<BufferAccessError> for WebGpuError {
|
||||
fn from(err: BufferAccessError) -> Self {
|
||||
match err {
|
||||
BufferAccessError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateBindGroupLayoutError> for WebGPUError {
|
||||
impl From<CreateBindGroupLayoutError> for WebGpuError {
|
||||
fn from(err: CreateBindGroupLayoutError) -> Self {
|
||||
match err {
|
||||
CreateBindGroupLayoutError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreatePipelineLayoutError> for WebGPUError {
|
||||
impl From<CreatePipelineLayoutError> for WebGpuError {
|
||||
fn from(err: CreatePipelineLayoutError) -> Self {
|
||||
match err {
|
||||
CreatePipelineLayoutError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateBindGroupError> for WebGPUError {
|
||||
impl From<CreateBindGroupError> for WebGpuError {
|
||||
fn from(err: CreateBindGroupError) -> Self {
|
||||
match err {
|
||||
CreateBindGroupError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RenderBundleError> for WebGPUError {
|
||||
impl From<RenderBundleError> for WebGpuError {
|
||||
fn from(err: RenderBundleError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateRenderBundleError> for WebGPUError {
|
||||
impl From<CreateRenderBundleError> for WebGpuError {
|
||||
fn from(err: CreateRenderBundleError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CommandAllocatorError> for WebGPUError {
|
||||
impl From<CommandAllocatorError> for WebGpuError {
|
||||
fn from(err: CommandAllocatorError) -> Self {
|
||||
match err {
|
||||
CommandAllocatorError::Device(err) => err.into(),
|
||||
|
@ -111,142 +111,142 @@ impl From<CommandAllocatorError> for WebGPUError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<CopyError> for WebGPUError {
|
||||
impl From<CopyError> for WebGpuError {
|
||||
fn from(err: CopyError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CommandEncoderError> for WebGPUError {
|
||||
impl From<CommandEncoderError> for WebGpuError {
|
||||
fn from(err: CommandEncoderError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<QueryError> for WebGPUError {
|
||||
impl From<QueryError> for WebGpuError {
|
||||
fn from(err: QueryError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ComputePassError> for WebGPUError {
|
||||
impl From<ComputePassError> for WebGpuError {
|
||||
fn from(err: ComputePassError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateComputePipelineError> for WebGPUError {
|
||||
impl From<CreateComputePipelineError> for WebGpuError {
|
||||
fn from(err: CreateComputePipelineError) -> Self {
|
||||
match err {
|
||||
CreateComputePipelineError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GetBindGroupLayoutError> for WebGPUError {
|
||||
impl From<GetBindGroupLayoutError> for WebGpuError {
|
||||
fn from(err: GetBindGroupLayoutError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateRenderPipelineError> for WebGPUError {
|
||||
impl From<CreateRenderPipelineError> for WebGpuError {
|
||||
fn from(err: CreateRenderPipelineError) -> Self {
|
||||
match err {
|
||||
CreateRenderPipelineError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RenderPassError> for WebGPUError {
|
||||
impl From<RenderPassError> for WebGpuError {
|
||||
fn from(err: RenderPassError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateSamplerError> for WebGPUError {
|
||||
impl From<CreateSamplerError> for WebGpuError {
|
||||
fn from(err: CreateSamplerError) -> Self {
|
||||
match err {
|
||||
CreateSamplerError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateShaderModuleError> for WebGPUError {
|
||||
impl From<CreateShaderModuleError> for WebGpuError {
|
||||
fn from(err: CreateShaderModuleError) -> Self {
|
||||
match err {
|
||||
CreateShaderModuleError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateTextureError> for WebGPUError {
|
||||
impl From<CreateTextureError> for WebGpuError {
|
||||
fn from(err: CreateTextureError) -> Self {
|
||||
match err {
|
||||
CreateTextureError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateTextureViewError> for WebGPUError {
|
||||
impl From<CreateTextureViewError> for WebGpuError {
|
||||
fn from(err: CreateTextureViewError) -> Self {
|
||||
WebGPUError::Validation(err.to_string())
|
||||
WebGpuError::Validation(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateQuerySetError> for WebGPUError {
|
||||
impl From<CreateQuerySetError> for WebGpuError {
|
||||
fn from(err: CreateQuerySetError) -> Self {
|
||||
match err {
|
||||
CreateQuerySetError::Device(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<QueueSubmitError> for WebGPUError {
|
||||
impl From<QueueSubmitError> for WebGpuError {
|
||||
fn from(err: QueueSubmitError) -> Self {
|
||||
match err {
|
||||
QueueSubmitError::Queue(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<QueueWriteError> for WebGPUError {
|
||||
impl From<QueueWriteError> for WebGpuError {
|
||||
fn from(err: QueueWriteError) -> Self {
|
||||
match err {
|
||||
QueueWriteError::Queue(err) => err.into(),
|
||||
err => WebGPUError::Validation(err.to_string()),
|
||||
err => WebGpuError::Validation(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DOMExceptionOperationError {
|
||||
pub struct DomExceptionOperationError {
|
||||
pub msg: String,
|
||||
}
|
||||
|
||||
impl DOMExceptionOperationError {
|
||||
impl DomExceptionOperationError {
|
||||
pub fn new(msg: &str) -> Self {
|
||||
DOMExceptionOperationError {
|
||||
DomExceptionOperationError {
|
||||
msg: msg.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DOMExceptionOperationError {
|
||||
impl fmt::Display for DomExceptionOperationError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.pad(&self.msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for DOMExceptionOperationError {}
|
||||
impl std::error::Error for DomExceptionOperationError {}
|
||||
|
||||
pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
|
||||
e.downcast_ref::<DOMExceptionOperationError>()
|
||||
e.downcast_ref::<DomExceptionOperationError>()
|
||||
.map(|_| "DOMExceptionOperationError")
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use std::rc::Rc;
|
|||
pub use wgpu_core;
|
||||
pub use wgpu_types;
|
||||
|
||||
use error::DOMExceptionOperationError;
|
||||
use error::WebGPUError;
|
||||
use error::DomExceptionOperationError;
|
||||
use error::WebGpuError;
|
||||
|
||||
#[macro_use]
|
||||
mod macros {
|
||||
|
@ -71,22 +71,22 @@ fn check_unstable(state: &OpState, api_name: &str) {
|
|||
|
||||
type Instance = wgpu_core::hub::Global<wgpu_core::hub::IdentityManagerFactory>;
|
||||
|
||||
struct WebGPUAdapter(wgpu_core::id::AdapterId);
|
||||
impl Resource for WebGPUAdapter {
|
||||
struct WebGpuAdapter(wgpu_core::id::AdapterId);
|
||||
impl Resource for WebGpuAdapter {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUAdapter".into()
|
||||
}
|
||||
}
|
||||
|
||||
struct WebGPUDevice(wgpu_core::id::DeviceId);
|
||||
impl Resource for WebGPUDevice {
|
||||
struct WebGpuDevice(wgpu_core::id::DeviceId);
|
||||
impl Resource for WebGpuDevice {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUDevice".into()
|
||||
}
|
||||
}
|
||||
|
||||
struct WebGPUQuerySet(wgpu_core::id::QuerySetId);
|
||||
impl Resource for WebGPUQuerySet {
|
||||
struct WebGpuQuerySet(wgpu_core::id::QuerySetId);
|
||||
impl Resource for WebGpuQuerySet {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUQuerySet".into()
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ pub async fn op_webgpu_request_adapter(
|
|||
"maxUniformBufferBindingSize": adapter_limits.max_uniform_buffer_binding_size
|
||||
});
|
||||
|
||||
let rid = state.resource_table.add(WebGPUAdapter(adapter));
|
||||
let rid = state.resource_table.add(WebGpuAdapter(adapter));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
|
@ -267,7 +267,7 @@ pub async fn op_webgpu_request_adapter(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPULimits {
|
||||
struct GpuLimits {
|
||||
_max_texture_dimension1d: Option<u32>,
|
||||
_max_texture_dimension2d: Option<u32>,
|
||||
_max_texture_dimension3d: Option<u32>,
|
||||
|
@ -293,7 +293,7 @@ pub struct RequestDeviceArgs {
|
|||
adapter_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
non_guaranteed_features: Option<Vec<String>>,
|
||||
non_guaranteed_limits: Option<GPULimits>,
|
||||
non_guaranteed_limits: Option<GpuLimits>,
|
||||
}
|
||||
|
||||
pub async fn op_webgpu_request_device(
|
||||
|
@ -304,7 +304,7 @@ pub async fn op_webgpu_request_device(
|
|||
let mut state = state.borrow_mut();
|
||||
let adapter_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUAdapter>(args.adapter_rid)
|
||||
.get::<WebGpuAdapter>(args.adapter_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let adapter = adapter_resource.0;
|
||||
let instance = state.borrow::<Instance>();
|
||||
|
@ -430,7 +430,7 @@ pub async fn op_webgpu_request_device(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
if let Some(err) = maybe_err {
|
||||
return Err(DOMExceptionOperationError::new(&err.to_string()).into());
|
||||
return Err(DomExceptionOperationError::new(&err.to_string()).into());
|
||||
}
|
||||
|
||||
let device_features =
|
||||
|
@ -449,7 +449,7 @@ pub async fn op_webgpu_request_device(
|
|||
"maxUniformBufferBindingSize": limits.max_uniform_buffer_binding_size,
|
||||
});
|
||||
|
||||
let rid = state.resource_table.add(WebGPUDevice(device));
|
||||
let rid = state.resource_table.add(WebGpuDevice(device));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
|
@ -476,7 +476,7 @@ pub fn op_webgpu_create_query_set(
|
|||
) -> Result<Value, AnyError> {
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUDevice>(args.device_rid)
|
||||
.get::<WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
let instance = &state.borrow::<Instance>();
|
||||
|
@ -542,10 +542,10 @@ pub fn op_webgpu_create_query_set(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUQuerySet(query_set));
|
||||
let rid = state.resource_table.add(WebGpuQuerySet(query_set));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from),
|
||||
"err": maybe_err.map(WebGpuError::from),
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -10,30 +10,30 @@ use deno_core::{OpState, Resource};
|
|||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUPipelineLayout(
|
||||
pub(crate) struct WebGpuPipelineLayout(
|
||||
pub(crate) wgpu_core::id::PipelineLayoutId,
|
||||
);
|
||||
impl Resource for WebGPUPipelineLayout {
|
||||
impl Resource for WebGpuPipelineLayout {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUPipelineLayout".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPUComputePipeline(
|
||||
pub(crate) struct WebGpuComputePipeline(
|
||||
pub(crate) wgpu_core::id::ComputePipelineId,
|
||||
);
|
||||
impl Resource for WebGPUComputePipeline {
|
||||
impl Resource for WebGpuComputePipeline {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUComputePipeline".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPURenderPipeline(
|
||||
pub(crate) struct WebGpuRenderPipeline(
|
||||
pub(crate) wgpu_core::id::RenderPipelineId,
|
||||
);
|
||||
impl Resource for WebGPURenderPipeline {
|
||||
impl Resource for WebGpuRenderPipeline {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPURenderPipeline".into()
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ fn serialize_stencil_operation(
|
|||
}
|
||||
|
||||
fn serialize_stencil_face_state(
|
||||
state: GPUStencilFaceState,
|
||||
state: GpuStencilFaceState,
|
||||
) -> wgpu_types::StencilFaceState {
|
||||
wgpu_types::StencilFaceState {
|
||||
compare: state
|
||||
|
@ -114,7 +114,7 @@ fn serialize_blend_factor(blend_factor: &str) -> wgpu_types::BlendFactor {
|
|||
}
|
||||
|
||||
fn serialize_blend_component(
|
||||
blend: GPUBlendComponent,
|
||||
blend: GpuBlendComponent,
|
||||
) -> wgpu_types::BlendState {
|
||||
wgpu_types::BlendState {
|
||||
src_factor: blend
|
||||
|
@ -145,7 +145,7 @@ fn serialize_blend_component(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUProgrammableStage {
|
||||
struct GpuProgrammableStage {
|
||||
module: u32,
|
||||
entry_point: String,
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ pub struct CreateComputePipelineArgs {
|
|||
device_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
layout: Option<u32>,
|
||||
compute: GPUProgrammableStage,
|
||||
compute: GpuProgrammableStage,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_create_compute_pipeline(
|
||||
|
@ -167,14 +167,14 @@ pub fn op_webgpu_create_compute_pipeline(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let pipeline_layout = if let Some(rid) = args.layout {
|
||||
let id = state
|
||||
.resource_table
|
||||
.get::<WebGPUPipelineLayout>(rid)
|
||||
.get::<WebGpuPipelineLayout>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
Some(id.0)
|
||||
} else {
|
||||
|
@ -183,7 +183,7 @@ pub fn op_webgpu_create_compute_pipeline(
|
|||
|
||||
let compute_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGPUShaderModule>(args.compute.module)
|
||||
.get::<super::shader::WebGpuShaderModule>(args.compute.module)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let descriptor = wgpu_core::pipeline::ComputePipelineDescriptor {
|
||||
|
@ -211,11 +211,11 @@ pub fn op_webgpu_create_compute_pipeline(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPUComputePipeline(compute_pipeline));
|
||||
.add(WebGpuComputePipeline(compute_pipeline));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from),
|
||||
"err": maybe_err.map(WebGpuError::from),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let compute_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUComputePipeline>(args.compute_pipeline_rid)
|
||||
.get::<WebGpuComputePipeline>(args.compute_pipeline_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pipeline = compute_pipeline_resource.0;
|
||||
|
||||
|
@ -244,18 +244,18 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(super::binding::WebGPUBindGroupLayout(bind_group_layout));
|
||||
.add(super::binding::WebGpuBindGroupLayout(bind_group_layout));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"label": label,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUPrimitiveState {
|
||||
struct GpuPrimitiveState {
|
||||
topology: Option<String>,
|
||||
strip_index_format: Option<String>,
|
||||
front_face: Option<String>,
|
||||
|
@ -264,7 +264,7 @@ struct GPUPrimitiveState {
|
|||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUBlendComponent {
|
||||
struct GpuBlendComponent {
|
||||
src_factor: Option<String>,
|
||||
dst_factor: Option<String>,
|
||||
operation: Option<String>,
|
||||
|
@ -272,22 +272,22 @@ struct GPUBlendComponent {
|
|||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUBlendState {
|
||||
color: GPUBlendComponent,
|
||||
alpha: GPUBlendComponent,
|
||||
struct GpuBlendState {
|
||||
color: GpuBlendComponent,
|
||||
alpha: GpuBlendComponent,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUColorTargetState {
|
||||
struct GpuColorTargetState {
|
||||
format: String,
|
||||
blend: Option<GPUBlendState>,
|
||||
blend: Option<GpuBlendState>,
|
||||
write_mask: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUStencilFaceState {
|
||||
struct GpuStencilFaceState {
|
||||
compare: Option<String>,
|
||||
fail_op: Option<String>,
|
||||
depth_fail_op: Option<String>,
|
||||
|
@ -296,12 +296,12 @@ struct GPUStencilFaceState {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUDepthStencilState {
|
||||
struct GpuDepthStencilState {
|
||||
format: String,
|
||||
depth_write_enabled: Option<bool>,
|
||||
depth_compare: Option<String>,
|
||||
stencil_front: Option<GPUStencilFaceState>,
|
||||
stencil_back: Option<GPUStencilFaceState>,
|
||||
stencil_front: Option<GpuStencilFaceState>,
|
||||
stencil_back: Option<GpuStencilFaceState>,
|
||||
stencil_read_mask: Option<u32>,
|
||||
stencil_write_mask: Option<u32>,
|
||||
depth_bias: Option<i32>,
|
||||
|
@ -312,7 +312,7 @@ struct GPUDepthStencilState {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUVertexAttribute {
|
||||
struct GpuVertexAttribute {
|
||||
format: String,
|
||||
offset: u64,
|
||||
shader_location: u32,
|
||||
|
@ -320,23 +320,23 @@ struct GPUVertexAttribute {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUVertexBufferLayout {
|
||||
struct GpuVertexBufferLayout {
|
||||
array_stride: u64,
|
||||
step_mode: Option<String>,
|
||||
attributes: Vec<GPUVertexAttribute>,
|
||||
attributes: Vec<GpuVertexAttribute>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUVertexState {
|
||||
struct GpuVertexState {
|
||||
module: u32,
|
||||
entry_point: String,
|
||||
buffers: Option<Vec<Option<GPUVertexBufferLayout>>>,
|
||||
buffers: Option<Vec<Option<GpuVertexBufferLayout>>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUMultisampleState {
|
||||
struct GpuMultisampleState {
|
||||
count: Option<u32>,
|
||||
mask: Option<u64>, // against spec, but future proof
|
||||
alpha_to_coverage_enabled: Option<bool>,
|
||||
|
@ -344,8 +344,8 @@ struct GPUMultisampleState {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUFragmentState {
|
||||
targets: Vec<GPUColorTargetState>,
|
||||
struct GpuFragmentState {
|
||||
targets: Vec<GpuColorTargetState>,
|
||||
module: u32,
|
||||
entry_point: String,
|
||||
}
|
||||
|
@ -356,11 +356,11 @@ pub struct CreateRenderPipelineArgs {
|
|||
device_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
layout: Option<u32>,
|
||||
vertex: GPUVertexState,
|
||||
primitive: Option<GPUPrimitiveState>,
|
||||
depth_stencil: Option<GPUDepthStencilState>,
|
||||
multisample: Option<GPUMultisampleState>,
|
||||
fragment: Option<GPUFragmentState>,
|
||||
vertex: GpuVertexState,
|
||||
primitive: Option<GpuPrimitiveState>,
|
||||
depth_stencil: Option<GpuDepthStencilState>,
|
||||
multisample: Option<GpuMultisampleState>,
|
||||
fragment: Option<GpuFragmentState>,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_create_render_pipeline(
|
||||
|
@ -371,14 +371,14 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let layout = if let Some(rid) = args.layout {
|
||||
let pipeline_layout_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUPipelineLayout>(rid)
|
||||
.get::<WebGpuPipelineLayout>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
Some(pipeline_layout_resource.0)
|
||||
} else {
|
||||
|
@ -387,7 +387,7 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
|
||||
let vertex_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGPUShaderModule>(args.vertex.module)
|
||||
.get::<super::shader::WebGpuShaderModule>(args.vertex.module)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
let descriptor = wgpu_core::pipeline::RenderPipelineDescriptor {
|
||||
|
@ -400,63 +400,61 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
},
|
||||
buffers: Cow::from(if let Some(buffers) = args.vertex.buffers {
|
||||
let mut return_buffers = vec![];
|
||||
for buffer in buffers {
|
||||
if let Some(buffer) = buffer {
|
||||
return_buffers.push(wgpu_core::pipeline::VertexBufferLayout {
|
||||
array_stride: buffer.array_stride,
|
||||
step_mode: match buffer.step_mode {
|
||||
Some(step_mode) => match step_mode.as_str() {
|
||||
"vertex" => wgpu_types::InputStepMode::Vertex,
|
||||
"instance" => wgpu_types::InputStepMode::Instance,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
None => wgpu_types::InputStepMode::Vertex,
|
||||
for buffer in buffers.into_iter().flatten() {
|
||||
return_buffers.push(wgpu_core::pipeline::VertexBufferLayout {
|
||||
array_stride: buffer.array_stride,
|
||||
step_mode: match buffer.step_mode {
|
||||
Some(step_mode) => match step_mode.as_str() {
|
||||
"vertex" => wgpu_types::InputStepMode::Vertex,
|
||||
"instance" => wgpu_types::InputStepMode::Instance,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
attributes: Cow::from(
|
||||
buffer
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|attribute| wgpu_types::VertexAttribute {
|
||||
format: match attribute.format.as_str() {
|
||||
"uchar2" => wgpu_types::VertexFormat::Uchar2,
|
||||
"uchar4" => wgpu_types::VertexFormat::Uchar4,
|
||||
"char2" => wgpu_types::VertexFormat::Char2,
|
||||
"char4" => wgpu_types::VertexFormat::Char4,
|
||||
"uchar2norm" => wgpu_types::VertexFormat::Uchar2Norm,
|
||||
"uchar4norm" => wgpu_types::VertexFormat::Uchar4,
|
||||
"char2norm" => wgpu_types::VertexFormat::Char2Norm,
|
||||
"char4norm" => wgpu_types::VertexFormat::Char4Norm,
|
||||
"ushort2" => wgpu_types::VertexFormat::Ushort2,
|
||||
"ushort4" => wgpu_types::VertexFormat::Ushort4,
|
||||
"short2" => wgpu_types::VertexFormat::Short2,
|
||||
"short4" => wgpu_types::VertexFormat::Short4,
|
||||
"ushort2norm" => wgpu_types::VertexFormat::Ushort2Norm,
|
||||
"ushort4norm" => wgpu_types::VertexFormat::Ushort4Norm,
|
||||
"short2norm" => wgpu_types::VertexFormat::Short2Norm,
|
||||
"short4norm" => wgpu_types::VertexFormat::Short4Norm,
|
||||
"half2" => wgpu_types::VertexFormat::Half2,
|
||||
"half4" => wgpu_types::VertexFormat::Half4,
|
||||
"float" => wgpu_types::VertexFormat::Float,
|
||||
"float2" => wgpu_types::VertexFormat::Float2,
|
||||
"float3" => wgpu_types::VertexFormat::Float3,
|
||||
"float4" => wgpu_types::VertexFormat::Float4,
|
||||
"uint" => wgpu_types::VertexFormat::Uint,
|
||||
"uint2" => wgpu_types::VertexFormat::Uint2,
|
||||
"uint3" => wgpu_types::VertexFormat::Uint3,
|
||||
"uint4" => wgpu_types::VertexFormat::Uint4,
|
||||
"int" => wgpu_types::VertexFormat::Int,
|
||||
"int2" => wgpu_types::VertexFormat::Int2,
|
||||
"int3" => wgpu_types::VertexFormat::Int3,
|
||||
"int4" => wgpu_types::VertexFormat::Int4,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
offset: attribute.offset,
|
||||
shader_location: attribute.shader_location,
|
||||
})
|
||||
.collect::<Vec<wgpu_types::VertexAttribute>>(),
|
||||
),
|
||||
})
|
||||
}
|
||||
None => wgpu_types::InputStepMode::Vertex,
|
||||
},
|
||||
attributes: Cow::from(
|
||||
buffer
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|attribute| wgpu_types::VertexAttribute {
|
||||
format: match attribute.format.as_str() {
|
||||
"uchar2" => wgpu_types::VertexFormat::Uchar2,
|
||||
"uchar4" => wgpu_types::VertexFormat::Uchar4,
|
||||
"char2" => wgpu_types::VertexFormat::Char2,
|
||||
"char4" => wgpu_types::VertexFormat::Char4,
|
||||
"uchar2norm" => wgpu_types::VertexFormat::Uchar2Norm,
|
||||
"uchar4norm" => wgpu_types::VertexFormat::Uchar4,
|
||||
"char2norm" => wgpu_types::VertexFormat::Char2Norm,
|
||||
"char4norm" => wgpu_types::VertexFormat::Char4Norm,
|
||||
"ushort2" => wgpu_types::VertexFormat::Ushort2,
|
||||
"ushort4" => wgpu_types::VertexFormat::Ushort4,
|
||||
"short2" => wgpu_types::VertexFormat::Short2,
|
||||
"short4" => wgpu_types::VertexFormat::Short4,
|
||||
"ushort2norm" => wgpu_types::VertexFormat::Ushort2Norm,
|
||||
"ushort4norm" => wgpu_types::VertexFormat::Ushort4Norm,
|
||||
"short2norm" => wgpu_types::VertexFormat::Short2Norm,
|
||||
"short4norm" => wgpu_types::VertexFormat::Short4Norm,
|
||||
"half2" => wgpu_types::VertexFormat::Half2,
|
||||
"half4" => wgpu_types::VertexFormat::Half4,
|
||||
"float" => wgpu_types::VertexFormat::Float,
|
||||
"float2" => wgpu_types::VertexFormat::Float2,
|
||||
"float3" => wgpu_types::VertexFormat::Float3,
|
||||
"float4" => wgpu_types::VertexFormat::Float4,
|
||||
"uint" => wgpu_types::VertexFormat::Uint,
|
||||
"uint2" => wgpu_types::VertexFormat::Uint2,
|
||||
"uint3" => wgpu_types::VertexFormat::Uint3,
|
||||
"uint4" => wgpu_types::VertexFormat::Uint4,
|
||||
"int" => wgpu_types::VertexFormat::Int,
|
||||
"int2" => wgpu_types::VertexFormat::Int2,
|
||||
"int3" => wgpu_types::VertexFormat::Int3,
|
||||
"int4" => wgpu_types::VertexFormat::Int4,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
offset: attribute.offset,
|
||||
shader_location: attribute.shader_location,
|
||||
})
|
||||
.collect::<Vec<wgpu_types::VertexAttribute>>(),
|
||||
),
|
||||
});
|
||||
}
|
||||
return_buffers
|
||||
} else {
|
||||
|
@ -540,7 +538,7 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
fragment: args.fragment.map(|fragment| {
|
||||
let fragment_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGPUShaderModule>(fragment.module)
|
||||
.get::<super::shader::WebGpuShaderModule>(fragment.module)
|
||||
.ok_or_else(bad_resource_id)
|
||||
.unwrap();
|
||||
|
||||
|
@ -601,11 +599,11 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(WebGPURenderPipeline(render_pipeline));
|
||||
.add(WebGpuRenderPipeline(render_pipeline));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -624,7 +622,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPipeline>(args.render_pipeline_rid)
|
||||
.get::<WebGpuRenderPipeline>(args.render_pipeline_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pipeline = render_pipeline_resource.0;
|
||||
|
||||
|
@ -634,11 +632,11 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
|
|||
|
||||
let rid = state
|
||||
.resource_table
|
||||
.add(super::binding::WebGPUBindGroupLayout(bind_group_layout));
|
||||
.add(super::binding::WebGpuBindGroupLayout(bind_group_layout));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"label": label,
|
||||
"err": maybe_err.map(WebGPUError::from),
|
||||
"err": maybe_err.map(WebGpuError::from),
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ use deno_core::ResourceId;
|
|||
use deno_core::ZeroCopyBuf;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
type WebGPUQueue = super::WebGPUDevice;
|
||||
type WebGpuQueue = super::WebGpuDevice;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -28,7 +28,7 @@ pub fn op_webgpu_queue_submit(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUQueue>(args.queue_rid)
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub fn op_webgpu_queue_submit(
|
|||
for rid in args.command_buffers {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGPUCommandBuffer>(rid)
|
||||
.get::<super::command_encoder::WebGpuCommandBuffer>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
ids.push(buffer_resource.0);
|
||||
}
|
||||
|
@ -45,12 +45,12 @@ pub fn op_webgpu_queue_submit(
|
|||
let maybe_err =
|
||||
gfx_select!(queue => instance.queue_submit(queue, &ids)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GPUImageDataLayout {
|
||||
struct GpuImageDataLayout {
|
||||
offset: Option<u64>,
|
||||
bytes_per_row: Option<u32>,
|
||||
rows_per_image: Option<u32>,
|
||||
|
@ -74,12 +74,12 @@ pub fn op_webgpu_write_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer = buffer_resource.0;
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUQueue>(args.queue_rid)
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
|
@ -95,16 +95,16 @@ pub fn op_webgpu_write_buffer(
|
|||
))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QueueWriteTextureArgs {
|
||||
queue_rid: ResourceId,
|
||||
destination: super::command_encoder::GPUImageCopyTexture,
|
||||
data_layout: GPUImageDataLayout,
|
||||
size: super::texture::GPUExtent3D,
|
||||
destination: super::command_encoder::GpuImageCopyTexture,
|
||||
data_layout: GpuImageDataLayout,
|
||||
size: super::texture::GpuExtent3D,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_write_texture(
|
||||
|
@ -115,11 +115,11 @@ pub fn op_webgpu_write_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGPUTexture>(args.destination.texture)
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUQueue>(args.queue_rid)
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
|
@ -154,5 +154,5 @@ pub fn op_webgpu_write_texture(
|
|||
))
|
||||
.err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ use serde::Deserialize;
|
|||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPURenderPass(
|
||||
pub(crate) struct WebGpuRenderPass(
|
||||
pub(crate) RefCell<wgpu_core::command::RenderPass>,
|
||||
);
|
||||
impl Resource for WebGPURenderPass {
|
||||
impl Resource for WebGpuRenderPass {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPURenderPass".into()
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ pub fn op_webgpu_render_pass_set_viewport(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_viewport(
|
||||
|
@ -74,7 +74,7 @@ pub fn op_webgpu_render_pass_set_scissor_rect(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_scissor_rect(
|
||||
|
@ -90,7 +90,7 @@ pub fn op_webgpu_render_pass_set_scissor_rect(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPUColor {
|
||||
pub struct GpuColor {
|
||||
pub r: f64,
|
||||
pub g: f64,
|
||||
pub b: f64,
|
||||
|
@ -101,7 +101,7 @@ pub struct GPUColor {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RenderPassSetBlendColorArgs {
|
||||
render_pass_rid: ResourceId,
|
||||
color: GPUColor,
|
||||
color: GpuColor,
|
||||
}
|
||||
|
||||
pub fn op_webgpu_render_pass_set_blend_color(
|
||||
|
@ -111,7 +111,7 @@ pub fn op_webgpu_render_pass_set_blend_color(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_blend_color(
|
||||
|
@ -141,7 +141,7 @@ pub fn op_webgpu_render_pass_set_stencil_reference(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_stencil_reference(
|
||||
|
@ -167,11 +167,11 @@ pub fn op_webgpu_render_pass_begin_pipeline_statistics_query(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -198,7 +198,7 @@ pub fn op_webgpu_render_pass_end_pipeline_statistics_query(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -225,11 +225,11 @@ pub fn op_webgpu_render_pass_write_timestamp(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUQuerySet>(args.query_set)
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -260,14 +260,14 @@ pub fn op_webgpu_render_pass_execute_bundles(
|
|||
for rid in &args.bundles {
|
||||
let render_bundle_resource = state
|
||||
.resource_table
|
||||
.get::<super::bundle::WebGPURenderBundle>(*rid)
|
||||
.get::<super::bundle::WebGpuRenderBundle>(*rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
render_bundle_ids.push(render_bundle_resource.0);
|
||||
}
|
||||
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -295,21 +295,21 @@ pub fn op_webgpu_render_pass_end_pass(
|
|||
) -> Result<Value, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGPUCommandEncoder>(
|
||||
.get::<super::command_encoder::WebGpuCommandEncoder>(
|
||||
args.command_encoder_rid,
|
||||
)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.take::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.take::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass = &render_pass_resource.0.borrow();
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
||||
let maybe_err = gfx_select!(command_encoder => instance.command_encoder_run_render_pass(command_encoder, render_pass)).err();
|
||||
|
||||
Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
|
||||
Ok(json!({ "err": maybe_err.map(WebGpuError::from) }))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -330,11 +330,11 @@ pub fn op_webgpu_render_pass_set_bind_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGPUBindGroup>(args.bind_group)
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
// I know this might look like it can be easily deduplicated, but it can not
|
||||
|
@ -385,7 +385,7 @@ pub fn op_webgpu_render_pass_push_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -413,7 +413,7 @@ pub fn op_webgpu_render_pass_pop_debug_group(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_pop_debug_group(
|
||||
|
@ -437,7 +437,7 @@ pub fn op_webgpu_render_pass_insert_debug_marker(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
unsafe {
|
||||
|
@ -466,11 +466,11 @@ pub fn op_webgpu_render_pass_set_pipeline(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGPURenderPipeline>(args.pipeline)
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_pipeline(
|
||||
|
@ -498,11 +498,11 @@ pub fn op_webgpu_render_pass_set_index_buffer(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
render_pass_resource.0.borrow_mut().set_index_buffer(
|
||||
|
@ -532,11 +532,11 @@ pub fn op_webgpu_render_pass_set_vertex_buffer(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_vertex_buffer(
|
||||
|
@ -567,7 +567,7 @@ pub fn op_webgpu_render_pass_draw(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw(
|
||||
|
@ -599,7 +599,7 @@ pub fn op_webgpu_render_pass_draw_indexed(
|
|||
) -> Result<Value, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed(
|
||||
|
@ -629,11 +629,11 @@ pub fn op_webgpu_render_pass_draw_indirect(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.indirect_buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indirect(
|
||||
|
@ -660,11 +660,11 @@ pub fn op_webgpu_render_pass_draw_indexed_indirect(
|
|||
) -> Result<Value, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGPUBuffer>(args.indirect_buffer)
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPURenderPass>(args.render_pass_rid)
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed_indirect(
|
||||
|
|
|
@ -10,10 +10,10 @@ use deno_core::{OpState, Resource};
|
|||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUSampler(pub(crate) wgpu_core::id::SamplerId);
|
||||
impl Resource for WebGPUSampler {
|
||||
pub(crate) struct WebGpuSampler(pub(crate) wgpu_core::id::SamplerId);
|
||||
impl Resource for WebGpuSampler {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUSampler".into()
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ pub fn op_webgpu_create_sampler(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -121,10 +121,10 @@ pub fn op_webgpu_create_sampler(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUSampler(sampler));
|
||||
let rid = state.resource_table.add(WebGpuSampler(sampler));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@ use deno_core::{OpState, Resource};
|
|||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
use super::error::WebGpuError;
|
||||
|
||||
pub(crate) struct WebGPUShaderModule(pub(crate) wgpu_core::id::ShaderModuleId);
|
||||
impl Resource for WebGPUShaderModule {
|
||||
pub(crate) struct WebGpuShaderModule(pub(crate) wgpu_core::id::ShaderModuleId);
|
||||
impl Resource for WebGpuShaderModule {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUShaderModule".into()
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub fn op_webgpu_create_shader_module(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -69,10 +69,10 @@ pub fn op_webgpu_create_shader_module(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUShaderModule(shader_module));
|
||||
let rid = state.resource_table.add(WebGpuShaderModule(shader_module));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -10,16 +10,16 @@ use deno_core::{OpState, Resource};
|
|||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::error::WebGPUError;
|
||||
pub(crate) struct WebGPUTexture(pub(crate) wgpu_core::id::TextureId);
|
||||
impl Resource for WebGPUTexture {
|
||||
use super::error::WebGpuError;
|
||||
pub(crate) struct WebGpuTexture(pub(crate) wgpu_core::id::TextureId);
|
||||
impl Resource for WebGpuTexture {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUTexture".into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct WebGPUTextureView(pub(crate) wgpu_core::id::TextureViewId);
|
||||
impl Resource for WebGPUTextureView {
|
||||
pub(crate) struct WebGpuTextureView(pub(crate) wgpu_core::id::TextureViewId);
|
||||
impl Resource for WebGpuTextureView {
|
||||
fn name(&self) -> Cow<str> {
|
||||
"webGPUTextureView".into()
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ pub fn serialize_dimension(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GPUExtent3D {
|
||||
pub struct GpuExtent3D {
|
||||
pub width: Option<u32>,
|
||||
pub height: Option<u32>,
|
||||
pub depth: Option<u32>,
|
||||
|
@ -136,7 +136,7 @@ pub struct GPUExtent3D {
|
|||
pub struct CreateTextureArgs {
|
||||
device_rid: ResourceId,
|
||||
label: Option<String>,
|
||||
size: GPUExtent3D,
|
||||
size: GpuExtent3D,
|
||||
mip_level_count: Option<u32>,
|
||||
sample_count: Option<u32>,
|
||||
dimension: Option<String>,
|
||||
|
@ -152,7 +152,7 @@ pub fn op_webgpu_create_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGPUDevice>(args.device_rid)
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
|
@ -184,11 +184,11 @@ pub fn op_webgpu_create_texture(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUTexture(texture));
|
||||
let rid = state.resource_table.add(WebGpuTexture(texture));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ pub fn op_webgpu_create_texture_view(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let texture_resource = state
|
||||
.resource_table
|
||||
.get::<WebGPUTexture>(args.texture_rid)
|
||||
.get::<WebGpuTexture>(args.texture_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let texture = texture_resource.0;
|
||||
|
||||
|
@ -248,10 +248,10 @@ pub fn op_webgpu_create_texture_view(
|
|||
std::marker::PhantomData
|
||||
));
|
||||
|
||||
let rid = state.resource_table.add(WebGPUTextureView(texture_view));
|
||||
let rid = state.resource_table.add(WebGpuTextureView(texture_view));
|
||||
|
||||
Ok(json!({
|
||||
"rid": rid,
|
||||
"err": maybe_err.map(WebGPUError::from)
|
||||
"err": maybe_err.map(WebGpuError::from)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ pub fn init(
|
|||
.unwrap()
|
||||
});
|
||||
state.put::<HttpClientDefaults>(HttpClientDefaults {
|
||||
ca_data,
|
||||
user_agent,
|
||||
ca_data,
|
||||
});
|
||||
}
|
||||
super::reg_json_sync(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>);
|
||||
|
|
|
@ -140,14 +140,14 @@ fn get_stdio_stream(
|
|||
use nix::sys::termios;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TTYMetadata {
|
||||
pub struct TtyMetadata {
|
||||
#[cfg(unix)]
|
||||
pub mode: Option<termios::Termios>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FileMetadata {
|
||||
pub tty: TTYMetadata,
|
||||
pub tty: TtyMetadata,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -504,21 +504,21 @@ fn op_listen(
|
|||
#[serde(untagged)]
|
||||
enum DnsReturnRecord {
|
||||
A(String),
|
||||
AAAA(String),
|
||||
ANAME(String),
|
||||
CNAME(String),
|
||||
MX {
|
||||
Aaaa(String),
|
||||
Aname(String),
|
||||
Cname(String),
|
||||
Mx {
|
||||
preference: u16,
|
||||
exchange: String,
|
||||
},
|
||||
PTR(String),
|
||||
SRV {
|
||||
Ptr(String),
|
||||
Srv {
|
||||
priority: u16,
|
||||
weight: u16,
|
||||
port: u16,
|
||||
target: String,
|
||||
},
|
||||
TXT(Vec<String>),
|
||||
Txt(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -610,24 +610,24 @@ fn rdata_to_return_record(
|
|||
AAAA => r
|
||||
.as_aaaa()
|
||||
.map(ToString::to_string)
|
||||
.map(DnsReturnRecord::AAAA),
|
||||
.map(DnsReturnRecord::Aaaa),
|
||||
ANAME => r
|
||||
.as_aname()
|
||||
.map(ToString::to_string)
|
||||
.map(DnsReturnRecord::ANAME),
|
||||
.map(DnsReturnRecord::Aname),
|
||||
CNAME => r
|
||||
.as_cname()
|
||||
.map(ToString::to_string)
|
||||
.map(DnsReturnRecord::CNAME),
|
||||
MX => r.as_mx().map(|mx| DnsReturnRecord::MX {
|
||||
.map(DnsReturnRecord::Cname),
|
||||
MX => r.as_mx().map(|mx| DnsReturnRecord::Mx {
|
||||
preference: mx.preference(),
|
||||
exchange: mx.exchange().to_string(),
|
||||
}),
|
||||
PTR => r
|
||||
.as_ptr()
|
||||
.map(ToString::to_string)
|
||||
.map(DnsReturnRecord::PTR),
|
||||
SRV => r.as_srv().map(|srv| DnsReturnRecord::SRV {
|
||||
.map(DnsReturnRecord::Ptr),
|
||||
SRV => r.as_srv().map(|srv| DnsReturnRecord::Srv {
|
||||
priority: srv.priority(),
|
||||
weight: srv.weight(),
|
||||
port: srv.port(),
|
||||
|
@ -641,7 +641,7 @@ fn rdata_to_return_record(
|
|||
bytes.iter().map(|&b| b as char).collect::<String>()
|
||||
})
|
||||
.collect();
|
||||
DnsReturnRecord::TXT(texts)
|
||||
DnsReturnRecord::Txt(texts)
|
||||
}),
|
||||
// TODO(magurotuna): Other record types are not supported
|
||||
_ => todo!(),
|
||||
|
@ -674,21 +674,21 @@ mod tests {
|
|||
fn rdata_to_return_record_aaaa() {
|
||||
let func = rdata_to_return_record(RecordType::AAAA);
|
||||
let rdata = RData::AAAA(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::AAAA("::1".to_string())));
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::Aaaa("::1".to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rdata_to_return_record_aname() {
|
||||
let func = rdata_to_return_record(RecordType::ANAME);
|
||||
let rdata = RData::ANAME(Name::new());
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::ANAME("".to_string())));
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::Aname("".to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rdata_to_return_record_cname() {
|
||||
let func = rdata_to_return_record(RecordType::CNAME);
|
||||
let rdata = RData::CNAME(Name::new());
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::CNAME("".to_string())));
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::Cname("".to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -697,7 +697,7 @@ mod tests {
|
|||
let rdata = RData::MX(MX::new(10, Name::new()));
|
||||
assert_eq!(
|
||||
func(&rdata),
|
||||
Some(DnsReturnRecord::MX {
|
||||
Some(DnsReturnRecord::Mx {
|
||||
preference: 10,
|
||||
exchange: "".to_string()
|
||||
})
|
||||
|
@ -708,7 +708,7 @@ mod tests {
|
|||
fn rdata_to_return_record_ptr() {
|
||||
let func = rdata_to_return_record(RecordType::PTR);
|
||||
let rdata = RData::PTR(Name::new());
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::PTR("".to_string())));
|
||||
assert_eq!(func(&rdata), Some(DnsReturnRecord::Ptr("".to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -717,7 +717,7 @@ mod tests {
|
|||
let rdata = RData::SRV(SRV::new(1, 2, 3, Name::new()));
|
||||
assert_eq!(
|
||||
func(&rdata),
|
||||
Some(DnsReturnRecord::SRV {
|
||||
Some(DnsReturnRecord::Srv {
|
||||
priority: 1,
|
||||
weight: 2,
|
||||
port: 3,
|
||||
|
@ -737,7 +737,7 @@ mod tests {
|
|||
]));
|
||||
assert_eq!(
|
||||
func(&rdata),
|
||||
Some(DnsReturnRecord::TXT(vec![
|
||||
Some(DnsReturnRecord::Txt(vec![
|
||||
"foo".to_string(),
|
||||
"bar".to_string(),
|
||||
"£".to_string(),
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConnectTLSArgs {
|
||||
pub struct ConnectTlsArgs {
|
||||
transport: String,
|
||||
hostname: String,
|
||||
port: u16,
|
||||
|
@ -88,7 +88,7 @@ pub struct ConnectTLSArgs {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct StartTLSArgs {
|
||||
struct StartTlsArgs {
|
||||
rid: ResourceId,
|
||||
cert_file: Option<String>,
|
||||
hostname: String,
|
||||
|
@ -96,7 +96,7 @@ struct StartTLSArgs {
|
|||
|
||||
async fn op_start_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: StartTLSArgs,
|
||||
args: StartTlsArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let rid = args.rid;
|
||||
|
@ -166,7 +166,7 @@ async fn op_start_tls(
|
|||
|
||||
async fn op_connect_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: ConnectTLSArgs,
|
||||
args: ConnectTlsArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
{
|
||||
|
|
|
@ -964,7 +964,7 @@ impl HttpServerCount {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
panic!(maybe_line.unwrap_err());
|
||||
panic!("{}", maybe_line.unwrap_err());
|
||||
}
|
||||
}
|
||||
self.test_server = Some(test_server);
|
||||
|
|
Loading…
Reference in a new issue