Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Avoid accidental purecalls in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukem9 committed Feb 16, 2024
1 parent 4c6b255 commit bc4ae88
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
51 changes: 23 additions & 28 deletions source/maindll/FFFrameInterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
#include "FFFrameInterpolator.h"
#include "Util.h"

FFFrameInterpolator::FFFrameInterpolator(
uint32_t OutputWidth,
uint32_t OutputHeight,
NGXInstanceParameters *NGXParameters)
FFFrameInterpolator::FFFrameInterpolator(uint32_t OutputWidth, uint32_t OutputHeight)
: m_SwapchainWidth(OutputWidth),
m_SwapchainHeight(OutputHeight)
{
Create(NGXParameters);
}

FFFrameInterpolator::~FFFrameInterpolator()
{
Destroy();
}

FfxErrorCode FFFrameInterpolator::Dispatch(void *CommandList, NGXInstanceParameters *NGXParameters)
Expand Down Expand Up @@ -84,6 +79,28 @@ FfxErrorCode FFFrameInterpolator::Dispatch(void *CommandList, NGXInstanceParamet
return dispatchStatus;
}

void FFFrameInterpolator::Create(NGXInstanceParameters *NGXParameters)
{
if (CreateBackend(NGXParameters) != FFX_OK)
throw std::runtime_error("Failed to create backend context.");

if (CreateDilationContext() != FFX_OK)
throw std::runtime_error("Failed to create dilation context.");

if (CreateOpticalFlowContext() != FFX_OK)
throw std::runtime_error("Failed to create optical flow context.");

m_FrameInterpolatorContext.emplace(m_FrameInterpolationBackendInterface, m_SwapchainWidth, m_SwapchainHeight);
}

void FFFrameInterpolator::Destroy()
{
m_FrameInterpolatorContext.reset();
DestroyOpticalFlowContext();
DestroyDilationContext();
DestroyBackend();
}

bool FFFrameInterpolator::CalculateResourceDimensions(NGXInstanceParameters *NGXParameters)
{
// NGX doesn't provide a direct method to query current gbuffer dimensions so we'll grab them
Expand Down Expand Up @@ -342,28 +359,6 @@ bool FFFrameInterpolator::BuildFrameInterpolationParameters(
return true;
}

void FFFrameInterpolator::Create(NGXInstanceParameters *NGXParameters)
{
if (CreateBackend(NGXParameters) != FFX_OK)
throw std::runtime_error("Failed to create backend context.");

if (CreateDilationContext() != FFX_OK)
throw std::runtime_error("Failed to create dilation context.");

if (CreateOpticalFlowContext() != FFX_OK)
throw std::runtime_error("Failed to create optical flow context.");

m_FrameInterpolatorContext.emplace(m_FrameInterpolationBackendInterface, m_SwapchainWidth, m_SwapchainHeight);
}

void FFFrameInterpolator::Destroy()
{
m_FrameInterpolatorContext.reset();
DestroyOpticalFlowContext();
DestroyDilationContext();
DestroyBackend();
}

FfxErrorCode FFFrameInterpolator::CreateBackend(NGXInstanceParameters *NGXParameters)
{
const uint32_t maxContexts = 3; // Assume 3 contexts per interface
Expand Down
8 changes: 5 additions & 3 deletions source/maindll/FFFrameInterpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FFFrameInterpolator
uint32_t m_PostUpscaleRenderHeight = 0;

public:
FFFrameInterpolator(uint32_t OutputWidth, uint32_t OutputHeight, NGXInstanceParameters *NGXParameters);
FFFrameInterpolator(uint32_t OutputWidth, uint32_t OutputHeight);
FFFrameInterpolator(const FFFrameInterpolator&) = delete;
FFFrameInterpolator& operator=(const FFFrameInterpolator&) = delete;
~FFFrameInterpolator();
Expand All @@ -63,15 +63,17 @@ class FFFrameInterpolator
FfxResource *OutFfxResource,
FfxResourceStates State) = 0;

protected:
void Create(NGXInstanceParameters *NGXParameters);
void Destroy();

private:
bool CalculateResourceDimensions(NGXInstanceParameters *NGXParameters);
void QueryHDRLuminanceRange(NGXInstanceParameters *NGXParameters);
bool BuildDilationParameters(FFDilatorDispatchParameters *OutParameters, NGXInstanceParameters *NGXParameters);
bool BuildOpticalFlowParameters(FfxOpticalflowDispatchDescription *OutParameters, NGXInstanceParameters *NGXParameters);
bool BuildFrameInterpolationParameters(FFInterpolatorDispatchParameters *OutParameters, NGXInstanceParameters *NGXParameters);

void Create(NGXInstanceParameters *NGXParameters);
void Destroy();
FfxErrorCode CreateBackend(NGXInstanceParameters *NGXParameters);
void DestroyBackend();
FfxErrorCode CreateDilationContext();
Expand Down
4 changes: 3 additions & 1 deletion source/maindll/FFFrameInterpolatorDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ FFFrameInterpolatorDX::FFFrameInterpolatorDX(
uint32_t OutputHeight,
NGXInstanceParameters *NGXParameters)
: m_Device(Device),
FFFrameInterpolator(OutputWidth, OutputHeight, NGXParameters)
FFFrameInterpolator(OutputWidth, OutputHeight)
{
m_Device->AddRef();
FFFrameInterpolator::Create(NGXParameters);
}

FFFrameInterpolatorDX::~FFFrameInterpolatorDX()
{
FFFrameInterpolator::Destroy();
m_Device->Release();
}

Expand Down
4 changes: 3 additions & 1 deletion source/maindll/FFFrameInterpolatorVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ FFFrameInterpolatorVK::FFFrameInterpolatorVK(
NGXInstanceParameters *NGXParameters)
: m_Device(LogicalDevice),
m_PhysicalDevice(PhysicalDevice),
FFFrameInterpolator(OutputWidth, OutputHeight, NGXParameters)
FFFrameInterpolator(OutputWidth, OutputHeight)
{
FFFrameInterpolator::Create(NGXParameters);
}

FFFrameInterpolatorVK::~FFFrameInterpolatorVK()
{
FFFrameInterpolator::Destroy();
}

FfxErrorCode FFFrameInterpolatorVK::Dispatch(void *CommandList, NGXInstanceParameters *NGXParameters)
Expand Down

0 comments on commit bc4ae88

Please sign in to comment.