[x265] Patch to restore performance prior to AQ mode 4 commit

Joel GalĂ­ joelgalid at gmail.com
Tue Oct 1 15:11:59 CEST 2019


Hi,

AQ mode 4 commit (21db162) causes slowdown even if not used aq-mode 4. Some
code related to AQ mode 4 is executed always.

Slowdown is aprox. 10% !! on my system encoding 1080p 8-bit using --aq-mode
3 and preset medium.

More info:
https://forum.doom9.org/showthread.php?p=1885998#post1885998

changeset:   12565:e39ec6f83fe5
tag:         tip
user:        joelgalid at gmail.com
date:        Mon Sep 30 18:23:41 2019 +0200
summary:     Fix: AQ mode 4 commit (21db162) introduces slowdown even is
not used AQ mode 4.

diff -r fdd69a766881 -r e39ec6f83fe5 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Wed Sep 25 17:58:14 2019 +0530
+++ b/source/encoder/slicetype.cpp Mon Sep 30 18:23:41 2019 +0200
@@ -480,17 +480,24 @@
             {
 #define AQ_EDGE_BIAS 0.5
 #define EDGE_INCLINATION 45
-                uint32_t numCuInHeight = (maxRow + param->maxCUSize - 1) /
param->maxCUSize;
-                int maxHeight = numCuInHeight * param->maxCUSize;
-                intptr_t stride = curFrame->m_fencPic->m_stride;
-                pixel *edgePic = X265_MALLOC(pixel, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)));
-                pixel *gaussianPic = X265_MALLOC(pixel, stride *
(maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));
-                pixel *thetaPic = X265_MALLOC(pixel, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)));
-                memset(edgePic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
-                memset(gaussianPic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
-                memset(thetaPic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
-                if (param->rc.aqMode == X265_AQ_EDGE)
-                    edgeFilter(curFrame, edgePic, gaussianPic, thetaPic,
stride, maxRow, maxCol);
+
+ pixel *edgePic = NULL;
+ pixel *gaussianPic = NULL;
+ pixel *thetaPic = NULL;
+
+ if (param->rc.aqMode == X265_AQ_EDGE)
+ {
+ uint32_t numCuInHeight = (maxRow + param->maxCUSize - 1) /
param->maxCUSize;
+ int maxHeight = numCuInHeight * param->maxCUSize;
+ intptr_t stride = curFrame->m_fencPic->m_stride;
+ edgePic = X265_MALLOC(pixel, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)));
+ gaussianPic = X265_MALLOC(pixel, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)));
+ thetaPic = X265_MALLOC(pixel, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)));
+ memset(edgePic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
+ memset(gaussianPic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
+ memset(thetaPic, 0, stride * (maxHeight +
(curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
+ edgeFilter(curFrame, edgePic, gaussianPic, thetaPic, stride, maxRow,
maxCol);
+ }

                 int blockXY = 0, inclinedEdge = 0;
                 double avg_adj_pow2 = 0, avg_adj = 0, qp_adj = 0;
@@ -507,8 +514,8 @@
                             energy = acEnergyCu(curFrame, blockX, blockY,
param->internalCsp, param->rc.qgSize);
                             if (param->rc.aqMode == X265_AQ_EDGE)
                             {
-                                pixel *edgeImage = edgePic +
curFrame->m_fencPic->m_lumaMarginY * stride +
curFrame->m_fencPic->m_lumaMarginX;
-                                pixel *edgeTheta = thetaPic +
curFrame->m_fencPic->m_lumaMarginY * stride +
curFrame->m_fencPic->m_lumaMarginX;
+                                pixel *edgeImage = edgePic +
curFrame->m_fencPic->m_lumaMarginY * curFrame->m_fencPic->m_stride +
curFrame->m_fencPic->m_lumaMarginX;
+                                pixel *edgeTheta = thetaPic +
curFrame->m_fencPic->m_lumaMarginY * curFrame->m_fencPic->m_stride +
curFrame->m_fencPic->m_lumaMarginX;
                                 edgeDensity = edgeDensityCu(curFrame,
edgeImage, edgeTheta, avgAngle, blockX, blockY, param->rc.qgSize);
                                 if (edgeDensity)
                                 {
@@ -541,10 +548,14 @@
                 }
                 else
                     strength = param->rc.aqStrength * 1.0397f;
-
-                X265_FREE(edgePic);
-                X265_FREE(gaussianPic);
-                X265_FREE(thetaPic);
+
+ if (param->rc.aqMode == X265_AQ_EDGE)
+ {
+ X265_FREE(edgePic);
+ X265_FREE(gaussianPic);
+ X265_FREE(thetaPic);
+ }
+
                 blockXY = 0;
                 for (int blockY = 0; blockY < maxRow; blockY += loopIncr)
                 {


Regards,
Joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20191001/bc788f3b/attachment.html>


More information about the x265-devel mailing list