Skip to content

Commit

Permalink
reduce package size
Browse files Browse the repository at this point in the history
  • Loading branch information
re-ovo committed Jan 5, 2025
1 parent bcca369 commit 8815456
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Cargo.lock
bin/
wasm-pack.log
.idea
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ wasm-bindgen = "0.2.84"
console_error_panic_hook = { version = "0.1.7", optional = true }
naga_oil = "0.16.0"
naga = { version = "23.1.0", features = ["wgsl-out"] }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.5"

[dev-dependencies]
wasm-bindgen-test = "0.3.34"
Expand Down
2 changes: 1 addition & 1 deletion pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/re-ovo/naga-oil-wasm"
},
"version": "0.1.0",
"version": "0.1.1",
"files": [
"naga_oil_wasm_bg.wasm",
"naga_oil_wasm.js",
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
mod shader_def;
mod utils;

use std::{collections::HashMap, iter::FromIterator};

use naga::{
back::wgsl,
valid::{Capabilities, ModuleInfo, ValidationFlags, Validator},
valid::{Capabilities, ValidationFlags, Validator},
};
use naga_oil::compose::{
ComposableModuleDescriptor, Composer, NagaModuleDescriptor,
ShaderDefValue as InternalShaderDefValue,
};
use shader_def::ShaderDefValue;
use wasm_bindgen::prelude::*;
use serde::{Deserialize, Serialize};

#[wasm_bindgen]
pub struct ShaderLibrary {
Expand Down Expand Up @@ -47,8 +43,11 @@ impl ShaderLibrary {
self.composer.remove_composable_module(name)
}

pub fn process(&mut self, source: &str, shader_defs: shader_def::ShaderDefs) -> Result<String, JsValue> {

pub fn process(
&mut self,
source: &str,
shader_defs: shader_def::ShaderDefs,
) -> Result<String, JsValue> {
// Create naga module
let module = self
.composer
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;

use naga::{
back::wgsl,
valid::{Capabilities, ModuleInfo, ValidationFlags, Validator},
valid::{Capabilities, ValidationFlags, Validator},
};
use naga_oil::compose::{
ComposableModuleDescriptor, Composer, NagaModuleDescriptor, ShaderDefValue,
Expand Down Expand Up @@ -31,10 +30,7 @@ fn process(composer: &mut Composer) {
let module = composer
.make_naga_module(NagaModuleDescriptor {
source: include_str!("../shaders/pbr.wgsl"),
shader_defs: [
("MAX_LIGHTS".to_string(), ShaderDefValue::Int(222)),
]
.into(),
shader_defs: [("MAX_LIGHTS".to_string(), ShaderDefValue::Int(222))].into(),
..Default::default()
})
.unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/shader_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ impl ShaderDefs {

impl ShaderDefs {
pub fn into_hash_map(self) -> HashMap<String, InternalShaderDefValue> {
self.shader_defs.into_iter().map(|(k, v)| (k, v.internal)).collect()
self.shader_defs
.into_iter()
.map(|(k, v)| (k, v.internal))
.collect()
}
}

0 comments on commit 8815456

Please sign in to comment.