Skip to content

Commit

Permalink
rt(d3d9): take viewport by reference to avoid AddRef/Release
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Sep 28, 2024
1 parent 7b7fd99 commit 7d483f2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions librashader-capi/src/runtime/d3d9/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ extern_fn! {
};

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)))?
} else {
let viewport = unsafe { viewport.read() };
Viewport {
x: viewport.x,
y: viewport.y,
output: ManuallyDrop::into_inner(out.clone()),
output: out.deref(),
size: Size {
height: viewport.height,
width: viewport.width
Expand Down
2 changes: 1 addition & 1 deletion librashader-cli/src/render/d3d9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl RenderTest for Direct3D9 {
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 {
filter_chain.frame(&self.texture, &viewport, frame, options.as_ref())?;
Expand Down
18 changes: 16 additions & 2 deletions librashader-common/src/d3d9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

fn size(&self) -> Result<Size<u32>, Self::Error> {
Expand All @@ -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;

fn size(&self) -> Result<Size<u32>, Self::Error> {
Expand All @@ -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 {
// /// Get the mipmap filtering mode for the given combination.
// pub fn d3d9_mip(&self, mip: FilterMode) -> Direct3D9::D3DTEXTUREFILTER {
Expand Down
2 changes: 1 addition & 1 deletion librashader-runtime-d3d9/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl FilterChainD3D9 {
pub unsafe fn frame(
&mut self,
input: &IDirect3DTexture9,
viewport: &Viewport<IDirect3DSurface9>,
viewport: &Viewport<&IDirect3DSurface9>,
frame_count: usize,
options: Option<&FrameOptionsD3D9>,
) -> error::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion librashader-runtime-d3d9/src/filter_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl FilterPass {
parent: &FilterCommon,
frame_count: u32,
options: &FrameOptionsD3D9,
viewport: &Viewport<IDirect3DSurface9>,
viewport: &Viewport<&IDirect3DSurface9>,
original: &D3D9InputTexture,
source: &D3D9InputTexture,
output: RenderTarget<IDirect3DSurface9>,
Expand Down
6 changes: 3 additions & 3 deletions librashader-runtime-d3d9/tests/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ pub mod d3d9_hello_triangle {
resources
.filter
.frame(
resources.texture.clone(),
&resources.texture,
&Viewport {
x: 0.0,
y: 0.0,
mvp: None,
output: backbuffer.clone(),
size: backbuffer.size().unwrap(),
output: &backbuffer,
size: backbuffer.size()?,
},
0,
None,
Expand Down

0 comments on commit 7d483f2

Please sign in to comment.