Hi Maarten,<div>I tried the v2 patch with my good old geforce 8600M GS, and it worked well. The CPU usage seems a little higher than usual, I&#39;d said 60% instead of 40% for a 720p video, but I&#39;ll try with a higher bitrate video and without building with debug parameters to see if I can found a performance gain.</div>

<div>The only problem is that I cannot seek through the video without an segfault on that error &quot;X11 error: BadAccess (attempt to access private resource denied)&quot;, I attached a gdb backtrace. It appears to be related to the drawing of the mplayer OSD.</div>

<div><div><br></div><div>Regards,</div>Emeric</div><div><br><div class="gmail_quote">2011/9/10 Maarten Lankhorst <span dir="ltr">&lt;<a href="mailto:m.b.lankhorst@gmail.com">m.b.lankhorst@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Try to use the PMPEG where available<br>
<br>
Signed-off-by: Maarten Lankhorst &lt;<a href="mailto:m.b.lankhorst@gmail.com">m.b.lankhorst@gmail.com</a>&gt;<br>
---<br>
<br>
v2: Fixed nvfx check, and use &gt; 0x80 to see if 8274 is available<br>
If that is incorrect, fix is8274 before committing, I&#39;m not 100%<br>
sure on what card 8274 is first available.<br>
<br>
 src/gallium/drivers/nouveau/nouveau_video.c |  892 ++++++++++++++++++++++++++-<br>
 src/gallium/drivers/nouveau/nouveau_video.h |   42 ++<br>
 src/gallium/drivers/nouveau/nv17_mpeg.xml.h |  265 ++++++++<br>
 src/gallium/drivers/nouveau/nv31_mpeg.xml.h |  130 ++++<br>
 src/gallium/drivers/nvfx/nvfx_context.c     |    4 +-<br>
 src/gallium/drivers/nvfx/nvfx_context.h     |    2 +<br>
 6 files changed, 1328 insertions(+), 7 deletions(-)<br>
 create mode 100644 src/gallium/drivers/nouveau/nouveau_video.h<br>
 create mode 100644 src/gallium/drivers/nouveau/nv17_mpeg.xml.h<br>
 create mode 100644 src/gallium/drivers/nouveau/nv31_mpeg.xml.h<br>
<br>
diff --git a/src/gallium/drivers/nouveau/nouveau_video.c b/src/gallium/drivers/nouveau/nouveau_video.c<br>
index 620c030..75124e5 100644<br>
--- a/src/gallium/drivers/nouveau/nouveau_video.c<br>
+++ b/src/gallium/drivers/nouveau/nouveau_video.c<br>
@@ -1,9 +1,842 @@<br>
+/*<br>
+ * Copyright 2011 Maarten Lankhorst<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the &quot;Software&quot;),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,<br>
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF<br>
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br>
+ * SOFTWARE.<br>
+ */<br>
<br>
 #include &quot;vl/vl_decoder.h&quot;<br>
 #include &quot;vl/vl_video_buffer.h&quot;<br>
<br>
-#include &quot;nouveau/nouveau_screen.h&quot;<br>
-#include &quot;nouveau/nouveau_context.h&quot;<br>
+#include &quot;nouveau_screen.h&quot;<br>
+#include &quot;nouveau_context.h&quot;<br>
+#include &quot;nouveau_video.h&quot;<br>
+<br>
+#include &quot;nvfx/nvfx_context.h&quot;<br>
+#include &quot;nvfx/nvfx_resource.h&quot;<br>
+#include &quot;nouveau/nouveau_bo.h&quot;<br>
+#include &quot;nouveau/nouveau_buffer.h&quot;<br>
+#include &quot;util/u_video.h&quot;<br>
+#include &quot;util/u_format.h&quot;<br>
+#include &quot;util/u_sampler.h&quot;<br>
+#include &quot;nouveau/nouveau_device.h&quot;<br>
+#include &quot;nouveau_winsys.h&quot;<br>
+<br>
+static bool<br>
+nouveau_video_is_nvfx(struct nouveau_decoder *dec) {<br>
+   if (dec-&gt;screen-&gt;device-&gt;chipset &lt; 0x50)<br>
+      return true;<br>
+   if (dec-&gt;screen-&gt;device-&gt;chipset &gt;= 0x60 &amp;&amp; dec-&gt;screen-&gt;device-&gt;chipset &lt; 0x70)<br>
+      return true;<br>
+   return false;<br>
+}<br>
+<br>
+static int<br>
+nouveau_vpe_init(struct nouveau_decoder *dec) {<br>
+   int ret;<br>
+   if (dec-&gt;cmds)<br>
+      return 0;<br>
+   ret = nouveau_bo_map(dec-&gt;cmd_bo, NOUVEAU_BO_RDWR);<br>
+   if (ret) {<br>
+      debug_printf(&quot;Mapping cmd bo: %s\n&quot;, strerror(-ret));<br>
+      return ret;<br>
+   }<br>
+   ret = nouveau_bo_map(dec-&gt;data_bo, NOUVEAU_BO_RDWR);<br>
+   if (ret) {<br>
+      nouveau_bo_unmap(dec-&gt;cmd_bo);<br>
+      debug_printf(&quot;Mapping data bo: %s\n&quot;, strerror(-ret));<br>
+      return ret;<br>
+   }<br>
+   dec-&gt;cmds = dec-&gt;cmd_bo-&gt;map;<br>
+   dec-&gt;data = dec-&gt;data_bo-&gt;map;<br>
+   return ret;<br>
+}<br>
+<br>
+static void<br>
+nouveau_vpe_synch(struct nouveau_decoder *dec) {<br>
+   struct nouveau_channel *chan = dec-&gt;screen-&gt;channel;<br>
+#if 0<br>
+   if (dec-&gt;fence_map) {<br>
+      BEGIN_RING(chan, dec-&gt;mpeg, NV84_MPEG_QUERY_COUNTER, 1);<br>
+      OUT_RING(chan, ++dec-&gt;fence_seq);<br>
+      FIRE_RING(chan);<br>
+      while (dec-&gt;fence_map[0] != dec-&gt;fence_seq)<br>
+         usleep(1000);<br>
+   } else<br>
+#endif<br>
+      FIRE_RING(chan);<br>
+}<br>
+<br>
+static void<br>
+nouveau_vpe_fini(struct nouveau_decoder *dec) {<br>
+   struct nouveau_channel *chan = dec-&gt;screen-&gt;channel;<br>
+   if (!dec-&gt;cmds)<br>
+      return;<br>
+<br>
+   nouveau_bo_unmap(dec-&gt;data_bo);<br>
+   nouveau_bo_unmap(dec-&gt;cmd_bo);<br>
+<br>
+   MARK_RING(chan, 8, 2);<br>
+   BEGIN_RING(chan, dec-&gt;mpeg, NV31_MPEG_CMD_OFFSET, 2);<br>
+   OUT_RELOCl(chan, dec-&gt;cmd_bo, 0, NOUVEAU_BO_RD|NOUVEAU_BO_GART);<br>
+   OUT_RING(chan, dec-&gt;ofs * 4);<br>
+<br>
+   BEGIN_RING(chan, dec-&gt;mpeg, NV31_MPEG_DATA_OFFSET, 2);<br>
+   OUT_RELOCl(chan, dec-&gt;data_bo, 0, NOUVEAU_BO_RD|NOUVEAU_BO_GART);<br>
+   OUT_RING(chan, dec-&gt;data_pos * 4);<br>
+<br>
+   BEGIN_RING(chan, dec-&gt;mpeg, NV31_MPEG_EXEC, 1);<br>
+   OUT_RING(chan, 1);<br>
+<br>
+   nouveau_vpe_synch(dec);<br>
+   dec-&gt;ofs = dec-&gt;data_pos = dec-&gt;num_surfaces = 0;<br>
+   dec-&gt;cmds = dec-&gt;data = NULL;<br>
+   dec-&gt;current = dec-&gt;future = dec-&gt;past = 8;<br>
+}<br>
+<br>
+static INLINE void<br>
+nouveau_vpe_mb_dct_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_macroblock *mb)<br>
+{<br>
+   int cbb;<br>
+   unsigned cbp = mb-&gt;coded_block_pattern;<br>
+   short *db = mb-&gt;blocks;<br>
+   for (cbb = 0x20; cbb &gt; 0; cbb &gt;&gt;= 1) {<br>
+      if (cbb &amp; cbp) {<br>
+         static const int lookup[64] = {<br>
+             0, 1, 8,16, 9, 2, 3,10,<br>
+            17,24,32,25,18,11, 4, 5,<br>
+            12,19,26,33,40,48,41,34,<br>
+            27,20,13, 6, 7,14,21,28,<br>
+            35,42,49,56,57,50,43,36,<br>
+            29,22,15,23,30,37,44,51,<br>
+            58,59,52,45,38,31,39,46,<br>
+            53,60,61,54,47,55,62,63<br>
+         };<br>
+         int i, j = 0, found = 0;<br>
+         for (i = 0; i &lt; 64; ++i) {<br>
+            if (!db[lookup[i]]) { j += 2; continue; }<br>
+            dec-&gt;data[dec-&gt;data_pos++] = (db[lookup[i]] &lt;&lt; 16) | j;<br>
+            j = 0;<br>
+            found = 1;<br>
+         }<br>
+         if (found)<br>
+            dec-&gt;data[dec-&gt;data_pos - 1] |= 1;<br>
+         else<br>
+            dec-&gt;data[dec-&gt;data_pos++] = 1;<br>
+         db += 64;<br>
+      } else if (mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_INTRA) {<br>
+         dec-&gt;data[dec-&gt;data_pos++] = 1;<br>
+      }<br>
+   }<br>
+}<br>
+<br>
+static INLINE void<br>
+nouveau_vpe_mb_data_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_macroblock *mb)<br>
+{<br>
+   int cbb;<br>
+   unsigned cbp = mb-&gt;coded_block_pattern;<br>
+   short *db = mb-&gt;blocks;<br>
+   for (cbb = 0x20; cbb &gt; 0; cbb &gt;&gt;= 1) {<br>
+      if (cbb &amp; cbp) {<br>
+         memcpy(&amp;dec-&gt;data[dec-&gt;data_pos], db, 128);<br>
+         dec-&gt;data_pos += 32;<br>
+         db += 64;<br>
+      } else if (mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_INTRA) {<br>
+         memset(&amp;dec-&gt;data[dec-&gt;data_pos], 0, 128);<br>
+         dec-&gt;data_pos += 32;<br>
+      }<br>
+   }<br>
+}<br>
+<br>
+static INLINE void<br>
+nouveau_vpe_mb_dct_header(struct nouveau_decoder *dec,<br>
+                          const struct pipe_mpeg12_macroblock *mb,<br>
+                          bool luma)<br>
+{<br>
+   unsigned base_dct, cbp;<br>
+   bool intra = mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_INTRA;<br>
+   unsigned x = mb-&gt;x * 16;<br>
+   unsigned y = luma ? mb-&gt;y * 16 : mb-&gt;y * 8;<br>
+<br>
+   /* Setup the base dct header */<br>
+   base_dct = dec-&gt;current &lt;&lt; NV17_MPEG_CMD_CHROMA_MB_HEADER_SURFACE__SHIFT;<br>
+   base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_RUN_SINGLE;<br>
+<br>
+   if (!(mb-&gt;x &amp; 1))<br>
+      base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_X_COORD_EVEN;<br>
+   if (intra)<br>
+      cbp = 0x3f;<br>
+   else<br>
+      cbp = mb-&gt;coded_block_pattern;<br>
+<br>
+   if (dec-&gt;picture_structure == PIPE_MPEG12_PICTURE_STRUCTURE_FRAME) {<br>
+      base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_TYPE_FRAME;<br>
+      if (luma &amp;&amp; mb-&gt;macroblock_modes.bits.dct_type == PIPE_MPEG12_DCT_TYPE_FIELD)<br>
+         base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_FRAME_DCT_TYPE_FIELD;<br>
+   } else {<br>
+      if (dec-&gt;picture_structure == PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_BOTTOM)<br>
+         base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_FIELD_BOTTOM;<br>
+      if (!intra)<br>
+         y *= 2;<br>
+   }<br>
+<br>
+   if (luma) {<br>
+      base_dct |= NV17_MPEG_CMD_LUMA_MB_HEADER_OP_LUMA_MB_HEADER;<br>
+      base_dct |= (cbp &gt;&gt; 2) &lt;&lt; NV17_MPEG_CMD_LUMA_MB_HEADER_CBP__SHIFT;<br>
+   } else {<br>
+      base_dct |= NV17_MPEG_CMD_CHROMA_MB_HEADER_OP_CHROMA_MB_HEADER;<br>
+      base_dct |= (cbp &amp; 3) &lt;&lt; NV17_MPEG_CMD_CHROMA_MB_HEADER_CBP__SHIFT;<br>
+   }<br>
+   nouveau_vpe_write(dec, base_dct);<br>
+   nouveau_vpe_write(dec, NV17_MPEG_CMD_MB_COORDS_OP_MB_COORDS |<br>
+                     x | (y &lt;&lt; NV17_MPEG_CMD_MB_COORDS_Y__SHIFT));<br>
+}<br>
+<br>
+static INLINE unsigned int<br>
+nouveau_vpe_mb_mv_flags(bool luma, int mv_h, int mv_v, bool forward, bool first, bool vert)<br>
+{<br>
+   unsigned mc_header = 0;<br>
+   if (luma)<br>
+      mc_header |= NV17_MPEG_CMD_LUMA_MV_HEADER_OP_LUMA_MV_HEADER;<br>
+   else<br>
+      mc_header |= NV17_MPEG_CMD_CHROMA_MV_HEADER_OP_CHROMA_MV_HEADER;<br>
+   if (mv_h &amp; 1)<br>
+      mc_header |= NV17_MPEG_CMD_CHROMA_MV_HEADER_X_HALF;<br>
+   if (mv_v &amp; 1)<br>
+      mc_header |= NV17_MPEG_CMD_CHROMA_MV_HEADER_Y_HALF;<br>
+   if (!forward)<br>
+      mc_header |= NV17_MPEG_CMD_CHROMA_MV_HEADER_DIRECTION_BACKWARD;<br>
+   if (!first)<br>
+      mc_header |= NV17_MPEG_CMD_CHROMA_MV_HEADER_IDX;<br>
+   if (vert)<br>
+      mc_header |= NV17_MPEG_CMD_LUMA_MV_HEADER_FIELD_BOTTOM;<br>
+   return mc_header;<br>
+}<br>
+<br>
+static unsigned pos(int pos, int mov, int max) {<br>
+   int ret = pos + mov;<br>
+   if (pos &lt; 0)<br>
+      return 0;<br>
+   if (pos &gt;= max)<br>
+      return max-1;<br>
+   return ret;<br>
+}<br>
+<br>
+/* because we want -1 / 2 = -1 */<br>
+static int div_down(int val, int mult) {<br>
+   val &amp;= ~(mult - 1);<br>
+   return val / mult;<br>
+}<br>
+<br>
+static int div_up(int val, int mult) {<br>
+   val += mult - 1;<br>
+   return val / mult;<br>
+}<br>
+<br>
+static INLINE void<br>
+nouveau_vpe_mb_mv(struct nouveau_decoder *dec, unsigned mc_header,<br>
+                   bool luma, bool frame, bool forward, bool vert,<br>
+                   int x, int y, const short motions[2],<br>
+                   unsigned surface, bool first)<br>
+{<br>
+   unsigned mc_vector;<br>
+   int mv_horizontal = motions[0];<br>
+   int mv_vertical = motions[1];<br>
+   int mv2 = mc_header &amp; NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_2;<br>
+   unsigned width = dec-&gt;base.width;<br>
+   unsigned height = dec-&gt;base.height;<br>
+   if (mv2)<br>
+      mv_vertical = div_down(mv_vertical, 2);<br>
+   assert(frame); // Untested for non-frames<br>
+   if (!frame)<br>
+      height *= 2;<br>
+<br>
+   mc_header |= surface &lt;&lt; NV17_MPEG_CMD_CHROMA_MV_HEADER_SURFACE__SHIFT;<br>
+   if (!luma) {<br>
+      mv_vertical = div_up(mv_vertical, 2);<br>
+      mv_horizontal = div_up(mv_horizontal, 2);<br>
+      height /= 2;<br>
+   }<br>
+   mc_header |= nouveau_vpe_mb_mv_flags(luma, mv_horizontal, mv_vertical, forward, first, vert);<br>
+   nouveau_vpe_write(dec, mc_header);<br>
+<br>
+   mc_vector = NV17_MPEG_CMD_MV_COORDS_OP_MV_COORDS;<br>
+   if (luma)<br>
+      mc_vector |= pos(x, div_down(mv_horizontal, 2), width);<br>
+   else<br>
+      mc_vector |= pos(x, mv_horizontal &amp; ~1, width);<br>
+   if (!mv2)<br>
+      mc_vector |= pos(y, div_down(mv_vertical, 2), height) &lt;&lt; NV17_MPEG_CMD_MV_COORDS_Y__SHIFT;<br>
+   else<br>
+      mc_vector |= pos(y, mv_vertical &amp; ~1, height) &lt;&lt; NV17_MPEG_CMD_MV_COORDS_Y__SHIFT;<br>
+   nouveau_vpe_write(dec, mc_vector);<br>
+}<br>
+<br>
+static void<br>
+nouveau_vpe_mb_mv_header(struct nouveau_decoder *dec,<br>
+                         const struct pipe_mpeg12_macroblock *mb,<br>
+                         bool luma)<br>
+{<br>
+   bool frame = dec-&gt;picture_structure == PIPE_MPEG12_PICTURE_STRUCTURE_FRAME;<br>
+   unsigned base;<br>
+   bool forward, backward;<br>
+   int y, y2, x = mb-&gt;x * 16;<br>
+   if (luma)<br>
+      y = mb-&gt;y * (frame ? 16 : 32);<br>
+   else<br>
+      y = mb-&gt;y * (frame ? 8 : 16);<br>
+   if (frame)<br>
+      y2 = y;<br>
+   else<br>
+      y2 = y + (luma ? 16 : 8);<br>
+<br>
+   forward = mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_MOTION_FORWARD;<br>
+   backward = mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_MOTION_BACKWARD;<br>
+   assert(!forward || dec-&gt;past &lt; 8);<br>
+   assert(!backward || dec-&gt;future &lt; 8);<br>
+   if (frame) {<br>
+      switch (mb-&gt;macroblock_modes.bits.frame_motion_type) {<br>
+      case PIPE_MPEG12_MO_TYPE_FRAME: goto mv1;<br>
+      case PIPE_MPEG12_MO_TYPE_FIELD: goto mv2;<br>
+      case PIPE_MPEG12_MO_TYPE_DUAL_PRIME: {<br>
+         base = NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_2;<br>
+         if (forward) {<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, FALSE,<br>
+                              x, y, mb-&gt;PMV[0][0], dec-&gt;past, TRUE);<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, TRUE,<br>
+                              x, y2, mb-&gt;PMV[0][0], dec-&gt;past, FALSE);<br>
+         }<br>
+         if (backward &amp;&amp; forward) {<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, TRUE,<br>
+                              x, y, mb-&gt;PMV[1][0], dec-&gt;future, TRUE);<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, FALSE,<br>
+                              x, y2, mb-&gt;PMV[1][1], dec-&gt;future, FALSE);<br>
+         } else assert(!backward);<br>
+         break;<br>
+      }<br>
+      default: assert(0);<br>
+      }<br>
+   } else {<br>
+      switch (mb-&gt;macroblock_modes.bits.field_motion_type) {<br>
+      case PIPE_MPEG12_MO_TYPE_FIELD: goto mv1;<br>
+      case PIPE_MPEG12_MO_TYPE_16x8: goto mv2;<br>
+      case PIPE_MPEG12_MO_TYPE_DUAL_PRIME: {<br>
+      base = NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_HALF_MB;<br>
+         if (frame)<br>
+            base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FRAME;<br>
+         if (forward)<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE,<br>
+                              dec-&gt;picture_structure != PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP,<br>
+                              x, y, mb-&gt;PMV[0][0], dec-&gt;past, TRUE);<br>
+         if (backward &amp;&amp; forward)<br>
+            nouveau_vpe_mb_mv(dec, base, luma, frame, FALSE,<br>
+                              dec-&gt;picture_structure == PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP,<br>
+                              x, y, mb-&gt;PMV[0][1], dec-&gt;future, TRUE);<br>
+         else assert(!backward);<br>
+         break;<br>
+      }<br>
+      default: assert(0);<br>
+      }<br>
+   }<br>
+   return;<br>
+<br>
+mv1:<br>
+   base = NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_HALF_MB;<br>
+   if (frame)<br>
+       base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FRAME;<br>
+    /* frame 16x16 */<br>
+   if (forward)<br>
+       nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, FALSE,<br>
+                         x, y, mb-&gt;PMV[0][0], dec-&gt;past, TRUE);<br>
+   if (backward)<br>
+       nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, FALSE,<br>
+                         x, y, mb-&gt;PMV[0][1], dec-&gt;future, TRUE);<br>
+    return;<br>
+<br>
+mv2:<br>
+   base = NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_2;<br>
+   if (!frame)<br>
+      base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_HALF_MB;<br>
+   if (forward) {<br>
+      nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE,<br>
+                        mb-&gt;motion_vertical_field_select &amp; PIPE_MPEG12_FS_FIRST_FORWARD,<br>
+                        x, y, mb-&gt;PMV[0][0], dec-&gt;past, TRUE);<br>
+      nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE,<br>
+                        mb-&gt;motion_vertical_field_select &amp; PIPE_MPEG12_FS_SECOND_FORWARD,<br>
+                        x, y2, mb-&gt;PMV[1][0], dec-&gt;past, FALSE);<br>
+   }<br>
+   if (backward) {<br>
+      nouveau_vpe_mb_mv(dec, base, luma, frame, !forward,<br>
+                        mb-&gt;motion_vertical_field_select &amp; PIPE_MPEG12_FS_FIRST_BACKWARD,<br>
+                        x, y, mb-&gt;PMV[0][1], dec-&gt;future, TRUE);<br>
+      nouveau_vpe_mb_mv(dec, base, luma, frame, !forward,<br>
+                        mb-&gt;motion_vertical_field_select &amp; PIPE_MPEG12_FS_SECOND_BACKWARD,<br>
+                        x, y2, mb-&gt;PMV[1][1], dec-&gt;future, FALSE);<br>
+   }<br>
+}<br>
+<br>
+static unsigned<br>
+nouveau_decoder_surface_index(struct nouveau_decoder *dec,<br>
+                              struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;<br>
+   struct nouveau_channel *chan = dec-&gt;screen-&gt;channel;<br>
+   struct nouveau_bo *bo_y, *bo_c;<br>
+   unsigned i;<br>
+<br>
+   if (!buf)<br>
+      return 8;<br>
+   for (i = 0; i &lt; dec-&gt;num_surfaces; ++i) {<br>
+      if (dec-&gt;surfaces[i] == buf)<br>
+         return i;<br>
+   }<br>
+   assert(i &lt; 8);<br>
+   dec-&gt;surfaces[i] = buf;<br>
+   dec-&gt;num_surfaces++;<br>
+<br>
+   if (nouveau_video_is_nvfx(dec)) {<br>
+      bo_y = ((struct nvfx_resource *)buf-&gt;resources[0])-&gt;bo;<br>
+      bo_c = ((struct nvfx_resource *)buf-&gt;resources[1])-&gt;bo;<br>
+   } else {<br>
+      bo_y = ((struct nv04_resource *)buf-&gt;resources[0])-&gt;bo;<br>
+      bo_c = ((struct nv04_resource *)buf-&gt;resources[1])-&gt;bo;<br>
+   }<br>
+   MARK_RING(chan, 3, 2);<br>
+   BEGIN_RING(chan, dec-&gt;mpeg, NV31_MPEG_IMAGE_Y_OFFSET(i), 2);<br>
+   OUT_RELOCl(chan, bo_y, 0, NOUVEAU_BO_RDWR);<br>
+   OUT_RELOCl(chan, bo_c, 0, NOUVEAU_BO_RDWR);<br>
+   return i;<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_set_picture_parameters(struct pipe_video_decoder *decoder,<br>
+                                       struct pipe_picture_desc *picture_desc)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder;<br>
+   struct pipe_mpeg12_picture_desc *desc;<br>
+   desc = (struct pipe_mpeg12_picture_desc *)picture_desc;<br>
+   dec-&gt;picture_structure = desc-&gt;picture_structure;<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_set_reference_frames(struct pipe_video_decoder *decoder,<br>
+                                     struct pipe_video_buffer **buffers,<br>
+                                     unsigned count)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder;<br>
+   if (count &gt;= 1 &amp;&amp; buffers[0])<br>
+      dec-&gt;past = nouveau_decoder_surface_index(dec, buffers[0]);<br>
+   if (count &gt;= 2 &amp;&amp; buffers[1])<br>
+      dec-&gt;future = nouveau_decoder_surface_index(dec, buffers[1]);<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_set_decode_target(struct pipe_video_decoder *decoder,<br>
+                                  struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder;<br>
+   dec-&gt;current = nouveau_decoder_surface_index(dec, buffer);<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_decode_macroblock(struct pipe_video_decoder *decoder,<br>
+                                  const struct pipe_macroblock *pipe_mb,<br>
+                                  unsigned num_macroblocks)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder;<br>
+   const struct pipe_mpeg12_macroblock *mb;<br>
+   unsigned i;<br>
+   assert(dec-&gt;current &lt; 8);<br>
+<br>
+   if (nouveau_vpe_init(dec)) return;<br>
+   mb = (const struct pipe_mpeg12_macroblock *)pipe_mb;<br>
+   for (i = 0; i &lt; num_macroblocks; ++i, mb++) {<br>
+      if (mb-&gt;macroblock_type &amp; PIPE_MPEG12_MB_TYPE_INTRA) {<br>
+         nouveau_vpe_mb_dct_header(dec, mb, TRUE);<br>
+         nouveau_vpe_mb_dct_header(dec, mb, FALSE);<br>
+      } else {<br>
+         nouveau_vpe_mb_mv_header(dec, mb, TRUE);<br>
+         nouveau_vpe_mb_dct_header(dec, mb, TRUE);<br>
+<br>
+         nouveau_vpe_mb_mv_header(dec, mb, FALSE);<br>
+         nouveau_vpe_mb_dct_header(dec, mb, FALSE);<br>
+      }<br>
+      if (dec-&gt;base.entrypoint &lt;= PIPE_VIDEO_ENTRYPOINT_IDCT)<br>
+         nouveau_vpe_mb_dct_blocks(dec, mb);<br>
+      else<br>
+         nouveau_vpe_mb_data_blocks(dec, mb);<br>
+   }<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_flush(struct pipe_video_decoder *decoder)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder;<br>
+   if (dec-&gt;ofs)<br>
+      nouveau_vpe_fini(dec);<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_destroy(struct pipe_video_decoder *decoder)<br>
+{<br>
+   struct nouveau_decoder *dec = (struct nouveau_decoder*)decoder;<br>
+<br>
+   if (dec-&gt;cmds) {<br>
+      nouveau_bo_unmap(dec-&gt;data_bo);<br>
+      nouveau_bo_unmap(dec-&gt;cmd_bo);<br>
+   }<br>
+<br>
+   if (dec-&gt;data_bo)<br>
+      nouveau_bo_ref(NULL, &amp;dec-&gt;data_bo);<br>
+   if (dec-&gt;cmd_bo)<br>
+      nouveau_bo_ref(NULL, &amp;dec-&gt;cmd_bo);<br>
+   if (dec-&gt;fence_bo)<br>
+      nouveau_bo_ref(NULL, &amp;dec-&gt;fence_bo);<br>
+   nouveau_grobj_free(&amp;dec-&gt;mpeg);<br>
+   FREE(dec);<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_begin_frame(struct pipe_video_decoder *decoder)<br>
+{<br>
+}<br>
+<br>
+static void<br>
+nouveau_decoder_end_frame(struct pipe_video_decoder *decoder)<br>
+{<br>
+}<br>
+<br>
+static struct pipe_video_decoder *<br>
+nouveau_create_decoder(struct pipe_context *context,<br>
+                       struct nouveau_screen *screen,<br>
+                       enum pipe_video_profile profile,<br>
+                       enum pipe_video_entrypoint entrypoint,<br>
+                       enum pipe_video_chroma_format chroma_format,<br>
+                       unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_channel *chan = screen-&gt;channel;<br>
+   struct nouveau_grobj *mpeg = NULL;<br>
+   struct nouveau_decoder *dec;<br>
+   int ret;<br>
+   bool is8274 = screen-&gt;device-&gt;chipset &gt; 0x80;<br>
+<br>
+   debug_printf(&quot;Acceleration level: %s\n&quot;, entrypoint &lt;= PIPE_VIDEO_ENTRYPOINT_BITSTREAM ? &quot;bit&quot;:<br>
+                                            entrypoint == PIPE_VIDEO_ENTRYPOINT_IDCT ? &quot;IDCT&quot; : &quot;MC&quot;);<br>
+<br>
+   if (getenv(&quot;XVMC_VL&quot;))<br>
+      goto vl;<br>
+   if (u_reduce_video_profile(profile) != PIPE_VIDEO_CODEC_MPEG12)<br>
+      goto vl;<br>
+   if (screen-&gt;device-&gt;chipset &gt;= 0x98 &amp;&amp; screen-&gt;device-&gt;chipset != 0xa0)<br>
+      goto vl;<br>
+<br>
+   width = align(width, 64);<br>
+   height = align(height, 64);<br>
+<br>
+   if (is8274)<br>
+       ret = nouveau_grobj_alloc(chan, 0xbeef8274, 0x8274, &amp;mpeg);<br>
+   else<br>
+       ret = nouveau_grobj_alloc(chan, 0xbeef8274, 0x3174, &amp;mpeg);<br>
+   if (ret &lt; 0) {<br>
+      debug_printf(&quot;Creation failed: %s (%i)\n&quot;, strerror(-ret), ret);<br>
+      return NULL;<br>
+   }<br>
+<br>
+   dec = CALLOC_STRUCT(nouveau_decoder);<br>
+   if (!dec) {<br>
+      nouveau_grobj_free(&amp;mpeg);<br>
+      goto fail;<br>
+   }<br>
+   dec-&gt;mpeg = mpeg;<br>
+   dec-&gt;base.context = context;<br>
+   dec-&gt;base.profile = profile;<br>
+   dec-&gt;base.entrypoint = entrypoint;<br>
+   dec-&gt;base.chroma_format = chroma_format;<br>
+   dec-&gt;base.width = width;<br>
+   dec-&gt;base.height = height;<br>
+   dec-&gt;base.destroy = nouveau_decoder_destroy;<br>
+   dec-&gt;base.begin_frame = nouveau_decoder_begin_frame;<br>
+   dec-&gt;base.end_frame = nouveau_decoder_end_frame;<br>
+   dec-&gt;base.set_decode_target = nouveau_decoder_set_decode_target;<br>
+   dec-&gt;base.set_picture_parameters = nouveau_decoder_set_picture_parameters;<br>
+   dec-&gt;base.set_reference_frames = nouveau_decoder_set_reference_frames;<br>
+   dec-&gt;base.decode_macroblock = nouveau_decoder_decode_macroblock;<br>
+   dec-&gt;base.flush = nouveau_decoder_flush;<br>
+   dec-&gt;screen = screen;<br>
+<br>
+   ret = nouveau_bo_new(dec-&gt;screen-&gt;device, NOUVEAU_BO_GART, 0, 1024 * 1024, &amp;dec-&gt;cmd_bo);<br>
+   if (ret)<br>
+      goto fail;<br>
+<br>
+   ret = nouveau_bo_new(dec-&gt;screen-&gt;device, NOUVEAU_BO_GART, 0, width * height * 6, &amp;dec-&gt;data_bo);<br>
+   if (ret)<br>
+      goto fail;<br>
+<br>
+   ret = nouveau_bo_new(dec-&gt;screen-&gt;device, NOUVEAU_BO_GART|NOUVEAU_BO_MAP, 0, 4096,<br>
+                        &amp;dec-&gt;fence_bo);<br>
+   if (ret)<br>
+      goto fail;<br>
+   nouveau_bo_map(dec-&gt;fence_bo, NOUVEAU_BO_RDWR);<br>
+   dec-&gt;fence_map = dec-&gt;fence_bo-&gt;map;<br>
+   nouveau_bo_unmap(dec-&gt;fence_bo);<br>
+   dec-&gt;fence_map[0] = 0;<br>
+<br>
+   if (is8274)<br>
+      MARK_RING(chan, 25, 3);<br>
+   else<br>
+      MARK_RING(chan, 20, 2);<br>
+<br>
+   BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_CMD, 1);<br>
+   OUT_RING(chan, chan-&gt;vram-&gt;handle);<br>
+<br>
+   BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_DATA, 1);<br>
+   OUT_RING(chan, chan-&gt;vram-&gt;handle);<br>
+<br>
+   BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_IMAGE, 1);<br>
+   OUT_RING(chan, chan-&gt;vram-&gt;handle);<br>
+<br>
+   BEGIN_RING(chan, mpeg, NV31_MPEG_PITCH, 2);<br>
+   OUT_RING(chan, width | NV31_MPEG_PITCH_UNK);<br>
+   OUT_RING(chan, (height &lt;&lt; NV31_MPEG_SIZE_H__SHIFT) | width);<br>
+<br>
+   BEGIN_RING(chan, mpeg, NV31_MPEG_FORMAT, 2);<br>
+   OUT_RING(chan, 0);<br>
+   switch (entrypoint) {<br>
+      case PIPE_VIDEO_ENTRYPOINT_BITSTREAM: OUT_RING(chan, 0x100); break;<br>
+      case PIPE_VIDEO_ENTRYPOINT_IDCT: OUT_RING(chan, 1); break;<br>
+      case PIPE_VIDEO_ENTRYPOINT_MC: OUT_RING(chan, 0); break;<br>
+      default: assert(0);<br>
+   }<br>
+<br>
+   if (is8274) {<br>
+      BEGIN_RING(chan, mpeg, NV84_MPEG_DMA_QUERY, 1);<br>
+      OUT_RING(chan, chan-&gt;vram-&gt;handle);<br>
+<br>
+      BEGIN_RING(chan, mpeg, NV84_MPEG_QUERY_OFFSET, 2);<br>
+      OUT_RELOCl(chan, dec-&gt;fence_bo, 0, NOUVEAU_BO_WR|NOUVEAU_BO_GART);<br>
+      OUT_RING(chan, dec-&gt;fence_seq);<br>
+   }<br>
+<br>
+   ret = nouveau_vpe_init(dec);<br>
+   if (ret)<br>
+      goto fail;<br>
+   nouveau_vpe_fini(dec);<br>
+   return &amp;dec-&gt;base;<br>
+<br>
+fail:<br>
+   nouveau_decoder_destroy(&amp;dec-&gt;base);<br>
+   return NULL;<br>
+<br>
+vl:<br>
+   debug_printf(&quot;Using g3dvl renderer\n&quot;);<br>
+   return vl_create_decoder(context, profile, entrypoint,<br>
+                            chroma_format, width, height);<br>
+}<br>
+<br>
+static struct pipe_sampler_view **<br>
+nouveau_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;<br>
+   struct pipe_sampler_view sv_templ;<br>
+   struct pipe_context *pipe;<br>
+   unsigned i;<br>
+<br>
+   assert(buf);<br>
+<br>
+   pipe = buf-&gt;base.context;<br>
+<br>
+   for (i = 0; i &lt; buf-&gt;num_planes; ++i ) {<br>
+      if (!buf-&gt;sampler_view_planes[i]) {<br>
+         memset(&amp;sv_templ, 0, sizeof(sv_templ));<br>
+         u_sampler_view_default_template(&amp;sv_templ, buf-&gt;resources[i], buf-&gt;resources[i]-&gt;format);<br>
+<br>
+         if (util_format_get_nr_components(buf-&gt;resources[i]-&gt;format) == 1)<br>
+            sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_RED;<br>
+<br>
+         buf-&gt;sampler_view_planes[i] = pipe-&gt;create_sampler_view(pipe, buf-&gt;resources[i], &amp;sv_templ);<br>
+         if (!buf-&gt;sampler_view_planes[i])<br>
+            goto error;<br>
+      }<br>
+   }<br>
+<br>
+   return buf-&gt;sampler_view_planes;<br>
+<br>
+error:<br>
+   for (i = 0; i &lt; buf-&gt;num_planes; ++i )<br>
+      pipe_sampler_view_reference(&amp;buf-&gt;sampler_view_planes[i], NULL);<br>
+<br>
+   return NULL;<br>
+}<br>
+<br>
+static struct pipe_sampler_view **<br>
+nouveau_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;<br>
+   struct pipe_sampler_view sv_templ;<br>
+   struct pipe_context *pipe;<br>
+   unsigned i, j, component;<br>
+<br>
+   assert(buf);<br>
+<br>
+   pipe = buf-&gt;base.context;<br>
+<br>
+   for (component = 0, i = 0; i &lt; buf-&gt;num_planes; ++i ) {<br>
+      unsigned nr_components = util_format_get_nr_components(buf-&gt;resources[i]-&gt;format);<br>
+<br>
+      for (j = 0; j &lt; nr_components; ++j, ++component) {<br>
+         assert(component &lt; VL_MAX_PLANES);<br>
+<br>
+         if (!buf-&gt;sampler_view_components[component]) {<br>
+            memset(&amp;sv_templ, 0, sizeof(sv_templ));<br>
+            u_sampler_view_default_template(&amp;sv_templ, buf-&gt;resources[i], buf-&gt;resources[i]-&gt;format);<br>
+            sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j;<br>
+            sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;<br>
+            buf-&gt;sampler_view_components[component] = pipe-&gt;create_sampler_view(pipe, buf-&gt;resources[i], &amp;sv_templ);<br>
+            if (!buf-&gt;sampler_view_components[component])<br>
+               goto error;<br>
+         }<br>
+      }<br>
+   }<br>
+<br>
+   return buf-&gt;sampler_view_components;<br>
+<br>
+error:<br>
+   for (i = 0; i &lt; 3; ++i )<br>
+      pipe_sampler_view_reference(&amp;buf-&gt;sampler_view_components[i], NULL);<br>
+<br>
+   return NULL;<br>
+}<br>
+<br>
+static struct pipe_surface **<br>
+nouveau_video_buffer_surfaces(struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;<br>
+   struct pipe_surface surf_templ;<br>
+   struct pipe_context *pipe;<br>
+   unsigned i;<br>
+<br>
+   assert(buf);<br>
+<br>
+   pipe = buf-&gt;base.context;<br>
+<br>
+   for (i = 0; i &lt; buf-&gt;num_planes; ++i ) {<br>
+      if (!buf-&gt;surfaces[i]) {<br>
+         memset(&amp;surf_templ, 0, sizeof(surf_templ));<br>
+         surf_templ.format = buf-&gt;resources[i]-&gt;format;<br>
+         surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;<br>
+         buf-&gt;surfaces[i] = pipe-&gt;create_surface(pipe, buf-&gt;resources[i], &amp;surf_templ);<br>
+         if (!buf-&gt;surfaces[i])<br>
+            goto error;<br>
+      }<br>
+   }<br>
+<br>
+   return buf-&gt;surfaces;<br>
+<br>
+error:<br>
+   for (i = 0; i &lt; buf-&gt;num_planes; ++i )<br>
+      pipe_surface_reference(&amp;buf-&gt;surfaces[i], NULL);<br>
+<br>
+   return NULL;<br>
+}<br>
+<br>
+static void<br>
+nouveau_video_buffer_destroy(struct pipe_video_buffer *buffer)<br>
+{<br>
+   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;<br>
+   unsigned i;<br>
+<br>
+   assert(buf);<br>
+<br>
+   for (i = 0; i &lt; buf-&gt;num_planes; ++i) {<br>
+      pipe_surface_reference(&amp;buf-&gt;surfaces[i], NULL);<br>
+      pipe_sampler_view_reference(&amp;buf-&gt;sampler_view_planes[i], NULL);<br>
+      pipe_sampler_view_reference(&amp;buf-&gt;sampler_view_components[i], NULL);<br>
+      pipe_resource_reference(&amp;buf-&gt;resources[i], NULL);<br>
+   }<br>
+   for (;i &lt; 3;++i)<br>
+      pipe_sampler_view_reference(&amp;buf-&gt;sampler_view_components[i], NULL);<br>
+<br>
+   FREE(buffer);<br>
+}<br>
+<br>
+static struct pipe_video_buffer *<br>
+nouveau_video_buffer_create(struct pipe_context *pipe,<br>
+                            struct nouveau_screen *screen,<br>
+                            enum pipe_format buffer_format,<br>
+                            enum pipe_video_chroma_format chroma_format,<br>
+                            unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_video_buffer *buffer;<br>
+   struct pipe_resource templ;<br>
+<br>
+   /* Only do a linear surface when a hardware decoder is used<br>
+    * hardware decoder is only supported on some chipsets<br>
+    * and it only supports the NV12 format<br>
+    */<br>
+   if (buffer_format != PIPE_FORMAT_NV12 || getenv(&quot;XVMC_VL&quot;) ||<br>
+       (screen-&gt;device-&gt;chipset &gt;= 0x98 &amp;&amp; screen-&gt;device-&gt;chipset != 0xa0))<br>
+      return vl_video_buffer_create(pipe, buffer_format, chroma_format, width, height);<br>
+<br>
+   assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);<br>
+   width = align(width, 64);<br>
+   height = align(height, 64);<br>
+<br>
+   buffer = CALLOC_STRUCT(nouveau_video_buffer);<br>
+   if (!buffer)<br>
+      return NULL;<br>
+<br>
+   buffer-&gt;base.context = pipe;<br>
+   buffer-&gt;base.destroy = nouveau_video_buffer_destroy;<br>
+   buffer-&gt;base.get_sampler_view_planes = nouveau_video_buffer_sampler_view_planes;<br>
+   buffer-&gt;base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components;<br>
+   buffer-&gt;base.get_surfaces = nouveau_video_buffer_surfaces;<br>
+   buffer-&gt;base.chroma_format = chroma_format;<br>
+   buffer-&gt;base.width = width;<br>
+   buffer-&gt;base.height = height;<br>
+   buffer-&gt;num_planes = 2;<br>
+<br>
+   memset(&amp;templ, 0, sizeof(templ));<br>
+   templ.target = PIPE_TEXTURE_2D;<br>
+   templ.format = PIPE_FORMAT_R8_UNORM;<br>
+   templ.width0 = width;<br>
+   templ.height0 = height;<br>
+   templ.depth0 = 1;<br>
+   templ.array_size = 1;<br>
+   templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;<br>
+   templ.usage = PIPE_USAGE_STATIC;<br>
+   templ.flags = NOUVEAU_RESOURCE_FLAG_LINEAR;<br>
+<br>
+   buffer-&gt;resources[0] = pipe-&gt;screen-&gt;resource_create(pipe-&gt;screen, &amp;templ);<br>
+   if (!buffer-&gt;resources[0])<br>
+      goto error;<br>
+   templ.width0 /= 2;<br>
+   templ.height0 /= 2;<br>
+   templ.format = PIPE_FORMAT_R8G8_UNORM;<br>
+   buffer-&gt;resources[1] = pipe-&gt;screen-&gt;resource_create(pipe-&gt;screen, &amp;templ);<br>
+   if (!buffer-&gt;resources[1])<br>
+      goto error;<br>
+   return &amp;buffer-&gt;base;<br>
+<br>
+error:<br>
+   nouveau_video_buffer_destroy(&amp;buffer-&gt;base);<br>
+   FREE(buffer);<br>
+   return NULL;<br>
+}<br>
<br>
 static int<br>
 nouveau_screen_get_video_param(struct pipe_screen *pscreen,<br>
@@ -33,9 +866,60 @@ nouveau_screen_init_vdec(struct nouveau_screen *screen)<br>
    screen-&gt;base.is_video_format_supported = vl_video_buffer_is_format_supported;<br>
 }<br>
<br>
+static struct pipe_video_decoder *<br>
+nvfx_context_create_decoder(struct pipe_context *context,<br>
+                            enum pipe_video_profile profile,<br>
+                            enum pipe_video_entrypoint entrypoint,<br>
+                            enum pipe_video_chroma_format chroma_format,<br>
+                            unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_screen *screen = &amp;nvfx_context(context)-&gt;screen-&gt;base;<br>
+   return nouveau_create_decoder(context, screen, profile, entrypoint,<br>
+                                 chroma_format, width, height);<br>
+}<br>
+<br>
+static struct pipe_video_buffer *<br>
+nvfx_context_video_buffer_create(struct pipe_context *pipe,<br>
+                                 enum pipe_format buffer_format,<br>
+                                 enum pipe_video_chroma_format chroma_format,<br>
+                                 unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_screen *screen = &amp;nvfx_context(pipe)-&gt;screen-&gt;base;<br>
+   return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);<br>
+}<br>
+<br>
+void<br>
+nvfx_context_init_vdec(struct nvfx_context *nv)<br>
+{<br>
+   nv-&gt;pipe.create_video_decoder = nvfx_context_create_decoder;<br>
+   nv-&gt;pipe.create_video_buffer = nvfx_context_video_buffer_create;<br>
+}<br>
+<br>
+static struct pipe_video_decoder *<br>
+nouveau_context_create_decoder(struct pipe_context *context,<br>
+                               enum pipe_video_profile profile,<br>
+                               enum pipe_video_entrypoint entrypoint,<br>
+                               enum pipe_video_chroma_format chroma_format,<br>
+                               unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_screen *screen = nouveau_context(context)-&gt;screen;<br>
+   return nouveau_create_decoder(context, screen, profile, entrypoint,<br>
+                                 chroma_format, width, height);<br>
+}<br>
+<br>
+static struct pipe_video_buffer *<br>
+nouveau_context_video_buffer_create(struct pipe_context *pipe,<br>
+                                    enum pipe_format buffer_format,<br>
+                                    enum pipe_video_chroma_format chroma_format,<br>
+                                    unsigned width, unsigned height)<br>
+{<br>
+   struct nouveau_screen *screen = nouveau_context(pipe)-&gt;screen;<br>
+   return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);<br>
+}<br>
+<br>
 void<br>
 nouveau_context_init_vdec(struct nouveau_context *nv)<br>
 {<br>
-   nv-&gt;pipe.create_video_decoder = vl_create_decoder;<br>
-   nv-&gt;pipe.create_video_buffer = vl_video_buffer_create;<br>
+   nv-&gt;pipe.create_video_decoder = nouveau_context_create_decoder;<br>
+   nv-&gt;pipe.create_video_buffer = nouveau_context_video_buffer_create;<br>
 }<br>
diff --git a/src/gallium/drivers/nouveau/nouveau_video.h b/src/gallium/drivers/nouveau/nouveau_video.h<br>
new file mode 100644<br>
index 0000000..c6875c3<br>
--- /dev/null<br>
+++ b/src/gallium/drivers/nouveau/nouveau_video.h<br>
@@ -0,0 +1,42 @@<br>
+#ifndef __NOUVEAU_VIDEO_H__<br>
+#define __NOUVEAU_SCREEN_H__<br>
+<br>
+#include &quot;nv17_mpeg.xml.h&quot;<br>
+#include &quot;nv31_mpeg.xml.h&quot;<br>
+<br>
+struct nouveau_video_buffer {<br>
+   struct pipe_video_buffer base;<br>
+   unsigned num_planes;<br>
+   struct pipe_resource     *resources[2];<br>
+   struct pipe_sampler_view *sampler_view_planes[2];<br>
+   struct pipe_sampler_view *sampler_view_components[3];<br>
+   struct pipe_surface      *surfaces[2];<br>
+};<br>
+<br>
+struct nouveau_decoder {<br>
+   struct pipe_video_decoder base;<br>
+   struct nouveau_screen *screen;<br>
+   struct nouveau_grobj *mpeg;<br>
+   struct nouveau_bo *cmd_bo, *data_bo, *fence_bo;<br>
+<br>
+   unsigned *fence_map;<br>
+   unsigned fence_seq;<br>
+<br>
+   unsigned ofs;<br>
+   unsigned *cmds;<br>
+<br>
+   unsigned *data;<br>
+   unsigned data_pos;<br>
+   unsigned picture_structure;<br>
+<br>
+   unsigned past, future, current;<br>
+   unsigned num_surfaces;<br>
+   struct nouveau_video_buffer *surfaces[8];<br>
+};<br>
+<br>
+static INLINE void<br>
+nouveau_vpe_write(struct nouveau_decoder *dec, unsigned data) {<br>
+   dec-&gt;cmds[dec-&gt;ofs++] = data;<br>
+}<br>
+<br>
+#endif<br>
diff --git a/src/gallium/drivers/nouveau/nv17_mpeg.xml.h b/src/gallium/drivers/nouveau/nv17_mpeg.xml.h<br>
new file mode 100644<br>
index 0000000..a27310f<br>
--- /dev/null<br>
+++ b/src/gallium/drivers/nouveau/nv17_mpeg.xml.h<br>
@@ -0,0 +1,265 @@<br>
+#ifndef ___RNNDB_NV17_MPEG_XML<br>
+#define ___RNNDB_NV17_MPEG_XML<br>
+<br>
+/* Autogenerated file, DO NOT EDIT manually!<br>
+<br>
+This file was generated by the rules-ng-ng headergen tool in this git repository:<br>
+<a href="http://0x04.net/cgit/index.cgi/rules-ng-ng" target="_blank">http://0x04.net/cgit/index.cgi/rules-ng-ng</a><br>
+git clone git://<a href="http://0x04.net/rules-ng-ng" target="_blank">0x04.net/rules-ng-ng</a><br>
+<br>
+The rules-ng-ng source files this header was generated from are:<br>
+- ../rnndb/nv17_mpeg.xml  (   6846 bytes, from 2011-08-08 14:21:26)<br>
+- ../rnndb/copyright.xml  (   6452 bytes, from 2011-07-15 12:42:43)<br>
+- ../rnndb/nvchipsets.xml (   3617 bytes, from 2011-07-22 11:37:48)<br>
+<br>
+Copyright (C) 2006-2011 by the following authors:<br>
+- Artur Huillet &lt;<a href="mailto:arthur.huillet@free.fr">arthur.huillet@free.fr</a>&gt; (ahuillet)<br>
+- Ben Skeggs (darktama, darktama_)<br>
+- B. R. &lt;<a href="mailto:koala_br@users.sourceforge.net">koala_br@users.sourceforge.net</a>&gt; (koala_br)<br>
+- Carlos Martin &lt;<a href="mailto:carlosmn@users.sf.net">carlosmn@users.sf.net</a>&gt; (carlosmn)<br>
+- Christoph Bumiller &lt;<a href="mailto:e0425955@student.tuwien.ac.at">e0425955@student.tuwien.ac.at</a>&gt; (calim, chrisbmr)<br>
+- Dawid Gajownik &lt;<a href="mailto:gajownik@users.sf.net">gajownik@users.sf.net</a>&gt; (gajownik)<br>
+- Dmitry Baryshkov<br>
+- Dmitry Eremin-Solenikov &lt;<a href="mailto:lumag@users.sf.net">lumag@users.sf.net</a>&gt; (lumag)<br>
+- EdB &lt;<a href="mailto:edb_@users.sf.net">edb_@users.sf.net</a>&gt; (edb_)<br>
+- Erik Waling &lt;<a href="mailto:erikwailing@users.sf.net">erikwailing@users.sf.net</a>&gt; (erikwaling)<br>
+- Francisco Jerez &lt;<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>&gt; (curro)<br>
+- imirkin &lt;<a href="mailto:imirkin@users.sf.net">imirkin@users.sf.net</a>&gt; (imirkin)<br>
+- jb17bsome &lt;<a href="mailto:jb17bsome@bellsouth.net">jb17bsome@bellsouth.net</a>&gt; (jb17bsome)<br>
+- Jeremy Kolb &lt;<a href="mailto:kjeremy@users.sf.net">kjeremy@users.sf.net</a>&gt; (kjeremy)<br>
+- Laurent Carlier &lt;<a href="mailto:lordheavym@gmail.com">lordheavym@gmail.com</a>&gt; (lordheavy)<br>
+- Luca Barbieri &lt;<a href="mailto:luca@luca-barbieri.com">luca@luca-barbieri.com</a>&gt; (lb, lb1)<br>
+- Maarten Maathuis &lt;<a href="mailto:madman2003@gmail.com">madman2003@gmail.com</a>&gt; (stillunknown)<br>
+- Marcin Kościelnicki &lt;<a href="mailto:koriakin@0x04.net">koriakin@0x04.net</a>&gt; (mwk, koriakin)<br>
+- Mark Carey &lt;<a href="mailto:mark.carey@gmail.com">mark.carey@gmail.com</a>&gt; (careym)<br>
+- Matthieu Castet &lt;<a href="mailto:matthieu.castet@parrot.com">matthieu.castet@parrot.com</a>&gt; (mat-c)<br>
+- nvidiaman &lt;<a href="mailto:nvidiaman@users.sf.net">nvidiaman@users.sf.net</a>&gt; (nvidiaman)<br>
+- Patrice Mandin &lt;<a href="mailto:patmandin@gmail.com">patmandin@gmail.com</a>&gt; (pmandin, pmdata)<br>
+- Pekka Paalanen &lt;<a href="mailto:pq@iki.fi">pq@iki.fi</a>&gt; (pq, ppaalanen)<br>
+- Peter Popov &lt;<a href="mailto:ironpeter@users.sf.net">ironpeter@users.sf.net</a>&gt; (ironpeter)<br>
+- Richard Hughes &lt;<a href="mailto:hughsient@users.sf.net">hughsient@users.sf.net</a>&gt; (hughsient)<br>
+- Rudi Cilibrasi &lt;<a href="mailto:cilibrar@users.sf.net">cilibrar@users.sf.net</a>&gt; (cilibrar)<br>
+- Serge Martin<br>
+- Simon Raffeiner<br>
+- Stephane Loeuillet &lt;<a href="mailto:leroutier@users.sf.net">leroutier@users.sf.net</a>&gt; (leroutier)<br>
+- Stephane Marchesin &lt;<a href="mailto:stephane.marchesin@gmail.com">stephane.marchesin@gmail.com</a>&gt; (marcheu)<br>
+- sturmflut &lt;<a href="mailto:sturmflut@users.sf.net">sturmflut@users.sf.net</a>&gt; (sturmflut)<br>
+- Sylvain Munaut &lt;tnt@246tNt.com&gt;<br>
+- Victor Stinner &lt;<a href="mailto:victor.stinner@haypocalc.com">victor.stinner@haypocalc.com</a>&gt; (haypo)<br>
+- Wladmir van der Laan &lt;<a href="mailto:laanwj@gmail.com">laanwj@gmail.com</a>&gt; (miathan6)<br>
+- Younes Manton &lt;<a href="mailto:younes.m@gmail.com">younes.m@gmail.com</a>&gt; (ymanton)<br>
+<br>
+Permission is hereby granted, free of charge, to any person obtaining<br>
+a copy of this software and associated documentation files (the<br>
+&quot;Software&quot;), to deal in the Software without restriction, including<br>
+without limitation the rights to use, copy, modify, merge, publish,<br>
+distribute, sublicense, and/or sell copies of the Software, and to<br>
+permit persons to whom the Software is furnished to do so, subject to<br>
+the following conditions:<br>
+<br>
+The above copyright notice and this permission notice (including the<br>
+next paragraph) shall be included in all copies or substantial<br>
+portions of the Software.<br>
+<br>
+THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,<br>
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.<br>
+IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE<br>
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION<br>
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION<br>
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
+*/<br>
+<br>
+<br>
+#define NV17_MPEG_CMD_NOP_OP__MASK                             0xf0000000<br>
+#define NV17_MPEG_CMD_NOP_OP__SHIFT                            28<br>
+#define NV17_MPEG_CMD_NOP_OP_NOP                               0x10000000<br>
+#define NV17_MPEG_CMD_SURFACE_OFFSET__MASK                     0x00ffffff<br>
+#define NV17_MPEG_CMD_SURFACE_OFFSET__SHIFT                    0<br>
+#define NV17_MPEG_CMD_SURFACE_OFFSET__SHR                      5<br>
+#define NV17_MPEG_CMD_SURFACE_PLANE__MASK                      0x01000000<br>
+#define NV17_MPEG_CMD_SURFACE_PLANE__SHIFT                     24<br>
+#define NV17_MPEG_CMD_SURFACE_PLANE_LUMA                       0x00000000<br>
+#define NV17_MPEG_CMD_SURFACE_PLANE_CHROMA                     0x01000000<br>
+#define NV17_MPEG_CMD_SURFACE_INDEX__MASK                      0x0e000000<br>
+#define NV17_MPEG_CMD_SURFACE_INDEX__SHIFT                     25<br>
+#define NV17_MPEG_CMD_SURFACE_OP__MASK                         0xf0000000<br>
+#define NV17_MPEG_CMD_SURFACE_OP__SHIFT                                28<br>
+#define NV17_MPEG_CMD_SURFACE_OP_SURFACE                       0x20000000<br>
+#define NV17_MPEG_CMD_SIZE_WIDTH__MASK                         0x000007ff<br>
+#define NV17_MPEG_CMD_SIZE_WIDTH__SHIFT                                0<br>
+#define NV17_MPEG_CMD_SIZE_HEIGHT__MASK                                0x007ff000<br>
+#define NV17_MPEG_CMD_SIZE_HEIGHT__SHIFT                       12<br>
+#define NV17_MPEG_CMD_SIZE_OP__MASK                            0xff000000<br>
+#define NV17_MPEG_CMD_SIZE_OP__SHIFT                           24<br>
+#define NV17_MPEG_CMD_SIZE_OP_SIZE                             0x30000000<br>
+#define NV17_MPEG_CMD_PITCH_PITCH__MASK                                0x0000007f<br>
+#define NV17_MPEG_CMD_PITCH_PITCH__SHIFT                       0<br>
+#define NV17_MPEG_CMD_PITCH_OP__MASK                           0xff000000<br>
+#define NV17_MPEG_CMD_PITCH_OP__SHIFT                          24<br>
+#define NV17_MPEG_CMD_PITCH_OP_PITCH                           0x31000000<br>
+#define NV17_MPEG_CMD_MODE_IDCT_ENABLE                         0x00000001<br>
+#define NV17_MPEG_CMD_MODE_IQ_ENABLE                           0x00000010<br>
+#define NV17_MPEG_CMD_MODE_OP__MASK                            0xff000000<br>
+#define NV17_MPEG_CMD_MODE_OP__SHIFT                           24<br>
+#define NV17_MPEG_CMD_MODE_OP_MODE                             0x32000000<br>
+#define NV17_MPEG_CMD_IQ_SETUP_QUANT_SCALE__MASK               0x000001fe<br>
+#define NV17_MPEG_CMD_IQ_SETUP_QUANT_SCALE__SHIFT              1<br>
+#define NV17_MPEG_CMD_IQ_SETUP_INTRA_DC_MULT__MASK             0x00001e00<br>
+#define NV17_MPEG_CMD_IQ_SETUP_INTRA_DC_MULT__SHIFT            9<br>
+#define NV17_MPEG_CMD_IQ_SETUP_UNK13__MASK                     0x00006000<br>
+#define NV17_MPEG_CMD_IQ_SETUP_UNK13__SHIFT                    13<br>
+#define NV17_MPEG_CMD_IQ_SETUP_OP__MASK                                0xf0000000<br>
+#define NV17_MPEG_CMD_IQ_SETUP_OP__SHIFT                       28<br>
+#define NV17_MPEG_CMD_IQ_SETUP_OP_IQ_SETUP                     0x40000000<br>
+#define NV17_MPEG_CMD_IQ_MATRIX_INTRA                          0x00000001<br>
+#define NV17_MPEG_CMD_IQ_MATRIX_OP__MASK                       0xf0000000<br>
+#define NV17_MPEG_CMD_IQ_MATRIX_OP__SHIFT                      28<br>
+#define NV17_MPEG_CMD_IQ_MATRIX_OP_IQ_MATRIX                   0x50000000<br>
+#define NV17_MPEG_CMD_BLOCK_DATA_INTRA                         0x00000001<br>
+#define NV17_MPEG_CMD_BLOCK_DATA_OP__MASK                      0xf0000000<br>
+#define NV17_MPEG_CMD_BLOCK_DATA_OP__SHIFT                     28<br>
+#define NV17_MPEG_CMD_BLOCK_DATA_OP_BLOCK_DATA                 0x60000000<br>
+#define NV17_MPEG_BLOCK_DATA_LAST                              0x00000001<br>
+#define NV17_MPEG_BLOCK_DATA_IDX__MASK                         0x0000003e<br>
+#define NV17_MPEG_BLOCK_DATA_IDX__SHIFT                                1<br>
+#define NV17_MPEG_BLOCK_DATA_IDX__SHR                          1<br>
+#define NV17_MPEG_BLOCK_DATA_COORD1__MASK                      0x0003ffc0<br>
+#define NV17_MPEG_BLOCK_DATA_COORD1__SHIFT                     6<br>
+#define NV17_MPEG_BLOCK_DATA_COORD1_FORCE_0                    0x00010000<br>
+#define NV17_MPEG_BLOCK_DATA_COORD0__MASK                      0x7ff80000<br>
+#define NV17_MPEG_BLOCK_DATA_COORD0__SHIFT                     19<br>
+#define NV17_MPEG_BLOCK_DATA_COORD0_FORCE_0                    0x80000000<br>
+#define NV17_MPEG_CMD_SYNC_INTR                                        0x00000001<br>
+#define NV17_MPEG_CMD_SYNC_OP__MASK                            0xff000000<br>
+#define NV17_MPEG_CMD_SYNC_OP__SHIFT                           24<br>
+#define NV17_MPEG_CMD_SYNC_OP_SYNC                             0x70000000<br>
+#define NV17_MPEG_CMD_SEQUENCE_OP__MASK                                0xff000000<br>
+#define NV17_MPEG_CMD_SEQUENCE_OP__SHIFT                       24<br>
+#define NV17_MPEG_CMD_SEQUENCE_OP_SEQUENCE                     0x71000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_X_COORD__MASK           0x00008000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_X_COORD__SHIFT          15<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_X_COORD_ODD             0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_X_COORD_EVEN            0x00008000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_RUN__MASK               0x00010000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_RUN__SHIFT              16<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_RUN_DOUBLE              0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_RUN_SINGLE              0x00010000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FIELD__MASK             0x00020000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FIELD__SHIFT            17<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FIELD_TOP               0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FIELD_BOTTOM            0x00020000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_TYPE__MASK              0x00080000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_TYPE__SHIFT             19<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_TYPE_FIELD              0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_TYPE_FRAME              0x00080000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_SURFACE__MASK           0x00700000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_SURFACE__SHIFT          20<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FRAME_DCT_TYPE__MASK    0x00800000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FRAME_DCT_TYPE__SHIFT   23<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FRAME_DCT_TYPE_FRAME    0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_FRAME_DCT_TYPE_FIELD    0x00800000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_CBP__MASK               0x0c000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_CBP__SHIFT              26<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_OP__MASK                        0xf0000000<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_OP__SHIFT               28<br>
+#define NV17_MPEG_CMD_CHROMA_MB_HEADER_OP_CHROMA_MB_HEADER     0x80000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_X_COORD__MASK             0x00008000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_X_COORD__SHIFT            15<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_X_COORD_ODD               0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_X_COORD_EVEN              0x00008000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_RUN__MASK                 0x00010000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_RUN__SHIFT                        16<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_RUN_DOUBLE                        0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_RUN_SINGLE                        0x00010000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FIELD__MASK               0x00020000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FIELD__SHIFT              17<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FIELD_TOP                 0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FIELD_BOTTOM              0x00020000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_TYPE__MASK                        0x00080000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_TYPE__SHIFT               19<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_TYPE_FIELD                        0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_TYPE_FRAME                        0x00080000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_SURFACE__MASK             0x00700000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_SURFACE__SHIFT            20<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FRAME_DCT_TYPE__MASK      0x00800000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FRAME_DCT_TYPE__SHIFT     23<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FRAME_DCT_TYPE_FRAME      0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_FRAME_DCT_TYPE_FIELD      0x00800000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_CBP__MASK                 0x0f000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_CBP__SHIFT                        24<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_OP__MASK                  0xf0000000<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_OP__SHIFT                 28<br>
+#define NV17_MPEG_CMD_LUMA_MB_HEADER_OP_LUMA_MB_HEADER         0x90000000<br>
+#define NV17_MPEG_CMD_MB_COORDS_X__MASK                                0x000007ff<br>
+#define NV17_MPEG_CMD_MB_COORDS_X__SHIFT                       0<br>
+#define NV17_MPEG_CMD_MB_COORDS_Y__MASK                                0x007ff000<br>
+#define NV17_MPEG_CMD_MB_COORDS_Y__SHIFT                       12<br>
+#define NV17_MPEG_CMD_MB_COORDS_OP__MASK                       0xf0000000<br>
+#define NV17_MPEG_CMD_MB_COORDS_OP__SHIFT                      28<br>
+#define NV17_MPEG_CMD_MB_COORDS_OP_MB_COORDS                   0xa0000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT__MASK             0x00010000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT__SHIFT            16<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_1                 0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_2                 0x00010000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_FIELD__MASK             0x00020000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_FIELD__SHIFT            17<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_FIELD_TOP               0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_FIELD_BOTTOM            0x00020000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE__MASK              0x00080000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE__SHIFT             19<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FIELD              0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FRAME              0x00080000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_SURFACE__MASK           0x00700000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_SURFACE__SHIFT          20<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_IDX                     0x00800000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT__MASK          0x01000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT__SHIFT         24<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_FIELD          0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_HALF_MB                0x01000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_Y_HALF                  0x02000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_X_HALF                  0x04000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_DIRECTION__MASK         0x08000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_DIRECTION__SHIFT                27<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_DIRECTION_FORWARD       0x00000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_DIRECTION_BACKWARD      0x08000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_OP__MASK                        0xf0000000<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_OP__SHIFT               28<br>
+#define NV17_MPEG_CMD_CHROMA_MV_HEADER_OP_CHROMA_MV_HEADER     0xc0000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_COUNT__MASK               0x00010000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_COUNT__SHIFT              16<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_COUNT_1                   0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_COUNT_2                   0x00010000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_FIELD__MASK               0x00020000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_FIELD__SHIFT              17<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_FIELD_TOP                 0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_FIELD_BOTTOM              0x00020000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_TYPE__MASK                        0x00080000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_TYPE__SHIFT               19<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_TYPE_FIELD                        0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_TYPE_FRAME                        0x00080000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_SURFACE__MASK             0x00700000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_SURFACE__SHIFT            20<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_IDX                       0x00800000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_MV_SPLIT__MASK            0x01000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_MV_SPLIT__SHIFT           24<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_MV_SPLIT_FIELD            0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_MV_SPLIT_HALF_MB          0x01000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_Y_HALF                    0x02000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_X_HALF                    0x04000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_DIRECTION__MASK           0x08000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_DIRECTION__SHIFT          27<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_DIRECTION_FORWARD         0x00000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_DIRECTION_BACKWARD                0x08000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_OP__MASK                  0xf0000000<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_OP__SHIFT                 28<br>
+#define NV17_MPEG_CMD_LUMA_MV_HEADER_OP_LUMA_MV_HEADER         0xd0000000<br>
+#define NV17_MPEG_CMD_MV_COORDS_X__MASK                                0x000007ff<br>
+#define NV17_MPEG_CMD_MV_COORDS_X__SHIFT                       0<br>
+#define NV17_MPEG_CMD_MV_COORDS_Y__MASK                                0x007ff000<br>
+#define NV17_MPEG_CMD_MV_COORDS_Y__SHIFT                       12<br>
+#define NV17_MPEG_CMD_MV_COORDS_OP__MASK                       0xf0000000<br>
+#define NV17_MPEG_CMD_MV_COORDS_OP__SHIFT                      28<br>
+#define NV17_MPEG_CMD_MV_COORDS_OP_MV_COORDS                   0xe0000000<br>
+<br>
+#endif /* ___RNNDB_NV17_MPEG_XML */<br>
diff --git a/src/gallium/drivers/nouveau/nv31_mpeg.xml.h b/src/gallium/drivers/nouveau/nv31_mpeg.xml.h<br>
new file mode 100644<br>
index 0000000..a8c1e32<br>
--- /dev/null<br>
+++ b/src/gallium/drivers/nouveau/nv31_mpeg.xml.h<br>
@@ -0,0 +1,130 @@<br>
+#ifndef ___RNNDB_NV31_MPEG_XML<br>
+#define ___RNNDB_NV31_MPEG_XML<br>
+<br>
+/* Autogenerated file, DO NOT EDIT manually!<br>
+<br>
+This file was generated by the rules-ng-ng headergen tool in this git repository:<br>
+<a href="http://0x04.net/cgit/index.cgi/rules-ng-ng" target="_blank">http://0x04.net/cgit/index.cgi/rules-ng-ng</a><br>
+git clone git://<a href="http://0x04.net/rules-ng-ng" target="_blank">0x04.net/rules-ng-ng</a><br>
+<br>
+The rules-ng-ng source files this header was generated from are:<br>
+- ../rnndb/nv31_mpeg.xml  (   2269 bytes, from 2011-08-02 11:17:20)<br>
+- ../rnndb/copyright.xml  (   6452 bytes, from 2011-07-15 12:42:43)<br>
+- ../rnndb/nvchipsets.xml (   3617 bytes, from 2011-07-22 11:37:48)<br>
+- ../rnndb/nv_object.xml  (  12672 bytes, from 2011-07-15 12:42:43)<br>
+- ../rnndb/nv_defs.xml    (   4437 bytes, from 2011-07-15 12:42:43)<br>
+- ../rnndb/nv50_defs.xml  (   5468 bytes, from 2011-07-15 12:42:43)<br>
+<br>
+Copyright (C) 2006-2011 by the following authors:<br>
+- Artur Huillet &lt;<a href="mailto:arthur.huillet@free.fr">arthur.huillet@free.fr</a>&gt; (ahuillet)<br>
+- Ben Skeggs (darktama, darktama_)<br>
+- B. R. &lt;<a href="mailto:koala_br@users.sourceforge.net">koala_br@users.sourceforge.net</a>&gt; (koala_br)<br>
+- Carlos Martin &lt;<a href="mailto:carlosmn@users.sf.net">carlosmn@users.sf.net</a>&gt; (carlosmn)<br>
+- Christoph Bumiller &lt;<a href="mailto:e0425955@student.tuwien.ac.at">e0425955@student.tuwien.ac.at</a>&gt; (calim, chrisbmr)<br>
+- Dawid Gajownik &lt;<a href="mailto:gajownik@users.sf.net">gajownik@users.sf.net</a>&gt; (gajownik)<br>
+- Dmitry Baryshkov<br>
+- Dmitry Eremin-Solenikov &lt;<a href="mailto:lumag@users.sf.net">lumag@users.sf.net</a>&gt; (lumag)<br>
+- EdB &lt;<a href="mailto:edb_@users.sf.net">edb_@users.sf.net</a>&gt; (edb_)<br>
+- Erik Waling &lt;<a href="mailto:erikwailing@users.sf.net">erikwailing@users.sf.net</a>&gt; (erikwaling)<br>
+- Francisco Jerez &lt;<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>&gt; (curro)<br>
+- imirkin &lt;<a href="mailto:imirkin@users.sf.net">imirkin@users.sf.net</a>&gt; (imirkin)<br>
+- jb17bsome &lt;<a href="mailto:jb17bsome@bellsouth.net">jb17bsome@bellsouth.net</a>&gt; (jb17bsome)<br>
+- Jeremy Kolb &lt;<a href="mailto:kjeremy@users.sf.net">kjeremy@users.sf.net</a>&gt; (kjeremy)<br>
+- Laurent Carlier &lt;<a href="mailto:lordheavym@gmail.com">lordheavym@gmail.com</a>&gt; (lordheavy)<br>
+- Luca Barbieri &lt;<a href="mailto:luca@luca-barbieri.com">luca@luca-barbieri.com</a>&gt; (lb, lb1)<br>
+- Maarten Maathuis &lt;<a href="mailto:madman2003@gmail.com">madman2003@gmail.com</a>&gt; (stillunknown)<br>
+- Marcin Kościelnicki &lt;<a href="mailto:koriakin@0x04.net">koriakin@0x04.net</a>&gt; (mwk, koriakin)<br>
+- Mark Carey &lt;<a href="mailto:mark.carey@gmail.com">mark.carey@gmail.com</a>&gt; (careym)<br>
+- Matthieu Castet &lt;<a href="mailto:matthieu.castet@parrot.com">matthieu.castet@parrot.com</a>&gt; (mat-c)<br>
+- nvidiaman &lt;<a href="mailto:nvidiaman@users.sf.net">nvidiaman@users.sf.net</a>&gt; (nvidiaman)<br>
+- Patrice Mandin &lt;<a href="mailto:patmandin@gmail.com">patmandin@gmail.com</a>&gt; (pmandin, pmdata)<br>
+- Pekka Paalanen &lt;<a href="mailto:pq@iki.fi">pq@iki.fi</a>&gt; (pq, ppaalanen)<br>
+- Peter Popov &lt;<a href="mailto:ironpeter@users.sf.net">ironpeter@users.sf.net</a>&gt; (ironpeter)<br>
+- Richard Hughes &lt;<a href="mailto:hughsient@users.sf.net">hughsient@users.sf.net</a>&gt; (hughsient)<br>
+- Rudi Cilibrasi &lt;<a href="mailto:cilibrar@users.sf.net">cilibrar@users.sf.net</a>&gt; (cilibrar)<br>
+- Serge Martin<br>
+- Simon Raffeiner<br>
+- Stephane Loeuillet &lt;<a href="mailto:leroutier@users.sf.net">leroutier@users.sf.net</a>&gt; (leroutier)<br>
+- Stephane Marchesin &lt;<a href="mailto:stephane.marchesin@gmail.com">stephane.marchesin@gmail.com</a>&gt; (marcheu)<br>
+- sturmflut &lt;<a href="mailto:sturmflut@users.sf.net">sturmflut@users.sf.net</a>&gt; (sturmflut)<br>
+- Sylvain Munaut &lt;tnt@246tNt.com&gt;<br>
+- Victor Stinner &lt;<a href="mailto:victor.stinner@haypocalc.com">victor.stinner@haypocalc.com</a>&gt; (haypo)<br>
+- Wladmir van der Laan &lt;<a href="mailto:laanwj@gmail.com">laanwj@gmail.com</a>&gt; (miathan6)<br>
+- Younes Manton &lt;<a href="mailto:younes.m@gmail.com">younes.m@gmail.com</a>&gt; (ymanton)<br>
+<br>
+Permission is hereby granted, free of charge, to any person obtaining<br>
+a copy of this software and associated documentation files (the<br>
+&quot;Software&quot;), to deal in the Software without restriction, including<br>
+without limitation the rights to use, copy, modify, merge, publish,<br>
+distribute, sublicense, and/or sell copies of the Software, and to<br>
+permit persons to whom the Software is furnished to do so, subject to<br>
+the following conditions:<br>
+<br>
+The above copyright notice and this permission notice (including the<br>
+next paragraph) shall be included in all copies or substantial<br>
+portions of the Software.<br>
+<br>
+THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,<br>
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.<br>
+IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE<br>
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION<br>
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION<br>
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
+*/<br>
+<br>
+<br>
+<br>
+#define NV31_MPEG_PITCH                                                0x00000160<br>
+#define NV31_MPEG_PITCH_PITCH__MASK                            0x00001fff<br>
+#define NV31_MPEG_PITCH_PITCH__SHIFT                           0<br>
+#define NV31_MPEG_PITCH_UNK                                    0x00010000<br>
+<br>
+#define NV31_MPEG_SIZE                                         0x00000164<br>
+#define NV31_MPEG_SIZE_W__MASK                                 0x0000ffff<br>
+#define NV31_MPEG_SIZE_W__SHIFT                                        0<br>
+#define NV31_MPEG_SIZE_H__MASK                                 0xffff0000<br>
+#define NV31_MPEG_SIZE_H__SHIFT                                        16<br>
+<br>
+#define NV31_MPEG_DMA_CMD                                      0x00000190<br>
+<br>
+#define NV31_MPEG_DMA_DATA                                     0x000001a0<br>
+<br>
+#define NV31_MPEG_DMA_IMAGE                                    0x000001b0<br>
+<br>
+#define NV84_MPEG_DMA_QUERY                                    0x000001c0<br>
+<br>
+#define NV31_MPEG_IMAGE_Y_OFFSET(i0)                          (0x00000200 + 0x8*(i0))<br>
+#define NV31_MPEG_IMAGE_Y_OFFSET__ESIZE                                0x00000008<br>
+#define NV31_MPEG_IMAGE_Y_OFFSET__LEN                          0x00000008<br>
+<br>
+#define NV31_MPEG_IMAGE_C_OFFSET(i0)                          (0x00000204 + 0x8*(i0))<br>
+#define NV31_MPEG_IMAGE_C_OFFSET__ESIZE                                0x00000008<br>
+#define NV31_MPEG_IMAGE_C_OFFSET__LEN                          0x00000008<br>
+<br>
+#define NV31_MPEG_FORMAT                                       0x00000310<br>
+#define NV31_MPEG_FORMAT_DATA_FORMAT__MASK                     0x00000001<br>
+#define NV31_MPEG_FORMAT_DATA_FORMAT__SHIFT                    0<br>
+#define NV31_MPEG_FORMAT_DATA_FORMAT_S16                       0x00000000<br>
+#define NV31_MPEG_FORMAT_DATA_FORMAT_S8                                0x00000001<br>
+#define NV31_MPEG_FORMAT_UNK8                                  0x00000100<br>
+<br>
+#define NV31_MPEG_IDCT_ENABLE                                  0x00000314<br>
+<br>
+<br>
+#define NV84_MPEG_QUERY_OFFSET                                 0x0000031c<br>
+<br>
+#define NV84_MPEG_QUERY_COUNTER                                        0x00000320<br>
+<br>
+#define NV31_MPEG_CMD_OFFSET                                   0x00000380<br>
+<br>
+#define NV31_MPEG_CMD_SIZE                                     0x00000384<br>
+<br>
+#define NV31_MPEG_DATA_OFFSET                                  0x0000038c<br>
+<br>
+#define NV31_MPEG_DATA_SIZE                                    0x00000390<br>
+<br>
+#define NV31_MPEG_EXEC                                         0x00000394<br>
+<br>
+<br>
+#endif /* ___RNNDB_NV31_MPEG_XML */<br>
diff --git a/src/gallium/drivers/nvfx/nvfx_context.c b/src/gallium/drivers/nvfx/nvfx_context.c<br>
index e2cdcf6..37425b1 100644<br>
--- a/src/gallium/drivers/nvfx/nvfx_context.c<br>
+++ b/src/gallium/drivers/nvfx/nvfx_context.c<br>
@@ -90,9 +90,6 @@ nvfx_create(struct pipe_screen *pscreen, void *priv)<br>
        nvfx-&gt;pipe.clear = nvfx_clear;<br>
        nvfx-&gt;pipe.flush = nvfx_flush;<br>
<br>
-       nvfx-&gt;pipe.create_video_decoder = vl_create_decoder;<br>
-       nvfx-&gt;pipe.create_video_buffer = vl_video_buffer_create;<br>
-<br>
        nvfx-&gt;is_nv4x = screen-&gt;is_nv4x;<br>
        nvfx-&gt;use_nv4x = screen-&gt;use_nv4x;<br>
        /* TODO: it seems that nv30 might have fixed function clipping usable with vertex programs<br>
@@ -126,6 +123,7 @@ nvfx_create(struct pipe_screen *pscreen, void *priv)<br>
        nvfx-&gt;relocs_needed = NVFX_RELOCATE_ALL;<br>
<br>
        LIST_INITHEAD(&amp;nvfx-&gt;render_cache);<br>
+       nvfx_context_init_vdec(nvfx);<br>
<br>
        return &amp;nvfx-&gt;pipe;<br>
 }<br>
diff --git a/src/gallium/drivers/nvfx/nvfx_context.h b/src/gallium/drivers/nvfx/nvfx_context.h<br>
index dad912b..cb40a52 100644<br>
--- a/src/gallium/drivers/nvfx/nvfx_context.h<br>
+++ b/src/gallium/drivers/nvfx/nvfx_context.h<br>
@@ -340,6 +340,8 @@ extern void nvfx_init_vertprog_functions(struct nvfx_context *nvfx);<br>
 /* nvfx_push.c */<br>
 extern void nvfx_push_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info);<br>
<br>
+extern void nvfx_context_init_vdec(struct nvfx_context *);<br>
+<br>
 static inline void nvfx_emit_vtx_attr(struct nouveau_channel* chan,<br>
                struct nouveau_grobj *eng3d, unsigned attrib, const float* v,<br>
                unsigned ncomp)<br>
--<br>
1.7.6<br>
<br>
<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div>