changeset 11881:71f700844b0b

wavefront: fix for triggering rows for multiple slices when wpp is enabled It is required to trigger alternative rows in slices for encoding when wpp is enabled.
author Ashok Kumar Mishra <ashok@multicorewareinc.com>
date Tue, 12 Sep 2017 18:13:03 +0530
parents 1a7edb6fd993
children 0967d0add97e
files source/common/wavefront.cpp source/common/wavefront.h source/encoder/frameencoder.cpp
diffstat 3 files changed, 38 insertions(+-), 10 deletions(-) [+]
line wrap: on
line diff
--- a/source/common/wavefront.cpp	Thu Jun 29 13:13:56 2017 +0530
+++ b/source/common/wavefront.cpp	Tue Sep 12 18:13:03 2017 +0530
@@ -43,11 +43,17 @@ bool WaveFront::init(int numRows)
     if (m_externalDependencyBitmap)
         memset((void*)m_externalDependencyBitmap, 0, sizeof(uint32_t) * m_numWords);
 
+    m_row_to_idx = X265_MALLOC(uint32_t, m_numRows);
+    m_idx_to_row = X265_MALLOC(uint32_t, m_numRows);
+
     return m_internalDependencyBitmap && m_externalDependencyBitmap;
 }
 
 WaveFront::~WaveFront()
 {
+    x265_free((void*)m_row_to_idx);
+    x265_free((void*)m_idx_to_row);
+
     x265_free((void*)m_internalDependencyBitmap);
     x265_free((void*)m_externalDependencyBitmap);
 }
--- a/source/common/wavefront.h	Thu Jun 29 13:13:56 2017 +0530
+++ b/source/common/wavefront.h	Tue Sep 12 18:13:03 2017 +0530
@@ -52,6 +52,10 @@ private:
 
     int m_numRows;
 
+protected:
+    uint32_t *m_row_to_idx;
+    uint32_t *m_idx_to_row;
+
 public:
 
     WaveFront()
--- a/source/encoder/frameencoder.cpp	Thu Jun 29 13:13:56 2017 +0530
+++ b/source/encoder/frameencoder.cpp	Tue Sep 12 18:13:03 2017 +0530
@@ -701,6 +701,24 @@ void FrameEncoder::compressFrame()
     {
         m_rows[m_sliceBaseRow[sliceId]].active = true;
     }
+    if (m_param->bEnableWavefront)
+    {
+        int i = 0;
+        for (uint32_t rowInSlice = 0; rowInSlice < m_sliceGroupSize; rowInSlice++)
+        {
+            for (uint32_t sliceId = 0; sliceId < m_param->maxSlices; sliceId++)
+            {
+                const uint32_t sliceStartRow = m_sliceBaseRow[sliceId];
+                const uint32_t sliceEndRow = m_sliceBaseRow[sliceId + 1] - 1;
+                const uint32_t row = sliceStartRow + rowInSlice;
+                if (row > sliceEndRow)
+                    continue;
+                m_row_to_idx[row] = i;
+                m_idx_to_row[i] = row;
+                i += 1;
+            }
+        }
+    }
 
     if (m_param->bEnableWavefront)
     {
@@ -735,11 +753,11 @@ void FrameEncoder::compressFrame()
                     }
                 }
 
-                enableRowEncoder(row); /* clear external dependency for this row */
+                enableRowEncoder(m_row_to_idx[row]); /* clear external dependency for this row */
                 if (!rowInSlice)
                 {
                     m_row0WaitTime = x265_mdate();
-                    enqueueRowEncoder(row); /* clear internal dependency, start wavefront */
+                    enqueueRowEncoder(m_row_to_idx[row]); /* clear internal dependency, start wavefront */
                 }
                 tryWakeOne();
             } // end of loop rowInSlice
@@ -1196,8 +1214,8 @@ void FrameEncoder::processRow(int row, i
     if (ATOMIC_INC(&m_activeWorkerCount) == 1 && m_stallStartTime)
         m_totalNoWorkerTime += x265_mdate() - m_stallStartTime;
 
-    const uint32_t realRow = row >> 1;
-    const uint32_t typeNum = row & 1;
+    const uint32_t realRow = m_idx_to_row[row >> 1];
+    const uint32_t typeNum = m_idx_to_row[row & 1];
 
     if (!typeNum)
         processRowEncoder(realRow, m_tld[threadId]);
@@ -1207,7 +1225,7 @@ void FrameEncoder::processRow(int row, i
 
         // NOTE: Active next row
         if (realRow != m_sliceBaseRow[m_rows[realRow].sliceId + 1] - 1)
-            enqueueRowFilter(realRow + 1);
+            enqueueRowFilter(m_row_to_idx[realRow + 1]);
     }
 
     if (ATOMIC_DEC(&m_activeWorkerCount) == 0)
@@ -1649,7 +1667,7 @@ void FrameEncoder::processRowEncoder(int
                 m_rows[row + 1].completed + 2 <= curRow.completed)
             {
                 m_rows[row + 1].active = true;
-                enqueueRowEncoder(row + 1);
+                enqueueRowEncoder(m_row_to_idx[row + 1]);
                 tryWakeOne(); /* wake up a sleeping thread or set the help wanted flag */
             }
         }
@@ -1736,11 +1754,11 @@ void FrameEncoder::processRowEncoder(int
     {
         if (rowInSlice >= m_filterRowDelay)
         {
-            enableRowFilter(row - m_filterRowDelay);
+            enableRowFilter(m_row_to_idx[row - m_filterRowDelay]);
 
             /* NOTE: Activate filter if first row (row 0) */
             if (rowInSlice == m_filterRowDelay)
-                enqueueRowFilter(row - m_filterRowDelay);
+                enqueueRowFilter(m_row_to_idx[row - m_filterRowDelay]);
             tryWakeOne();
         }
 
@@ -1748,7 +1766,7 @@ void FrameEncoder::processRowEncoder(int
         {
             for (uint32_t i = endRowInSlicePlus1 - m_filterRowDelay; i < endRowInSlicePlus1; i++)
             {
-                enableRowFilter(i);
+                enableRowFilter(m_row_to_idx[i]);
             }
             tryWakeOne();
         }
@@ -1756,7 +1774,7 @@ void FrameEncoder::processRowEncoder(int
         // handle specially case - single row slice
         if  (bFirstRowInSlice & bLastRowInSlice)
         {
-            enqueueRowFilter(row);
+            enqueueRowFilter(m_row_to_idx[row]);
             tryWakeOne();
         }
     }