fmt: clean up warnings

This commit is contained in:
chyyran 2023-02-09 21:03:55 -05:00
parent 55e800b67e
commit 121209da10
21 changed files with 172 additions and 212 deletions

View file

@ -106,7 +106,9 @@ Please report an issue if you run into a shader that works in RetroArch, but not
* Shaders are compiled in parallel where possible. This should noticeably decrease preset compile times.
Parallel shader compilation is not available to OpenGL.
* HDR10 support is not part of any shader runtime and is not supported by librashader.
* For performance reasons, mipmaps are never generated for the input texture. In theory, this means that
presets with `mipmap_input0 = "true"` will not get a mipmapped input. In practice, no known shader presets set
`mipmap_input0 = "true"`.
### Runtime specific differences
* OpenGL
* Copying of in-flight framebuffer contents to history is done via `glBlitFramebuffer` rather than drawing a quad into an intermediate FBO.

View file

@ -2,7 +2,7 @@ use crate::error::{assume_d3d11_init, FilterChainError};
use crate::texture::D3D11InputView;
use crate::util::d3d11_get_closest_format;
use crate::{error, D3D11OutputView};
use librashader_common::{ImageFormat, Size, Viewport};
use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
use windows::core::Interface;
@ -14,7 +14,7 @@ use windows::Win32::Graphics::Direct3D11::{
D3D11_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0,
D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_RTV_DIMENSION_TEXTURE2D,
D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV,
D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_VIEWPORT,
D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT,
};
use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC};
@ -227,20 +227,6 @@ impl OwnedFramebuffer {
Ok(())
}
}
#[derive(Debug, Clone)]
pub(crate) struct OutputFramebuffer {
pub rtv: ID3D11RenderTargetView,
pub size: Size<u32>,
}
impl<'a> From<&Viewport<'a, D3D11OutputView>> for OutputFramebuffer {
fn from(value: &Viewport<'a, D3D11OutputView>) -> Self {
OutputFramebuffer {
rtv: value.output.handle.clone(),
size: value.output.size,
}
}
}
fn default_desc(size: Size<u32>, format: DXGI_FORMAT, mip_levels: u32) -> D3D11_TEXTURE2D_DESC {
D3D11_TEXTURE2D_DESC {
@ -259,16 +245,6 @@ fn default_desc(size: Size<u32>, format: DXGI_FORMAT, mip_levels: u32) -> D3D11_
MiscFlags: D3D11_RESOURCE_MISC_GENERATE_MIPS,
}
}
pub const fn default_viewport(size: Size<u32>) -> D3D11_VIEWPORT {
D3D11_VIEWPORT {
TopLeftX: 0.0,
TopLeftY: 0.0,
Width: size.width as f32,
Height: size.height as f32,
MinDepth: 0.0,
MaxDepth: 1.0,
}
}
impl ScaleFramebuffer for OwnedFramebuffer {
type Error = FilterChainError;

View file

@ -19,7 +19,7 @@ pub struct D3D11StateSaveGuard<'a> {
saved_blend_factor: [f32; 4],
saved_blend_mask: u32,
saved_rs: Option<ID3D11RasterizerState>,
state: &'a D3D11State,
_state: &'a D3D11State,
}
impl D3D11State {
@ -95,7 +95,7 @@ impl D3D11State {
saved_blend_factor,
saved_blend_mask,
saved_rs,
state: self,
_state: self,
}
};

View file

@ -84,11 +84,11 @@ pub trait DXSample {
}
#[inline]
pub fn LOWORD(l: usize) -> u32 {
pub fn loword(l: usize) -> u32 {
(l & 0xffff) as u32
}
#[inline]
pub fn HIWORD(l: usize) -> u32 {
pub fn hiword(l: usize) -> u32 {
((l >> 16) & 0xffff) as u32
}
@ -179,7 +179,7 @@ fn sample_wndproc<S: DXSample>(sample: &mut S, message: u32, wparam: WPARAM) ->
true
}
WM_SIZE => {
sample.resize(LOWORD(wparam.0), HIWORD(wparam.0)).unwrap();
sample.resize(loword(wparam.0), hiword(wparam.0)).unwrap();
true
}
_ => false,

View file

@ -84,7 +84,7 @@ mod tests {
FILTER_PATH,
Some(&FilterChainOptionsD3D11 {
use_deferred_context: false,
force_no_mipmaps: true,
force_no_mipmaps: false,
}),
// replace below with 'None' for the triangle
// None,

View file

@ -47,7 +47,7 @@ use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleO
use windows::Win32::System::WindowsProgramming::INFINITE;
use librashader_runtime::render_target::RenderTarget;
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer};
use librashader_runtime::scaling::ScaleFramebuffer;
use rayon::prelude::*;
const MIPMAP_RESERVED_WORKHEAP_DESCRIPTORS: usize = 1024;
@ -310,7 +310,7 @@ impl FilterChainD3D12 {
NodeMask: 0,
})?;
let fence_event = unsafe { CreateEventA(None, false, false, None)? };
let fence_event = CreateEventA(None, false, false, None)?;
let fence: ID3D12Fence = device.CreateFence(0, D3D12_FENCE_FLAG_NONE)?;
let mut residuals = Vec::new();
@ -338,11 +338,10 @@ impl FilterChainD3D12 {
queue.Signal(&fence, 1)?;
// Wait until finished
if unsafe { fence.GetCompletedValue() } < 1 {
unsafe { fence.SetEventOnCompletion(1, fence_event)? };
unsafe { WaitForSingleObject(fence_event, INFINITE) };
unsafe { ResetEvent(fence_event) };
if fence.GetCompletedValue() < 1 {
fence.SetEventOnCompletion(1, fence_event)?;
WaitForSingleObject(fence_event, INFINITE);
ResetEvent(fence_event);
}
cmd.Reset(&command_pool, None)?;
@ -360,11 +359,10 @@ impl FilterChainD3D12 {
queue.ExecuteCommandLists(&[cmd.cast()?]);
queue.Signal(&fence, 2)?;
//
if unsafe { fence.GetCompletedValue() } < 2 {
unsafe { fence.SetEventOnCompletion(2, fence_event)? }
unsafe { WaitForSingleObject(fence_event, INFINITE) };
unsafe { CloseHandle(fence_event) };
if fence.GetCompletedValue() < 2 {
fence.SetEventOnCompletion(2, fence_event)?;
WaitForSingleObject(fence_event, INFINITE);
CloseHandle(fence_event);
}
drop(residuals);
@ -701,21 +699,19 @@ impl FilterChainD3D12 {
);
if target.max_mipmap > 1 && !self.disable_mipmaps {
let residuals = unsafe {
self.common.mipmap_gen.mipmapping_context(
cmd,
&mut self.mipmap_heap,
|ctx| {
ctx.generate_mipmaps(
&target.handle,
target.max_mipmap,
target.size,
target.format.into(),
)?;
Ok::<(), FilterChainError>(())
},
)?
};
let residuals = self.common.mipmap_gen.mipmapping_context(
cmd,
&mut self.mipmap_heap,
|ctx| {
ctx.generate_mipmaps(
&target.handle,
target.max_mipmap,
target.size,
target.format.into(),
)?;
Ok::<(), FilterChainError>(())
},
)?;
self.residuals.dispose_mipmap_handles(residuals);
}

View file

@ -44,69 +44,67 @@ impl OwnedImage {
format: ImageFormat,
mipmap: bool,
) -> error::Result<OwnedImage> {
unsafe {
let miplevels = if mipmap {
size.calculate_miplevels()
} else {
1
};
let mut desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
Alignment: 0,
Width: size.width as u64,
Height: size.height,
DepthOrArraySize: 1,
MipLevels: miplevels as u16,
Format: format.into(),
SampleDesc: DXGI_SAMPLE_DESC {
Count: 1,
Quality: 0,
},
Layout: Default::default(),
Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET,
};
let miplevels = if mipmap {
size.calculate_miplevels()
} else {
1
};
let mut desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
Alignment: 0,
Width: size.width as u64,
Height: size.height,
DepthOrArraySize: 1,
MipLevels: miplevels as u16,
Format: format.into(),
SampleDesc: DXGI_SAMPLE_DESC {
Count: 1,
Quality: 0,
},
Layout: Default::default(),
Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET,
};
let mut format_support = D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: desc.Format,
Support1: D3D12_FORMAT_SUPPORT1_TEXTURE2D
| D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE
| D3D12_FORMAT_SUPPORT1_RENDER_TARGET,
..Default::default()
};
let mut format_support = D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: desc.Format,
Support1: D3D12_FORMAT_SUPPORT1_TEXTURE2D
| D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE
| D3D12_FORMAT_SUPPORT1_RENDER_TARGET,
..Default::default()
};
if mipmap {
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
format_support.Support1 |= D3D12_FORMAT_SUPPORT1_MIP;
}
desc.Format = d3d12_get_closest_format(device, desc.Format, format_support);
let mut resource: Option<ID3D12Resource> = None;
unsafe {
device.CreateCommittedResource(
&D3D12_HEAP_PROPERTIES {
Type: D3D12_HEAP_TYPE_DEFAULT,
CPUPageProperty: D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
MemoryPoolPreference: D3D12_MEMORY_POOL_UNKNOWN,
CreationNodeMask: 1,
VisibleNodeMask: 1,
},
D3D12_HEAP_FLAG_NONE,
&desc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
None,
&mut resource,
)?;
}
assume_d3d12_init!(resource, "CreateCommittedResource");
Ok(OwnedImage {
handle: resource,
size,
format,
device: device.clone(),
max_mipmap: miplevels as u16,
})
if mipmap {
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
format_support.Support1 |= D3D12_FORMAT_SUPPORT1_MIP;
}
desc.Format = d3d12_get_closest_format(device, desc.Format, format_support);
let mut resource: Option<ID3D12Resource> = None;
unsafe {
device.CreateCommittedResource(
&D3D12_HEAP_PROPERTIES {
Type: D3D12_HEAP_TYPE_DEFAULT,
CPUPageProperty: D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
MemoryPoolPreference: D3D12_MEMORY_POOL_UNKNOWN,
CreationNodeMask: 1,
VisibleNodeMask: 1,
},
D3D12_HEAP_FLAG_NONE,
&desc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
None,
&mut resource,
)?;
}
assume_d3d12_init!(resource, "CreateCommittedResource");
Ok(OwnedImage {
handle: resource,
size,
format,
device: device.clone(),
max_mipmap: miplevels as u16,
})
}
/// SAFETY: self must fit the source image

View file

@ -307,27 +307,21 @@ impl D3D12GraphicsPipeline {
root_signature: &D3D12RootSignature,
render_format: DXGI_FORMAT,
) -> error::Result<D3D12GraphicsPipeline> {
unsafe {
let vertex_dxil = util::dxc_compile_shader(
library,
dxc,
&shader_assembly.vertex,
BindingStage::VERTEX,
)?;
let fragment_dxil = util::dxc_compile_shader(
library,
dxc,
&shader_assembly.fragment,
BindingStage::FRAGMENT,
)?;
let vertex_dxil =
util::dxc_compile_shader(library, dxc, &shader_assembly.vertex, BindingStage::VERTEX)?;
let fragment_dxil = util::dxc_compile_shader(
library,
dxc,
&shader_assembly.fragment,
BindingStage::FRAGMENT,
)?;
Self::new_from_blobs(
device,
vertex_dxil,
fragment_dxil,
root_signature,
render_format,
)
}
Self::new_from_blobs(
device,
vertex_dxil,
fragment_dxil,
root_signature,
render_format,
)
}
}

View file

@ -1,3 +1,4 @@
#![cfg(test)]
use std::ffi::CStr;
use windows::{
core::*, Win32::Foundation::*, Win32::Graphics::Direct3D::Fxc::*, Win32::Graphics::Direct3D::*,
@ -56,18 +57,6 @@ pub struct SampleCommandLine {
pub use_warp_device: bool,
}
fn build_command_line() -> SampleCommandLine {
let mut use_warp_device = false;
for arg in std::env::args() {
if arg.eq_ignore_ascii_case("-warp") || arg.eq_ignore_ascii_case("/warp") {
use_warp_device = true;
}
}
SampleCommandLine { use_warp_device }
}
fn run_sample<S>(mut sample: S) -> Result<()>
where
S: DXSample,
@ -938,7 +927,7 @@ pub mod d3d12_hello_triangle {
}
}
pub fn main<S: DXSample>(sample: S) -> Result<()> {
pub(crate) fn main<S: DXSample>(sample: S) -> Result<()> {
run_sample(sample)?;
Ok(())

View file

@ -156,29 +156,27 @@ impl LutTexture {
}
assume_d3d12_init!(upload, "CreateCommittedResource");
unsafe {
let subresource = [D3D12_SUBRESOURCE_DATA {
pData: source.bytes.as_ptr().cast(),
RowPitch: 4 * source.size.width as isize,
SlicePitch: (4 * source.size.width * source.size.height) as isize,
}];
let subresource = [D3D12_SUBRESOURCE_DATA {
pData: source.bytes.as_ptr().cast(),
RowPitch: 4 * source.size.width as isize,
SlicePitch: (4 * source.size.width * source.size.height) as isize,
}];
d3d12_resource_transition(
cmd,
&resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_COPY_DEST,
);
d3d12_resource_transition(
cmd,
&resource,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_COPY_DEST,
);
d3d12_update_subresources(cmd, &resource, &upload, 0, 0, 1, &subresource)?;
d3d12_update_subresources(cmd, &resource, &upload, 0, 0, 1, &subresource)?;
d3d12_resource_transition(
cmd,
&resource,
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
)
}
d3d12_resource_transition(
cmd,
&resource,
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
);
let view = InputTexture::new(
resource.clone(),

View file

@ -67,7 +67,6 @@ pub struct D3D12MipmapGen {
root_signature: ID3D12RootSignature,
pipeline: ID3D12PipelineState,
own_heaps: bool,
root_index_offset: usize,
}
#[derive(Copy, Clone, Zeroable, Pod)]
@ -147,7 +146,6 @@ impl D3D12MipmapGen {
root_signature,
pipeline,
own_heaps,
root_index_offset: 0,
})
}
}
@ -169,6 +167,10 @@ impl D3D12MipmapGen {
///
/// If own_heap is false, then you must ensure that the compute root signature
/// is already bound before entering the context.
///
/// The list of returned descriptors must be kept around until the command list has been
/// submitted.
#[must_use]
pub fn mipmapping_context<F, E>(
&self,
cmd: &ID3D12GraphicsCommandList,

View file

@ -70,7 +70,7 @@ const FINAL_VBO_DATA: [D3D12Vertex; 4] = [
static VBO_DATA: &[D3D12Vertex; 8] = &concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_VBO_DATA);
pub(crate) struct DrawQuad {
buffer: ID3D12Resource,
_buffer: ID3D12Resource,
view: D3D12_VERTEX_BUFFER_VIEW,
}
@ -91,7 +91,10 @@ impl DrawQuad {
};
let buffer = buffer.into_raw();
Ok(DrawQuad { buffer, view })
Ok(DrawQuad {
_buffer: buffer,
view,
})
}
pub fn bind_vertices_for_frame(&self, cmd: &ID3D12GraphicsCommandList) {

View file

@ -10,7 +10,7 @@ use windows::Win32::Graphics::Direct3D12::{
pub struct SamplerSet {
samplers: FxHashMap<(WrapMode, FilterMode), D3D12DescriptorHeapSlot<SamplerPaletteHeap>>,
heap: D3D12DescriptorHeap<SamplerPaletteHeap>,
_heap: D3D12DescriptorHeap<SamplerPaletteHeap>,
}
impl SamplerSet {
@ -73,6 +73,9 @@ impl SamplerSet {
}
}
Ok(SamplerSet { samplers, heap })
Ok(SamplerSet {
samplers,
_heap: heap,
})
}
}

View file

@ -287,19 +287,18 @@ pub fn d3d12_update_subresources(
let mut num_rows = vec![0; num_subresources as usize];
let mut row_sizes_in_bytes = vec![0; num_subresources as usize];
let mut required_size = 0;
// texture upload
unsafe {
device.GetCopyableFootprints(
&destination_desc,
first_subresouce,
num_subresources,
intermediate_offset,
Some(layouts.as_mut_ptr()),
Some(num_rows.as_mut_ptr()),
Some(row_sizes_in_bytes.as_mut_ptr()),
Some(&mut required_size),
);
}
device.GetCopyableFootprints(
&destination_desc,
first_subresouce,
num_subresources,
intermediate_offset,
Some(layouts.as_mut_ptr()),
Some(num_rows.as_mut_ptr()),
Some(row_sizes_in_bytes.as_mut_ptr()),
Some(&mut required_size),
);
update_subresources(
cmd,

View file

@ -5,8 +5,8 @@ use ash::vk;
use std::sync::Arc;
pub struct VulkanCommandPool {
pool: vk::CommandPool,
device: Arc<ash::Device>,
_pool: vk::CommandPool,
_device: Arc<ash::Device>,
pub buffers: Vec<vk::CommandBuffer>,
}
@ -29,8 +29,8 @@ impl VulkanCommandPool {
let buffers = base.device.allocate_command_buffers(&buffer_info)?;
Ok(VulkanCommandPool {
pool,
device: base.device.clone(),
_pool: pool,
_device: base.device.clone(),
buffers,
})
}

View file

@ -8,6 +8,7 @@ pub struct VulkanDebug {
messenger: DebugUtilsMessengerEXT,
}
#[allow(dead_code)]
impl VulkanDebug {
pub fn new(
entry: &ash::Entry,

View file

@ -1,3 +1,5 @@
#![cfg(test)]
#![allow(unused_variables)]
mod command;
mod debug;
mod framebuffer;
@ -6,7 +8,7 @@ mod pipeline;
mod surface;
mod swapchain;
mod syncobjects;
pub mod vulkan_base;
pub(crate) mod vulkan_base;
use crate::filter_chain::FilterChainVulkan;
use crate::hello_triangle::command::VulkanCommandPool;
@ -391,7 +393,7 @@ pub fn find_memorytype_index(
}
pub struct VulkanDraw {
surface: VulkanSurface,
_surface: VulkanSurface,
base: VulkanBase,
pub swapchain: VulkanSwapchain,
pub pipeline: VulkanPipeline,
@ -435,7 +437,7 @@ pub fn main(vulkan: VulkanBase, filter_chain: FilterChainVulkan) {
let sync = SyncObjects::new(&vulkan.device, MAX_FRAMES_IN_FLIGHT).unwrap();
let vulkan = VulkanDraw {
surface,
_surface: surface,
swapchain,
base: vulkan,
pipeline,

View file

@ -12,7 +12,7 @@ pub struct VulkanSwapchain {
pub loader: ash::extensions::khr::Swapchain,
pub format: vk::SurfaceFormatKHR,
pub extent: vk::Extent2D,
mode: vk::PresentModeKHR,
pub mode: vk::PresentModeKHR,
pub swapchain_images: Vec<vk::Image>,
pub swapchain_image_views: Vec<vk::ImageView>,
@ -92,7 +92,7 @@ impl VulkanSwapchain {
unsafe {
let image = base.device.create_image(&create_info, None)?;
let mem_reqs = unsafe { base.device.get_image_memory_requirements(image) };
let mem_reqs = base.device.get_image_memory_requirements(image);
let memory =
VulkanImageMemory::new(&base.device, &base.allocator, mem_reqs, &image)

View file

@ -7,7 +7,7 @@ use crate::hello_triangle::physicaldevice::{find_queue_family, pick_physical_dev
use crate::util;
use ash::prelude::VkResult;
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc};
use gpu_allocator::vulkan::Allocator;
use parking_lot::RwLock;
use std::ffi::CStr;
use std::sync::Arc;
@ -44,7 +44,7 @@ impl VulkanBase {
ash::extensions::ext::DebugUtils::name().as_ptr(),
];
let layers = unsafe { [KHRONOS_VALIDATION.as_ptr().cast()] };
let layers = [KHRONOS_VALIDATION.as_ptr().cast()];
let create_info = vk::InstanceCreateInfo::builder()
.application_info(&app_info)
@ -125,6 +125,7 @@ impl VulkanBase {
}
}
#[allow(unused)]
unsafe extern "system" fn vulkan_debug_callback(
_message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
_message_type: vk::DebugUtilsMessageTypeFlagsEXT,

View file

@ -15,7 +15,6 @@ use std::sync::Arc;
pub struct VulkanImageMemory {
allocation: Option<Allocation>,
allocator: Arc<RwLock<Allocator>>,
device: Arc<ash::Device>,
}
impl VulkanImageMemory {
@ -38,7 +37,6 @@ impl VulkanImageMemory {
Ok(VulkanImageMemory {
allocation: Some(allocation),
allocator: Arc::clone(allocator),
device: Arc::clone(device),
})
}
}
@ -46,12 +44,10 @@ impl VulkanImageMemory {
impl Drop for VulkanImageMemory {
fn drop(&mut self) {
unsafe {
let allocation = self.allocation.take();
if let Some(allocation) = allocation {
if let Err(e) = self.allocator.write().free(allocation) {
println!("librashader-runtime-vk: [warn] failed to deallocate image buffer {e}")
}
let allocation = self.allocation.take();
if let Some(allocation) = allocation {
if let Err(e) = self.allocator.write().free(allocation) {
println!("librashader-runtime-vk: [warn] failed to deallocate image buffer {e}")
}
}
}

View file

@ -1,6 +1,6 @@
use ash::vk;
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc};
use gpu_allocator::AllocatorDebugSettings;
use parking_lot::RwLock;
use std::sync::Arc;