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. * Shaders are compiled in parallel where possible. This should noticeably decrease preset compile times.
Parallel shader compilation is not available to OpenGL. Parallel shader compilation is not available to OpenGL.
* HDR10 support is not part of any shader runtime and is not supported by librashader. * 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 ### Runtime specific differences
* OpenGL * OpenGL
* Copying of in-flight framebuffer contents to history is done via `glBlitFramebuffer` rather than drawing a quad into an intermediate FBO. * 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::texture::D3D11InputView;
use crate::util::d3d11_get_closest_format; use crate::util::d3d11_get_closest_format;
use crate::{error, D3D11OutputView}; use crate::{error, D3D11OutputView};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
use windows::core::Interface; 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_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0,
D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_RTV_DIMENSION_TEXTURE2D, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_RTV_DIMENSION_TEXTURE2D,
D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV, 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}; use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC};
@ -227,20 +227,6 @@ impl OwnedFramebuffer {
Ok(()) 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 { fn default_desc(size: Size<u32>, format: DXGI_FORMAT, mip_levels: u32) -> D3D11_TEXTURE2D_DESC {
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, 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 { impl ScaleFramebuffer for OwnedFramebuffer {
type Error = FilterChainError; type Error = FilterChainError;

View file

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

View file

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

View file

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

View file

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

View file

@ -44,69 +44,67 @@ impl OwnedImage {
format: ImageFormat, format: ImageFormat,
mipmap: bool, mipmap: bool,
) -> error::Result<OwnedImage> { ) -> error::Result<OwnedImage> {
unsafe { let miplevels = if mipmap {
let miplevels = if mipmap { size.calculate_miplevels()
size.calculate_miplevels() } else {
} else { 1
1 };
}; let mut desc = D3D12_RESOURCE_DESC {
let mut desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Alignment: 0,
Alignment: 0, Width: size.width as u64,
Width: size.width as u64, Height: size.height,
Height: size.height, DepthOrArraySize: 1,
DepthOrArraySize: 1, MipLevels: miplevels as u16,
MipLevels: miplevels as u16, Format: format.into(),
Format: format.into(), SampleDesc: DXGI_SAMPLE_DESC {
SampleDesc: DXGI_SAMPLE_DESC { Count: 1,
Count: 1, Quality: 0,
Quality: 0, },
}, Layout: Default::default(),
Layout: Default::default(), Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET,
Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, };
};
let mut format_support = D3D12_FEATURE_DATA_FORMAT_SUPPORT { let mut format_support = D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: desc.Format, Format: desc.Format,
Support1: D3D12_FORMAT_SUPPORT1_TEXTURE2D Support1: D3D12_FORMAT_SUPPORT1_TEXTURE2D
| D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE
| D3D12_FORMAT_SUPPORT1_RENDER_TARGET, | D3D12_FORMAT_SUPPORT1_RENDER_TARGET,
..Default::default() ..Default::default()
}; };
if mipmap { if mipmap {
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
format_support.Support1 |= D3D12_FORMAT_SUPPORT1_MIP; 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,
})
} }
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 /// SAFETY: self must fit the source image

View file

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

View file

@ -1,3 +1,4 @@
#![cfg(test)]
use std::ffi::CStr; use std::ffi::CStr;
use windows::{ use windows::{
core::*, Win32::Foundation::*, Win32::Graphics::Direct3D::Fxc::*, Win32::Graphics::Direct3D::*, core::*, Win32::Foundation::*, Win32::Graphics::Direct3D::Fxc::*, Win32::Graphics::Direct3D::*,
@ -56,18 +57,6 @@ pub struct SampleCommandLine {
pub use_warp_device: bool, 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<()> fn run_sample<S>(mut sample: S) -> Result<()>
where where
S: DXSample, 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)?; run_sample(sample)?;
Ok(()) Ok(())

View file

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

View file

@ -67,7 +67,6 @@ pub struct D3D12MipmapGen {
root_signature: ID3D12RootSignature, root_signature: ID3D12RootSignature,
pipeline: ID3D12PipelineState, pipeline: ID3D12PipelineState,
own_heaps: bool, own_heaps: bool,
root_index_offset: usize,
} }
#[derive(Copy, Clone, Zeroable, Pod)] #[derive(Copy, Clone, Zeroable, Pod)]
@ -147,7 +146,6 @@ impl D3D12MipmapGen {
root_signature, root_signature,
pipeline, pipeline,
own_heaps, 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 /// If own_heap is false, then you must ensure that the compute root signature
/// is already bound before entering the context. /// 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>( pub fn mipmapping_context<F, E>(
&self, &self,
cmd: &ID3D12GraphicsCommandList, 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); static VBO_DATA: &[D3D12Vertex; 8] = &concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_VBO_DATA);
pub(crate) struct DrawQuad { pub(crate) struct DrawQuad {
buffer: ID3D12Resource, _buffer: ID3D12Resource,
view: D3D12_VERTEX_BUFFER_VIEW, view: D3D12_VERTEX_BUFFER_VIEW,
} }
@ -91,7 +91,10 @@ impl DrawQuad {
}; };
let buffer = buffer.into_raw(); let buffer = buffer.into_raw();
Ok(DrawQuad { buffer, view }) Ok(DrawQuad {
_buffer: buffer,
view,
})
} }
pub fn bind_vertices_for_frame(&self, cmd: &ID3D12GraphicsCommandList) { pub fn bind_vertices_for_frame(&self, cmd: &ID3D12GraphicsCommandList) {

View file

@ -10,7 +10,7 @@ use windows::Win32::Graphics::Direct3D12::{
pub struct SamplerSet { pub struct SamplerSet {
samplers: FxHashMap<(WrapMode, FilterMode), D3D12DescriptorHeapSlot<SamplerPaletteHeap>>, samplers: FxHashMap<(WrapMode, FilterMode), D3D12DescriptorHeapSlot<SamplerPaletteHeap>>,
heap: D3D12DescriptorHeap<SamplerPaletteHeap>, _heap: D3D12DescriptorHeap<SamplerPaletteHeap>,
} }
impl SamplerSet { 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 num_rows = vec![0; num_subresources as usize];
let mut row_sizes_in_bytes = vec![0; num_subresources as usize]; let mut row_sizes_in_bytes = vec![0; num_subresources as usize];
let mut required_size = 0; let mut required_size = 0;
// texture upload // texture upload
unsafe { device.GetCopyableFootprints(
device.GetCopyableFootprints( &destination_desc,
&destination_desc, first_subresouce,
first_subresouce, num_subresources,
num_subresources, intermediate_offset,
intermediate_offset, Some(layouts.as_mut_ptr()),
Some(layouts.as_mut_ptr()), Some(num_rows.as_mut_ptr()),
Some(num_rows.as_mut_ptr()), Some(row_sizes_in_bytes.as_mut_ptr()),
Some(row_sizes_in_bytes.as_mut_ptr()), Some(&mut required_size),
Some(&mut required_size), );
);
}
update_subresources( update_subresources(
cmd, cmd,

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ pub struct VulkanSwapchain {
pub loader: ash::extensions::khr::Swapchain, pub loader: ash::extensions::khr::Swapchain,
pub format: vk::SurfaceFormatKHR, pub format: vk::SurfaceFormatKHR,
pub extent: vk::Extent2D, pub extent: vk::Extent2D,
mode: vk::PresentModeKHR, pub mode: vk::PresentModeKHR,
pub swapchain_images: Vec<vk::Image>, pub swapchain_images: Vec<vk::Image>,
pub swapchain_image_views: Vec<vk::ImageView>, pub swapchain_image_views: Vec<vk::ImageView>,
@ -92,7 +92,7 @@ impl VulkanSwapchain {
unsafe { unsafe {
let image = base.device.create_image(&create_info, None)?; 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 = let memory =
VulkanImageMemory::new(&base.device, &base.allocator, mem_reqs, &image) 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 crate::util;
use ash::prelude::VkResult; use ash::prelude::VkResult;
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc}; use gpu_allocator::vulkan::Allocator;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::ffi::CStr; use std::ffi::CStr;
use std::sync::Arc; use std::sync::Arc;
@ -44,7 +44,7 @@ impl VulkanBase {
ash::extensions::ext::DebugUtils::name().as_ptr(), 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() let create_info = vk::InstanceCreateInfo::builder()
.application_info(&app_info) .application_info(&app_info)
@ -125,6 +125,7 @@ impl VulkanBase {
} }
} }
#[allow(unused)]
unsafe extern "system" fn vulkan_debug_callback( unsafe extern "system" fn vulkan_debug_callback(
_message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, _message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
_message_type: vk::DebugUtilsMessageTypeFlagsEXT, _message_type: vk::DebugUtilsMessageTypeFlagsEXT,

View file

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

View file

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