rt(wgpu): sampler set

This commit is contained in:
chyyran 2023-12-14 22:47:33 +09:00 committed by Ronny Chan
parent 4e052159e7
commit f9df72a02d
3 changed files with 110 additions and 37 deletions

View file

@ -12,9 +12,10 @@
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" /> <cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="02471831-07cd-4975-a00c-e042450023a1" name="Changes" comment="reflect(wgsl): give push uniform a non-overlapping bind group"> <list default="true" id="02471831-07cd-4975-a00c-e042450023a1" name="Changes" comment="rt(wgpu): create pipeline bind group layouts">
<change afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/src/samplers.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/src/graphics_pipeline.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/src/graphics_pipeline.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/src/lib.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/src/lib.rs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -57,39 +58,39 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"Cargo.Build `Test back::wgsl::test::test_into`.executor": "Run", &quot;Cargo.Build `Test back::wgsl::test::test_into`.executor&quot;: &quot;Run&quot;,
"Cargo.Build `Test reflect::cross::test::test_into`.executor": "Run", &quot;Cargo.Build `Test reflect::cross::test::test_into`.executor&quot;: &quot;Run&quot;,
"Cargo.Test back::wgsl::test::test_into.executor": "Run", &quot;Cargo.Test back::wgsl::test::test_into.executor&quot;: &quot;Run&quot;,
"Cargo.Test front::naga::test::naga_playground (1).executor": "Run", &quot;Cargo.Test front::naga::test::naga_playground (1).executor&quot;: &quot;Run&quot;,
"Cargo.Test front::naga::test::naga_playground.executor": "Run", &quot;Cargo.Test front::naga::test::naga_playground.executor&quot;: &quot;Run&quot;,
"Cargo.Test reflect::cross::test::test_into.executor": "Run", &quot;Cargo.Test reflect::cross::test::test_into.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_d3d11.executor": "Run", &quot;Cargo.Test triangle_d3d11.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_d3d12.executor": "Run", &quot;Cargo.Test triangle_d3d12.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_gl.executor": "Run", &quot;Cargo.Test triangle_gl.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_gl46.executor": "Run", &quot;Cargo.Test triangle_gl46.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_vk.executor": "Run", &quot;Cargo.Test triangle_vk.executor&quot;: &quot;Run&quot;,
"Cargo.Test triangle_wgpu.executor": "Run", &quot;Cargo.Test triangle_wgpu.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.RadMigrateCodeStyle": "true", &quot;RunOnceActivity.RadMigrateCodeStyle&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.cidr.known.project.marker": "true", &quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
"RunOnceActivity.readMode.enableVisualFormatting": "true", &quot;RunOnceActivity.readMode.enableVisualFormatting&quot;: &quot;true&quot;,
"cf.first.check.clang-format": "false", &quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
"cidr.known.project.marker": "true", &quot;cidr.known.project.marker&quot;: &quot;true&quot;,
"git-widget-placeholder": "feat-wgpu-runtime", &quot;git-widget-placeholder&quot;: &quot;feat-wgpu-runtime&quot;,
"last_opened_file_path": "C:/coding/librashader", &quot;last_opened_file_path&quot;: &quot;C:/coding/librashader&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", &quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;,
"settings.editor.selected.configurable": "language.rust", &quot;settings.editor.selected.configurable&quot;: &quot;language.rust&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="F:\coding\librashader\librashader-reflect\src\back\wgsl" /> <recent name="F:\coding\librashader\librashader-reflect\src\back\wgsl" />
@ -264,7 +265,8 @@
<workItem from="1702425796345" duration="12240000" /> <workItem from="1702425796345" duration="12240000" />
<workItem from="1702482450853" duration="399000" /> <workItem from="1702482450853" duration="399000" />
<workItem from="1702482871248" duration="556000" /> <workItem from="1702482871248" duration="556000" />
<workItem from="1702484102491" duration="4924000" /> <workItem from="1702484102491" duration="5258000" />
<workItem from="1702561144428" duration="385000" />
</task> </task>
<task id="LOCAL-00001" summary="rt(wgpu): basic triangle example"> <task id="LOCAL-00001" summary="rt(wgpu): basic triangle example">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -306,7 +308,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1702513440377</updated> <updated>1702513440377</updated>
</task> </task>
<option name="localTasksCounter" value="6" /> <task id="LOCAL-00006" summary="rt(wgpu): create pipeline bind group layouts">
<option name="closed" value="true" />
<created>1702514856945</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1702514856945</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -319,7 +329,8 @@
<MESSAGE value="rt(wgpu): basic triangle example" /> <MESSAGE value="rt(wgpu): basic triangle example" />
<MESSAGE value="rt(wgpu): load shaders" /> <MESSAGE value="rt(wgpu): load shaders" />
<MESSAGE value="reflect(wgsl): give push uniform a non-overlapping bind group" /> <MESSAGE value="reflect(wgsl): give push uniform a non-overlapping bind group" />
<option name="LAST_COMMIT_MESSAGE" value="reflect(wgsl): give push uniform a non-overlapping bind group" /> <MESSAGE value="rt(wgpu): create pipeline bind group layouts" />
<option name="LAST_COMMIT_MESSAGE" value="rt(wgpu): create pipeline bind group layouts" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View file

@ -14,6 +14,7 @@ mod texture;
mod filter_pass; mod filter_pass;
mod graphics_pipeline; mod graphics_pipeline;
mod util; mod util;
mod samplers;
pub use filter_chain::FilterChainWGPU; pub use filter_chain::FilterChainWGPU;
pub use filter_pass::FilterPass; pub use filter_pass::FilterPass;

View file

@ -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<SamplerSet> {
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 })
}
}