Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Apply specialization to shader reflection #2329

Merged
merged 8 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Changes to the `khr_display` extension:
- Added `DeviceMemory::{map, unmap, mapping_state, invalidate_range, flush_range}`, `MappedDeviceMemory` has been deprecated.
- Added `MemoryMapInfo`, `MemoryUnmapInfo`, `MappingState` and `MappedMemoryRange`.
- Added `ShaderModule::single_entry_point()` which may replace `entry_point("main")` calls in common setups.
- Added `ShaderModule::single_entry_point_of_execution`.
- Added `ShaderModule::single_entry_point_with_execution`.
marc0246 marked this conversation as resolved.
Show resolved Hide resolved
- Added `GenericMemoryAllocatorCreateInfo::memory_type_bits` and `AllocationCreateInfo::memory_type_bits`.

### Bugs fixed
Expand Down
25 changes: 13 additions & 12 deletions examples/src/bin/dynamic-local-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,22 @@ fn main() {

let pipeline = {
let cs = cs::load(device.clone())
.unwrap()
.with_specialization(
[
(0, 0.2f32.into()),
(1, local_size_x.into()),
(2, local_size_y.into()),
(3, 0.5f32.into()),
(4, 1.0f32.into()),
]
.into_iter()
.collect(),
)
.unwrap()
.entry_point("main")
.unwrap();
let stage = PipelineShaderStageCreateInfo {
specialization_info: [
(0, 0.2f32.into()),
(1, local_size_x.into()),
(2, local_size_y.into()),
(3, 0.5f32.into()),
(4, 1.0f32.into()),
]
.into_iter()
.collect(),
..PipelineShaderStageCreateInfo::new(cs)
};
let stage = PipelineShaderStageCreateInfo::new(cs);
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([&stage])
Expand Down
14 changes: 6 additions & 8 deletions examples/src/bin/shader-types-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,12 @@ fn main() {
// Load the first shader, and create a pipeline for the shader.
let mult_pipeline = {
let cs = shaders::load_mult(device.clone())
.unwrap()
.with_specialization([(0, true.into())].into_iter().collect())
.unwrap()
.entry_point("main")
.unwrap();
let stage = PipelineShaderStageCreateInfo {
specialization_info: [(0, true.into())].into_iter().collect(),
..PipelineShaderStageCreateInfo::new(cs)
};
let stage = PipelineShaderStageCreateInfo::new(cs);
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([&stage])
Expand All @@ -281,13 +280,12 @@ fn main() {
// Load the second shader, and create a pipeline for the shader.
let add_pipeline = {
let cs = shaders::load_add(device.clone())
.unwrap()
.with_specialization([(0, true.into())].into_iter().collect())
.unwrap()
.entry_point("main")
.unwrap();
let stage = PipelineShaderStageCreateInfo {
specialization_info: [(0, true.into())].into_iter().collect(),
..PipelineShaderStageCreateInfo::new(cs)
};
let stage = PipelineShaderStageCreateInfo::new(cs);
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([&stage])
Expand Down
13 changes: 7 additions & 6 deletions examples/src/bin/specialization-constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ fn main() {

let pipeline = {
let cs = cs::load(device.clone())
.unwrap()
.with_specialization(
[(0, 1i32.into()), (1, 1.0f32.into()), (2, true.into())]
.into_iter()
.collect(),
)
.unwrap()
.entry_point("main")
.unwrap();
let stage = PipelineShaderStageCreateInfo {
specialization_info: [(0, 1i32.into()), (1, 1.0f32.into()), (2, true.into())]
.into_iter()
.collect(),
..PipelineShaderStageCreateInfo::new(cs)
};
let stage = PipelineShaderStageCreateInfo::new(cs);
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([&stage])
Expand Down
36 changes: 3 additions & 33 deletions vulkano-shaders/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// according to those terms.

use crate::{
entry_point,
structs::{self, TypeRegistry},
MacroInput,
};
Expand All @@ -23,10 +22,7 @@ use std::{
path::{Path, PathBuf},
};
use syn::{Error, LitStr};
use vulkano::{
shader::{reflect, spirv::Spirv},
Version,
};
use vulkano::shader::spirv::Spirv;

pub struct Shader {
pub source: LitStr,
Expand Down Expand Up @@ -238,29 +234,6 @@ pub(super) fn reflect(
}
});

let spirv_version = {
let Version {
major,
minor,
patch,
} = shader.spirv.version();

quote! {
::vulkano::Version {
major: #major,
minor: #minor,
patch: #patch,
}
}
};
let spirv_capabilities = reflect::spirv_capabilities(&shader.spirv).map(|capability| {
let name = format_ident!("{}", format!("{:?}", capability));
quote! { &::vulkano::shader::spirv::Capability::#name }
});
let spirv_extensions = reflect::spirv_extensions(&shader.spirv);
let entry_points =
reflect::entry_points(&shader.spirv).map(|info| entry_point::write_entry_point(&info));

let load_name = if shader.name.is_empty() {
format_ident!("load")
} else {
Expand All @@ -282,13 +255,9 @@ pub(super) fn reflect(
static WORDS: &[u32] = &[ #( #words ),* ];

unsafe {
::vulkano::shader::ShaderModule::new_with_data(
::vulkano::shader::ShaderModule::new(
device,
::vulkano::shader::ShaderModuleCreateInfo::new(&WORDS),
[ #( #entry_points ),* ],
#spirv_version,
[ #( #spirv_capabilities ),* ],
[ #( #spirv_extensions ),* ],
)
}
}
Expand All @@ -302,6 +271,7 @@ pub(super) fn reflect(
#[cfg(test)]
mod tests {
use super::*;
use vulkano::shader::reflect;

fn convert_paths(root_path: &Path, paths: &[PathBuf]) -> Vec<String> {
paths
Expand Down
Loading