From 7a7f9f0405b86124a07f37c43f87977dfd6612f6 Mon Sep 17 00:00:00 2001 From: chyyran Date: Thu, 20 Jul 2023 01:13:22 -0400 Subject: [PATCH] fmt: cargo fmt --- librashader-cache/src/compilation.rs | 4 +- librashader-cache/src/d3d.rs | 21 +++++--- librashader-capi/src/error.rs | 12 ++--- librashader-preprocess/src/include.rs | 2 +- librashader-reflect/Cargo.toml | 2 +- librashader-reflect/src/reflect/cross.rs | 49 +++++++++++++++---- librashader-reflect/src/reflect/semantics.rs | 4 +- librashader-runtime-d3d12/src/filter_chain.rs | 7 +-- librashader-runtime-d3d12/src/luts.rs | 2 +- librashader-runtime-d3d12/src/util.rs | 4 +- .../tests/hello_triangle/mod.rs | 8 ++- librashader-runtime-d3d12/tests/triangle.rs | 4 +- librashader-runtime-gl/src/lib.rs | 3 +- librashader-runtime-vk/src/filter_chain.rs | 2 +- librashader-runtime-vk/src/memory.rs | 11 ++--- 15 files changed, 87 insertions(+), 48 deletions(-) diff --git a/librashader-cache/src/compilation.rs b/librashader-cache/src/compilation.rs index ef1ad16c..b3feeca9 100644 --- a/librashader-cache/src/compilation.rs +++ b/librashader-cache/src/compilation.rs @@ -17,8 +17,8 @@ impl serde::Deserialize<'de> + serde::Serialize let Ok(cache) = cache else { return Ok(CachedCompilation { - compilation: T::compile(source)? - }) + compilation: T::compile(source)?, + }); }; let key = { diff --git a/librashader-cache/src/d3d.rs b/librashader-cache/src/d3d.rs index 17daf588..3dcc8b0c 100644 --- a/librashader-cache/src/d3d.rs +++ b/librashader-cache/src/d3d.rs @@ -18,7 +18,9 @@ impl CacheKey for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob { impl Cacheable for windows::Win32::Graphics::Direct3D::ID3DBlob { fn from_bytes(bytes: &[u8]) -> Option { - let Some(blob) = (unsafe { windows::Win32::Graphics::Direct3D::Fxc::D3DCreateBlob(bytes.len()).ok() }) else { + let Some(blob) = + (unsafe { windows::Win32::Graphics::Direct3D::Fxc::D3DCreateBlob(bytes.len()).ok() }) + else { return None; }; @@ -44,11 +46,18 @@ impl Cacheable for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob { fn from_bytes(bytes: &[u8]) -> Option { let Some(blob) = (unsafe { windows::Win32::Graphics::Direct3D::Dxc::DxcCreateInstance( - &windows::Win32::Graphics::Direct3D::Dxc::CLSID_DxcLibrary) - .and_then(|library: windows::Win32::Graphics::Direct3D::Dxc::IDxcUtils| { - library.CreateBlob(bytes.as_ptr().cast(), bytes.len() as u32, - windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0)) - }).ok() + &windows::Win32::Graphics::Direct3D::Dxc::CLSID_DxcLibrary, + ) + .and_then( + |library: windows::Win32::Graphics::Direct3D::Dxc::IDxcUtils| { + library.CreateBlob( + bytes.as_ptr().cast(), + bytes.len() as u32, + windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0), + ) + }, + ) + .ok() }) else { return None; }; diff --git a/librashader-capi/src/error.rs b/librashader-capi/src/error.rs index 78462c97..3ba44f55 100644 --- a/librashader-capi/src/error.rs +++ b/librashader-capi/src/error.rs @@ -67,7 +67,7 @@ pub type PFN_libra_error_errno = extern "C" fn(error: libra_error_t) -> LIBRA_ER /// - `error` must be valid and initialized. pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO { let Some(error) = error else { - return LIBRA_ERRNO::UNKNOWN_ERROR + return LIBRA_ERRNO::UNKNOWN_ERROR; }; unsafe { error.as_ref().get_code() } @@ -82,9 +82,7 @@ pub type PFN_libra_error_print = extern "C" fn(error: libra_error_t) -> i32; /// ## Safety /// - `error` must be a valid and initialized instance of `libra_error_t`. pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 { - let Some(error) = error else { - return 1 - }; + let Some(error) = error else { return 1 }; unsafe { let error = error.as_ref(); println!("{error:?}: {error}"); @@ -130,9 +128,7 @@ pub unsafe extern "C" fn libra_error_write( error: libra_error_t, out: *mut MaybeUninit<*mut c_char>, ) -> i32 { - let Some(error) = error else { - return 1 - }; + let Some(error) = error else { return 1 }; if out.is_null() { return 1; } @@ -140,7 +136,7 @@ pub unsafe extern "C" fn libra_error_write( unsafe { let error = error.as_ref(); let Ok(cstring) = CString::new(format!("{error:?}: {error}")) else { - return 1 + return 1; }; out.write(MaybeUninit::new(cstring.into_raw())) diff --git a/librashader-preprocess/src/include.rs b/librashader-preprocess/src/include.rs index 9e17443b..c9ed7c83 100644 --- a/librashader-preprocess/src/include.rs +++ b/librashader-preprocess/src/include.rs @@ -25,7 +25,7 @@ fn read_file(path: impl AsRef) -> Result { let buf = e.into_bytes(); let decoder = WINDOWS_1252.new_decoder(); let Some(len) = decoder.max_utf8_buffer_length_without_replacement(buf.len()) else { - return Err(PreprocessError::EncodingError(path.to_path_buf())) + return Err(PreprocessError::EncodingError(path.to_path_buf())); }; let mut latin1_string = String::with_capacity(len); diff --git a/librashader-reflect/Cargo.toml b/librashader-reflect/Cargo.toml index a30bb52f..db3bb785 100644 --- a/librashader-reflect/Cargo.toml +++ b/librashader-reflect/Cargo.toml @@ -24,7 +24,7 @@ librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4" librashader-presets = { path = "../librashader-presets", version = "0.1.4" } spirv_cross = { package = "librashader-spirv-cross", version = "0.23", optional = true } -spirv-to-dxil = { version = "0.3", optional = true } +spirv-to-dxil = { version = "0.4", optional = true } naga = { version = "0.11.0", features = ["glsl-in", "spv-in", "spv-out", "glsl-out", "wgsl-out"], optional = true } rspirv = { version = "0.11.0+1.5.4", optional = true } diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index e0e08cda..0f468e09 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -54,10 +54,26 @@ pub(crate) type GlslReflect = CrossReflect; impl ValidateTypeSemantics for UniqueSemantics { fn validate_type(&self, ty: &Type) -> Option { - let (Type::Float { ref array, vecsize, columns, .. } - | Type::Int { ref array, vecsize, columns, .. } - | Type::UInt { ref array, vecsize, columns, .. }) = *ty else { - return None + let (Type::Float { + ref array, + vecsize, + columns, + .. + } + | Type::Int { + ref array, + vecsize, + columns, + .. + } + | Type::UInt { + ref array, + vecsize, + columns, + .. + }) = *ty + else { + return None; }; if !array.is_empty() { @@ -93,8 +109,14 @@ impl ValidateTypeSemantics for UniqueSemantics { impl ValidateTypeSemantics for TextureSemantics { fn validate_type(&self, ty: &Type) -> Option { - let Type::Float { ref array, vecsize, columns, .. } = *ty else { - return None + let Type::Float { + ref array, + vecsize, + columns, + .. + } = *ty + else { + return None; }; if !array.is_empty() { @@ -295,7 +317,7 @@ where if let Some(parameter) = semantics.uniform_semantics.get_unique_semantic(&name) { let Some(typeinfo) = parameter.semantics.validate_type(&range_type) else { - return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name))) + return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name))); }; match ¶meter.semantics { @@ -372,7 +394,7 @@ where } } else if let Some(texture) = semantics.uniform_semantics.get_texture_semantic(&name) { let Some(_typeinfo) = texture.semantics.validate_type(&range_type) else { - return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name))) + return Err(blame.error(SemanticsErrorKind::InvalidTypeForSemantic(name))); }; if let TextureSemantics::PassOutput = texture.semantics { @@ -488,8 +510,15 @@ where semantics: &ShaderSemantics, meta: &mut BindingMeta, ) -> Result<(), ShaderReflectError> { - let Some(semantic) = semantics.texture_semantics.get_texture_semantic(texture.name) else { - return Err(SemanticErrorBlame::Fragment.error(SemanticsErrorKind::UnknownSemantics(texture.name.to_string()))) + let Some(semantic) = semantics + .texture_semantics + .get_texture_semantic(texture.name) + else { + return Err( + SemanticErrorBlame::Fragment.error(SemanticsErrorKind::UnknownSemantics( + texture.name.to_string(), + )), + ); }; if semantic.semantics == TextureSemantics::PassOutput && semantic.index >= pass_number { diff --git a/librashader-reflect/src/reflect/semantics.rs b/librashader-reflect/src/reflect/semantics.rs index b97f1162..2a1286be 100644 --- a/librashader-reflect/src/reflect/semantics.rs +++ b/librashader-reflect/src/reflect/semantics.rs @@ -361,7 +361,9 @@ impl TextureSemanticMap for FxHashMap> { { if semantics.is_indexed() { let index = &name[semantics.texture_name().len()..]; - let Ok(index) = usize::from_str(index) else {return None}; + let Ok(index) = usize::from_str(index) else { + return None; + }; return Some(Semantic { semantics: *semantics, index, diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index a3e9e1a7..d5d4a001 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -144,7 +144,7 @@ impl Drop for FrameResiduals { } type DxilShaderPassMeta = -ShaderPassArtifact + Send>; + ShaderPassArtifact + Send>; fn compile_passes_dxil( shaders: Vec, textures: &[TextureConfig], @@ -161,7 +161,7 @@ fn compile_passes_dxil( Ok((passes, semantics)) } type HlslShaderPassMeta = -ShaderPassArtifact + Send>; + ShaderPassArtifact + Send>; fn compile_passes_hlsl( shaders: Vec, textures: &[TextureConfig], @@ -249,7 +249,8 @@ impl FilterChainD3D12 { let shader_copy = preset.shaders.clone(); let disable_cache = options.map_or(false, |o| o.disable_cache); - let (passes, semantics) = compile_passes_dxil(preset.shaders, &preset.textures, disable_cache)?; + let (passes, semantics) = + compile_passes_dxil(preset.shaders, &preset.textures, disable_cache)?; let (hlsl_passes, _) = compile_passes_hlsl(shader_copy, &preset.textures, disable_cache)?; let samplers = SamplerSet::new(device)?; diff --git a/librashader-runtime-d3d12/src/luts.rs b/librashader-runtime-d3d12/src/luts.rs index 5298ff2c..ce177548 100644 --- a/librashader-runtime-d3d12/src/luts.rs +++ b/librashader-runtime-d3d12/src/luts.rs @@ -1,6 +1,7 @@ use crate::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap}; use crate::error; use crate::error::assume_d3d12_init; +use crate::filter_chain::FrameResiduals; use crate::mipmap::MipmapGenContext; use crate::texture::InputTexture; use crate::util::{d3d12_get_closest_format, d3d12_resource_transition, d3d12_update_subresources}; @@ -22,7 +23,6 @@ use windows::Win32::Graphics::Direct3D12::{ D3D12_TEX2D_SRV, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; -use crate::filter_chain::FrameResiduals; pub struct LutTexture { resource: ID3D12Resource, diff --git a/librashader-runtime-d3d12/src/util.rs b/librashader-runtime-d3d12/src/util.rs index a33e4f39..7ffd0de8 100644 --- a/librashader-runtime-d3d12/src/util.rs +++ b/librashader-runtime-d3d12/src/util.rs @@ -10,6 +10,7 @@ use windows::Win32::Graphics::Direct3D::Dxc::{ DXC_CP_UTF8, }; +use crate::filter_chain::FrameResiduals; use windows::Win32::Graphics::Direct3D12::{ ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT, D3D12_FEATURE_FORMAT_SUPPORT, D3D12_MEMCPY_DEST, D3D12_PLACED_SUBRESOURCE_FOOTPRINT, @@ -20,7 +21,6 @@ use windows::Win32::Graphics::Direct3D12::{ D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, }; use windows::Win32::Graphics::Dxgi::Common::*; -use crate::filter_chain::FrameResiduals; /// wtf retroarch? const DXGI_FORMAT_EX_A4R4G4B4_UNORM: DXGI_FORMAT = DXGI_FORMAT(1000); @@ -273,7 +273,7 @@ pub(crate) fn d3d12_update_subresources( &num_rows, &row_sizes_in_bytes, source, - gc + gc, ) } } diff --git a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs index 7df0627a..d972bd84 100644 --- a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs +++ b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs @@ -228,11 +228,11 @@ unsafe extern "system" fn debug_log( } pub mod d3d12_hello_triangle { - use std::mem::ManuallyDrop; use super::*; use crate::hello_triangle::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap}; use librashader_common::{Size, Viewport}; use librashader_runtime_d3d12::{D3D12InputImage, D3D12OutputView, FilterChainD3D12}; + use std::mem::ManuallyDrop; use std::ops::Deref; use std::path::Path; @@ -571,7 +571,11 @@ pub mod d3d12_hello_triangle { // Record commands. unsafe { // TODO: workaround for https://github.com/microsoft/win32metadata/issues/1006 - command_list.ClearRenderTargetView(rtv_handle, &*[0.3, 0.4, 0.6, 1.0].as_ptr(), Some(&[])); + command_list.ClearRenderTargetView( + rtv_handle, + &*[0.3, 0.4, 0.6, 1.0].as_ptr(), + Some(&[]), + ); command_list.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); command_list.IASetVertexBuffers(0, Some(&[resources.vbv])); command_list.DrawInstanced(3, 1, 0, 0); diff --git a/librashader-runtime-d3d12/tests/triangle.rs b/librashader-runtime-d3d12/tests/triangle.rs index 100175f8..103022b0 100644 --- a/librashader-runtime-d3d12/tests/triangle.rs +++ b/librashader-runtime-d3d12/tests/triangle.rs @@ -7,7 +7,7 @@ fn triangle_d3d12() { let sample = hello_triangle::d3d12_hello_triangle::Sample::new( //"../test/shaders_slang/crt/crt-lottes.slangp", // "../test/basic.slangp", - "../test/shaders_slang/handheld/console-border/gbc-lcd-grid-v2.slangp", + "../test/shaders_slang/handheld/console-border/gbc-lcd-grid-v2.slangp", // "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_GBA_SP/GBA_SP-[ADV]-[LCD-GRID]-[Night].slangp", // "../test/slang-shaders/test/feedback.slangp", // "../test/slang-shaders/test/history.slangp", @@ -17,6 +17,6 @@ fn triangle_d3d12() { use_warp_device: false, }, ) - .unwrap(); + .unwrap(); hello_triangle::main(sample).unwrap() } diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index fae05657..db32ca21 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -4,8 +4,9 @@ //! See [`librashader::runtime::gl`](https://docs.rs/librashader/latest/librashader/runtime/gl/index.html) instead. #![deny(unsafe_op_in_unsafe_fn)] #![feature(strict_provenance)] -#![feature(type_alias_impl_trait)] #![feature(let_chains)] +#![feature(type_alias_impl_trait)] +#![feature(impl_trait_in_assoc_type)] mod binding; mod filter_chain; diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index efc83203..33f72446 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -206,7 +206,7 @@ impl Drop for FrameResiduals { } type ShaderPassMeta = -ShaderPassArtifact + Send>; + ShaderPassArtifact + Send>; fn compile_passes( shaders: Vec, textures: &[TextureConfig], diff --git a/librashader-runtime-vk/src/memory.rs b/librashader-runtime-vk/src/memory.rs index 96adc111..e775ef24 100644 --- a/librashader-runtime-vk/src/memory.rs +++ b/librashader-runtime-vk/src/memory.rs @@ -100,10 +100,10 @@ impl VulkanBuffer { pub fn as_mut_slice(&mut self) -> error::Result<&mut [u8]> { let Some(allocation) = self.memory.as_mut() else { - return Err(FilterChainError::AllocationDoesNotExist) + return Err(FilterChainError::AllocationDoesNotExist); }; let Some(allocation) = allocation.mapped_slice_mut() else { - return Err(FilterChainError::AllocationDoesNotExist) + return Err(FilterChainError::AllocationDoesNotExist); }; Ok(allocation) } @@ -147,11 +147,8 @@ impl RawVulkanBuffer { ) -> error::Result { let buffer = ManuallyDrop::new(VulkanBuffer::new(device, allocator, usage, size)?); - let Some(ptr) = buffer.memory - .as_ref() - .map(|m| m.mapped_ptr()) - .flatten() else { - return Err(FilterChainError::AllocationDoesNotExist) + let Some(ptr) = buffer.memory.as_ref().map(|m| m.mapped_ptr()).flatten() else { + return Err(FilterChainError::AllocationDoesNotExist); }; Ok(RawVulkanBuffer { buffer, ptr })