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"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
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.
#[cfg(feature = "runtime-vulkan")]

View file

@ -6,14 +6,16 @@ use std::ffi::CStr;
use std::mem::{ManuallyDrop, MaybeUninit};
use std::ptr::NonNull;
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;
pub use librashader::runtime::d3d12::capi::options::FilterChainOptionsD3D12;
pub use librashader::runtime::d3d12::capi::options::FrameOptionsD3D12;
use librashader::runtime::{FilterChainParameters, Size, Viewport};
use librashader::runtime::d3d12::{D3D12InputImage, D3D12OutputView};
use librashader::runtime::{FilterChainParameters, Size, Viewport};
/// Direct3D 11 parameters for the source image.
#[repr(C)]

View file

@ -13,4 +13,4 @@ pub mod d3d11;
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
pub mod d3d12;
pub mod d3d12;

View file

@ -2,7 +2,9 @@ use crate::back::spirv::WriteSpirV;
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
pub use spirv_to_dxil::DxilObject;
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::error::{ShaderCompileError, ShaderReflectError};

View file

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

View file

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

View file

@ -13,11 +13,11 @@ use std::collections::VecDeque;
use std::path::Path;
use crate::draw_quad::DrawQuad;
use crate::error::{assume_d3d11_init, FilterChainError};
use crate::filter_pass::{ConstantBufferBinding, FilterPass};
use crate::framebuffer::OwnedFramebuffer;
use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11};
use crate::draw_quad::DrawQuad;
use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet;
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::quad::{QuadType, IDENTITY_MVP};
use librashader_runtime::uniforms::UniformStorage;
use rayon::prelude::*;
use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC,
D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS,
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC,
};
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
use rayon::prelude::*;
pub struct FilterMutable {
pub(crate) passes_enabled: usize,
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.
pub struct FilterChainD3D11 {
@ -222,35 +223,35 @@ impl FilterChainD3D11 {
semantics: &ShaderSemantics,
) -> error::Result<Vec<FilterPass>> {
// access to ID3D11Device is thread safe.
let filters: Vec<error::Result<FilterPass>> =
passes.into_par_iter()
.enumerate()
.map(|(index, (config, source, mut reflect)) | {
let reflection = reflect.reflect(index, semantics)?;
let hlsl = reflect.compile(None)?;
let filters: Vec<error::Result<FilterPass>> = passes
.into_par_iter()
.enumerate()
.map(|(index, (config, source, mut reflect))| {
let reflection = reflect.reflect(index, semantics)?;
let hlsl = reflect.compile(None)?;
let vertex_dxbc =
util::d3d_compile_shader(hlsl.vertex.as_bytes(), b"main\0", b"vs_5_0\0")?;
let vs = d3d11_compile_bound_shader(
device,
&vertex_dxbc,
None,
ID3D11Device::CreateVertexShader,
)?;
let vertex_dxbc =
util::d3d_compile_shader(hlsl.vertex.as_bytes(), b"main\0", b"vs_5_0\0")?;
let vs = d3d11_compile_bound_shader(
device,
&vertex_dxbc,
None,
ID3D11Device::CreateVertexShader,
)?;
let ia_desc = DrawQuad::get_spirv_cross_vbo_desc();
let vao = util::d3d11_create_input_layout(device, &ia_desc, &vertex_dxbc)?;
let ia_desc = DrawQuad::get_spirv_cross_vbo_desc();
let vao = util::d3d11_create_input_layout(device, &ia_desc, &vertex_dxbc)?;
let fragment_dxbc =
util::d3d_compile_shader(hlsl.fragment.as_bytes(), b"main\0", b"ps_5_0\0")?;
let ps = d3d11_compile_bound_shader(
device,
&fragment_dxbc,
None,
ID3D11Device::CreatePixelShader,
)?;
let fragment_dxbc =
util::d3d_compile_shader(hlsl.fragment.as_bytes(), b"main\0", b"ps_5_0\0")?;
let ps = d3d11_compile_bound_shader(
device,
&fragment_dxbc,
None,
ID3D11Device::CreatePixelShader,
)?;
let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 {
let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 {
let buffer = FilterChainD3D11::create_constant_buffer(device, ubo.size)?;
Some(ConstantBufferBinding {
binding: ubo.binding,
@ -262,7 +263,7 @@ impl FilterChainD3D11 {
None
};
let push_cbuffer = if let Some(push) = &reflection.push_constant && push.size != 0 {
let push_cbuffer = if let Some(push) = &reflection.push_constant && push.size != 0 {
let buffer = FilterChainD3D11::create_constant_buffer(device, push.size)?;
Some(ConstantBufferBinding {
binding: if ubo_cbuffer.is_some() { 1 } else { 0 },
@ -274,29 +275,30 @@ impl FilterChainD3D11 {
None
};
let uniform_storage = UniformStorage::new(
reflection.ubo.as_ref().map_or(0, |ubo| ubo.size as usize),
reflection
.push_constant
.as_ref()
.map_or(0, |push| push.size as usize),
);
let uniform_storage = UniformStorage::new(
reflection.ubo.as_ref().map_or(0, |ubo| ubo.size as usize),
reflection
.push_constant
.as_ref()
.map_or(0, |push| push.size as usize),
);
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
Ok(FilterPass {
reflection,
vertex_shader: vs,
vertex_layout: vao,
pixel_shader: ps,
uniform_bindings,
uniform_storage,
uniform_buffer: ubo_cbuffer,
push_buffer: push_cbuffer,
source,
config: config.clone(),
})
}).collect();
Ok(FilterPass {
reflection,
vertex_shader: vs,
vertex_layout: vao,
pixel_shader: ps,
uniform_bindings,
uniform_storage,
uniform_buffer: ubo_cbuffer,
push_buffer: push_cbuffer,
source,
config: config.clone(),
})
})
.collect();
let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect();
let filters = filters?;

View file

@ -9,13 +9,13 @@
#[cfg(test)]
mod hello_triangle;
mod draw_quad;
pub mod error;
mod filter_chain;
mod filter_pass;
mod framebuffer;
pub mod options;
mod parameters;
mod draw_quad;
mod render_target;
mod samplers;
mod texture;
@ -86,7 +86,7 @@ mod tests {
}),
// replace below with 'None' for the triangle
// None,
Some(Image::load(IMAGE_PATH, UVDirection::TopLeft).unwrap())
Some(Image::load(IMAGE_PATH, UVDirection::TopLeft).unwrap()),
)
.unwrap();
// 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);
util::d3d12_resource_transition_subresource(
cmd,
resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i - 1,
);
let barriers = [
util::d3d12_get_resource_transition_subresource(
resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i - 1,
),
util::d3d12_get_resource_transition_subresource(
resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i,
),
];
util::d3d12_resource_transition_subresource(
cmd,
resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
i,
);
cmd.ResourceBarrier(&barriers);
cmd.SetComputeRootDescriptorTable(1, *heap_slots[i as usize].deref().as_ref());
cmd.SetComputeRoot32BitConstants(
@ -297,29 +298,27 @@ impl D3D12MipmapGen {
pResource: windows::core::ManuallyDrop::new(resource),
});
let barrier = [D3D12_RESOURCE_BARRIER {
Type: D3D12_RESOURCE_BARRIER_TYPE_UAV,
Anonymous: D3D12_RESOURCE_BARRIER_0 { UAV: uav_barrier },
..Default::default()
}];
let barriers = [
D3D12_RESOURCE_BARRIER {
Type: D3D12_RESOURCE_BARRIER_TYPE_UAV,
Anonymous: D3D12_RESOURCE_BARRIER_0 { UAV: uav_barrier },
..Default::default()
},
util::d3d12_get_resource_transition_subresource(
resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i,
),
util::d3d12_get_resource_transition_subresource(
resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i - 1,
),
];
cmd.ResourceBarrier(&barrier);
util::d3d12_resource_transition_subresource(
cmd,
resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i,
);
util::d3d12_resource_transition_subresource(
cmd,
resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
i - 1,
);
cmd.ResourceBarrier(&barriers);
}
Ok(heap_slots)

View file

@ -40,7 +40,8 @@ pub struct VulkanObjects {
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.
#[derive(Clone)]
@ -311,7 +312,8 @@ impl FilterChainVulkan {
) -> error::Result<Box<[FilterPass]>> {
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()
.map(|(index, (config, source, mut reflect))| {
let reflection = reflect.reflect(index, semantics)?;
@ -331,8 +333,7 @@ impl FilterChainVulkan {
.map_or(0, |push| push.size as usize),
);
let uniform_bindings = reflection.meta
.create_binding_map(|param| param.offset());
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
let render_pass_format = if !use_render_pass {
vk::Format::UNDEFINED
@ -365,7 +366,8 @@ impl FilterChainVulkan {
// ubo_ring,
frames_in_flight,
})
}).collect();
})
.collect();
let filters: error::Result<Vec<FilterPass>> = filters.into_iter().collect();
let filters = filters?;

View file

@ -145,12 +145,15 @@ where
}
impl<H, C, U> UniformStorage<H, C, U, Box<[u8]>>
where
C: Copy,
U: Deref<Target = [u8]> + DerefMut,
where
C: Copy,
U: Deref<Target = [u8]> + DerefMut,
{
/// 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 {
ubo: storage,
push: vec![0u8; push_size].into_boxed_slice(),

View file

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