Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RenderScale #920

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions Engine/EffectInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ EffectInstance::getImage(int inputNb,
/*
* These are the data fields stored in the TLS from the on-going render action or instance changed action
*/
unsigned int mipMapLevel = Image::getLevelFromScale(scale.x);
unsigned int mipMapLevel = scale.toMipmapLevel();
RoIMap inputsRoI;
bool isIdentity = false;
EffectInstancePtr identityInput;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ EffectInstance::calcDefaultRegionOfDefinition(U64 /*hash*/,
RectD *rod)
{

unsigned int mipMapLevel = Image::getLevelFromScale(scale.x);
unsigned int mipMapLevel = scale.toMipmapLevel();
RectI format = getOutputFormat();
double par = getAspectRatio(-1);
*rod = format.toCanonical_noClipping(mipMapLevel, par);
Expand Down Expand Up @@ -1258,7 +1258,7 @@ EffectInstance::ifInfiniteApplyHeuristic(U64 hash,
bool isProjectFormat;
RenderScale inputScale = scale;
if (input->supportsRenderScaleMaybe() == eSupportsNo) {
inputScale.x = inputScale.y = 1.;
inputScale = RenderScale::identity;
}
StatusEnum st = input->getRegionOfDefinition_public(hash, time, inputScale, view, &inputRod, &isProjectFormat);
if (st != eStatusFailed) {
Expand All @@ -1281,7 +1281,7 @@ EffectInstance::ifInfiniteApplyHeuristic(U64 hash,
RectI format = getOutputFormat();
assert(!format.isNull());
double par = getAspectRatio(-1);
unsigned int mipMapLevel = Image::getLevelFromScale(scale.x);
unsigned int mipMapLevel = scale.toMipmapLevel();
canonicalFormat = format.toCanonical_noClipping(mipMapLevel, par);
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ EffectInstance::getRegionsOfInterest(double time,
//Tiles not supported: get the RoD as RoI
RectD rod;
bool isPF;
RenderScale inpScale(input->supportsRenderScale() ? scale.x : 1.);
RenderScale inpScale = (input->supportsRenderScale() ? scale : RenderScale::identity);
StatusEnum stat = input->getRegionOfDefinition_public(input->getRenderHash(), time, inpScale, view, &rod, &isPF);
if (stat == eStatusFailed) {
return;
Expand Down Expand Up @@ -2060,10 +2060,11 @@ EffectInstance::transformInputRois(const EffectInstance* self,
invertTransform = Transform::matInverse(*it->second.cat, det);
}

Transform::Matrix3x3 canonicalToPixel = Transform::matCanonicalToPixel(par, scale.x,
scale.y, false);
Transform::Matrix3x3 pixelToCanonical = Transform::matPixelToCanonical(par, scale.x,
scale.y, false);
const auto scalePt = scale.toOfxPointD();
Transform::Matrix3x3 canonicalToPixel = Transform::matCanonicalToPixel(par, scalePt.x,
scalePt.y, false);
Transform::Matrix3x3 pixelToCanonical = Transform::matPixelToCanonical(par, scalePt.x,
scalePt.y, false);

invertTransform = Transform::matMul(Transform::matMul(pixelToCanonical, invertTransform), canonicalToPixel);
Transform::transformRegionFromRoD(foundRoI->second, invertTransform, transformedRenderWindow);
Expand Down Expand Up @@ -2275,7 +2276,7 @@ EffectInstance::Implementation::tiledRenderingFunctor(const RectToRender & rectT
}

#ifndef NDEBUG
RenderScale scale( Image::getScaleFromMipMapLevel(mipMapLevel) );
RenderScale scale = RenderScale::fromMipmapLevel(mipMapLevel);
// check the dimensions of all input and output images
const RectD & dstRodCanonical = firstPlaneToRender.renderMappedImage->getRoD();
const RectI dstBounds = dstRodCanonical.toPixelEnclosing(firstPlaneToRender.renderMappedImage->getMipMapLevel(), par); // compute dstRod at level 0
Expand Down Expand Up @@ -2401,10 +2402,9 @@ EffectInstance::Implementation::renderHandler(const EffectTLSDataPtr& tls,
RenderActionArgs actionArgs;
actionArgs.byPassCache = byPassCache;
actionArgs.processChannels = processChannels;
actionArgs.mappedScale.x = actionArgs.mappedScale.y = Image::getScaleFromMipMapLevel( firstPlane.renderMappedImage->getMipMapLevel() );
actionArgs.mappedScale = RenderScale::fromMipmapLevel(firstPlane.renderMappedImage->getMipMapLevel());
assert(isSupportedRenderScale(_publicInterface->supportsRenderScaleMaybe(), actionArgs.mappedScale));
actionArgs.originalScale.x = Image::getScaleFromMipMapLevel(mipMapLevel);
actionArgs.originalScale.y = actionArgs.originalScale.x;
actionArgs.originalScale = RenderScale::fromMipmapLevel(mipMapLevel);
actionArgs.draftMode = frameArgs->draftMode;
actionArgs.useOpenGL = planes.useOpenGL;

Expand Down Expand Up @@ -3303,7 +3303,7 @@ EffectInstance::drawOverlay_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3335,7 +3335,7 @@ EffectInstance::onOverlayPenDown_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3379,7 +3379,7 @@ EffectInstance::onOverlayPenDoubleClicked_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3425,7 +3425,7 @@ EffectInstance::onOverlayPenMotion_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3471,7 +3471,7 @@ EffectInstance::onOverlayPenUp_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3515,7 +3515,7 @@ EffectInstance::onOverlayKeyDown_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3551,7 +3551,7 @@ EffectInstance::onOverlayKeyUp_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3587,7 +3587,7 @@ EffectInstance::onOverlayKeyRepeat_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3620,7 +3620,7 @@ EffectInstance::onOverlayFocusGained_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3654,7 +3654,7 @@ EffectInstance::onOverlayFocusLost_public(double time,

RenderScale actualScale;
if ( !canHandleRenderScaleForOverlays() ) {
actualScale.x = actualScale.y = 1.;
actualScale = RenderScale::identity;
} else {
actualScale = renderScale;
}
Expand Down Expand Up @@ -3815,7 +3815,7 @@ EffectInstance::getRegionOfDefinitionFromCache(U64 hash,
RectD* rod,
bool* isProjectFormat)
{
unsigned int mipMapLevel = Image::getLevelFromScale(scale.x);
unsigned int mipMapLevel = scale.toMipmapLevel();
bool foundInCache = _imp->actionsCache->getRoDResult(hash, time, view, mipMapLevel, rod);

if (foundInCache) {
Expand Down Expand Up @@ -3844,7 +3844,7 @@ EffectInstance::getRegionOfDefinition_public(U64 hash,
return eStatusFailed;
}

unsigned int mipMapLevel = Image::getLevelFromScale(scale.x);
unsigned int mipMapLevel = scale.toMipmapLevel();
bool foundInCache = _imp->actionsCache->getRoDResult(hash, time, view, mipMapLevel, rod);
if (foundInCache) {
if (isProjectFormat) {
Expand Down Expand Up @@ -3881,12 +3881,11 @@ EffectInstance::getRegionOfDefinition_public(U64 hash,
}

StatusEnum ret;
RenderScale scaleOne(1.);
{
RECURSIVE_ACTION();


ret = getRegionOfDefinition(hash, time, supportsRenderScaleMaybe() == eSupportsNo ? scaleOne : scale, view, rod);
ret = getRegionOfDefinition(hash, time, supportsRenderScaleMaybe() == eSupportsNo ? RenderScale::identity : scale, view, rod);

if ( (ret != eStatusOK) && (ret != eStatusReplyDefault) ) {
// rod is not valid
Expand Down Expand Up @@ -4643,11 +4642,11 @@ EffectInstance::redrawOverlayInteract()
RenderScale
EffectInstance::getOverlayInteractRenderScale() const
{
RenderScale renderScale(1.);
RenderScale renderScale;

if (isDoingInteractAction() && _imp->overlaysViewport) {
unsigned int mmLevel = _imp->overlaysViewport->getCurrentRenderScale();
renderScale.x = renderScale.y = Image::getScaleFromMipMapLevel(mmLevel);
renderScale = RenderScale::fromMipmapLevel(mmLevel);
}

return renderScale;
Expand Down Expand Up @@ -5070,15 +5069,14 @@ EffectInstancePtr
EffectInstance::getNearestNonIdentity(double time)
{
U64 hash = getRenderHash();
RenderScale scale(1.);
Format frmt;

getApp()->getProject()->getProjectDefaultFormat(&frmt);

double inputTimeIdentity;
int inputNbIdentity;
ViewIdx inputView;
if ( !isIdentity_public(true, hash, time, scale, frmt, ViewIdx(0), &inputTimeIdentity, &inputView, &inputNbIdentity) ) {
if ( !isIdentity_public(true, hash, time, RenderScale::identity, frmt, ViewIdx(0), &inputTimeIdentity, &inputView, &inputNbIdentity) ) {
return shared_from_this();
} else {
if (inputNbIdentity < 0) {
Expand Down
5 changes: 3 additions & 2 deletions Engine/EffectInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "Engine/Knob.h" // for KnobHolder
#include "Engine/RectD.h"
#include "Engine/RectI.h"
#include "Engine/RenderScale.h"
#include "Engine/RenderStats.h"
#include "Engine/EngineFwd.h"
#include "Engine/ParallelRenderArgs.h"
Expand Down Expand Up @@ -158,7 +159,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON

RenderRoIArgs()
: time(0)
, scale(1.)
, scale()
, mipMapLevel(0)
, view(0)
, roi()
Expand Down Expand Up @@ -1132,7 +1133,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON
**/
static bool isSupportedRenderScale(SupportsEnum supportsRS, const RenderScale renderScale)
{
return (supportsRS != eSupportsNo) || (renderScale.x == 1. && renderScale.y == 1.);
return (supportsRS != eSupportsNo) || (renderScale == RenderScale::identity);
}

public:
Expand Down
10 changes: 5 additions & 5 deletions Engine/EffectInstanceRenderRoI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ EffectInstance::renderRoI(const RenderRoIArgs & args,
} else {
renderMappedMipMapLevel = args.mipMapLevel;
}
RenderScale renderMappedScale( Image::getScaleFromMipMapLevel(renderMappedMipMapLevel) );
RenderScale renderMappedScale( RenderScale::fromMipmapLevel(renderMappedMipMapLevel) );
assert(isSupportedRenderScale(supportsRS, renderMappedScale));


Expand Down Expand Up @@ -426,7 +426,7 @@ EffectInstance::renderRoI(const RenderRoIArgs & args,
supportsRS = supportsRenderScaleMaybe();
renderFullScaleThenDownscale = (supportsRS == eSupportsNo && mipMapLevel != 0);
if (renderFullScaleThenDownscale) {
renderMappedScale.x = renderMappedScale.y = 1.;
renderMappedScale = RenderScale::identity;
renderMappedMipMapLevel = 0;
}
}
Expand Down Expand Up @@ -572,7 +572,7 @@ EffectInstance::renderRoI(const RenderRoIArgs & args,
if ( (supportsRS == eSupportsMaybe) && (mipMapLevel != 0) ) {
// supportsRenderScaleMaybe may have changed, update it
renderFullScaleThenDownscale = true;
renderMappedScale.x = renderMappedScale.y = 1.;
renderMappedScale = RenderScale::identity;
renderMappedMipMapLevel = 0;
}

Expand Down Expand Up @@ -838,7 +838,7 @@ EffectInstance::renderRoI(const RenderRoIArgs & args,
if (renderFullScaleThenDownscale) {
renderFullScaleThenDownscale = false;
renderMappedMipMapLevel = args.mipMapLevel;
renderMappedScale.x = renderMappedScale.y = Image::getScaleFromMipMapLevel(renderMappedMipMapLevel);
renderMappedScale = RenderScale::fromMipmapLevel(renderMappedMipMapLevel);
if (frameArgs->tilesSupported) {
roi = args.roi;
if ( !roi.clipIfOverlaps(downscaledImageBoundsNc) ) {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ EffectInstance::renderRoIInternal(EffectInstance* self,
}
}

RenderScale renderMappedScale( Image::getScaleFromMipMapLevel(renderMappedMipMapLevel) );
RenderScale renderMappedScale( RenderScale::fromMipmapLevel(renderMappedMipMapLevel) );
RenderingFunctorRetEnum renderStatus = eRenderingFunctorRetOK;
if ( planesToRender->rectsToRender.empty() ) {
retCode = EffectInstance::eRenderRoIStatusImageAlreadyRendered;
Expand Down
2 changes: 2 additions & 0 deletions Engine/Engine.pro
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ SOURCES += \
ReadNode.cpp \
RectD.cpp \
RectI.cpp \
RenderScale.cpp \
RenderStats.cpp \
RotoContext.cpp \
RotoDrawableItem.cpp \
Expand Down Expand Up @@ -343,6 +344,7 @@ HEADERS += \
RectDSerialization.h \
RectI.h \
RectISerialization.h \
RenderScale.h \
RenderStats.h \
RotoContext.h \
RotoContextPrivate.h \
Expand Down
1 change: 1 addition & 0 deletions Engine/EngineFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class ProjectSerialization;
class RectD;
class RectI;
class RenderEngine;
class RenderScale;
class RenderStats;
class RenderingFlagSetter;
class RotoContext;
Expand Down
6 changes: 0 additions & 6 deletions Engine/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,12 +2333,6 @@ Image::buildMipMapLevel(const RectD& dstRoD,
}
} // buildMipMapLevel

double
Image::getScaleFromMipMapLevel(unsigned int level)
{
return 1. / (1 << level);
}

#ifndef M_LN2
#define M_LN2 0.693147180559945309417232121458176568 /* loge(2) */
#endif
Expand Down
6 changes: 0 additions & 6 deletions Engine/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ class Image
return this->_params->getMipMapLevel();
}

double getScale() const
{
return getScaleFromMipMapLevel( getMipMapLevel() );
}

unsigned int getComponentsCount() const;
const ImagePlaneDesc& getComponents() const
{
Expand Down Expand Up @@ -766,7 +761,6 @@ class Image
void upscaleMipMap(const RectI & roi, unsigned int fromLevel, unsigned int toLevel, Image* output) const;


static double getScaleFromMipMapLevel(unsigned int level);
static unsigned int getLevelFromScale(double s);

/**
Expand Down
Loading