d3d11: don't copy texture data, just copy the resource

This commit is contained in:
chyyran 2022-11-30 01:52:08 -05:00
parent 5088e1c55b
commit f044d0e91b
2 changed files with 24 additions and 43 deletions

View file

@ -67,7 +67,6 @@ pub struct FilterCommon {
impl FilterChain { impl FilterChain {
fn create_constant_buffer(device: &ID3D11Device, size: u32) -> util::Result<ID3D11Buffer> { fn create_constant_buffer(device: &ID3D11Device, size: u32) -> util::Result<ID3D11Buffer> {
eprintln!("{size}");
unsafe { unsafe {
let buffer = device.CreateBuffer( let buffer = device.CreateBuffer(
&D3D11_BUFFER_DESC { &D3D11_BUFFER_DESC {
@ -313,27 +312,7 @@ impl FilterChain {
fn push_history(&mut self, input: &DxImageView) -> util::Result<()> { fn push_history(&mut self, input: &DxImageView) -> util::Result<()> {
if let Some(mut back) = self.history_framebuffers.pop_back() { if let Some(mut back) = self.history_framebuffers.pop_back() {
let resource = unsafe { back.copy_from(&input)?;
let mut resource = None;
input.handle.GetResource(&mut resource);
// todo: make panic-free
resource.unwrap()
};
let format = unsafe {
let mut desc = Default::default();
input.handle.GetDesc(&mut desc);
desc.Format
};
if back.size != input.size || (format != DXGI_FORMAT(0) && format != back.format) {
eprintln!("[history] resizing");
back.init(input.size, ImageFormat::from(format))?;
}
back.copy_from(&resource)?;
self.history_framebuffers.push_front(back) self.history_framebuffers.push_front(back)
} }

View file

@ -1,4 +1,5 @@
use crate::texture::Texture; use windows::core::Interface;
use crate::texture::{DxImageView, Texture};
use crate::util; use crate::util;
use crate::util::d3d11_get_closest_format; use crate::util::d3d11_get_closest_format;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size};
@ -41,7 +42,6 @@ impl OwnedFramebuffer {
| D3D11_FORMAT_SUPPORT_SHADER_SAMPLE.0 | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE.0
| D3D11_FORMAT_SUPPORT_RENDER_TARGET.0, | D3D11_FORMAT_SUPPORT_RENDER_TARGET.0,
); );
eprintln!("{format:?}");
let desc = default_desc(size, format); let desc = default_desc(size, format);
let texture = device.CreateTexture2D(&desc, None)?; let texture = device.CreateTexture2D(&desc, None)?;
@ -105,6 +105,7 @@ impl OwnedFramebuffer {
drop(texture) drop(texture)
} }
self.format = format; self.format = format;
self.size = size;
Ok(()) Ok(())
} }
@ -150,26 +151,27 @@ impl OwnedFramebuffer {
}) })
} }
pub fn copy_from(&self, image: &ID3D11Resource) -> util::Result<()> { pub fn copy_from(&mut self, image: &DxImageView) -> util::Result<()> {
unsafe { let resource: ID3D11Texture2D = unsafe {
self.context.CopySubresourceRegion( let mut resource = None;
&self.texture, image.handle.GetResource(&mut resource);
0,
0, // todo: make panic-free
0, resource.unwrap().cast()?
0, };
image,
0, let format = unsafe {
Some(&D3D11_BOX { let mut desc = Default::default();
left: 0, resource.GetDesc(&mut desc);
top: 0, desc.Format
front: 0, };
right: self.size.width,
bottom: self.size.height, if self.size != image.size || format != self.format {
back: 1, eprintln!("[history] resizing");
}), self.init(image.size, ImageFormat::from(format))?;
)
} }
self.texture = resource.clone();
Ok(()) Ok(())
} }
} }