diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 525d248..1a39b46 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,9 +12,10 @@ - + + - + - { + "keyToString": { + "Cargo.Build `Test back::wgsl::test::test_into`.executor": "Run", + "Cargo.Build `Test reflect::cross::test::test_into`.executor": "Run", + "Cargo.Test back::wgsl::test::test_into.executor": "Run", + "Cargo.Test front::naga::test::naga_playground (1).executor": "Run", + "Cargo.Test front::naga::test::naga_playground.executor": "Run", + "Cargo.Test reflect::cross::test::test_into.executor": "Run", + "Cargo.Test triangle_d3d11.executor": "Run", + "Cargo.Test triangle_d3d12.executor": "Run", + "Cargo.Test triangle_gl.executor": "Run", + "Cargo.Test triangle_gl46.executor": "Run", + "Cargo.Test triangle_vk.executor": "Run", + "Cargo.Test triangle_wgpu.executor": "Run", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.RadMigrateCodeStyle": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "RunOnceActivity.readMode.enableVisualFormatting": "true", + "cf.first.check.clang-format": "false", + "cidr.known.project.marker": "true", + "git-widget-placeholder": "feat-wgpu-runtime", + "last_opened_file_path": "C:/coding/librashader", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", + "settings.editor.selected.configurable": "language.rust", + "vue.rearranger.settings.migration": "true" } -}]]> +} @@ -264,7 +265,8 @@ - + + - @@ -319,7 +329,8 @@ - diff --git a/librashader-runtime-wgpu/src/lib.rs b/librashader-runtime-wgpu/src/lib.rs index 86ad583..dee60f9 100644 --- a/librashader-runtime-wgpu/src/lib.rs +++ b/librashader-runtime-wgpu/src/lib.rs @@ -14,6 +14,7 @@ mod texture; mod filter_pass; mod graphics_pipeline; mod util; +mod samplers; pub use filter_chain::FilterChainWGPU; pub use filter_pass::FilterPass; \ No newline at end of file diff --git a/librashader-runtime-wgpu/src/samplers.rs b/librashader-runtime-wgpu/src/samplers.rs new file mode 100644 index 0000000..b6f1a5a --- /dev/null +++ b/librashader-runtime-wgpu/src/samplers.rs @@ -0,0 +1,61 @@ +use librashader_common::{FilterMode, WrapMode}; +use crate::error; +use rustc_hash::FxHashMap; +use std::sync::Arc; +use wgpu::{Sampler, SamplerBorderColor, SamplerDescriptor}; + +pub struct SamplerSet { + // todo: may need to deal with differences in mip filter. + samplers: FxHashMap<(WrapMode, FilterMode, FilterMode), Sampler>, +} + +impl SamplerSet { + #[inline(always)] + pub fn get(&self, wrap: WrapMode, filter: FilterMode, mipmap: FilterMode) -> &Sampler { + // eprintln!("{wrap}, {filter}, {mip}"); + // SAFETY: the sampler set is complete for the matrix + // wrap x filter x mipmap + unsafe { + self.samplers + .get(&(wrap, filter, mipmap)) + .unwrap_unchecked() + } + } + + pub fn new(device: &wgpu::Device) -> error::Result { + let mut samplers = FxHashMap::default(); + let wrap_modes = &[ + WrapMode::ClampToBorder, + WrapMode::ClampToEdge, + WrapMode::Repeat, + WrapMode::MirroredRepeat, + ]; + for wrap_mode in wrap_modes { + for filter_mode in &[FilterMode::Linear, FilterMode::Nearest] { + for mipmap_filter in &[FilterMode::Linear, FilterMode::Nearest] { + samplers.insert( + (*wrap_mode, *filter_mode, *mipmap_filter), + device.create_sampler(&SamplerDescriptor { + label: None, + address_mode_u: wrap_mode.into(), + address_mode_v: wrap_mode.into(), + address_mode_w: wrap_mode.into(), + mag_filter: filter_mode.into(), + min_filter: filter_mode.into(), + mipmap_filter: mipmap_filter.into(), + lod_min_clamp: 0.0, + lod_max_clamp: 1000.0, + compare: None, + anisotropy_clamp: 1, + border_color: Some(SamplerBorderColor::TransparentBlack), + }) + ); + } + } + } + + // assert all samplers were created. + assert_eq!(samplers.len(), wrap_modes.len() * 2 * 2); + Ok(SamplerSet { samplers }) + } +}