rt(d3d9): take viewport by reference to avoid AddRef/Release

This commit is contained in:
chyyran 2024-09-28 02:04:07 -04:00 committed by Ronny Chan
parent 7b7fd99b92
commit 7d483f2e08
6 changed files with 24 additions and 10 deletions

View file

@ -160,14 +160,14 @@ extern_fn! {
}; };
let viewport = if viewport.is_null() { let viewport = if viewport.is_null() {
Viewport::new_render_target_sized_origin(ManuallyDrop::into_inner(out.clone()), mvp) Viewport::new_render_target_sized_origin(out.deref(), mvp)
.map_err(|e| LibrashaderError::D3D9FilterError(FilterChainError::Direct3DError(e)))? .map_err(|e| LibrashaderError::D3D9FilterError(FilterChainError::Direct3DError(e)))?
} else { } else {
let viewport = unsafe { viewport.read() }; let viewport = unsafe { viewport.read() };
Viewport { Viewport {
x: viewport.x, x: viewport.x,
y: viewport.y, y: viewport.y,
output: ManuallyDrop::into_inner(out.clone()), output: out.deref(),
size: Size { size: Size {
height: viewport.height, height: viewport.height,
width: viewport.width width: viewport.width

View file

@ -92,7 +92,7 @@ impl RenderTest for Direct3D9 {
current_subframe: options.current_subframe, current_subframe: options.current_subframe,
}); });
let viewport = Viewport::new_render_target_sized_origin(surface.clone(), None)?; let viewport = Viewport::new_render_target_sized_origin(&surface, None)?;
for frame in 0..=frame_count { for frame in 0..=frame_count {
filter_chain.frame(&self.texture, &viewport, frame, options.as_ref())?; filter_chain.frame(&self.texture, &viewport, frame, options.as_ref())?;

View file

@ -64,7 +64,7 @@ impl From<FilterMode> for Direct3D9::D3DTEXTUREFILTER {
} }
} }
impl GetSize<u32> for Direct3D9::IDirect3DSurface9 { impl GetSize<u32> for &Direct3D9::IDirect3DSurface9 {
type Error = windows::core::Error; type Error = windows::core::Error;
fn size(&self) -> Result<Size<u32>, Self::Error> { fn size(&self) -> Result<Size<u32>, Self::Error> {
@ -80,7 +80,14 @@ impl GetSize<u32> for Direct3D9::IDirect3DSurface9 {
} }
} }
impl GetSize<u32> for Direct3D9::IDirect3DTexture9 { impl GetSize<u32> for Direct3D9::IDirect3DSurface9 {
type Error = windows::core::Error;
fn size(&self) -> Result<Size<u32>, Self::Error> {
<&Self as GetSize<u32>>::size(&self)
}
}
impl GetSize<u32> for &Direct3D9::IDirect3DTexture9 {
type Error = windows::core::Error; type Error = windows::core::Error;
fn size(&self) -> Result<Size<u32>, Self::Error> { fn size(&self) -> Result<Size<u32>, Self::Error> {
@ -96,6 +103,13 @@ impl GetSize<u32> for Direct3D9::IDirect3DTexture9 {
} }
} }
impl GetSize<u32> for Direct3D9::IDirect3DTexture9 {
type Error = windows::core::Error;
fn size(&self) -> Result<Size<u32>, Self::Error> {
<&Self as GetSize<u32>>::size(&self)
}
}
// impl FilterMode { // impl FilterMode {
// /// Get the mipmap filtering mode for the given combination. // /// Get the mipmap filtering mode for the given combination.
// pub fn d3d9_mip(&self, mip: FilterMode) -> Direct3D9::D3DTEXTUREFILTER { // pub fn d3d9_mip(&self, mip: FilterMode) -> Direct3D9::D3DTEXTUREFILTER {

View file

@ -289,7 +289,7 @@ impl FilterChainD3D9 {
pub unsafe fn frame( pub unsafe fn frame(
&mut self, &mut self,
input: &IDirect3DTexture9, input: &IDirect3DTexture9,
viewport: &Viewport<IDirect3DSurface9>, viewport: &Viewport<&IDirect3DSurface9>,
frame_count: usize, frame_count: usize,
options: Option<&FrameOptionsD3D9>, options: Option<&FrameOptionsD3D9>,
) -> error::Result<()> { ) -> error::Result<()> {

View file

@ -144,7 +144,7 @@ impl FilterPass {
parent: &FilterCommon, parent: &FilterCommon,
frame_count: u32, frame_count: u32,
options: &FrameOptionsD3D9, options: &FrameOptionsD3D9,
viewport: &Viewport<IDirect3DSurface9>, viewport: &Viewport<&IDirect3DSurface9>,
original: &D3D9InputTexture, original: &D3D9InputTexture,
source: &D3D9InputTexture, source: &D3D9InputTexture,
output: RenderTarget<IDirect3DSurface9>, output: RenderTarget<IDirect3DSurface9>,

View file

@ -431,13 +431,13 @@ pub mod d3d9_hello_triangle {
resources resources
.filter .filter
.frame( .frame(
resources.texture.clone(), &resources.texture,
&Viewport { &Viewport {
x: 0.0, x: 0.0,
y: 0.0, y: 0.0,
mvp: None, mvp: None,
output: backbuffer.clone(), output: &backbuffer,
size: backbuffer.size().unwrap(), size: backbuffer.size()?,
}, },
0, 0,
None, None,