[instancer/L4] Implement an optimization

This commit is contained in:
Behdad Esfahbod 2023-06-21 17:45:19 -06:00
parent 17761cc616
commit 10bc7a804a
2 changed files with 92 additions and 66 deletions

View File

@ -153,16 +153,47 @@ def _solve(tent, axisLimit, negative=False):
out.append((scalar1 - gain, loc1))
out.append((scalar2 - gain, loc2))
else:
# Special-case if peak is at axisMax.
if axisMax == peak:
upper = peak
# Case pre3:
# we keep deltas as is and only scale the axis upper to achieve
# the desired new tent if feasible.
#
# | peak |
# 1.........|............o...|..................
# | /x\ |
# | /xxx\ |
# | /xxxxx\|
# | /xxxxxxx+
# | /xxxxxxxx|\
# 0---|-----|------oxxxxxxxxx|xo---------------1
# axisMin | lower | upper
# | |
# axisDef axisMax
#
newUpper = peak + (1 - gain) * (upper - peak)
if axisMax <= newUpper and newUpper <= axisDef + (axisMax - axisDef) * 2:
upper = newUpper
if not negative and axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper:
# we clamp +2.0 to the max F2Dot14 (~1.99994) for convenience
upper = axisDef + (axisMax - axisDef) * MAX_F2DOT14
assert peak < upper
loc = (max(axisDef, lower), peak, upper)
scalar = 1
out.append((scalar - gain, loc))
# Case 3: Outermost limit still fits within F2Dot14 bounds;
# we keep deltas as is and only scale the axes bounds. Deltas beyond -1.0
# or +1.0 will never be applied as implementations must clamp to that range.
# We keep axis bound as is. Deltas beyond -1.0 or +1.0 will never be
# applied as implementations must clamp to that range.
#
# A second tent is needed for cases when gain is positive, though we add it
# unconditionally and it will be dropped because scalar ends up 0.
#
# TODO: See if we can just move upper closer to adjust the slope, instead of
# second tent.
#
# | peak |
# 1.........|............o...|..................
# | /x\ |
@ -181,10 +212,6 @@ def _solve(tent, axisLimit, negative=False):
upper = axisDef + (axisMax - axisDef) * MAX_F2DOT14
assert peak < upper
# Special-case if peak is at axisMax.
if axisMax == peak:
upper = peak
loc1 = (max(axisDef, lower), peak, upper)
scalar1 = 1

View File

@ -137,8 +137,7 @@ class RebaseTentTest(object):
(0.25, 0.25, 0.75),
[
(0.5, None),
(0.5, (0, 0.5, 1.5)),
(-0.5, (0.5, 1.5, 1.5)),
(0.5, (0, 0.5, 1.0)),
],
),
# Case 1neg