Skip to content

Commit

Permalink
Upgrade from spirq 0.6.2 to 1.0.2 (#68)
Browse files Browse the repository at this point in the history
* Upgrade from spirq 0.6.2 to 1.0.2
* Improve spirv error logging

---------

Co-authored-by: John Wells <[email protected]>
  • Loading branch information
PENGUINLIONG and attackgoat authored Dec 24, 2023
1 parent dfc7f9c commit 704760b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
32 changes: 22 additions & 10 deletions src/driver/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand All @@ -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
})?;
Expand All @@ -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,
Expand Down Expand Up @@ -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),
},
Expand Down

0 comments on commit 704760b

Please sign in to comment.