fmt: cargo fmt

This commit is contained in:
chyyran 2023-02-06 21:56:30 -05:00
parent 7ba2b26baa
commit 3eae38f815
12 changed files with 116 additions and 109 deletions

View file

@ -24,8 +24,7 @@ pub type libra_d3d11_filter_chain_t =
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))] #[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))] #[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
pub type libra_d3d12_filter_chain_t = pub type libra_d3d12_filter_chain_t =
Option<NonNull<librashader::runtime::d3d12::capi::FilterChainD3D12>>; Option<NonNull<librashader::runtime::d3d12::capi::FilterChainD3D12>>;
/// A handle to a Vulkan filter chain. /// A handle to a Vulkan filter chain.
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]

View file

@ -6,14 +6,16 @@ use std::ffi::CStr;
use std::mem::{ManuallyDrop, MaybeUninit}; use std::mem::{ManuallyDrop, MaybeUninit};
use std::ptr::NonNull; use std::ptr::NonNull;
use std::slice; use std::slice;
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_DESCRIPTOR_HANDLE, ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource}; use windows::Win32::Graphics::Direct3D12::{
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE,
};
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT;
pub use librashader::runtime::d3d12::capi::options::FilterChainOptionsD3D12; pub use librashader::runtime::d3d12::capi::options::FilterChainOptionsD3D12;
pub use librashader::runtime::d3d12::capi::options::FrameOptionsD3D12; pub use librashader::runtime::d3d12::capi::options::FrameOptionsD3D12;
use librashader::runtime::{FilterChainParameters, Size, Viewport};
use librashader::runtime::d3d12::{D3D12InputImage, D3D12OutputView}; use librashader::runtime::d3d12::{D3D12InputImage, D3D12OutputView};
use librashader::runtime::{FilterChainParameters, Size, Viewport};
/// Direct3D 11 parameters for the source image. /// Direct3D 11 parameters for the source image.
#[repr(C)] #[repr(C)]

View file

@ -2,7 +2,9 @@ use crate::back::spirv::WriteSpirV;
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput}; use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
pub use spirv_to_dxil::DxilObject; pub use spirv_to_dxil::DxilObject;
pub use spirv_to_dxil::ShaderModel; pub use spirv_to_dxil::ShaderModel;
use spirv_to_dxil::{PushConstantBufferConfig, RuntimeConfig, RuntimeDataBufferConfig, ShaderStage, ValidatorVersion}; use spirv_to_dxil::{
PushConstantBufferConfig, RuntimeConfig, RuntimeDataBufferConfig, ShaderStage, ValidatorVersion,
};
use crate::back::targets::{OutputTarget, DXIL}; use crate::back::targets::{OutputTarget, DXIL};
use crate::error::{ShaderCompileError, ShaderReflectError}; use crate::error::{ShaderCompileError, ShaderReflectError};

View file

@ -29,11 +29,9 @@ impl TryFrom<&GlslangCompilation> for NagaReflect {
fn try_from(value: &GlslangCompilation) -> Result<Self, Self::Error> { fn try_from(value: &GlslangCompilation) -> Result<Self, Self::Error> {
let ops = Options::default(); let ops = Options::default();
let vertex = let vertex =
naga::front::spv::Parser::new(value.vertex.clone().into_iter(), &ops) naga::front::spv::Parser::new(value.vertex.clone().into_iter(), &ops).parse()?;
.parse()?;
let fragment = let fragment =
naga::front::spv::Parser::new(value.fragment.clone().into_iter(), &ops) naga::front::spv::Parser::new(value.fragment.clone().into_iter(), &ops).parse()?;
.parse()?;
Ok(NagaReflect { vertex, fragment }) Ok(NagaReflect { vertex, fragment })
} }
} }

View file

@ -1,6 +1,6 @@
use array_concat::concat_arrays;
use crate::error; use crate::error;
use crate::error::assume_d3d11_init; use crate::error::assume_d3d11_init;
use array_concat::concat_arrays;
use bytemuck::offset_of; use bytemuck::offset_of;
use librashader_runtime::quad::QuadType; use librashader_runtime::quad::QuadType;
use windows::core::PCSTR; use windows::core::PCSTR;

View file

@ -13,11 +13,11 @@ use std::collections::VecDeque;
use std::path::Path; use std::path::Path;
use crate::draw_quad::DrawQuad;
use crate::error::{assume_d3d11_init, FilterChainError}; use crate::error::{assume_d3d11_init, FilterChainError};
use crate::filter_pass::{ConstantBufferBinding, FilterPass}; use crate::filter_pass::{ConstantBufferBinding, FilterPass};
use crate::framebuffer::OwnedFramebuffer; use crate::framebuffer::OwnedFramebuffer;
use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11}; use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11};
use crate::draw_quad::DrawQuad;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::util::d3d11_compile_bound_shader; use crate::util::d3d11_compile_bound_shader;
@ -26,20 +26,21 @@ use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtif
use librashader_runtime::binding::{BindingUtil, TextureInput}; use librashader_runtime::binding::{BindingUtil, TextureInput};
use librashader_runtime::quad::{QuadType, IDENTITY_MVP}; use librashader_runtime::quad::{QuadType, IDENTITY_MVP};
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use rayon::prelude::*;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC,
D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS,
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC,
}; };
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
use rayon::prelude::*;
pub struct FilterMutable { pub struct FilterMutable {
pub(crate) passes_enabled: usize, pub(crate) passes_enabled: usize,
pub(crate) parameters: FxHashMap<String, f32>, pub(crate) parameters: FxHashMap<String, f32>,
} }
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>; type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
/// A Direct3D 11 filter chain. /// A Direct3D 11 filter chain.
pub struct FilterChainD3D11 { pub struct FilterChainD3D11 {
@ -222,10 +223,10 @@ impl FilterChainD3D11 {
semantics: &ShaderSemantics, semantics: &ShaderSemantics,
) -> error::Result<Vec<FilterPass>> { ) -> error::Result<Vec<FilterPass>> {
// access to ID3D11Device is thread safe. // access to ID3D11Device is thread safe.
let filters: Vec<error::Result<FilterPass>> = let filters: Vec<error::Result<FilterPass>> = passes
passes.into_par_iter() .into_par_iter()
.enumerate() .enumerate()
.map(|(index, (config, source, mut reflect)) | { .map(|(index, (config, source, mut reflect))| {
let reflection = reflect.reflect(index, semantics)?; let reflection = reflect.reflect(index, semantics)?;
let hlsl = reflect.compile(None)?; let hlsl = reflect.compile(None)?;
@ -296,7 +297,8 @@ impl FilterChainD3D11 {
source, source,
config: config.clone(), config: config.clone(),
}) })
}).collect(); })
.collect();
let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect(); let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect();
let filters = filters?; let filters = filters?;

View file

@ -9,13 +9,13 @@
#[cfg(test)] #[cfg(test)]
mod hello_triangle; mod hello_triangle;
mod draw_quad;
pub mod error; pub mod error;
mod filter_chain; mod filter_chain;
mod filter_pass; mod filter_pass;
mod framebuffer; mod framebuffer;
pub mod options; pub mod options;
mod parameters; mod parameters;
mod draw_quad;
mod render_target; mod render_target;
mod samplers; mod samplers;
mod texture; mod texture;
@ -86,7 +86,7 @@ mod tests {
}), }),
// replace below with 'None' for the triangle // replace below with 'None' for the triangle
// None, // None,
Some(Image::load(IMAGE_PATH, UVDirection::TopLeft).unwrap()) Some(Image::load(IMAGE_PATH, UVDirection::TopLeft).unwrap()),
) )
.unwrap(); .unwrap();
// let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new( // let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new(

View file

@ -261,21 +261,22 @@ impl D3D12MipmapGen {
let mipmap_params = bytemuck::bytes_of(&mipmap_params); let mipmap_params = bytemuck::bytes_of(&mipmap_params);
util::d3d12_resource_transition_subresource( let barriers = [
cmd, util::d3d12_get_resource_transition_subresource(
resource, resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i - 1, i - 1,
); ),
util::d3d12_get_resource_transition_subresource(
util::d3d12_resource_transition_subresource(
cmd,
resource, resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i, i,
); ),
];
cmd.ResourceBarrier(&barriers);
cmd.SetComputeRootDescriptorTable(1, *heap_slots[i as usize].deref().as_ref()); cmd.SetComputeRootDescriptorTable(1, *heap_slots[i as usize].deref().as_ref());
cmd.SetComputeRoot32BitConstants( cmd.SetComputeRoot32BitConstants(
@ -297,29 +298,27 @@ impl D3D12MipmapGen {
pResource: windows::core::ManuallyDrop::new(resource), pResource: windows::core::ManuallyDrop::new(resource),
}); });
let barrier = [D3D12_RESOURCE_BARRIER { let barriers = [
D3D12_RESOURCE_BARRIER {
Type: D3D12_RESOURCE_BARRIER_TYPE_UAV, Type: D3D12_RESOURCE_BARRIER_TYPE_UAV,
Anonymous: D3D12_RESOURCE_BARRIER_0 { UAV: uav_barrier }, Anonymous: D3D12_RESOURCE_BARRIER_0 { UAV: uav_barrier },
..Default::default() ..Default::default()
}]; },
util::d3d12_get_resource_transition_subresource(
cmd.ResourceBarrier(&barrier);
util::d3d12_resource_transition_subresource(
cmd,
resource, resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i, i,
); ),
util::d3d12_get_resource_transition_subresource(
util::d3d12_resource_transition_subresource(
cmd,
resource, resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i - 1, i - 1,
); ),
];
cmd.ResourceBarrier(&barriers);
} }
Ok(heap_slots) Ok(heap_slots)

View file

@ -40,7 +40,8 @@ pub struct VulkanObjects {
pipeline_cache: vk::PipelineCache, pipeline_cache: vk::PipelineCache,
} }
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>; type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>;
/// A collection of handles needed to access the Vulkan instance. /// A collection of handles needed to access the Vulkan instance.
#[derive(Clone)] #[derive(Clone)]
@ -311,7 +312,8 @@ impl FilterChainVulkan {
) -> error::Result<Box<[FilterPass]>> { ) -> error::Result<Box<[FilterPass]>> {
let frames_in_flight = std::cmp::max(1, frames_in_flight); let frames_in_flight = std::cmp::max(1, frames_in_flight);
let filters: Vec<error::Result<FilterPass>> = passes.into_par_iter() let filters: Vec<error::Result<FilterPass>> = passes
.into_par_iter()
.enumerate() .enumerate()
.map(|(index, (config, source, mut reflect))| { .map(|(index, (config, source, mut reflect))| {
let reflection = reflect.reflect(index, semantics)?; let reflection = reflect.reflect(index, semantics)?;
@ -331,8 +333,7 @@ impl FilterChainVulkan {
.map_or(0, |push| push.size as usize), .map_or(0, |push| push.size as usize),
); );
let uniform_bindings = reflection.meta let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
.create_binding_map(|param| param.offset());
let render_pass_format = if !use_render_pass { let render_pass_format = if !use_render_pass {
vk::Format::UNDEFINED vk::Format::UNDEFINED
@ -365,7 +366,8 @@ impl FilterChainVulkan {
// ubo_ring, // ubo_ring,
frames_in_flight, frames_in_flight,
}) })
}).collect(); })
.collect();
let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect(); let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect();
let filters = filters?; let filters = filters?;

View file

@ -145,12 +145,15 @@ where
} }
impl<H, C, U> UniformStorage<H, C, U, Box<[u8]>> impl<H, C, U> UniformStorage<H, C, U, Box<[u8]>>
where where
C: Copy, C: Copy,
U: Deref<Target = [u8]> + DerefMut, U: Deref<Target = [u8]> + DerefMut,
{ {
/// Create a new `UniformStorage` with the given backing storage /// Create a new `UniformStorage` with the given backing storage
pub fn new_with_ubo_storage(storage: U, push_size: usize) -> UniformStorage<H, C, U, Box<[u8]>> { pub fn new_with_ubo_storage(
storage: U,
push_size: usize,
) -> UniformStorage<H, C, U, Box<[u8]>> {
UniformStorage { UniformStorage {
ubo: storage, ubo: storage,
push: vec![0u8; push_size].into_boxed_slice(), push: vec![0u8; push_size].into_boxed_slice(),

View file

@ -129,9 +129,9 @@ pub mod preprocess {
pub mod reflect { pub mod reflect {
/// Supported shader compiler targets. /// Supported shader compiler targets.
pub mod targets { pub mod targets {
pub use librashader_reflect::back::targets::DXIL;
pub use librashader_reflect::back::targets::GLSL; pub use librashader_reflect::back::targets::GLSL;
pub use librashader_reflect::back::targets::HLSL; pub use librashader_reflect::back::targets::HLSL;
pub use librashader_reflect::back::targets::DXIL;
pub use librashader_reflect::back::targets::SPIRV; pub use librashader_reflect::back::targets::SPIRV;
} }