rt(d3d11): take viewport by reference to avoid AddRef/Release
This commit is contained in:
parent
28931ae50a
commit
7b7fd99b92
|
@ -241,14 +241,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::D3D11FilterError(FilterChainError::Direct3DError(e)))?
|
.map_err(|e| LibrashaderError::D3D11FilterError(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
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl RenderTest for Direct3D11 {
|
||||||
if let Some(setter) = param_setter {
|
if let Some(setter) = param_setter {
|
||||||
setter(filter_chain.parameters());
|
setter(filter_chain.parameters());
|
||||||
}
|
}
|
||||||
let viewport = Viewport::new_render_target_sized_origin(rtv, None)?;
|
let viewport = Viewport::new_render_target_sized_origin(&rtv, None)?;
|
||||||
let options = frame_options.map(|options| FrameOptions {
|
let options = frame_options.map(|options| FrameOptions {
|
||||||
clear_history: options.clear_history,
|
clear_history: options.clear_history,
|
||||||
frame_direction: options.frame_direction,
|
frame_direction: options.frame_direction,
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl From<FilterMode> for Direct3D11::D3D11_FILTER {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetSize<u32> for Direct3D11::ID3D11RenderTargetView {
|
impl GetSize<u32> for &Direct3D11::ID3D11RenderTargetView {
|
||||||
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> {
|
||||||
|
@ -55,33 +55,49 @@ impl GetSize<u32> for Direct3D11::ID3D11RenderTargetView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GetSize<u32> for Direct3D11::ID3D11RenderTargetView {
|
||||||
|
type Error = windows::core::Error;
|
||||||
|
|
||||||
|
fn size(&self) -> Result<Size<u32>, Self::Error> {
|
||||||
|
<&Self as GetSize<u32>>::size(&self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetSize<u32> for &Direct3D11::ID3D11ShaderResourceView {
|
||||||
|
type Error = windows::core::Error;
|
||||||
|
|
||||||
|
fn size(&self) -> Result<Size<u32>, Self::Error> {
|
||||||
|
let parent: ID3D11Texture2D = unsafe {
|
||||||
|
let resource = self.GetResource()?;
|
||||||
|
if resource.GetType() != D3D11_RESOURCE_DIMENSION_TEXTURE2D {
|
||||||
|
return Err(windows::core::Error::new(
|
||||||
|
E_NOINTERFACE,
|
||||||
|
"expected ID3D11Texture2D as the resource for the view.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
// SAFETY: We know tha the resource is an `ID3D11Texture2D`.
|
||||||
|
// This downcast is safe because ID3D11Texture2D has ID3D11Resource in its
|
||||||
|
// inheritance chain.
|
||||||
|
//
|
||||||
|
// This check + transmute is cheaper than doing `.cast` (i.e. `QueryInterface`).
|
||||||
|
std::mem::transmute(resource)
|
||||||
|
};
|
||||||
|
let mut desc = Default::default();
|
||||||
|
unsafe {
|
||||||
|
parent.GetDesc(&mut desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Size {
|
||||||
|
height: desc.Height,
|
||||||
|
width: desc.Width,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GetSize<u32> for Direct3D11::ID3D11ShaderResourceView {
|
impl GetSize<u32> for Direct3D11::ID3D11ShaderResourceView {
|
||||||
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> {
|
||||||
let parent: ID3D11Texture2D = unsafe {
|
<&Self as GetSize<u32>>::size(&self)
|
||||||
let resource = self.GetResource()?;
|
|
||||||
if resource.GetType() != D3D11_RESOURCE_DIMENSION_TEXTURE2D {
|
|
||||||
return Err(windows::core::Error::new(
|
|
||||||
E_NOINTERFACE,
|
|
||||||
"expected ID3D11Texture2D as the resource for the view.",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// SAFETY: We know tha the resource is an `ID3D11Texture2D`.
|
|
||||||
// This downcast is safe because ID3D11Texture2D has ID3D11Resource in its
|
|
||||||
// inheritance chain.
|
|
||||||
//
|
|
||||||
// This check + transmute is cheaper than doing `.cast` (i.e. `QueryInterface`).
|
|
||||||
std::mem::transmute(resource)
|
|
||||||
};
|
|
||||||
let mut desc = Default::default();
|
|
||||||
unsafe {
|
|
||||||
parent.GetDesc(&mut desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Size {
|
|
||||||
height: desc.Height,
|
|
||||||
width: desc.Width,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,7 +401,7 @@ impl FilterChainD3D11 {
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: Option<&ID3D11DeviceContext>,
|
ctx: Option<&ID3D11DeviceContext>,
|
||||||
input: &ID3D11ShaderResourceView,
|
input: &ID3D11ShaderResourceView,
|
||||||
viewport: &Viewport<ID3D11RenderTargetView>,
|
viewport: &Viewport<&ID3D11RenderTargetView>,
|
||||||
frame_count: usize,
|
frame_count: usize,
|
||||||
options: Option<&FrameOptionsD3D11>,
|
options: Option<&FrameOptionsD3D11>,
|
||||||
) -> error::Result<()> {
|
) -> error::Result<()> {
|
||||||
|
|
|
@ -151,7 +151,7 @@ impl FilterPass {
|
||||||
parent: &FilterCommon,
|
parent: &FilterCommon,
|
||||||
frame_count: u32,
|
frame_count: u32,
|
||||||
options: &FrameOptionsD3D11,
|
options: &FrameOptionsD3D11,
|
||||||
viewport: &Viewport<ID3D11RenderTargetView>,
|
viewport: &Viewport<&ID3D11RenderTargetView>,
|
||||||
original: &InputTexture,
|
original: &InputTexture,
|
||||||
source: &InputTexture,
|
source: &InputTexture,
|
||||||
output: RenderTarget<ID3D11RenderTargetView>,
|
output: RenderTarget<ID3D11RenderTargetView>,
|
||||||
|
|
|
@ -569,7 +569,7 @@ pub mod d3d11_hello_triangle {
|
||||||
let srv = input_srv.unwrap();
|
let srv = input_srv.unwrap();
|
||||||
|
|
||||||
// eprintln!("w: {} h: {}", backbuffer_desc.Width, backbuffer_desc.Height);
|
// eprintln!("w: {} h: {}", backbuffer_desc.Width, backbuffer_desc.Height);
|
||||||
let output = resources.backbuffer_rtv.as_ref().unwrap().clone();
|
let output = resources.backbuffer_rtv.as_ref().unwrap();
|
||||||
let size: Size<u32> = output.size().unwrap();
|
let size: Size<u32> = output.size().unwrap();
|
||||||
self.filter
|
self.filter
|
||||||
.frame(
|
.frame(
|
||||||
|
|
Loading…
Reference in a new issue