rt(wgpu): update to wgpu 0.19

This commit is contained in:
chyyran 2024-01-17 22:35:52 -05:00 committed by Ronny Chan
parent 34f224cc5d
commit 555ff6f9fc
10 changed files with 722 additions and 254 deletions

View file

@ -4,6 +4,5 @@
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/test/shaders_slang" vcs="Git" /> <mapping directory="$PROJECT_DIR$/test/shaders_slang" vcs="Git" />
<mapping directory="$PROJECT_DIR$/test/slang-shaders" vcs="Git" />
</component> </component>
</project> </project>

View file

@ -12,7 +12,18 @@
<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="rt(wgpu): create pipeline" /> <list default="true" id="02471831-07cd-4975-a00c-e042450023a1" name="Changes" comment="rt(wgpu): create pipeline">
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-common/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-common/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-reflect/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-reflect/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-reflect/src/reflect/naga.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-reflect/src/reflect/naga.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/src/draw_quad.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/src/draw_quad.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/src/filter_chain.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/src/filter_chain.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/librashader-runtime-wgpu/tests/hello_triangle.rs" beforeDir="false" afterPath="$PROJECT_DIR$/librashader-runtime-wgpu/tests/hello_triangle.rs" afterDir="false" />
</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" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -71,14 +82,15 @@
"cf.first.check.clang-format": "false", "cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true", "cidr.known.project.marker": "true",
"git-widget-placeholder": "feat-wgpu-runtime", "git-widget-placeholder": "feat-wgpu-runtime",
"last_opened_file_path": "F:/coding/librashader", "ignore.virus.scanning.warn.message": "true",
"last_opened_file_path": "D:/Runtime/Rust/rustup",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true", "node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)", "node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm", "nodejs_package_manager_path": "npm",
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
"settings.editor.selected.configurable": "project.propVCSSupport.DirectoryMappings", "settings.editor.selected.configurable": "language.rust",
"vue.rearranger.settings.migration": "true" "vue.rearranger.settings.migration": "true"
} }
}]]></component> }]]></component>
@ -88,10 +100,11 @@
<recent name="F:\coding\librashader\test" /> <recent name="F:\coding\librashader\test" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Cargo.Test back::wgsl::test::test_into"> <component name="RunManager" selected="Cargo.Test triangle_wgpu">
<configuration name="Run librashader-build-script" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> <configuration name="Run librashader-build-script" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package librashader-build-script --bin librashader-build-script" /> <option name="command" value="run --package librashader-build-script --bin librashader-build-script" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -99,7 +112,6 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -109,6 +121,7 @@
<configuration name="Test back::wgsl::test::test_into" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Test back::wgsl::test::test_into" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-reflect --lib back::wgsl::test::test_into -- --exact" /> <option name="command" value="test --package librashader-reflect --lib back::wgsl::test::test_into -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -116,7 +129,6 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -126,6 +138,7 @@
<configuration name="Test librashader" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> <configuration name="Test librashader" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="test --workspace" /> <option name="command" value="test --workspace" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -133,7 +146,6 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -143,6 +155,7 @@
<configuration name="Test triangle_d3d11" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Test triangle_d3d11" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-runtime-d3d11 --test triangle triangle_d3d11 -- --exact" /> <option name="command" value="test --package librashader-runtime-d3d11 --test triangle triangle_d3d11 -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -150,24 +163,6 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test triangle_d3d12" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-runtime-d3d12 --test triangle triangle_d3d12 -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -177,6 +172,7 @@
<configuration name="Test triangle_gl46" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Test triangle_gl46" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-runtime-gl --test triangle triangle_gl46 -- --exact" /> <option name="command" value="test --package librashader-runtime-gl --test triangle triangle_gl46 -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -184,7 +180,6 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -194,6 +189,7 @@
<configuration name="Test triangle_vk" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Test triangle_vk" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-runtime-vk --test triangle triangle_vk -- --exact" /> <option name="command" value="test --package librashader-runtime-vk --test triangle triangle_vk -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@ -201,7 +197,23 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test triangle_wgpu" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package librashader-runtime-wgpu --test triangle triangle_wgpu -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs /> <envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" /> <option name="redirectInputPath" value="" />
<method v="2"> <method v="2">
@ -210,25 +222,25 @@
</configuration> </configuration>
<list> <list>
<item itemvalue="Cargo.Run librashader-build-script" /> <item itemvalue="Cargo.Run librashader-build-script" />
<item itemvalue="Cargo.Test back::wgsl::test::test_into" />
<item itemvalue="Cargo.Test librashader" /> <item itemvalue="Cargo.Test librashader" />
<item itemvalue="Cargo.Test triangle_wgpu" />
<item itemvalue="Cargo.Test back::wgsl::test::test_into" />
<item itemvalue="Cargo.Test triangle_d3d11" /> <item itemvalue="Cargo.Test triangle_d3d11" />
<item itemvalue="Cargo.Test triangle_d3d12" />
<item itemvalue="Cargo.Test triangle_gl46" /> <item itemvalue="Cargo.Test triangle_gl46" />
<item itemvalue="Cargo.Test triangle_vk" /> <item itemvalue="Cargo.Test triangle_vk" />
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Cargo.Test triangle_wgpu" />
<item itemvalue="Cargo.Test back::wgsl::test::test_into" /> <item itemvalue="Cargo.Test back::wgsl::test::test_into" />
<item itemvalue="Cargo.Test triangle_gl46" /> <item itemvalue="Cargo.Test triangle_gl46" />
<item itemvalue="Cargo.Test triangle_vk" /> <item itemvalue="Cargo.Test triangle_vk" />
<item itemvalue="Cargo.Test triangle_d3d11" /> <item itemvalue="Cargo.Test triangle_d3d11" />
<item itemvalue="Cargo.Test triangle_d3d12" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="RustProjectSettings"> <component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.rustup/toolchains/nightly-x86_64-pc-windows-msvc/bin" /> <option name="toolchainHomeDirectory" value="D:/Runtime/Rust/cargo/bin" />
</component> </component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
@ -260,6 +272,8 @@
<workItem from="1702561144428" duration="1836000" /> <workItem from="1702561144428" duration="1836000" />
<workItem from="1702640983281" duration="967000" /> <workItem from="1702640983281" duration="967000" />
<workItem from="1705541451154" duration="11000" /> <workItem from="1705541451154" duration="11000" />
<workItem from="1705545414525" duration="65000" />
<workItem from="1705545579395" duration="3250000" />
</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" />

755
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ wgpu = ["wgpu-types"]
[dependencies] [dependencies]
gl = { version = "0.14.0", optional = true } gl = { version = "0.14.0", optional = true }
ash = { version = "0.37", optional = true } ash = { version = "0.37", optional = true }
wgpu-types = { version = "0.18.0", optional = true } wgpu-types = { version = "0.19.0", optional = true }
num-traits = "0.2.15" num-traits = "0.2.15"

View file

@ -25,9 +25,9 @@ librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.2
spirv_cross = { package = "librashader-spirv-cross", version = "0.23", optional = true } spirv_cross = { package = "librashader-spirv-cross", version = "0.23", optional = true }
naga = { version = "0.14.2", features = ["spv-in", "wgsl-out"], optional = true } naga = { version = "0.19.0", features = ["spv-in", "wgsl-out"], optional = true }
rspirv = { version = "0.11.0+1.5.4", optional = true } rspirv = { version = "0.12.0+sdk-1.3.268.0", optional = true }
spirv = { version = "0.2.0+1.5.4", optional = true} spirv = { version = "0.3.0+sdk-1.3.268.0", optional = true}
serde = { version = "1.0", features = ["derive"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true }

View file

@ -1,9 +1,6 @@
use crate::error::{SemanticsErrorKind, ShaderReflectError}; use crate::error::{SemanticsErrorKind, ShaderReflectError};
use naga::{ use naga::{AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, Scalar, ScalarKind, TypeInner, VectorSize};
AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, ScalarKind,
TypeInner, VectorSize,
};
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
use crate::reflect::semantics::{ use crate::reflect::semantics::{
@ -29,7 +26,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
match self { match self {
UniqueSemantics::MVP => { UniqueSemantics::MVP => {
if matches!(ty, TypeInner::Matrix { columns, rows, width } if *columns == VectorSize::Quad if matches!(ty, TypeInner::Matrix { columns, rows, scalar: Scalar { width, .. } } if *columns == VectorSize::Quad
&& *rows == VectorSize::Quad && *width == 4) && *rows == VectorSize::Quad && *width == 4)
{ {
return Some(TypeInfo { return Some(TypeInfo {
@ -40,7 +37,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
} }
UniqueSemantics::FrameCount => { UniqueSemantics::FrameCount => {
// Uint32 == width 4 // Uint32 == width 4
if matches!(ty, TypeInner::Scalar { kind, width } if *kind == ScalarKind::Uint && *width == 4) if matches!(ty, TypeInner::Scalar( Scalar { kind, width }) if *kind == ScalarKind::Uint && *width == 4)
{ {
return Some(TypeInfo { return Some(TypeInfo {
size: 1, size: 1,
@ -50,7 +47,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
} }
UniqueSemantics::FrameDirection => { UniqueSemantics::FrameDirection => {
// Uint32 == width 4 // Uint32 == width 4
if matches!(ty, TypeInner::Scalar { kind, width } if *kind == ScalarKind::Sint && *width == 4) if matches!(ty, TypeInner::Scalar( Scalar { kind, width }) if *kind == ScalarKind::Sint && *width == 4)
{ {
return Some(TypeInfo { return Some(TypeInfo {
size: 1, size: 1,
@ -60,7 +57,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
} }
UniqueSemantics::FloatParameter => { UniqueSemantics::FloatParameter => {
// Float32 == width 4 // Float32 == width 4
if matches!(ty, TypeInner::Scalar { kind, width } if *kind == ScalarKind::Float && *width == 4) if matches!(ty, TypeInner::Scalar( Scalar { kind, width }) if *kind == ScalarKind::Float && *width == 4)
{ {
return Some(TypeInfo { return Some(TypeInfo {
size: 1, size: 1,
@ -69,7 +66,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
} }
} }
_ => { _ => {
if matches!(ty, TypeInner::Vector { kind, width, size } if *kind == ScalarKind::Float && *width == 4 && *size == VectorSize::Quad) if matches!(ty, TypeInner::Vector { scalar: Scalar { width, kind }, size } if *kind == ScalarKind::Float && *width == 4 && *size == VectorSize::Quad)
{ {
return Some(TypeInfo { return Some(TypeInfo {
size: 4, size: 4,
@ -85,7 +82,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
impl ValidateTypeSemantics<&TypeInner> for TextureSemantics { impl ValidateTypeSemantics<&TypeInner> for TextureSemantics {
fn validate_type(&self, ty: &&TypeInner) -> Option<TypeInfo> { fn validate_type(&self, ty: &&TypeInner) -> Option<TypeInfo> {
let TypeInner::Vector { size, kind, width } = ty else { let TypeInner::Vector { scalar: Scalar { width, kind }, size } = ty else {
return None; return None;
}; };

View file

@ -12,7 +12,7 @@ librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.2", features = [] } librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.2", features = [] }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.2" } librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.2" }
wgpu = { version = "0.18.0", features = ["spirv"] } wgpu = { version = "0.19.0", features = ["spirv"] }
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
image = "0.24.7" image = "0.24.7"
thiserror = "1.0.50" thiserror = "1.0.50"
@ -22,12 +22,14 @@ rayon = "1.8.0"
bytemuck = { version = "1.14.0", features = ["derive"] } bytemuck = { version = "1.14.0", features = ["derive"] }
array-concat = "0.5.2" array-concat = "0.5.2"
config = "0.13.4"
once_cell = "1.19.0"
[dev-dependencies] [dev-dependencies]
config = { version = "0.13.4", features = [] } config = { version = "0.13.4", features = [] }
env_logger = "0.10.1" env_logger = "0.10.1"
raw-window-handle = "0.5" raw-window-handle = "0.6.0"
winit = "0.28.7" winit = "0.29.10"
pollster = "0.3" pollster = "0.3"
log = "0.4.20" log = "0.4.20"

View file

@ -1,7 +1,7 @@
use array_concat::concat_arrays; use array_concat::concat_arrays;
use librashader_runtime::quad::QuadType; use librashader_runtime::quad::QuadType;
use wgpu::util::{BufferInitDescriptor, DeviceExt}; use wgpu::util::{BufferInitDescriptor, DeviceExt};
use wgpu::{Buffer, BufferDescriptor, Device, RenderPass}; use wgpu::{Buffer, BufferAddress, BufferDescriptor, Device, Maintain, Queue, RenderPass};
#[rustfmt::skip] #[rustfmt::skip]
const VBO_OFFSCREEN: [f32; 16] = [ const VBO_OFFSCREEN: [f32; 16] = [
@ -21,16 +21,17 @@ const VBO_DEFAULT_FINAL: [f32; 16] = [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static VBO_DATA: &[f32; 32] = &concat_arrays!(VBO_OFFSCREEN, VBO_DEFAULT_FINAL); const VBO_DATA: [f32; 32] = concat_arrays!(VBO_OFFSCREEN, VBO_DEFAULT_FINAL);
pub struct DrawQuad { pub struct DrawQuad {
buffer: Buffer, buffer: Buffer,
} }
impl DrawQuad { impl DrawQuad {
pub fn new(device: &Device) -> DrawQuad { pub fn new(device: &Device, queue: &mut Queue) -> DrawQuad {
let buffer = device.create_buffer_init(&BufferInitDescriptor { let buffer = device.create_buffer_init(&BufferInitDescriptor {
label: Some("librashader vbo"), label: Some("librashader vbo"),
contents: bytemuck::cast_slice(VBO_DATA), contents: bytemuck::cast_slice(&VBO_DATA),
usage: wgpu::BufferUsages::VERTEX, usage: wgpu::BufferUsages::VERTEX,
}); });

View file

@ -126,7 +126,7 @@ impl FilterChainWGPU {
// FrameResiduals::new(&device.device) // FrameResiduals::new(&device.device)
// }); // });
let draw_quad = DrawQuad::new(&device); let draw_quad = DrawQuad::new(&device, queue);
Ok(FilterChainWGPU { Ok(FilterChainWGPU {
common: FilterCommon { common: FilterCommon {

View file

@ -1,3 +1,5 @@
use std::sync::Arc;
use wgpu::{ Maintain, };
use winit::{ use winit::{
event::*, event::*,
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
@ -8,6 +10,7 @@ use librashader_presets::ShaderPreset;
use librashader_runtime_wgpu::FilterChainWGPU; use librashader_runtime_wgpu::FilterChainWGPU;
use wgpu::util::DeviceExt; use wgpu::util::DeviceExt;
use winit::event_loop::EventLoopBuilder; use winit::event_loop::EventLoopBuilder;
use winit::keyboard::{Key, KeyCode, PhysicalKey};
use winit::platform::windows::EventLoopBuilderExtWindows; use winit::platform::windows::EventLoopBuilderExtWindows;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -58,9 +61,9 @@ const VERTICES: &[Vertex] = &[
}, },
]; ];
struct State { struct State<'a> {
surface: wgpu::Surface, surface: wgpu::Surface<'a>,
device: wgpu::Device, device: Arc<wgpu::Device>,
queue: wgpu::Queue, queue: wgpu::Queue,
config: wgpu::SurfaceConfiguration, config: wgpu::SurfaceConfiguration,
size: winit::dpi::PhysicalSize<u32>, size: winit::dpi::PhysicalSize<u32>,
@ -72,8 +75,8 @@ struct State {
num_vertices: u32, num_vertices: u32,
chain: FilterChainWGPU, chain: FilterChainWGPU,
} }
impl State { impl<'a> State<'a> {
async fn new(window: &Window) -> Self { async fn new(window: &'a Window) -> Self {
let size = window.inner_size(); let size = window.inner_size();
let instance = wgpu::Instance::default(); let instance = wgpu::Instance::default();
@ -88,11 +91,11 @@ impl State {
.await .await
.unwrap(); .unwrap();
let (device, queue) = adapter let (device, mut queue) = adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
features: wgpu::Features::default(), required_features: wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
limits: wgpu::Limits::default(), required_limits: wgpu::Limits::default(),
label: None, label: None,
}, },
None, None,
@ -108,13 +111,27 @@ impl State {
width: size.width, width: size.width,
height: size.height, height: size.height,
present_mode: wgpu::PresentMode::Fifo, present_mode: wgpu::PresentMode::Fifo,
desired_maximum_frame_latency: 2,
alpha_mode: swapchain_capabilities.alpha_modes[0], alpha_mode: swapchain_capabilities.alpha_modes[0],
view_formats: vec![], view_formats: vec![],
}; };
let device = Arc::new(device);
let mut cmd = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("start encoder"),
});
let preset = let preset =
ShaderPreset::try_parse("../test/shaders_slang/crt/crt-royale.slangp").unwrap(); ShaderPreset::try_parse("../test/shaders_slang/crt/crt-royale.slangp").unwrap();
let chain = FilterChainWGPU::load_from_preset_deferred(&device, preset).unwrap();
let chain = FilterChainWGPU::load_from_preset_deferred(Arc::clone(&device), &mut queue, &mut cmd, preset).unwrap();
let cmd = cmd.finish();
let index = queue.submit([cmd]);
device.poll(Maintain::WaitForSubmissionIndex(index));
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"), label: Some("Shader"),
@ -162,7 +179,7 @@ impl State {
}); });
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Vertex Buffer"), label: Some("triangle vertices"),
contents: bytemuck::cast_slice(VERTICES), contents: bytemuck::cast_slice(VERTICES),
usage: wgpu::BufferUsages::VERTEX, usage: wgpu::BufferUsages::VERTEX,
}); });
@ -243,56 +260,45 @@ pub fn run() {
let event_loop = EventLoopBuilder::new() let event_loop = EventLoopBuilder::new()
.with_any_thread(true) .with_any_thread(true)
.with_dpi_aware(true) .with_dpi_aware(true)
.build(); .build()
.unwrap();
let window = WindowBuilder::new().build(&event_loop).unwrap(); let window = WindowBuilder::new().build(&event_loop).unwrap();
pollster::block_on(async { pollster::block_on(async {
let mut state = State::new(&window).await; let mut state = State::new(&window).await;
event_loop.run(move |event, _, control_flow| { event_loop.run(|event, target| {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
ref event, window_id: _,
window_id, event
} if window_id == window.id() => { } => match event {
if !state.input(event) { WindowEvent::Resized(new_size) => {
// UPDATED! state.resize(new_size);
match event { // On macos the window needs to be redrawn manually after resizing
WindowEvent::CloseRequested window.request_redraw();
| WindowEvent::KeyboardInput { }
input: WindowEvent::RedrawRequested => {
KeyboardInput { state.update();
state: ElementState::Pressed, match state.render() {
virtual_keycode: Some(VirtualKeyCode::Escape), Ok(_) => {}
.. Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
}, state.resize(state.size)
..
} => *control_flow = ControlFlow::Exit,
WindowEvent::Resized(physical_size) => {
state.resize(*physical_size);
} }
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { Err(wgpu::SurfaceError::OutOfMemory) => target.exit(),
state.resize(**new_inner_size); Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
}
_ => {}
} }
} }
WindowEvent::CloseRequested => target.exit(),
_ => {}
} }
Event::RedrawRequested(window_id) if window_id == window.id() => { Event::AboutToWait => {
state.update(); window.request_redraw()
match state.render() {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
}
}
Event::RedrawEventsCleared => {
window.request_redraw();
} }
_ => {} _ => {}
} }
});
}).unwrap();
}); });
} }