fmt: format pass

This commit is contained in:
chyyran 2023-01-29 21:26:34 -05:00
parent 92caad292c
commit 964da2874c
7 changed files with 66 additions and 46 deletions

View file

@ -23,6 +23,7 @@ use crate::samplers::SamplerSet;
use crate::util::d3d11_compile_bound_shader; use crate::util::d3d11_compile_bound_shader;
use crate::{error, util, D3D11OutputView}; use crate::{error, util, D3D11OutputView};
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_runtime::binding::TextureInput;
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC,
@ -30,7 +31,6 @@ use windows::Win32::Graphics::Direct3D11::{
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC,
}; };
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
use librashader_runtime::binding::TextureInput;
pub struct FilterMutable { pub struct FilterMutable {
pub(crate) passes_enabled: usize, pub(crate) passes_enabled: usize,
@ -121,7 +121,7 @@ impl FilterChainD3D11 {
&current_context, &current_context,
Size::new(1, 1), Size::new(1, 1),
ImageFormat::R8G8B8A8Unorm, ImageFormat::R8G8B8A8Unorm,
false false,
) )
}); });
@ -141,7 +141,7 @@ impl FilterChainD3D11 {
&current_context, &current_context,
Size::new(1, 1), Size::new(1, 1),
ImageFormat::R8G8B8A8Unorm, ImageFormat::R8G8B8A8Unorm,
false false,
) )
}); });
// resolve all results // resolve all results
@ -353,7 +353,13 @@ impl FilterChainD3D11 {
// eprintln!("[history] using frame history with {required_images} images"); // eprintln!("[history] using frame history with {required_images} images");
let mut framebuffers = VecDeque::with_capacity(required_images); let mut framebuffers = VecDeque::with_capacity(required_images);
framebuffers.resize_with(required_images, || { framebuffers.resize_with(required_images, || {
OwnedFramebuffer::new(device, context, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, false) OwnedFramebuffer::new(
device,
context,
Size::new(1, 1),
ImageFormat::R8G8B8A8Unorm,
false,
)
}); });
let framebuffers = framebuffers let framebuffers = framebuffers
@ -481,7 +487,7 @@ impl FilterChainD3D11 {
pass.get_format(), pass.get_format(),
&viewport.output.size, &viewport.output.size,
&source_size, &source_size,
should_mipmap should_mipmap,
)?; )?;
self.feedback_framebuffers[index].scale( self.feedback_framebuffers[index].scale(
@ -489,7 +495,7 @@ impl FilterChainD3D11 {
pass.get_format(), pass.get_format(),
&viewport.output.size, &viewport.output.size,
&source_size, &source_size,
should_mipmap should_mipmap,
)?; )?;
source_size = next_size; source_size = next_size;

View file

@ -1,6 +1,6 @@
use crate::error; use crate::error;
use crate::error::assume_d3d11_init; use crate::error::assume_d3d11_init;
use crate::texture::{D3D11InputView, InputTexture}; use crate::texture::{D3D11InputView};
use crate::util::d3d11_get_closest_format; use crate::util::d3d11_get_closest_format;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
@ -57,7 +57,11 @@ impl OwnedFramebuffer {
device: device.clone(), device: device.clone(),
context: context.clone(), context: context.clone(),
is_raw: false, is_raw: false,
max_mipmap: if mipmap { size.calculate_miplevels() } else { 1 }, max_mipmap: if mipmap {
size.calculate_miplevels()
} else {
1
},
}) })
} }
} }

View file

@ -180,8 +180,8 @@ fn sample_wndproc<S: DXSample>(sample: &mut S, message: u32, wparam: WPARAM) ->
} }
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,
} }
} }
@ -242,13 +242,13 @@ pub mod d3d11_hello_triangle {
use crate::filter_chain::FilterChainD3D11; use crate::filter_chain::FilterChainD3D11;
use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11}; use crate::options::{FilterChainOptionsD3D11};
use crate::texture::{D3D11InputView, LutTexture}; use crate::texture::{D3D11InputView, LutTexture};
use crate::D3D11OutputView; use crate::D3D11OutputView;
use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode};
use librashader_runtime::image::Image;
use std::slice; use std::slice;
use std::time::Instant; use std::time::Instant;
use librashader_runtime::image::Image;
pub struct Sample { pub struct Sample {
pub dxgi_factory: IDXGIFactory4, pub dxgi_factory: IDXGIFactory4,
@ -256,7 +256,7 @@ pub mod d3d11_hello_triangle {
pub context: ID3D11DeviceContext, pub context: ID3D11DeviceContext,
pub resources: Option<Resources>, pub resources: Option<Resources>,
pub filter: FilterChainD3D11, pub filter: FilterChainD3D11,
pub lut: Option<ID3D11Texture2D> pub lut: Option<ID3D11Texture2D>,
} }
pub struct Resources { pub struct Resources {
@ -291,21 +291,29 @@ pub mod d3d11_hello_triangle {
let (dxgi_factory, device, context) = create_device()?; let (dxgi_factory, device, context) = create_device()?;
let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap(); let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap();
let lut = if let Some(image) = image { let lut = if let Some(image) = image {
let lut = LutTexture::new(&device, &context, &image, D3D11_TEXTURE2D_DESC { let lut = LutTexture::new(
Width: image.size.width, &device,
Height: image.size.height, &context,
MipLevels: 1, &image,
ArraySize: 0, D3D11_TEXTURE2D_DESC {
Format: ImageFormat::R8G8B8A8Unorm.into(), Width: image.size.width,
SampleDesc: DXGI_SAMPLE_DESC { Height: image.size.height,
Count: 1, MipLevels: 1,
Quality: 0, ArraySize: 0,
}, Format: ImageFormat::R8G8B8A8Unorm.into(),
Usage: D3D11_USAGE_DYNAMIC, SampleDesc: DXGI_SAMPLE_DESC {
BindFlags: D3D11_BIND_SHADER_RESOURCE, Count: 1,
CPUAccessFlags: Default::default(), Quality: 0,
MiscFlags: Default::default(), },
}, FilterMode::Linear, WrapMode::ClampToEdge).unwrap(); Usage: D3D11_USAGE_DYNAMIC,
BindFlags: D3D11_BIND_SHADER_RESOURCE,
CPUAccessFlags: Default::default(),
MiscFlags: Default::default(),
},
FilterMode::Linear,
WrapMode::ClampToEdge,
)
.unwrap();
Some(lut.handle) Some(lut.handle)
} else { } else {
None None
@ -372,11 +380,12 @@ pub mod d3d11_hello_triangle {
backbuffer.GetDesc(&mut desc); backbuffer.GetDesc(&mut desc);
desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
self.device.CreateTexture2D(&desc, None, Some(&mut renderbuffer))?; self.device
.CreateTexture2D(&desc, None, Some(&mut renderbuffer))?;
let renderbuffer = renderbuffer.unwrap(); let renderbuffer = renderbuffer.unwrap();
self.device.CreateRenderTargetView(&renderbuffer, None, Some(&mut rtv))?; self.device
.CreateRenderTargetView(&renderbuffer, None, Some(&mut rtv))?;
(renderbuffer, rtv.unwrap()) (renderbuffer, rtv.unwrap())
}; };
self.resources = Some(Resources { self.resources = Some(Resources {
swapchain, swapchain,
@ -411,14 +420,15 @@ pub mod d3d11_hello_triangle {
Ok(()) Ok(())
} }
fn resize(&mut self, w: u32, h: u32) -> Result<()> { fn resize(&mut self, _w: u32, _h: u32) -> Result<()> {
unsafe { unsafe {
if let Some(resources) = self.resources.as_mut() { if let Some(resources) = self.resources.as_mut() {
drop(resources.backbuffer_rtv.take()); drop(resources.backbuffer_rtv.take());
drop(resources.backbuffer.take()); drop(resources.backbuffer.take());
resources.swapchain.ResizeBuffers(0, 0, resources
0, DXGI_FORMAT_UNKNOWN, 0) .swapchain
.unwrap_or_else(|f| eprintln!("{:?}", f)); .ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0)
.unwrap_or_else(|f| eprintln!("{f:?}"));
let (rtv, backbuffer) = create_rtv(&self.device, &resources.swapchain)?; let (rtv, backbuffer) = create_rtv(&self.device, &resources.swapchain)?;
resources.backbuffer = Some(backbuffer); resources.backbuffer = Some(backbuffer);
@ -525,7 +535,11 @@ pub mod d3d11_hello_triangle {
let mut tex2d_desc = Default::default(); let mut tex2d_desc = Default::default();
input.GetDesc(&mut tex2d_desc); input.GetDesc(&mut tex2d_desc);
let mut backbuffer_desc = Default::default(); let mut backbuffer_desc = Default::default();
resources.backbuffer.as_ref().unwrap().GetDesc(&mut backbuffer_desc); resources
.backbuffer
.as_ref()
.unwrap()
.GetDesc(&mut backbuffer_desc);
let mut input_srv = None; let mut input_srv = None;
self.device.CreateShaderResourceView( self.device.CreateShaderResourceView(

View file

@ -27,22 +27,22 @@ pub use texture::D3D11OutputView;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use librashader_runtime::image::{Image, UVDirection};
use super::*; use super::*;
use crate::options::FilterChainOptionsD3D11; use crate::options::FilterChainOptionsD3D11;
use librashader_runtime::image::{Image, UVDirection};
#[test] #[test]
fn triangle_d3d11() { fn triangle_d3d11() {
let sample = hello_triangle::d3d11_hello_triangle::Sample::new( let sample = hello_triangle::d3d11_hello_triangle::Sample::new(
"../test/slang-shaders/crt/crt-royale.slangp", "../test/slang-shaders/crt/crt-royale.slangp",
// "../test/slang-shaders/presets/crt-geom-ntsc-upscale-sharp.slangp", // "../test/slang-shaders/presets/crt-geom-ntsc-upscale-sharp.slangp",
// "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", // "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
// "../test/null.slangp", // "../test/null.slangp",
Some(&FilterChainOptionsD3D11 { Some(&FilterChainOptionsD3D11 {
use_deferred_context: false, use_deferred_context: false,
force_no_mipmaps: false, force_no_mipmaps: false,
}), }),
Some(Image::load("../test/sf2.png", UVDirection::TopLeft).unwrap()) Some(Image::load("../test/sf2.png", UVDirection::TopLeft).unwrap()),
) )
.unwrap(); .unwrap();
// let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new( // let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new(

View file

@ -1,5 +1,6 @@
use librashader_common::{FilterMode, Size, WrapMode}; use librashader_common::{FilterMode, Size, WrapMode};
use librashader_runtime::image::Image; use librashader_runtime::image::Image;
use librashader_runtime::scaling::MipmapSize;
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Device, ID3D11DeviceContext, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Device, ID3D11DeviceContext, ID3D11RenderTargetView, ID3D11ShaderResourceView,
@ -10,7 +11,6 @@ use windows::Win32::Graphics::Direct3D11::{
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING,
}; };
use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC;
use librashader_runtime::scaling::MipmapSize;
use crate::error::{assume_d3d11_init, Result}; use crate::error::{assume_d3d11_init, Result};
use crate::framebuffer::OwnedFramebuffer; use crate::framebuffer::OwnedFramebuffer;

View file

@ -2,7 +2,6 @@ use crate::error::{FilterChainError, Result};
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::InputTexture;
use gl::types::{GLenum, GLint, GLsizei}; use gl::types::{GLenum, GLint, GLsizei};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
@ -46,8 +45,7 @@ impl FramebufferInterface for Gl3Framebuffer {
return Ok(fb.size); return Ok(fb.size);
} }
let size = source_size let size = source_size.scale_viewport(scaling, viewport.output.size);
.scale_viewport(scaling, viewport.output.size);
if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) {
fb.size = size; fb.size = size;

View file

@ -2,7 +2,6 @@ use crate::error::{FilterChainError, Result};
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::InputTexture;
use gl::types::{GLenum, GLint, GLsizei}; use gl::types::{GLenum, GLint, GLsizei};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
@ -44,8 +43,7 @@ impl FramebufferInterface for Gl46Framebuffer {
return Ok(fb.size); return Ok(fb.size);
} }
let size = source_size let size = source_size.scale_viewport(scaling, viewport.output.size);
.scale_viewport(scaling, viewport.output.size);
if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) {
fb.size = size; fb.size = size;