Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 262575b
Author: munrocket <munsocket@protonmail.com>
Date:   Fri May 10 01:16:48 2024 +0400

    add optional extensions

commit de75501
Author: munrocket <munsocket@protonmail.com>
Date:   Thu May 9 21:46:51 2024 +0400

    comment timestamp
  • Loading branch information
davidar committed May 19, 2024
1 parent 287f58f commit edabd75
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pub async fn init_wgpu(width: u32, height: u32, bind_id: &str) -> Result<WgpuCon
})
.await
.ok_or("unable to create adapter")?;

log::info!("adapter.features = {:#?}", adapter.features());
log::info!("adapter.limits = {:#?}", adapter.limits());

let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
Expand Down Expand Up @@ -141,7 +145,6 @@ pub async fn init_wgpu(width: u32, height: u32, bind_id: &str) -> Result<WgpuCon
};
surface.configure(&device, &surface_config);

log::info!("adapter.limits = {:#?}", adapter.limits());
Ok(WgpuContext {
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
event_loop: Some(event_loop),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ fn passSampleLevelBilinearRepeat(pass_index: int, uv: float2, lod: float) -> flo

pub fn compile(&mut self, source: SourceMap) {
let now = instant::Instant::now();
let prelude = self.prelude(); // prelude must be generated after preprocessor has run
let prelude = format!("{}{}", source.extensions, self.prelude());

// FIXME: remove pending resolution of this issue: https://github.com/gfx-rs/wgpu/issues/2130
let prelude_len = count_newlines(&prelude);
Expand Down
17 changes: 12 additions & 5 deletions src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ impl WGSLError {

#[wasm_bindgen]
pub struct SourceMap {
#[wasm_bindgen(skip)]
pub extensions: String,
#[wasm_bindgen(skip)]
pub source: String,
#[wasm_bindgen(skip)]
Expand All @@ -54,6 +56,7 @@ pub struct SourceMap {
impl SourceMap {
pub fn new() -> Self {
Self {
extensions: String::new(),
source: String::new(),
map: vec![0],
workgroup_count: HashMap::new(),
Expand Down Expand Up @@ -81,7 +84,7 @@ pub struct Preprocessor {
source: SourceMap,
storage_count: usize,
assert_count: usize,
enable_strings: bool,
special_strings: bool,
}

static RE_COMMENT: Lazy<Regex> = lazy_regex!(r"(//.*|(?s:/\*.*?\*/))");
Expand All @@ -103,7 +106,7 @@ impl Preprocessor {
source: SourceMap::new(),
storage_count: 0,
assert_count: 0,
enable_strings: false,
special_strings: false,
}
}

Expand All @@ -129,7 +132,11 @@ impl Preprocessor {
#[async_recursion(?Send)]
async fn process_line(&mut self, line_orig: &str, n: usize) -> Result<(), WGSLError> {
let mut line = self.subst_defines(line_orig);
if line.trim_start().starts_with('#') {
if line.trim_start().starts_with("enable") {
line = RE_COMMENT.replace(&line, "").to_string();
self.source.extensions.push_str(&line);
self.source.extensions.push('\n');
} else if line.trim_start().starts_with('#') {
line = RE_COMMENT.replace(&line, "").to_string();
let tokens: Vec<&str> = line.trim().split(' ').collect();
match tokens[..] {
Expand All @@ -145,7 +152,7 @@ impl Preprocessor {
Some(cap) => {
let path = &cap[1];
if path == "string" {
self.enable_strings = true;
self.special_strings = true;
}
fetch_include(format!("std/{path}")).await
}
Expand Down Expand Up @@ -242,7 +249,7 @@ impl Preprocessor {
}
}
} else {
if self.enable_strings {
if self.special_strings {
let mut err = None;
line = RE_QUOTES.replace(&line, |caps: &Captures| {
if let Ok(s) = snailquote::unescape(&caps[0]) {
Expand Down
4 changes: 1 addition & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::WGSLError;

#[cfg(target_arch = "wasm32")]
use {
cached::proc_macro::cached, std::future::Future, wasm_bindgen::prelude::*,
};
use {cached::proc_macro::cached, std::future::Future, wasm_bindgen::prelude::*};

pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
Expand Down

0 comments on commit edabd75

Please sign in to comment.