rt(wgpu): update to wgpu 0.19
This commit is contained in:
parent
34f224cc5d
commit
555ff6f9fc
|
@ -4,6 +4,5 @@
|
|||
<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/slang-shaders" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -12,7 +12,18 @@
|
|||
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
||||
</component>
|
||||
<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="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
|
@ -71,14 +82,15 @@
|
|||
"cf.first.check.clang-format": "false",
|
||||
"cidr.known.project.marker": "true",
|
||||
"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.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": "project.propVCSSupport.DirectoryMappings",
|
||||
"settings.editor.selected.configurable": "language.rust",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
|
@ -88,10 +100,11 @@
|
|||
<recent name="F:\coding\librashader\test" />
|
||||
</key>
|
||||
</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">
|
||||
<option name="command" value="run --package librashader-build-script --bin librashader-build-script" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -99,7 +112,6 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -109,6 +121,7 @@
|
|||
<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="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -116,7 +129,6 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -126,6 +138,7 @@
|
|||
<configuration name="Test librashader" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||
<option name="command" value="test --workspace" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -133,7 +146,6 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -143,6 +155,7 @@
|
|||
<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="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -150,24 +163,6 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<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="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -177,6 +172,7 @@
|
|||
<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="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -184,7 +180,6 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -194,6 +189,7 @@
|
|||
<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="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<envs />
|
||||
<option name="emulateTerminal" value="true" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
|
@ -201,7 +197,23 @@
|
|||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<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 />
|
||||
<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="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
|
@ -210,25 +222,25 @@
|
|||
</configuration>
|
||||
<list>
|
||||
<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 triangle_wgpu" />
|
||||
<item itemvalue="Cargo.Test back::wgsl::test::test_into" />
|
||||
<item itemvalue="Cargo.Test triangle_d3d11" />
|
||||
<item itemvalue="Cargo.Test triangle_d3d12" />
|
||||
<item itemvalue="Cargo.Test triangle_gl46" />
|
||||
<item itemvalue="Cargo.Test triangle_vk" />
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Cargo.Test triangle_wgpu" />
|
||||
<item itemvalue="Cargo.Test back::wgsl::test::test_into" />
|
||||
<item itemvalue="Cargo.Test triangle_gl46" />
|
||||
<item itemvalue="Cargo.Test triangle_vk" />
|
||||
<item itemvalue="Cargo.Test triangle_d3d11" />
|
||||
<item itemvalue="Cargo.Test triangle_d3d12" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<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 name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
|
@ -260,6 +272,8 @@
|
|||
<workItem from="1702561144428" duration="1836000" />
|
||||
<workItem from="1702640983281" duration="967000" />
|
||||
<workItem from="1705541451154" duration="11000" />
|
||||
<workItem from="1705545414525" duration="65000" />
|
||||
<workItem from="1705545579395" duration="3250000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="rt(wgpu): basic triangle example">
|
||||
<option name="closed" value="true" />
|
||||
|
|
755
Cargo.lock
generated
755
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -23,7 +23,7 @@ wgpu = ["wgpu-types"]
|
|||
[dependencies]
|
||||
gl = { version = "0.14.0", 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"
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
||||
naga = { version = "0.14.2", features = ["spv-in", "wgsl-out"], optional = true }
|
||||
rspirv = { version = "0.11.0+1.5.4", optional = true }
|
||||
spirv = { version = "0.2.0+1.5.4", optional = true}
|
||||
naga = { version = "0.19.0", features = ["spv-in", "wgsl-out"], optional = true }
|
||||
rspirv = { version = "0.12.0+sdk-1.3.268.0", optional = true }
|
||||
spirv = { version = "0.3.0+sdk-1.3.268.0", optional = true}
|
||||
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use crate::error::{SemanticsErrorKind, ShaderReflectError};
|
||||
|
||||
use naga::{
|
||||
AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, ScalarKind,
|
||||
TypeInner, VectorSize,
|
||||
};
|
||||
use naga::{AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, Scalar, ScalarKind, TypeInner, VectorSize};
|
||||
|
||||
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
|
||||
use crate::reflect::semantics::{
|
||||
|
@ -29,7 +26,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
|
|||
|
||||
match self {
|
||||
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)
|
||||
{
|
||||
return Some(TypeInfo {
|
||||
|
@ -40,7 +37,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
|
|||
}
|
||||
UniqueSemantics::FrameCount => {
|
||||
// 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 {
|
||||
size: 1,
|
||||
|
@ -50,7 +47,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
|
|||
}
|
||||
UniqueSemantics::FrameDirection => {
|
||||
// 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 {
|
||||
size: 1,
|
||||
|
@ -60,7 +57,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
|
|||
}
|
||||
UniqueSemantics::FloatParameter => {
|
||||
// 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 {
|
||||
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 {
|
||||
size: 4,
|
||||
|
@ -85,7 +82,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics {
|
|||
|
||||
impl ValidateTypeSemantics<&TypeInner> for TextureSemantics {
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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-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"
|
||||
image = "0.24.7"
|
||||
thiserror = "1.0.50"
|
||||
|
@ -22,12 +22,14 @@ rayon = "1.8.0"
|
|||
bytemuck = { version = "1.14.0", features = ["derive"] }
|
||||
|
||||
array-concat = "0.5.2"
|
||||
config = "0.13.4"
|
||||
once_cell = "1.19.0"
|
||||
|
||||
[dev-dependencies]
|
||||
config = { version = "0.13.4", features = [] }
|
||||
env_logger = "0.10.1"
|
||||
raw-window-handle = "0.5"
|
||||
winit = "0.28.7"
|
||||
raw-window-handle = "0.6.0"
|
||||
winit = "0.29.10"
|
||||
pollster = "0.3"
|
||||
log = "0.4.20"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use array_concat::concat_arrays;
|
||||
use librashader_runtime::quad::QuadType;
|
||||
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
||||
use wgpu::{Buffer, BufferDescriptor, Device, RenderPass};
|
||||
use wgpu::{Buffer, BufferAddress, BufferDescriptor, Device, Maintain, Queue, RenderPass};
|
||||
|
||||
#[rustfmt::skip]
|
||||
const VBO_OFFSCREEN: [f32; 16] = [
|
||||
|
@ -21,16 +21,17 @@ const VBO_DEFAULT_FINAL: [f32; 16] = [
|
|||
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 {
|
||||
buffer: Buffer,
|
||||
}
|
||||
|
||||
impl DrawQuad {
|
||||
pub fn new(device: &Device) -> DrawQuad {
|
||||
pub fn new(device: &Device, queue: &mut Queue) -> DrawQuad {
|
||||
let buffer = device.create_buffer_init(&BufferInitDescriptor {
|
||||
label: Some("librashader vbo"),
|
||||
contents: bytemuck::cast_slice(VBO_DATA),
|
||||
contents: bytemuck::cast_slice(&VBO_DATA),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ impl FilterChainWGPU {
|
|||
// FrameResiduals::new(&device.device)
|
||||
// });
|
||||
|
||||
let draw_quad = DrawQuad::new(&device);
|
||||
let draw_quad = DrawQuad::new(&device, queue);
|
||||
|
||||
Ok(FilterChainWGPU {
|
||||
common: FilterCommon {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
use wgpu::{ Maintain, };
|
||||
use winit::{
|
||||
event::*,
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
|
@ -8,6 +10,7 @@ use librashader_presets::ShaderPreset;
|
|||
use librashader_runtime_wgpu::FilterChainWGPU;
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::event_loop::EventLoopBuilder;
|
||||
use winit::keyboard::{Key, KeyCode, PhysicalKey};
|
||||
use winit::platform::windows::EventLoopBuilderExtWindows;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
@ -58,9 +61,9 @@ const VERTICES: &[Vertex] = &[
|
|||
},
|
||||
];
|
||||
|
||||
struct State {
|
||||
surface: wgpu::Surface,
|
||||
device: wgpu::Device,
|
||||
struct State<'a> {
|
||||
surface: wgpu::Surface<'a>,
|
||||
device: Arc<wgpu::Device>,
|
||||
queue: wgpu::Queue,
|
||||
config: wgpu::SurfaceConfiguration,
|
||||
size: winit::dpi::PhysicalSize<u32>,
|
||||
|
@ -72,8 +75,8 @@ struct State {
|
|||
num_vertices: u32,
|
||||
chain: FilterChainWGPU,
|
||||
}
|
||||
impl State {
|
||||
async fn new(window: &Window) -> Self {
|
||||
impl<'a> State<'a> {
|
||||
async fn new(window: &'a Window) -> Self {
|
||||
let size = window.inner_size();
|
||||
|
||||
let instance = wgpu::Instance::default();
|
||||
|
@ -88,11 +91,11 @@ impl State {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let (device, queue) = adapter
|
||||
let (device, mut queue) = adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
features: wgpu::Features::default(),
|
||||
limits: wgpu::Limits::default(),
|
||||
required_features: wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
required_limits: wgpu::Limits::default(),
|
||||
label: None,
|
||||
},
|
||||
None,
|
||||
|
@ -108,13 +111,27 @@ impl State {
|
|||
width: size.width,
|
||||
height: size.height,
|
||||
present_mode: wgpu::PresentMode::Fifo,
|
||||
desired_maximum_frame_latency: 2,
|
||||
alpha_mode: swapchain_capabilities.alpha_modes[0],
|
||||
view_formats: vec![],
|
||||
};
|
||||
|
||||
let device = Arc::new(device);
|
||||
|
||||
let mut cmd = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("start encoder"),
|
||||
});
|
||||
|
||||
let preset =
|
||||
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 {
|
||||
label: Some("Shader"),
|
||||
|
@ -162,7 +179,7 @@ impl State {
|
|||
});
|
||||
|
||||
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex Buffer"),
|
||||
label: Some("triangle vertices"),
|
||||
contents: bytemuck::cast_slice(VERTICES),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
|
@ -243,56 +260,45 @@ pub fn run() {
|
|||
let event_loop = EventLoopBuilder::new()
|
||||
.with_any_thread(true)
|
||||
.with_dpi_aware(true)
|
||||
.build();
|
||||
.build()
|
||||
.unwrap();
|
||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||
|
||||
pollster::block_on(async {
|
||||
let mut state = State::new(&window).await;
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
event_loop.run(|event, target| {
|
||||
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
if !state.input(event) {
|
||||
// UPDATED!
|
||||
match event {
|
||||
WindowEvent::CloseRequested
|
||||
| WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
state: ElementState::Pressed,
|
||||
virtual_keycode: Some(VirtualKeyCode::Escape),
|
||||
..
|
||||
},
|
||||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
WindowEvent::Resized(physical_size) => {
|
||||
state.resize(*physical_size);
|
||||
window_id: _,
|
||||
event
|
||||
} => match event {
|
||||
WindowEvent::Resized(new_size) => {
|
||||
state.resize(new_size);
|
||||
// On macos the window needs to be redrawn manually after resizing
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::RedrawRequested => {
|
||||
state.update();
|
||||
match state.render() {
|
||||
Ok(_) => {}
|
||||
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
|
||||
state.resize(state.size)
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
||||
state.resize(**new_inner_size);
|
||||
}
|
||||
_ => {}
|
||||
Err(wgpu::SurfaceError::OutOfMemory) => target.exit(),
|
||||
Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
|
||||
}
|
||||
}
|
||||
WindowEvent::CloseRequested => target.exit(),
|
||||
_ => {}
|
||||
}
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
state.update();
|
||||
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();
|
||||
Event::AboutToWait => {
|
||||
window.request_redraw()
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).unwrap();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue