From 22aa59b598641d8cdc88e3a15c59b46b50fd8f41 Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 18 Feb 2024 15:16:16 -0500 Subject: [PATCH] reflect: move spirv_passes out of naga --- librashader-reflect/src/front/mod.rs | 1 + .../spirv_passes/link_input_outputs.rs | 0 .../spirv_passes/lower_samplers.rs | 0 .../src/front/spirv_passes/mod.rs | 10 ++++++++++ librashader-reflect/src/reflect/naga/mod.rs | 18 +++--------------- .../src/reflect/naga/spirv_passes/mod.rs | 2 -- 6 files changed, 14 insertions(+), 17 deletions(-) rename librashader-reflect/src/{reflect/naga => front}/spirv_passes/link_input_outputs.rs (100%) rename librashader-reflect/src/{reflect/naga => front}/spirv_passes/lower_samplers.rs (100%) create mode 100644 librashader-reflect/src/front/spirv_passes/mod.rs delete mode 100644 librashader-reflect/src/reflect/naga/spirv_passes/mod.rs diff --git a/librashader-reflect/src/front/mod.rs b/librashader-reflect/src/front/mod.rs index 7386d40..dddd595 100644 --- a/librashader-reflect/src/front/mod.rs +++ b/librashader-reflect/src/front/mod.rs @@ -1,6 +1,7 @@ use crate::error::ShaderCompileError; use librashader_preprocess::ShaderSource; use serde::{Deserialize, Serialize}; +pub(crate) mod spirv_passes; mod glslang; diff --git a/librashader-reflect/src/reflect/naga/spirv_passes/link_input_outputs.rs b/librashader-reflect/src/front/spirv_passes/link_input_outputs.rs similarity index 100% rename from librashader-reflect/src/reflect/naga/spirv_passes/link_input_outputs.rs rename to librashader-reflect/src/front/spirv_passes/link_input_outputs.rs diff --git a/librashader-reflect/src/reflect/naga/spirv_passes/lower_samplers.rs b/librashader-reflect/src/front/spirv_passes/lower_samplers.rs similarity index 100% rename from librashader-reflect/src/reflect/naga/spirv_passes/lower_samplers.rs rename to librashader-reflect/src/front/spirv_passes/lower_samplers.rs diff --git a/librashader-reflect/src/front/spirv_passes/mod.rs b/librashader-reflect/src/front/spirv_passes/mod.rs new file mode 100644 index 0000000..2c64871 --- /dev/null +++ b/librashader-reflect/src/front/spirv_passes/mod.rs @@ -0,0 +1,10 @@ +pub mod link_input_outputs; +pub mod lower_samplers; + +// Load SPIR-V as an rspirv module +pub(crate) fn load_module(words: &[u32]) -> rspirv::dr::Module { + let mut loader = rspirv::dr::Loader::new(); + rspirv::binary::parse_words(words, &mut loader).unwrap(); + let module = loader.module(); + module +} diff --git a/librashader-reflect/src/reflect/naga/mod.rs b/librashader-reflect/src/reflect/naga/mod.rs index 666ff77..e7305e9 100644 --- a/librashader-reflect/src/reflect/naga/mod.rs +++ b/librashader-reflect/src/reflect/naga/mod.rs @@ -1,6 +1,5 @@ pub mod msl; pub mod spirv; -mod spirv_passes; pub mod wgsl; use crate::error::{SemanticsErrorKind, ShaderReflectError}; @@ -14,8 +13,8 @@ use rspirv::binary::Assemble; use rspirv::dr::Builder; use rustc_hash::FxHashSet; +use crate::front::spirv_passes::lower_samplers; use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; -use crate::reflect::naga::spirv_passes::{link_input_outputs, lower_samplers}; use crate::reflect::semantics::{ BindingMeta, BindingStage, BufferReflection, MemberOffset, ShaderSemantics, TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UniformMemberBlock, @@ -115,13 +114,6 @@ impl TryFrom<&SpirvCompilation> for NagaReflect { type Error = ShaderReflectError; fn try_from(compile: &SpirvCompilation) -> Result { - fn load_module(words: &[u32]) -> rspirv::dr::Module { - let mut loader = rspirv::dr::Loader::new(); - rspirv::binary::parse_words(words, &mut loader).unwrap(); - let module = loader.module(); - module - } - fn lower_fragment_shader(builder: &mut Builder) { let mut pass = lower_samplers::LowerCombinedImageSamplerPass::new(builder); pass.ensure_op_type_sampler(); @@ -134,20 +126,16 @@ impl TryFrom<&SpirvCompilation> for NagaReflect { block_ctx_dump_prefix: None, }; - let vertex = load_module(&compile.vertex); - let fragment = load_module(&compile.fragment); + let vertex = crate::front::spirv_passes::load_module(&compile.vertex); + let fragment = crate::front::spirv_passes::load_module(&compile.fragment); let mut fragment = Builder::new_from_module(fragment); lower_fragment_shader(&mut fragment); - let mut pass = link_input_outputs::LinkInputs::new(&vertex, &mut fragment); - pass.do_pass(); - let vertex = vertex.assemble(); let fragment = fragment.module().assemble(); let vertex = naga::front::spv::parse_u8_slice(bytemuck::cast_slice(&vertex), &options)?; - let fragment = naga::front::spv::parse_u8_slice(bytemuck::cast_slice(&fragment), &options)?; Ok(NagaReflect { vertex, fragment }) diff --git a/librashader-reflect/src/reflect/naga/spirv_passes/mod.rs b/librashader-reflect/src/reflect/naga/spirv_passes/mod.rs deleted file mode 100644 index 2af9848..0000000 --- a/librashader-reflect/src/reflect/naga/spirv_passes/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod link_input_outputs; -pub mod lower_samplers;