Skip to content

Commit

Permalink
Box context
Browse files Browse the repository at this point in the history
  • Loading branch information
VZout committed Nov 28, 2023
1 parent f496543 commit 3bc9425
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fsr/src/d3d12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub unsafe fn get_texture_resource(
shader_component_mapping: u32,
) {
fsr_sys::d3d12::GetResourceDX12(
&mut context.context,
context.context.as_mut(),
resource as *mut _ as _,
U16String::from_str(name).as_ptr(),
state,
Expand Down
10 changes: 5 additions & 5 deletions fsr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub use fsr_sys::ResourceStates;
pub struct CommandList(fsr_sys::CommandList);
/// A structure encapsulating the FidelityFX Super Resolution 2 context.
pub struct Context {
pub(crate) context: fsr_sys::Context,
pub(crate) context: Box<fsr_sys::Context>, // `fsr_sys::Context` is rather large to live on the stack.
_interface: Interface,
}

Expand Down Expand Up @@ -352,9 +352,9 @@ impl From<DispatchDescription> for fsr_sys::DispatchDescription {

impl Context {
pub unsafe fn new(desc: ContextDescription<'_>) -> Result<Self, Error> {
let mut context = fsr_sys::Context::default();
let mut context = Box::new(fsr_sys::Context::default());
unsafe {
let error = fsr_sys::ContextCreate(&mut context, &(&desc).into());
let error = fsr_sys::ContextCreate(context.as_mut(), &(&desc).into());
if error != fsr_sys::FFX_OK {
return Err(Error::Fsr(FsrError::from_error_code(error)));
}
Expand All @@ -366,15 +366,15 @@ impl Context {
}

pub unsafe fn dispatch(&mut self, desc: DispatchDescription) -> Result<(), Error> {
let error = unsafe { fsr_sys::ContextDispatch(&mut self.context, &desc.into()) };
let error = unsafe { fsr_sys::ContextDispatch(self.context.as_mut(), &desc.into()) };
if error != fsr_sys::FFX_OK {
return Err(Error::Fsr(FsrError::from_error_code(error)));
}
Ok(())
}

pub unsafe fn destroy(&mut self) -> Result<(), Error> {
let error = unsafe { fsr_sys::ContextDestroy(&mut self.context) };
let error = unsafe { fsr_sys::ContextDestroy(self.context.as_mut()) };
if error != fsr_sys::FFX_OK {
return Err(Error::Fsr(FsrError::from_error_code(error)));
}
Expand Down
2 changes: 1 addition & 1 deletion fsr/src/vk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub unsafe fn get_texture_resource(
) -> Resource {
unsafe {
fsr_sys::vk::GetTextureResourceVK(
&mut context.context,
context.context.as_mut(),
image.as_raw(),
image_view.as_raw(),
size[0],
Expand Down

0 comments on commit 3bc9425

Please sign in to comment.