From 704760bcb7e76095c0558947077b4d411d0be092 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Mon, 25 Dec 2023 00:35:04 +0800 Subject: [PATCH] Upgrade from spirq 0.6.2 to 1.0.2 (#68) * Upgrade from spirq 0.6.2 to 1.0.2 * Improve spirv error logging --------- Co-authored-by: John Wells --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/driver/shader.rs | 32 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51700b3..d702ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Ability to select from available swapchain surface formats when creating an `EventLoop` +### Changed + +- Upgraded to spirq v1.0.2 + ## [0.9.0] - 2023-09-07 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 2f06e29..4a04224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ parking_lot = "0.12" paste = "1.0" profiling = "1.0" raw-window-handle = "0.5" -spirq = "=0.6.2" +spirq = "1.0.2" vk-sync = { version = "0.4.0", package = "vk-sync-fork" } # // SEE: https://github.com/gwihlidal/vk-sync-rs/pull/4 -> https://github.com/expenses/vk-sync-rs winit = { version = "0.28" } diff --git a/src/driver/shader.rs b/src/driver/shader.rs index ab7ef9f..cdd25d5 100644 --- a/src/driver/shader.rs +++ b/src/driver/shader.rs @@ -7,8 +7,10 @@ use { log::{debug, error, trace, warn}, ordered_float::OrderedFloat, spirq::{ - ty::{ScalarType, Type}, - DescriptorType, EntryPoint, ReflectConfig, Variable, + entry_point::EntryPoint, + ty::{DescriptorType, ScalarType, SpirvType, Type}, + var::Variable, + ReflectConfig, }, std::{ collections::{BTreeMap, HashMap}, @@ -914,7 +916,9 @@ impl Shader { }) .flatten() .map(|push_const| { - push_const.offset..push_const.offset + push_const.ty.nbyte().unwrap_or_default() + let offset = push_const.offset.unwrap_or_default(); + let size = push_const.ty.nbyte().unwrap_or_default(); + offset..offset + size }) .reduce(|a, b| a.start.min(b.start)..a.end.max(b.end)) .map(|push_const| vk::PushConstantRange { @@ -938,13 +942,17 @@ impl Shader { spec.constant_id, spec_info.data[spec.offset as usize..spec.offset as usize + spec.size] .try_into() - .map_err(|_| DriverError::InvalidData)?, + .map_err(|err| { + error!("Unable to specialize spirv: {err}"); + + DriverError::InvalidData + })?, ); } } - let entry_points = config.reflect().map_err(|_| { - error!("Unable to reflect spirv"); + let entry_points = config.reflect().map_err(|err| { + error!("Unable to reflect spirv: {err}"); DriverError::InvalidData })?; @@ -968,21 +976,25 @@ impl Shader { fn scalar_format(ty: &ScalarType, byte_len: u32) -> vk::Format { match ty { - ScalarType::Float(_) => match byte_len { + ScalarType::Float { .. } => match byte_len { 4 => vk::Format::R32_SFLOAT, 8 => vk::Format::R32G32_SFLOAT, 12 => vk::Format::R32G32B32_SFLOAT, 16 => vk::Format::R32G32B32A32_SFLOAT, _ => unimplemented!("byte_len {byte_len}"), }, - ScalarType::Signed(_) => match byte_len { + ScalarType::Integer { + is_signed: true, .. + } => match byte_len { 4 => vk::Format::R32_SINT, 8 => vk::Format::R32G32_SINT, 12 => vk::Format::R32G32B32_SINT, 16 => vk::Format::R32G32B32A32_SINT, _ => unimplemented!("byte_len {byte_len}"), }, - ScalarType::Unsigned(_) => match byte_len { + ScalarType::Integer { + is_signed: false, .. + } => match byte_len { 4 => vk::Format::R32_UINT, 8 => vk::Format::R32G32_UINT, 12 => vk::Format::R32G32B32_UINT, @@ -1032,7 +1044,7 @@ impl Shader { location, binding, format: match ty { - Type::Scalar(ty) => scalar_format(ty, ty.nbyte() as _), + Type::Scalar(ty) => scalar_format(ty, ty.nbyte().unwrap_or_default() as _), Type::Vector(ty) => scalar_format(&ty.scalar_ty, byte_stride), _ => unimplemented!("{:?}", ty), },