Skip to content

Commit

Permalink
backend: Clarify resampler phase precision usage
Browse files Browse the repository at this point in the history
The current code uses ScalePrecision/UnityScale for the resampler phase
calculations. Make things clearer by specifying PhasePrecision/UnityPhase
which share the same value, but make the calculations more understansable.

While at it, fix the phase value validation maximum limit.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Aug 5, 2024
1 parent 5fa5519 commit 61d651a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/libpisp/backend/backend_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace
constexpr unsigned int MaxStripeHeight = 3072;
// Precision for the scaler blocks
constexpr unsigned int ScalePrecision = 12;
constexpr unsigned int UnityScale = 1 << 12;
constexpr unsigned int PhasePrecision = 12;
constexpr unsigned int UnityScale = 1 << ScalePrecision;
constexpr unsigned int UnityPhase = 1 << PhasePrecision;
// PPF properties
constexpr unsigned int ResamplePrecision = 10;
constexpr unsigned int NumPhases = 16;
Expand Down Expand Up @@ -837,8 +839,8 @@ std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config
unsigned int frac_y = (resample_size.y.offset * be_config_.downscale[j].scale_factor_v) &
((1 << ScalePrecision) - 1);
// Fractional component of the input required to generate the output pixel.
t.downscale_phase_x[p * variant_.BackEndNumBranches(0) + j] = (UnityScale - frac_x);
t.downscale_phase_y[p * variant_.BackEndNumBranches(0) + j] = (UnityScale - frac_y);
t.downscale_phase_x[p * variant_.BackEndNumBranches(0) + j] = (UnityPhase - frac_x);
t.downscale_phase_y[p * variant_.BackEndNumBranches(0) + j] = (UnityPhase - frac_y);
}

if (be_config_.global.rgb_enables & PISP_BE_RGB_ENABLE_RESAMPLE(j))
Expand All @@ -859,15 +861,15 @@ std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config
t.resample_phase_y[p * variant_.BackEndNumBranches(0) + j] +=
be_config_extra_.resample[j].initial_phase_v[p];
// Have to be within this range, else some calculation went wrong.
PISP_ASSERT(t.resample_phase_x[p * variant_.BackEndNumBranches(0) + j] <= 2 * (UnityScale - 1));
PISP_ASSERT(t.resample_phase_y[p * variant_.BackEndNumBranches(0) + j] <= 2 * (UnityScale - 1));
PISP_ASSERT(t.resample_phase_x[p * variant_.BackEndNumBranches(0) + j] <= (2 * UnityPhase - 1));
PISP_ASSERT(t.resample_phase_y[p * variant_.BackEndNumBranches(0) + j] <= (2 * UnityPhase - 1));
}
}

// Phase difference between planes cannot be > 0.5 pixels on the output dimenstions.
if (be_config_.global.rgb_enables & PISP_BE_RGB_ENABLE_RESAMPLE(j))
{
int phase_max = (be_config_.resample[j].scale_factor_h * UnityScale / 2) >> ScalePrecision;
int phase_max = (be_config_.resample[j].scale_factor_h * UnityPhase / 2) >> ScalePrecision;
if (std::abs(t.resample_phase_x[0 * variant_.BackEndNumBranches(0) + j] -
t.resample_phase_x[1 * variant_.BackEndNumBranches(0) + j]) > phase_max ||
std::abs(t.resample_phase_x[1 * variant_.BackEndNumBranches(0) + j] -
Expand All @@ -877,7 +879,7 @@ std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config
{
throw std::runtime_error("Resample phase x for tile is > 0.5 pixels on the output dimensions.");
}
phase_max = (be_config_.resample[j].scale_factor_v * UnityScale / 2) >> ScalePrecision;
phase_max = (be_config_.resample[j].scale_factor_v * UnityPhase / 2) >> ScalePrecision;
if (std::abs(t.resample_phase_y[0 * variant_.BackEndNumBranches(0) + j] -
t.resample_phase_y[1 * variant_.BackEndNumBranches(0) + j]) > phase_max ||
std::abs(t.resample_phase_y[1 * variant_.BackEndNumBranches(0) + j] -
Expand Down

0 comments on commit 61d651a

Please sign in to comment.