Update dependencies (#765)

This commit is contained in:
Ashley Hauck 2021-10-14 16:38:15 +02:00 committed by GitHub
parent f8a1130377
commit e2db97f899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 506 additions and 731 deletions

1040
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"examples/runners/cpu",
"examples/runners/ash",

View File

@ -49,7 +49,7 @@ topological-sort = "0.1"
[dev-dependencies]
pipe = "0.4"
pretty_assertions = "0.7"
pretty_assertions = "1.0"
tempfile = "3.2"
[package.metadata.rust-analyzer]

View File

@ -12,7 +12,7 @@ bitflags = "1.2.1"
num-traits = { version = "0.2.14", default-features = false, features = ["libm"] }
spirv-types = { path = "./shared", version = "0.4.0-alpha.12" }
spirv-std-macros = { path = "./macros", version = "0.4.0-alpha.12" }
glam = { version = ">=0.17, <=0.18", default-features = false, features = ["libm"], optional = true }
glam = { version = ">=0.17, <=0.19", default-features = false, features = ["libm"], optional = true }
[features]
default = []

View File

@ -70,6 +70,7 @@ exceptions = [
# so we prefer to not have dependencies using it
# https://tldrlegal.com/license/creative-commons-cc0-1.0-universal
{ allow = ["CC0-1.0"], name = "notify" },
{ allow = ["CC0-1.0"], name = "hexf-parse" },
]
copyleft = "deny"

View File

@ -13,9 +13,9 @@ use-installed-tools = ["spirv-builder/use-installed-tools"]
use-compiled-tools = ["spirv-builder/use-compiled-tools"]
[dependencies]
ash = "0.32"
ash-window = "0.6"
winit = "0.25.0"
ash = "0.33"
ash-window = "0.7"
winit = { git = "https://github.com/rust-windowing/winit", rev = "1b3b82a3c1369c5248a2e6a251230ba6c615e918" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3.20"
@ -23,5 +23,9 @@ cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" }
spirv-builder = { path = "../../../crates/spirv-builder", default-features = false }
# TODO: Remove this once no longer needed, only needed to make cargo-deny happy for some reason.
# https://rustsec.org/advisories/RUSTSEC-2021-0119
nix = "0.20.2"
[target.'cfg(target_os = "macos")'.dependencies]
ash-molten = { git = "https://github.com/EmbarkStudios/ash-molten.git", rev = "fea270b0c9186b8a45e62215314204f4c16a57b6", features = ["pre-built"] }
ash-molten = { version = "0.11.0", features = ["pre-built"] }

View File

@ -73,7 +73,6 @@
use ash::{
extensions::{ext, khr},
util::read_spv,
version::{DeviceV1_0, EntryV1_0, InstanceV1_0},
vk,
};
@ -247,7 +246,7 @@ impl RenderBase {
pub fn new(window: winit::window::Window, options: &Options) -> Self {
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
let entry = ash_molten::MoltenEntry::load().unwrap();
let entry = ash_molten::MoltenEntry::load();
} else {
let entry = unsafe { ash::Entry::new().unwrap() };
}
@ -280,7 +279,7 @@ impl RenderBase {
.application_version(0)
.engine_name(&app_name)
.engine_version(0)
.api_version(vk::make_version(1, 2, 0));
.api_version(vk::make_api_version(1, 2, 0, 0));
let instance_create_info = vk::InstanceCreateInfo::builder()
.application_info(&appinfo)

View File

@ -19,23 +19,23 @@ use-compiled-tools = ["spirv-builder/use-compiled-tools"]
cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" }
futures = { version = "0.3", default-features = false, features = ["std", "executor"] }
wgpu = "0.9"
winit = { version = "0.25.0", features = ["web-sys"] }
clap = "3.0.0-beta.2"
strum = { version = "0.21.0", default_features = false, features = ["derive"] }
wgpu = { version = "0.11", features = ["spirv"] }
winit = { git = "https://github.com/rust-windowing/winit", rev = "1b3b82a3c1369c5248a2e6a251230ba6c615e918" }
structopt = "0.3"
strum = { version = "0.22.0", default_features = false, features = ["std", "derive"] }
bytemuck = "1.6.3"
[target.'cfg(not(any(target_os = "android", target_arch = "wasm32")))'.dependencies]
spirv-builder = { path = "../../../crates/spirv-builder", default-features = false, features = ["watch"] }
[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = "0.3"
ndk-glue = "0.4"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.8.4"
env_logger = "0.9.0"
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = "=0.3.50"
web-sys = "=0.3.55"
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wasm-bindgen-futures = "0.4.18"

View File

@ -22,12 +22,13 @@ pub fn start(options: &Options) {
pub async fn start_internal(
_options: &Options,
shader_binary: wgpu::ShaderModuleDescriptor<'static>,
shader_binary: wgpu::ShaderModuleDescriptorSpirV<'static>,
) {
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
force_fallback_adapter: false,
compatible_surface: None,
})
.await
@ -37,7 +38,8 @@ pub async fn start_internal(
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::TIMESTAMP_QUERY,
features: wgpu::Features::TIMESTAMP_QUERY
| wgpu::Features::SPIRV_SHADER_PASSTHROUGH,
limits: wgpu::Limits::default(),
},
None,
@ -50,7 +52,7 @@ pub async fn start_internal(
let timestamp_period = queue.get_timestamp_period();
// Load the shaders from disk
let module = device.create_shader_module(&shader_binary);
let module = unsafe { device.create_shader_module_spirv(&shader_binary) };
let top = 2u32.pow(20);
let src_range = 1..top;
@ -70,7 +72,7 @@ pub async fn start_internal(
wgpu::BindGroupLayoutEntry {
binding: 0,
count: None,
visibility: wgpu::ShaderStage::COMPUTE,
visibility: wgpu::ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
has_dynamic_offset: false,
min_binding_size: Some(NonZeroU64::new(1).unwrap()),
@ -97,22 +99,22 @@ pub async fn start_internal(
label: None,
size: src.len() as wgpu::BufferAddress,
// Can be read to the CPU, and can be copied from the shader's storage buffer
usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let storage_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Collatz Conjecture Input"),
contents: &src,
usage: wgpu::BufferUsage::STORAGE
| wgpu::BufferUsage::COPY_DST
| wgpu::BufferUsage::COPY_SRC,
usage: wgpu::BufferUsages::STORAGE
| wgpu::BufferUsages::COPY_DST
| wgpu::BufferUsages::COPY_SRC,
});
let timestamp_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Timestamps buffer"),
size: 16,
usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: true,
});
timestamp_buffer.unmap();
@ -127,6 +129,7 @@ pub async fn start_internal(
});
let queries = device.create_query_set(&wgpu::QuerySetDescriptor {
label: None,
count: 2,
ty: wgpu::QueryType::Timestamp,
});

View File

@ -33,13 +33,11 @@ fn mouse_button_index(button: MouseButton) -> usize {
}
async fn run(
event_loop: EventLoop<wgpu::ShaderModuleDescriptor<'static>>,
event_loop: EventLoop<wgpu::ShaderModuleDescriptorSpirV<'static>>,
window: Window,
swapchain_format: wgpu::TextureFormat,
shader_binary: wgpu::ShaderModuleDescriptor<'static>,
shader_binary: wgpu::ShaderModuleDescriptorSpirV<'static>,
) {
let size = window.inner_size();
let instance = wgpu::Instance::new(wgpu::BackendBit::VULKAN | wgpu::BackendBit::METAL);
let instance = wgpu::Instance::new(wgpu::Backends::VULKAN | wgpu::Backends::METAL);
// Wait for Resumed event on Android; the surface is only needed early to
// find an adapter that can render to this surface.
@ -52,13 +50,14 @@ async fn run(
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
force_fallback_adapter: false,
// Request an adapter which can render to our surface
compatible_surface: surface.as_ref(),
})
.await
.expect("Failed to find an appropriate adapter");
let features = wgpu::Features::PUSH_CONSTANTS;
let features = wgpu::Features::PUSH_CONSTANTS | wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
let limits = wgpu::Limits {
max_push_constant_size: 256,
..Default::default()
@ -83,25 +82,33 @@ async fn run(
label: None,
bind_group_layouts: &[],
push_constant_ranges: &[wgpu::PushConstantRange {
stages: wgpu::ShaderStage::all(),
stages: wgpu::ShaderStages::all(),
range: 0..std::mem::size_of::<ShaderConstants>() as u32,
}],
});
let mut render_pipeline =
create_pipeline(&device, &pipeline_layout, swapchain_format, shader_binary);
let preferred_format = if let Some(surface) = &surface {
surface.get_preferred_format(&adapter).unwrap()
} else {
// if Surface is none, we're guaranteed to be on android
wgpu::TextureFormat::Rgba8UnormSrgb
};
let mut sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: swapchain_format,
let mut render_pipeline =
create_pipeline(&device, &pipeline_layout, preferred_format, shader_binary);
let size = window.inner_size();
let mut surface_config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: preferred_format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
};
let mut swap_chain = surface
.as_ref()
.map(|surface| device.create_swap_chain(surface, &sc_desc));
if let Some(surface) = &mut surface {
surface.configure(&device, &surface_config);
}
let start = std::time::Instant::now();
@ -126,12 +133,12 @@ async fn run(
}
Event::Resumed => {
let s = unsafe { instance.create_surface(&window) };
swap_chain = Some(device.create_swap_chain(&s, &sc_desc));
surface_config.format = s.get_preferred_format(&adapter).unwrap();
s.configure(&device, &surface_config);
surface = Some(s);
}
Event::Suspended => {
surface = None;
swap_chain = None;
}
Event::WindowEvent {
event: WindowEvent::Resized(size),
@ -139,29 +146,41 @@ async fn run(
} => {
if size.width != 0 && size.height != 0 {
// Recreate the swap chain with the new size
sc_desc.width = size.width;
sc_desc.height = size.height;
surface_config.width = size.width;
surface_config.height = size.height;
if let Some(surface) = &surface {
swap_chain = Some(device.create_swap_chain(surface, &sc_desc));
surface.configure(&device, &surface_config);
}
} else {
// Swap chains must have non-zero dimensions
swap_chain = None;
}
}
Event::RedrawRequested(_) => {
if let Some(swap_chain) = &mut swap_chain {
let frame = swap_chain
.get_current_frame()
.expect("Failed to acquire next swap chain texture")
.output;
if let Some(surface) = &mut surface {
let output = match surface.get_current_texture() {
Ok(surface) => surface,
Err(err) => {
eprintln!("get_current_texture error: {:?}", err);
match err {
wgpu::SurfaceError::Lost => {
surface.configure(&device, &surface_config);
}
wgpu::SurfaceError::OutOfMemory => {
*control_flow = ControlFlow::Exit;
}
_ => (),
}
return;
}
};
let output_view = output
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = device
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &frame.view,
view: &output_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
@ -195,7 +214,7 @@ async fn run(
rpass.set_pipeline(render_pipeline);
rpass.set_push_constants(
wgpu::ShaderStage::all(),
wgpu::ShaderStages::all(),
0,
bytemuck::bytes_of(&push_constants),
);
@ -203,6 +222,7 @@ async fn run(
}
queue.submit(Some(encoder.finish()));
output.present();
}
}
Event::WindowEvent {
@ -251,7 +271,7 @@ async fn run(
}
Event::UserEvent(new_module) => {
*render_pipeline =
create_pipeline(&device, &pipeline_layout, swapchain_format, new_module);
create_pipeline(&device, &pipeline_layout, surface_config.format, new_module);
window.request_redraw();
*control_flow = ControlFlow::Poll;
}
@ -263,10 +283,10 @@ async fn run(
fn create_pipeline(
device: &wgpu::Device,
pipeline_layout: &wgpu::PipelineLayout,
swapchain_format: wgpu::TextureFormat,
shader_binary: wgpu::ShaderModuleDescriptor<'_>,
surface_format: wgpu::TextureFormat,
shader_binary: wgpu::ShaderModuleDescriptorSpirV<'_>,
) -> wgpu::RenderPipeline {
let module = device.create_shader_module(&shader_binary);
let module = unsafe { device.create_shader_module_spirv(&shader_binary) };
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(pipeline_layout),
@ -294,9 +314,9 @@ fn create_pipeline(
module: &module,
entry_point: shaders::main_fs,
targets: &[wgpu::ColorTargetState {
format: swapchain_format,
format: surface_format,
blend: None,
write_mask: wgpu::ColorWrite::ALL,
write_mask: wgpu::ColorWrites::ALL,
}],
}),
})
@ -335,22 +355,15 @@ pub fn start(options: &Options) {
.ok()
})
.expect("couldn't append canvas to document body");
// Temporarily avoid srgb formats for the swapchain on the web
wasm_bindgen_futures::spawn_local(run(
event_loop,
window,
wgpu::TextureFormat::Bgra8Unorm,
initial_shader,
));
} else {
futures::executor::block_on(run(
event_loop,
window,
if cfg!(target_os = "android") {
wgpu::TextureFormat::Rgba8UnormSrgb
} else {
wgpu::TextureFormat::Bgra8UnormSrgb
},
initial_shader,
));

View File

@ -70,7 +70,7 @@
// crate-specific exceptions:
#![allow()]
use clap::Clap;
use structopt::StructOpt;
use strum::{Display, EnumString};
mod compute;
@ -86,8 +86,8 @@ pub enum RustGPUShader {
fn maybe_watch(
shader: RustGPUShader,
on_watch: Option<Box<dyn FnMut(wgpu::ShaderModuleDescriptor<'static>) + Send + 'static>>,
) -> wgpu::ShaderModuleDescriptor<'static> {
on_watch: Option<Box<dyn FnMut(wgpu::ShaderModuleDescriptorSpirV<'static>) + Send + 'static>>,
) -> wgpu::ShaderModuleDescriptorSpirV<'static> {
#[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
{
use spirv_builder::{Capability, CompileResult, MetadataPrintout, SpirvBuilder};
@ -126,22 +126,13 @@ fn maybe_watch(
};
fn handle_compile_result(
compile_result: CompileResult,
) -> wgpu::ShaderModuleDescriptor<'static> {
) -> wgpu::ShaderModuleDescriptorSpirV<'static> {
let module_path = compile_result.module.unwrap_single();
let data = std::fs::read(module_path).unwrap();
let spirv = wgpu::util::make_spirv(&data);
let spirv = match spirv {
wgpu::ShaderSource::Wgsl(cow) => {
wgpu::ShaderSource::Wgsl(Cow::Owned(cow.into_owned()))
}
wgpu::ShaderSource::SpirV(cow) => {
wgpu::ShaderSource::SpirV(Cow::Owned(cow.into_owned()))
}
};
wgpu::ShaderModuleDescriptor {
let spirv = Cow::Owned(wgpu::util::make_spirv_raw(&data).into_owned());
wgpu::ShaderModuleDescriptorSpirV {
label: None,
source: spirv,
flags: wgpu::ShaderFlags::default(),
}
}
handle_compile_result(initial_result)
@ -149,10 +140,10 @@ fn maybe_watch(
#[cfg(any(target_os = "android", target_arch = "wasm32"))]
{
match shader {
RustGPUShader::Simplest => wgpu::include_spirv!(env!("simplest_shader.spv")),
RustGPUShader::Sky => wgpu::include_spirv!(env!("sky_shader.spv")),
RustGPUShader::Compute => wgpu::include_spirv!(env!("compute_shader.spv")),
RustGPUShader::Mouse => wgpu::include_spirv!(env!("mouse_shader.spv")),
RustGPUShader::Simplest => wgpu::include_spirv_raw!(env!("simplest_shader.spv")),
RustGPUShader::Sky => wgpu::include_spirv_raw!(env!("sky_shader.spv")),
RustGPUShader::Compute => wgpu::include_spirv_raw!(env!("compute_shader.spv")),
RustGPUShader::Mouse => wgpu::include_spirv_raw!(env!("mouse_shader.spv")),
}
}
}
@ -161,16 +152,17 @@ fn is_compute_shader(shader: RustGPUShader) -> bool {
shader == RustGPUShader::Compute
}
#[derive(Clap)]
#[derive(StructOpt)]
#[structopt(name = "example-runner-wgpu")]
pub struct Options {
#[clap(short, long, default_value = "Sky")]
#[structopt(short, long, default_value = "Sky")]
shader: RustGPUShader,
}
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
pub fn main() {
env_logger::init();
let options: Options = Options::parse();
let options: Options = Options::from_args();
if is_compute_shader(options.shader) {
compute::start(&options);