fmt: cargo fmt

This commit is contained in:
chyyran 2023-07-20 01:13:22 -04:00 committed by Ronny Chan
parent b09a5295ab
commit f5da7d8421
15 changed files with 87 additions and 48 deletions

View file

@ -17,8 +17,8 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
let Ok(cache) = cache else { let Ok(cache) = cache else {
return Ok(CachedCompilation { return Ok(CachedCompilation {
compilation: T::compile(source)? compilation: T::compile(source)?,
}) });
}; };
let key = { let key = {

View file

@ -18,7 +18,9 @@ impl CacheKey for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob {
impl Cacheable for windows::Win32::Graphics::Direct3D::ID3DBlob { impl Cacheable for windows::Win32::Graphics::Direct3D::ID3DBlob {
fn from_bytes(bytes: &[u8]) -> Option<Self> { fn from_bytes(bytes: &[u8]) -> Option<Self> {
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; return None;
}; };
@ -44,11 +46,18 @@ impl Cacheable for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob {
fn from_bytes(bytes: &[u8]) -> Option<Self> { fn from_bytes(bytes: &[u8]) -> Option<Self> {
let Some(blob) = (unsafe { let Some(blob) = (unsafe {
windows::Win32::Graphics::Direct3D::Dxc::DxcCreateInstance( windows::Win32::Graphics::Direct3D::Dxc::DxcCreateInstance(
&windows::Win32::Graphics::Direct3D::Dxc::CLSID_DxcLibrary) &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, .and_then(
windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0)) |library: windows::Win32::Graphics::Direct3D::Dxc::IDxcUtils| {
}).ok() library.CreateBlob(
bytes.as_ptr().cast(),
bytes.len() as u32,
windows::Win32::Graphics::Direct3D::Dxc::DXC_CP(0),
)
},
)
.ok()
}) else { }) else {
return None; return None;
}; };

View file

@ -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. /// - `error` must be valid and initialized.
pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO { pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO {
let Some(error) = error else { let Some(error) = error else {
return LIBRA_ERRNO::UNKNOWN_ERROR return LIBRA_ERRNO::UNKNOWN_ERROR;
}; };
unsafe { error.as_ref().get_code() } 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 /// ## Safety
/// - `error` must be a valid and initialized instance of `libra_error_t`. /// - `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 { pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
let Some(error) = error else { let Some(error) = error else { return 1 };
return 1
};
unsafe { unsafe {
let error = error.as_ref(); let error = error.as_ref();
println!("{error:?}: {error}"); println!("{error:?}: {error}");
@ -130,9 +128,7 @@ pub unsafe extern "C" fn libra_error_write(
error: libra_error_t, error: libra_error_t,
out: *mut MaybeUninit<*mut c_char>, out: *mut MaybeUninit<*mut c_char>,
) -> i32 { ) -> i32 {
let Some(error) = error else { let Some(error) = error else { return 1 };
return 1
};
if out.is_null() { if out.is_null() {
return 1; return 1;
} }
@ -140,7 +136,7 @@ pub unsafe extern "C" fn libra_error_write(
unsafe { unsafe {
let error = error.as_ref(); let error = error.as_ref();
let Ok(cstring) = CString::new(format!("{error:?}: {error}")) else { let Ok(cstring) = CString::new(format!("{error:?}: {error}")) else {
return 1 return 1;
}; };
out.write(MaybeUninit::new(cstring.into_raw())) out.write(MaybeUninit::new(cstring.into_raw()))

View file

@ -25,7 +25,7 @@ fn read_file(path: impl AsRef<Path>) -> Result<String, PreprocessError> {
let buf = e.into_bytes(); let buf = e.into_bytes();
let decoder = WINDOWS_1252.new_decoder(); let decoder = WINDOWS_1252.new_decoder();
let Some(len) = decoder.max_utf8_buffer_length_without_replacement(buf.len()) else { 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); let mut latin1_string = String::with_capacity(len);

View file

@ -24,7 +24,7 @@ librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4"
librashader-presets = { path = "../librashader-presets", 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_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 } 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 } rspirv = { version = "0.11.0+1.5.4", optional = true }

View file

@ -54,10 +54,26 @@ pub(crate) type GlslReflect = CrossReflect<glsl::Target>;
impl ValidateTypeSemantics<Type> for UniqueSemantics { impl ValidateTypeSemantics<Type> for UniqueSemantics {
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> { fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
let (Type::Float { ref array, vecsize, columns, .. } let (Type::Float {
| Type::Int { ref array, vecsize, columns, .. } ref array,
| Type::UInt { ref array, vecsize, columns, .. }) = *ty else { vecsize,
return None columns,
..
}
| Type::Int {
ref array,
vecsize,
columns,
..
}
| Type::UInt {
ref array,
vecsize,
columns,
..
}) = *ty
else {
return None;
}; };
if !array.is_empty() { if !array.is_empty() {
@ -93,8 +109,14 @@ impl ValidateTypeSemantics<Type> for UniqueSemantics {
impl ValidateTypeSemantics<Type> for TextureSemantics { impl ValidateTypeSemantics<Type> for TextureSemantics {
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> { fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
let Type::Float { ref array, vecsize, columns, .. } = *ty else { let Type::Float {
return None ref array,
vecsize,
columns,
..
} = *ty
else {
return None;
}; };
if !array.is_empty() { if !array.is_empty() {
@ -295,7 +317,7 @@ where
if let Some(parameter) = semantics.uniform_semantics.get_unique_semantic(&name) { if let Some(parameter) = semantics.uniform_semantics.get_unique_semantic(&name) {
let Some(typeinfo) = parameter.semantics.validate_type(&range_type) else { 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 &parameter.semantics { match &parameter.semantics {
@ -372,7 +394,7 @@ where
} }
} else if let Some(texture) = semantics.uniform_semantics.get_texture_semantic(&name) { } else if let Some(texture) = semantics.uniform_semantics.get_texture_semantic(&name) {
let Some(_typeinfo) = texture.semantics.validate_type(&range_type) else { 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 { if let TextureSemantics::PassOutput = texture.semantics {
@ -488,8 +510,15 @@ where
semantics: &ShaderSemantics, semantics: &ShaderSemantics,
meta: &mut BindingMeta, meta: &mut BindingMeta,
) -> Result<(), ShaderReflectError> { ) -> Result<(), ShaderReflectError> {
let Some(semantic) = semantics.texture_semantics.get_texture_semantic(texture.name) else { let Some(semantic) = semantics
return Err(SemanticErrorBlame::Fragment.error(SemanticsErrorKind::UnknownSemantics(texture.name.to_string()))) .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 { if semantic.semantics == TextureSemantics::PassOutput && semantic.index >= pass_number {

View file

@ -361,7 +361,9 @@ impl TextureSemanticMap for FxHashMap<String, Semantic<TextureSemantics>> {
{ {
if semantics.is_indexed() { if semantics.is_indexed() {
let index = &name[semantics.texture_name().len()..]; 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 { return Some(Semantic {
semantics: *semantics, semantics: *semantics,
index, index,

View file

@ -249,7 +249,8 @@ impl FilterChainD3D12 {
let shader_copy = preset.shaders.clone(); let shader_copy = preset.shaders.clone();
let disable_cache = options.map_or(false, |o| o.disable_cache); 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 (hlsl_passes, _) = compile_passes_hlsl(shader_copy, &preset.textures, disable_cache)?;
let samplers = SamplerSet::new(device)?; let samplers = SamplerSet::new(device)?;

View file

@ -1,6 +1,7 @@
use crate::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap}; use crate::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap};
use crate::error; use crate::error;
use crate::error::assume_d3d12_init; use crate::error::assume_d3d12_init;
use crate::filter_chain::FrameResiduals;
use crate::mipmap::MipmapGenContext; use crate::mipmap::MipmapGenContext;
use crate::texture::InputTexture; use crate::texture::InputTexture;
use crate::util::{d3d12_get_closest_format, d3d12_resource_transition, d3d12_update_subresources}; 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, D3D12_TEX2D_SRV, D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
}; };
use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC;
use crate::filter_chain::FrameResiduals;
pub struct LutTexture { pub struct LutTexture {
resource: ID3D12Resource, resource: ID3D12Resource,

View file

@ -10,6 +10,7 @@ use windows::Win32::Graphics::Direct3D::Dxc::{
DXC_CP_UTF8, DXC_CP_UTF8,
}; };
use crate::filter_chain::FrameResiduals;
use windows::Win32::Graphics::Direct3D12::{ use windows::Win32::Graphics::Direct3D12::{
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT, ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT,
D3D12_FEATURE_FORMAT_SUPPORT, D3D12_MEMCPY_DEST, D3D12_PLACED_SUBRESOURCE_FOOTPRINT, 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, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
}; };
use windows::Win32::Graphics::Dxgi::Common::*; use windows::Win32::Graphics::Dxgi::Common::*;
use crate::filter_chain::FrameResiduals;
/// wtf retroarch? /// wtf retroarch?
const DXGI_FORMAT_EX_A4R4G4B4_UNORM: DXGI_FORMAT = DXGI_FORMAT(1000); const DXGI_FORMAT_EX_A4R4G4B4_UNORM: DXGI_FORMAT = DXGI_FORMAT(1000);
@ -273,7 +273,7 @@ pub(crate) fn d3d12_update_subresources(
&num_rows, &num_rows,
&row_sizes_in_bytes, &row_sizes_in_bytes,
source, source,
gc gc,
) )
} }
} }

View file

@ -228,11 +228,11 @@ unsafe extern "system" fn debug_log(
} }
pub mod d3d12_hello_triangle { pub mod d3d12_hello_triangle {
use std::mem::ManuallyDrop;
use super::*; use super::*;
use crate::hello_triangle::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap}; use crate::hello_triangle::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeap};
use librashader_common::{Size, Viewport}; use librashader_common::{Size, Viewport};
use librashader_runtime_d3d12::{D3D12InputImage, D3D12OutputView, FilterChainD3D12}; use librashader_runtime_d3d12::{D3D12InputImage, D3D12OutputView, FilterChainD3D12};
use std::mem::ManuallyDrop;
use std::ops::Deref; use std::ops::Deref;
use std::path::Path; use std::path::Path;
@ -571,7 +571,11 @@ pub mod d3d12_hello_triangle {
// Record commands. // Record commands.
unsafe { unsafe {
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/1006 // 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.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
command_list.IASetVertexBuffers(0, Some(&[resources.vbv])); command_list.IASetVertexBuffers(0, Some(&[resources.vbv]));
command_list.DrawInstanced(3, 1, 0, 0); command_list.DrawInstanced(3, 1, 0, 0);

View file

@ -4,8 +4,9 @@
//! See [`librashader::runtime::gl`](https://docs.rs/librashader/latest/librashader/runtime/gl/index.html) instead. //! See [`librashader::runtime::gl`](https://docs.rs/librashader/latest/librashader/runtime/gl/index.html) instead.
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![feature(strict_provenance)] #![feature(strict_provenance)]
#![feature(type_alias_impl_trait)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]
mod binding; mod binding;
mod filter_chain; mod filter_chain;

View file

@ -100,10 +100,10 @@ impl VulkanBuffer {
pub fn as_mut_slice(&mut self) -> error::Result<&mut [u8]> { pub fn as_mut_slice(&mut self) -> error::Result<&mut [u8]> {
let Some(allocation) = self.memory.as_mut() else { let Some(allocation) = self.memory.as_mut() else {
return Err(FilterChainError::AllocationDoesNotExist) return Err(FilterChainError::AllocationDoesNotExist);
}; };
let Some(allocation) = allocation.mapped_slice_mut() else { let Some(allocation) = allocation.mapped_slice_mut() else {
return Err(FilterChainError::AllocationDoesNotExist) return Err(FilterChainError::AllocationDoesNotExist);
}; };
Ok(allocation) Ok(allocation)
} }
@ -147,11 +147,8 @@ impl RawVulkanBuffer {
) -> error::Result<Self> { ) -> error::Result<Self> {
let buffer = ManuallyDrop::new(VulkanBuffer::new(device, allocator, usage, size)?); let buffer = ManuallyDrop::new(VulkanBuffer::new(device, allocator, usage, size)?);
let Some(ptr) = buffer.memory let Some(ptr) = buffer.memory.as_ref().map(|m| m.mapped_ptr()).flatten() else {
.as_ref() return Err(FilterChainError::AllocationDoesNotExist);
.map(|m| m.mapped_ptr())
.flatten() else {
return Err(FilterChainError::AllocationDoesNotExist)
}; };
Ok(RawVulkanBuffer { buffer, ptr }) Ok(RawVulkanBuffer { buffer, ptr })