<div dir="ltr"><div><div>Hi,</div><div><br></div><div>AQ mode 4 commit (21db162) causes slowdown even if not used aq-mode 4. Some code related to AQ mode 4 is executed always. </div><div><br></div><div>Slowdown is aprox. 10% !! on my system encoding 1080p 8-bit using --aq-mode 3 and preset medium.</div><div><br></div><div>More info: </div><div><a href="https://forum.doom9.org/showthread.php?p=1885998#post1885998" target="_blank">https://forum.doom9.org/showthread.php?p=1885998#post1885998</a></div></div><div><br></div>changeset:   12565:e39ec6f83fe5<br>tag:         tip<br>user:        <a href="mailto:joelgalid@gmail.com" target="_blank">joelgalid@gmail.com</a><br>date:        Mon Sep 30 18:23:41 2019 +0200<br>summary:     Fix: AQ mode 4 commit (21db162) introduces slowdown even is not used AQ mode 4.<br><br>diff -r fdd69a766881 -r e39ec6f83fe5 source/encoder/slicetype.cpp<br>--- a/source/encoder/slicetype.cpp Wed Sep 25 17:58:14 2019 +0530<br>+++ b/source/encoder/slicetype.cpp Mon Sep 30 18:23:41 2019 +0200<br>@@ -480,17 +480,24 @@<br>             {<br> #define AQ_EDGE_BIAS 0.5<br> #define EDGE_INCLINATION 45<br>-                uint32_t numCuInHeight = (maxRow + param->maxCUSize - 1) / param->maxCUSize;<br>-                int maxHeight = numCuInHeight * param->maxCUSize;<br>-                intptr_t stride = curFrame->m_fencPic->m_stride;<br>-                pixel *edgePic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>-                pixel *gaussianPic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>-                pixel *thetaPic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>-                memset(edgePic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>-                memset(gaussianPic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>-                memset(thetaPic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>-                if (param->rc.aqMode == X265_AQ_EDGE)<br>-                    edgeFilter(curFrame, edgePic, gaussianPic, thetaPic, stride, maxRow, maxCol);<br>+<br>+ pixel *edgePic = NULL;<br>+ pixel *gaussianPic = NULL;<br>+ pixel *thetaPic = NULL;<br>+<br>+ if (param->rc.aqMode == X265_AQ_EDGE)<br>+ {<br>+ uint32_t numCuInHeight = (maxRow + param->maxCUSize - 1) / param->maxCUSize;<br>+ int maxHeight = numCuInHeight * param->maxCUSize;<br>+ intptr_t stride = curFrame->m_fencPic->m_stride;<br>+ edgePic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>+ gaussianPic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>+ thetaPic = X265_MALLOC(pixel, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)));<br>+ memset(edgePic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>+ memset(gaussianPic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>+ memset(thetaPic, 0, stride * (maxHeight + (curFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>+ edgeFilter(curFrame, edgePic, gaussianPic, thetaPic, stride, maxRow, maxCol);<br>+ }                  <br> <br>                 int blockXY = 0, inclinedEdge = 0;<br>                 double avg_adj_pow2 = 0, avg_adj = 0, qp_adj = 0;<br>@@ -507,8 +514,8 @@<br>                             energy = acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize);<br>                             if (param->rc.aqMode == X265_AQ_EDGE)<br>                             {<br>-                                pixel *edgeImage = edgePic + curFrame->m_fencPic->m_lumaMarginY * stride + curFrame->m_fencPic->m_lumaMarginX;<br>-                                pixel *edgeTheta = thetaPic + curFrame->m_fencPic->m_lumaMarginY * stride + curFrame->m_fencPic->m_lumaMarginX;<br>+                                pixel *edgeImage = edgePic + curFrame->m_fencPic->m_lumaMarginY * curFrame->m_fencPic->m_stride + curFrame->m_fencPic->m_lumaMarginX;<br>+                                pixel *edgeTheta = thetaPic + curFrame->m_fencPic->m_lumaMarginY * curFrame->m_fencPic->m_stride + curFrame->m_fencPic->m_lumaMarginX;<br>                                 edgeDensity = edgeDensityCu(curFrame, edgeImage, edgeTheta, avgAngle, blockX, blockY, param->rc.qgSize);<br>                                 if (edgeDensity)<br>                                 {<br>@@ -541,10 +548,14 @@<br>                 }<br>                 else<br>                     strength = param->rc.aqStrength * 1.0397f;<br>-<br>-                X265_FREE(edgePic);<br>-                X265_FREE(gaussianPic);<br>-                X265_FREE(thetaPic);<br>+<br>+ if (param->rc.aqMode == X265_AQ_EDGE)<br>+ {<br>+ X265_FREE(edgePic);<br>+ X265_FREE(gaussianPic);<br>+ X265_FREE(thetaPic);<br>+ }<br>+<br>                 blockXY = 0;<br>                 for (int blockY = 0; blockY < maxRow; blockY += loopIncr)<br>                 {<div></div><div><br></div><div><br></div><div>Regards,</div><div>Joel</div></div>