vk: move internal frame count to common

This commit is contained in:
chyyran 2023-02-16 21:16:42 -05:00
parent a6b1e0a412
commit af6f58981e
8 changed files with 27 additions and 38 deletions

View file

@ -14,9 +14,7 @@ impl SamplerSet {
pub fn get(&self, wrap: WrapMode, filter: FilterMode) -> &ID3D11SamplerState { pub fn get(&self, wrap: WrapMode, filter: FilterMode) -> &ID3D11SamplerState {
// SAFETY: the sampler set is complete for the matrix // SAFETY: the sampler set is complete for the matrix
// wrap x filter // wrap x filter
unsafe { unsafe { self.samplers.get(&(wrap, filter)).unwrap_unchecked() }
self.samplers.get(&(wrap, filter)).unwrap_unchecked()
}
} }
pub fn new(device: &ID3D11Device) -> Result<SamplerSet> { pub fn new(device: &ID3D11Device) -> Result<SamplerSet> {

View file

@ -22,9 +22,7 @@ impl SamplerSet {
) -> &D3D12DescriptorHeapSlot<SamplerPaletteHeap> { ) -> &D3D12DescriptorHeapSlot<SamplerPaletteHeap> {
// SAFETY: the sampler set is complete for the matrix // SAFETY: the sampler set is complete for the matrix
// wrap x filter // wrap x filter
unsafe { unsafe { self.samplers.get(&(wrap, filter)).unwrap_unchecked() }
self.samplers.get(&(wrap, filter)).unwrap_unchecked()
}
} }
pub fn new(device: &ID3D12Device) -> error::Result<SamplerSet> { pub fn new(device: &ID3D12Device) -> error::Result<SamplerSet> {
let mut samplers = FxHashMap::default(); let mut samplers = FxHashMap::default();

View file

@ -288,9 +288,8 @@ pub mod d3d12_hello_triangle {
} }
} }
let filter = unsafe { let filter =
FilterChainD3D12::load_from_path(filter, &device, None).unwrap() unsafe { FilterChainD3D12::load_from_path(filter, &device, None).unwrap() };
};
Ok(Sample { Ok(Sample {
dxgi_factory, dxgi_factory,

View file

@ -13,7 +13,10 @@ impl SamplerSet {
// SAFETY: the sampler set is complete for the matrix // SAFETY: the sampler set is complete for the matrix
// wrap x filter x mipmap // wrap x filter x mipmap
unsafe { unsafe {
*self.samplers.get(&(wrap, filter, mipmap)).unwrap_unchecked() *self
.samplers
.get(&(wrap, filter, mipmap))
.unwrap_unchecked()
} }
} }
@ -45,17 +48,9 @@ impl SamplerSet {
let mut sampler = 0; let mut sampler = 0;
unsafe { unsafe {
gl::GenSamplers(1, &mut sampler); gl::GenSamplers(1, &mut sampler);
SamplerSet::make_sampler( SamplerSet::make_sampler(sampler, *wrap_mode, *filter_mode, *mip_filter);
sampler,
*wrap_mode,
*filter_mode,
*mip_filter,
);
samplers.insert( samplers.insert((*wrap_mode, *filter_mode, *mip_filter), sampler);
(*wrap_mode, *filter_mode, *mip_filter),
sampler,
);
} }
} }
} }

View file

@ -17,8 +17,8 @@ fn triangle_gl() {
disable_cache: false, disable_cache: false,
}), }),
) )
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
.unwrap(); .unwrap();
hello_triangle::gl3::do_loop(glfw, window, events, shader, vao, &mut filter); hello_triangle::gl3::do_loop(glfw, window, events, shader, vao, &mut filter);
} }
} }
@ -39,8 +39,8 @@ fn triangle_gl46() {
disable_cache: false, disable_cache: false,
}), }),
) )
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
.unwrap(); .unwrap();
hello_triangle::gl46::do_loop(glfw, window, events, shader, vao, &mut filter); hello_triangle::gl46::do_loop(glfw, window, events, shader, vao, &mut filter);
} }
} }

View file

@ -142,6 +142,7 @@ pub(crate) struct FilterCommon {
pub history_textures: Box<[Option<InputImage>]>, pub history_textures: Box<[Option<InputImage>]>,
pub config: FilterMutable, pub config: FilterMutable,
pub device: Arc<ash::Device>, pub device: Arc<ash::Device>,
pub(crate) internal_frame_count: usize,
} }
/// Contains residual intermediate `VkImageView` and `VkImage` objects created /// Contains residual intermediate `VkImageView` and `VkImage` objects created
@ -380,6 +381,7 @@ impl FilterChainVulkan {
output_textures, output_textures,
feedback_textures, feedback_textures,
history_textures, history_textures,
internal_frame_count: 0,
}, },
passes: filters, passes: filters,
vulkan: device, vulkan: device,
@ -454,7 +456,6 @@ impl FilterChainVulkan {
graphics_pipeline, graphics_pipeline,
// ubo_ring, // ubo_ring,
frames_in_flight, frames_in_flight,
internal_frame_count: 0,
}) })
}) })
.collect(); .collect();
@ -482,12 +483,7 @@ impl FilterChainVulkan {
} }
// image must be in SHADER_READ_OPTIMAL // image must be in SHADER_READ_OPTIMAL
fn push_history( fn push_history(&mut self, input: &VulkanImage, cmd: vk::CommandBuffer) -> error::Result<()> {
&mut self,
input: &VulkanImage,
cmd: vk::CommandBuffer,
count: usize,
) -> error::Result<()> {
if let Some(mut back) = self.history_framebuffers.pop_back() { if let Some(mut back) = self.history_framebuffers.pop_back() {
if back.image.size != input.size if back.image.size != input.size
|| (input.format != vk::Format::UNDEFINED && input.format != back.image.format) || (input.format != vk::Format::UNDEFINED && input.format != back.image.format)
@ -498,7 +494,8 @@ impl FilterChainVulkan {
&mut back, &mut back,
OwnedImage::new(&self.vulkan, input.size, input.format.into(), 1)?, OwnedImage::new(&self.vulkan, input.size, input.format.into(), 1)?,
); );
self.residuals[count % self.residuals.len()].dispose_owned(old_back); self.residuals[self.common.internal_frame_count % self.residuals.len()]
.dispose_owned(old_back);
} }
unsafe { unsafe {
@ -556,7 +553,8 @@ impl FilterChainVulkan {
frame_count: usize, frame_count: usize,
options: Option<&FrameOptionsVulkan>, options: Option<&FrameOptionsVulkan>,
) -> error::Result<()> { ) -> error::Result<()> {
let intermediates = &mut self.residuals[frame_count % self.residuals.len()]; let intermediates =
&mut self.residuals[self.common.internal_frame_count % self.residuals.len()];
intermediates.dispose(); intermediates.dispose();
// limit number of passes to those enabled. // limit number of passes to those enabled.
@ -725,7 +723,8 @@ impl FilterChainVulkan {
intermediates.dispose_framebuffers(residual_fb); intermediates.dispose_framebuffers(residual_fb);
} }
self.push_history(input, cmd, frame_count)?; self.push_history(input, cmd)?;
self.common.internal_frame_count = self.common.internal_frame_count.wrapping_add(1);
Ok(()) Ok(())
} }
} }

View file

@ -32,7 +32,6 @@ pub struct FilterPass {
pub graphics_pipeline: VulkanGraphicsPipeline, pub graphics_pipeline: VulkanGraphicsPipeline,
// pub ubo_ring: VkUboRing, // pub ubo_ring: VkUboRing,
pub frames_in_flight: u32, pub frames_in_flight: u32,
pub internal_frame_count: usize,
} }
impl TextureInput for InputImage { impl TextureInput for InputImage {
@ -100,7 +99,7 @@ impl FilterPass {
vbo_type: QuadType, vbo_type: QuadType,
) -> error::Result<Option<vk::Framebuffer>> { ) -> error::Result<Option<vk::Framebuffer>> {
let mut descriptor = self.graphics_pipeline.layout.descriptor_sets let mut descriptor = self.graphics_pipeline.layout.descriptor_sets
[self.internal_frame_count % self.frames_in_flight as usize]; [parent.internal_frame_count % self.frames_in_flight as usize];
self.build_semantics( self.build_semantics(
pass_index, pass_index,
@ -181,7 +180,6 @@ impl FilterPass {
parent.draw_quad.draw_quad(cmd, vbo_type); parent.draw_quad.draw_quad(cmd, vbo_type);
self.graphics_pipeline.end_rendering(&parent.device, cmd); self.graphics_pipeline.end_rendering(&parent.device, cmd);
} }
self.internal_frame_count = self.internal_frame_count.wrapping_add(1);
Ok(residual) Ok(residual)
} }

View file

@ -62,7 +62,9 @@ impl SamplerSet {
// SAFETY: the sampler set is complete for the matrix // SAFETY: the sampler set is complete for the matrix
// wrap x filter x mipmap // wrap x filter x mipmap
unsafe { unsafe {
self.samplers.get(&(wrap, filter, mipmap)).unwrap_unchecked() self.samplers
.get(&(wrap, filter, mipmap))
.unwrap_unchecked()
} }
} }