Merge remote branch 'origin/master' into pipe-video
authorYounes Manton <younes.m@gmail.com>
Sun, 7 Mar 2010 17:47:45 +0000 (12:47 -0500)
committerYounes Manton <younes.m@gmail.com>
Fri, 12 Mar 2010 06:37:49 +0000 (01:37 -0500)
Conflicts:
configure.ac
src/gallium/auxiliary/vl/Makefile
src/gallium/auxiliary/vl/SConscript
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/drivers/nouveau/nouveau_winsys.h
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/include/pipe/p_video_state.h
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/xorg/xvmc/surface.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/g3dvl/nouveau/Makefile

17 files changed:
1  2 
configure.ac
src/gallium/auxiliary/Makefile
src/gallium/auxiliary/SConscript
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/drivers/nv40/nv40_miptree.c
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/include/pipe/p_video_state.h
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/dri/dri_context.c
src/gallium/state_trackers/xorg/xvmc/surface.c
src/gallium/winsys/drm/nouveau/dri/Makefile
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/g3dvl/xlib/xsp_winsys.c

diff --cc configure.ac
@@@ -1242,21 -1354,19 +1354,37 @@@ if test "x$enable_gallium_nouveau" = xy
  fi
  
  dnl
++<<<<<<< HEAD
 +dnl Gallium G3DVL configuration
 +dnl
 +AC_ARG_ENABLE([gallium-g3dvl],
 +    [AS_HELP_STRING([--enable-gallium-g3dvl],
 +        [build gallium g3dvl @<:@default=disabled@:>@])],
 +    [enable_gallium_g3dvl="$enableval"],
 +    [enable_gallium_g3dvl=no])
 +if test "x$enable_gallium_g3dvl" = xyes; then
 +    vl_winsys_dirs=""
 +    for dir in $GALLIUM_WINSYS_DIRS; do
 +        vl_winsys_dirs="$vl_winsys_dirs g3dvl/$dir"
 +    done
 +    GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $vl_winsys_dirs"
 +fi
 +
++=======
+ dnl Gallium swrast configuration
+ dnl
+ AC_ARG_ENABLE([gallium-swrast],
+     [AS_HELP_STRING([--enable-gallium-swrast],
+         [build gallium swrast @<:@default=disabled@:>@])],
+     [enable_gallium_swrast="$enableval"],
+     [enable_gallium_swrast=auto])
+ if test "x$enable_gallium_swrast" = xyes; then
+     GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast"
+ fi
+ dnl prepend CORE_DIRS to SRC_DIRS
+ SRC_DIRS="$CORE_DIRS $SRC_DIRS"
++>>>>>>> origin/master
  
  dnl Restore LDFLAGS and CPPFLAGS
  LDFLAGS="$_SAVE_LDFLAGS"
  TOP = ../../..
  include $(TOP)/configs/current
  
- SUBDIRS = $(GALLIUM_AUXILIARY_DIRS)
+ LIBNAME = gallium
+ C_SOURCES = \
+       cso_cache/cso_context.c \
+       cso_cache/cso_cache.c \
+       cso_cache/cso_hash.c \
+       draw/draw_context.c \
+       draw/draw_gs.c \
+       draw/draw_pipe.c \
+       draw/draw_pipe_aaline.c \
+       draw/draw_pipe_aapoint.c \
+       draw/draw_pipe_clip.c \
+       draw/draw_pipe_cull.c \
+       draw/draw_pipe_flatshade.c \
+       draw/draw_pipe_offset.c \
+       draw/draw_pipe_pstipple.c \
+       draw/draw_pipe_stipple.c \
+       draw/draw_pipe_twoside.c \
+       draw/draw_pipe_unfilled.c \
+       draw/draw_pipe_util.c \
+       draw/draw_pipe_validate.c \
+       draw/draw_pipe_vbuf.c \
+       draw/draw_pipe_wide_line.c \
+       draw/draw_pipe_wide_point.c \
+       draw/draw_pt.c \
+       draw/draw_pt_elts.c \
+       draw/draw_pt_emit.c \
+       draw/draw_pt_fetch.c \
+       draw/draw_pt_fetch_emit.c \
+       draw/draw_pt_fetch_shade_emit.c \
+       draw/draw_pt_fetch_shade_pipeline.c \
+       draw/draw_pt_post_vs.c \
+       draw/draw_pt_util.c \
+       draw/draw_pt_varray.c \
+       draw/draw_pt_vcache.c \
+       draw/draw_vertex.c \
+       draw/draw_vs.c \
+       draw/draw_vs_varient.c \
+       draw/draw_vs_aos.c \
+       draw/draw_vs_aos_io.c \
+       draw/draw_vs_aos_machine.c \
+       draw/draw_vs_exec.c \
+       draw/draw_vs_llvm.c \
+       draw/draw_vs_ppc.c \
+       draw/draw_vs_sse.c \
+       indices/u_indices_gen.c \
+       indices/u_unfilled_gen.c \
+       os/os_misc.c \
+       os/os_stream_log.c \
+       os/os_stream_stdc.c \
+       os/os_stream_str.c \
+       os/os_stream_null.c \
+       os/os_time.c \
+       pipebuffer/pb_buffer_fenced.c \
+       pipebuffer/pb_buffer_malloc.c \
+       pipebuffer/pb_bufmgr_alt.c \
+       pipebuffer/pb_bufmgr_cache.c \
+       pipebuffer/pb_bufmgr_debug.c \
+       pipebuffer/pb_bufmgr_mm.c \
+       pipebuffer/pb_bufmgr_ondemand.c \
+       pipebuffer/pb_bufmgr_pool.c \
+       pipebuffer/pb_bufmgr_slab.c \
+       pipebuffer/pb_validate.c \
+       rbug/rbug_connection.c \
+       rbug/rbug_core.c \
+       rbug/rbug_texture.c \
+       rbug/rbug_context.c \
+       rbug/rbug_shader.c \
+       rbug/rbug_demarshal.c \
+       rtasm/rtasm_cpu.c \
+       rtasm/rtasm_execmem.c \
+       rtasm/rtasm_x86sse.c \
+       rtasm/rtasm_ppc.c \
+       rtasm/rtasm_ppc_spe.c \
+       tgsi/tgsi_sanity.c \
+       tgsi/tgsi_build.c \
+       tgsi/tgsi_dump.c \
+       tgsi/tgsi_exec.c \
+       tgsi/tgsi_info.c \
+       tgsi/tgsi_iterate.c \
+       tgsi/tgsi_parse.c \
+       tgsi/tgsi_ppc.c \
+       tgsi/tgsi_scan.c \
+       tgsi/tgsi_sse2.c \
+       tgsi/tgsi_text.c \
+       tgsi/tgsi_transform.c \
+       tgsi/tgsi_ureg.c \
+       tgsi/tgsi_util.c \
+       translate/translate_generic.c \
+       translate/translate_sse.c \
+       translate/translate.c \
+       translate/translate_cache.c \
+       util/u_debug.c \
+       util/u_debug_symbol.c \
+       util/u_debug_stack.c \
+       util/u_dump_defines.c \
+       util/u_dump_state.c \
+       util/u_bitmask.c \
+       util/u_blit.c \
+       util/u_blitter.c \
+       util/u_cache.c \
+       util/u_cpu_detect.c \
+       util/u_dl.c \
+       util/u_draw_quad.c \
+       util/u_format_access.c \
+       util/u_format_table.c \
+       util/u_gen_mipmap.c \
+       util/u_handle_table.c \
+       util/u_hash_table.c \
+       util/u_hash.c \
+       util/u_keymap.c \
+       util/u_linear.c \
+       util/u_network.c \
+       util/u_math.c \
+       util/u_mm.c \
+       util/u_rect.c \
+       util/u_ringbuffer.c \
+       util/u_simple_shaders.c \
+       util/u_snprintf.c \
+       util/u_surface.c \
+       util/u_texture.c \
+       util/u_tile.c \
+       util/u_timed_winsys.c \
+       util/u_upload_mgr.c \
+       util/u_simple_screen.c \
+       vl/vl_bitstream_parser.c \
+       vl/vl_mpeg12_mc_renderer.c \
+       vl/vl_compositor.c \
 -      vl/vl_csc.c \
 -      vl/vl_shader_build.c
++      vl/vl_csc.c
+ GALLIVM_SOURCES = \
+         gallivm/lp_bld_alpha.c \
+         gallivm/lp_bld_arit.c \
+         gallivm/lp_bld_blend_aos.c \
+         gallivm/lp_bld_blend_logicop.c \
+         gallivm/lp_bld_blend_soa.c \
+         gallivm/lp_bld_const.c \
+         gallivm/lp_bld_conv.c \
+         gallivm/lp_bld_debug.c \
+         gallivm/lp_bld_depth.c \
+         gallivm/lp_bld_flow.c \
+         gallivm/lp_bld_format_aos.c \
+         gallivm/lp_bld_format_query.c \
+         gallivm/lp_bld_format_soa.c \
+         gallivm/lp_bld_interp.c \
+         gallivm/lp_bld_intr.c \
+         gallivm/lp_bld_logic.c \
+         gallivm/lp_bld_pack.c \
+         gallivm/lp_bld_sample.c \
+         gallivm/lp_bld_sample_soa.c \
+         gallivm/lp_bld_struct.c \
+         gallivm/lp_bld_swizzle.c \
+         gallivm/lp_bld_tgsi_soa.c \
+         gallivm/lp_bld_type.c
+ GALLIVM_CPP_SOURCES = \
+         gallivm/lp_bld_init.cpp
+ GENERATED_SOURCES = \
+       indices/u_indices_gen.c \
+       indices/u_unfilled_gen.c \
+       util/u_format_access.c \
+       util/u_format_pack.h \
+       util/u_format_table.c
+ ifeq ($(MESA_LLVM),1)
+ C_SOURCES += \
+       $(GALLIVM_SOURCES)
+ CPP_SOURCES += \
+       $(GALLIVM_CPP_SOURCES)
+ endif
+ LIBRARY_DEFINES += -D__STDC_CONSTANT_MACROS
+ include ../Makefile.template
+ indices/u_indices_gen.c: indices/u_indices_gen.py
+       python $< > $@
+ indices/u_unfilled_gen.c: indices/u_unfilled_gen.py
+       python $< > $@
+ util/u_format_table.c: util/u_format_table.py util/u_format_parse.py util/u_format.csv
+       python util/u_format_table.py util/u_format.csv > $@
+ util/u_format_pack.h: util/u_format_pack.py util/u_format_parse.py util/u_format.csv
+       python util/u_format_pack.py util/u_format.csv > $@
+ util/u_format_access.c: util/u_format_access.py util/u_format_parse.py util/u_format.csv
+       python util/u_format_access.py util/u_format.csv > $@
  
- default install clean:
-       @for dir in $(SUBDIRS) ; do \
-               if [ -d $$dir ] ; then \
-                       (cd $$dir && $(MAKE) $@) || exit 1; \
-               fi \
-       done
index 0000000,f365c4b..f0f3e78
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,210 +1,209 @@@
 -    'vl/vl_shader_build.c',
+ Import('*')
+ from sys import executable as python_cmd
+ env.Append(CPPPATH = [
+     'indices',
+     'util',
+ ])
+ env.CodeGenerate(
+     target = 'indices/u_indices_gen.c', 
+     script = 'indices/u_indices_gen.py', 
+     source = [],
+     command = python_cmd + ' $SCRIPT > $TARGET'
+ )
+ env.CodeGenerate(
+     target = 'indices/u_unfilled_gen.c', 
+     script = 'indices/u_unfilled_gen.py', 
+     source = [],
+     command = python_cmd + ' $SCRIPT > $TARGET'
+ )
+ env.CodeGenerate(
+     target = 'util/u_format_table.c',
+     script = 'util/u_format_table.py',
+     source = ['util/u_format.csv'],
+     command = 'python $SCRIPT $SOURCE > $TARGET'
+ )
+ env.CodeGenerate(
+     target = File('util/u_format_pack.h').srcnode(),
+     script = 'util/u_format_pack.py',
+     source = ['util/u_format.csv'],
+     command = 'python $SCRIPT $SOURCE > $TARGET'
+ )
+ env.CodeGenerate(
+     target = 'util/u_format_access.c',
+     script = 'util/u_format_access.py',
+     source = ['util/u_format.csv'],
+     command = 'python $SCRIPT $SOURCE > $TARGET'
+ )
+ source = [
+     'cso_cache/cso_context.c',
+     'cso_cache/cso_cache.c',
+     'cso_cache/cso_hash.c',
+     'draw/draw_context.c',
+     'draw/draw_pipe.c',
+     'draw/draw_pipe_aaline.c',
+     'draw/draw_pipe_aapoint.c',
+     'draw/draw_pipe_clip.c',
+     'draw/draw_pipe_cull.c',
+     'draw/draw_pipe_flatshade.c',
+     'draw/draw_pipe_offset.c',
+     'draw/draw_pipe_pstipple.c',
+     'draw/draw_pipe_stipple.c',
+     'draw/draw_pipe_twoside.c',
+     'draw/draw_pipe_unfilled.c',
+     'draw/draw_pipe_util.c',
+     'draw/draw_pipe_validate.c',
+     'draw/draw_pipe_vbuf.c',
+     'draw/draw_pipe_wide_line.c',
+     'draw/draw_pipe_wide_point.c',
+     'draw/draw_pt.c',
+     'draw/draw_pt_elts.c',
+     'draw/draw_pt_emit.c',
+     'draw/draw_pt_fetch.c',
+     'draw/draw_pt_fetch_emit.c',
+     'draw/draw_pt_fetch_shade_emit.c',
+     'draw/draw_pt_fetch_shade_pipeline.c',
+     'draw/draw_pt_post_vs.c',
+     'draw/draw_pt_util.c',
+     'draw/draw_pt_varray.c',
+     'draw/draw_pt_vcache.c',
+     'draw/draw_vertex.c',
+     'draw/draw_vs.c',
+     'draw/draw_vs_aos.c',
+     'draw/draw_vs_aos_io.c',
+     'draw/draw_vs_aos_machine.c',
+     'draw/draw_vs_exec.c',
+     'draw/draw_vs_llvm.c',
+     'draw/draw_vs_ppc.c',
+     'draw/draw_vs_sse.c',
+     'draw/draw_vs_varient.c',
+     'draw/draw_gs.c',
+     #'indices/u_indices.c',
+     #'indices/u_unfilled_indices.c',
+     'indices/u_indices_gen.c',
+     'indices/u_unfilled_gen.c',
+     'os/os_misc.c',
+     'os/os_stream_log.c',
+     'os/os_stream_stdc.c',
+     'os/os_stream_str.c',
+     'os/os_stream_null.c',
+     'os/os_time.c',
+     'pipebuffer/pb_buffer_fenced.c',
+     'pipebuffer/pb_buffer_malloc.c',
+     'pipebuffer/pb_bufmgr_alt.c',
+     'pipebuffer/pb_bufmgr_cache.c',
+     'pipebuffer/pb_bufmgr_debug.c',
+     'pipebuffer/pb_bufmgr_mm.c',
+     'pipebuffer/pb_bufmgr_ondemand.c',
+     'pipebuffer/pb_bufmgr_pool.c',
+     'pipebuffer/pb_bufmgr_slab.c',
+     'pipebuffer/pb_validate.c',
+     'rbug/rbug_core.c',
+     'rbug/rbug_shader.c',
+     'rbug/rbug_context.c',
+     'rbug/rbug_texture.c',
+     'rbug/rbug_demarshal.c',
+     'rbug/rbug_connection.c',
+     'rtasm/rtasm_cpu.c',
+     'rtasm/rtasm_execmem.c',
+     'rtasm/rtasm_x86sse.c',
+     'rtasm/rtasm_ppc.c',
+     'rtasm/rtasm_ppc_spe.c',
+     'tgsi/tgsi_build.c',
+     'tgsi/tgsi_dump.c',
+     'tgsi/tgsi_exec.c',
+     'tgsi/tgsi_info.c',
+     'tgsi/tgsi_iterate.c',
+     'tgsi/tgsi_parse.c',
+     'tgsi/tgsi_sanity.c',
+     'tgsi/tgsi_scan.c',
+     'tgsi/tgsi_ppc.c',
+     'tgsi/tgsi_sse2.c',
+     'tgsi/tgsi_text.c',
+     'tgsi/tgsi_transform.c',
+     'tgsi/tgsi_ureg.c',
+     'tgsi/tgsi_util.c',
+     'translate/translate_generic.c',
+     'translate/translate_sse.c',
+     'translate/translate.c',
+     'translate/translate_cache.c',
+     'util/u_bitmask.c',
+     'util/u_blit.c',
+     'util/u_blitter.c',
+     'util/u_cache.c',
+     'util/u_cpu_detect.c',
+     'util/u_debug.c',
+     'util/u_debug_memory.c',
+     'util/u_debug_stack.c',
+     'util/u_debug_symbol.c',
+     'util/u_dump_defines.c',
+     'util/u_dump_state.c',
+     'util/u_dl.c',
+     'util/u_draw_quad.c',
+     'util/u_format_access.c',
+     'util/u_format_table.c',
+     'util/u_gen_mipmap.c',
+     'util/u_handle_table.c',
+     'util/u_hash.c',
+     'util/u_hash_table.c',
+     'util/u_keymap.c',
+     'util/u_network.c',
+     'util/u_math.c',
+     'util/u_mm.c',
+     'util/u_rect.c',
+     'util/u_ringbuffer.c',
+     'util/u_simple_shaders.c',
+     'util/u_snprintf.c',
+     'util/u_surface.c',
+     'util/u_texture.c',
+     'util/u_tile.c',
+     'util/u_timed_winsys.c',
+     'util/u_upload_mgr.c',
+     'util/u_simple_screen.c',
+     'vl/vl_bitstream_parser.c',
+     'vl/vl_mpeg12_mc_renderer.c',
+     'vl/vl_compositor.c',
+     'vl/vl_csc.c',
+ ]
+ if drawllvm:
+     source += [
+     'gallivm/lp_bld_alpha.c',
+     'gallivm/lp_bld_arit.c',
+     'gallivm/lp_bld_blend_aos.c',
+     'gallivm/lp_bld_blend_logicop.c',
+     'gallivm/lp_bld_blend_soa.c',
+     'gallivm/lp_bld_const.c',
+     'gallivm/lp_bld_conv.c',
+     'gallivm/lp_bld_debug.c',
+     'gallivm/lp_bld_depth.c',
+     'gallivm/lp_bld_flow.c',
+     'gallivm/lp_bld_format_aos.c',
+     'gallivm/lp_bld_format_query.c',
+     'gallivm/lp_bld_format_soa.c',
+     'gallivm/lp_bld_interp.c',
+     'gallivm/lp_bld_intr.c',
+     'gallivm/lp_bld_logic.c',
+     'gallivm/lp_bld_init.cpp',
+     'gallivm/lp_bld_pack.c',
+     'gallivm/lp_bld_sample.c',
+     'gallivm/lp_bld_sample_soa.c',
+     'gallivm/lp_bld_struct.c',
+     'gallivm/lp_bld_swizzle.c',
+     'gallivm/lp_bld_tgsi_soa.c',
+     'gallivm/lp_bld_type.c',
+     ]
+ gallium = env.ConvenienceLibrary(
+     target = 'gallium',
+     source = source,
+ )
+ Export('gallium')
  #include "vl_compositor.h"
  #include <assert.h>
  #include <pipe/p_context.h>
- #include <pipe/p_inlines.h>
- #include <tgsi/tgsi_ureg.h>
+ #include <util/u_inlines.h>
 -#include <tgsi/tgsi_parse.h>
 -#include <tgsi/tgsi_build.h>
  #include <util/u_memory.h>
++#include <tgsi/tgsi_ureg.h>
  #include "vl_csc.h"
 -#include "vl_shader_build.h"
 -
 -struct vertex2f
 -{
 -   float x, y;
 -};
 -
 -struct vertex4f
 -{
 -   float x, y, z, w;
 -};
  
  struct vertex_shader_consts
  {
@@@ -209,15 -302,51 +208,17 @@@ init_buffers(struct vl_compositor *c
        c->pipe->screen,
        1,
        PIPE_BUFFER_USAGE_VERTEX,
 -      sizeof(struct vertex2f) * 4
 +      sizeof(struct vertex4f) * (VL_COMPOSITOR_MAX_LAYERS + 2) * 6
     );
  
 -   memcpy
 -   (
 -      pipe_buffer_map(c->pipe->screen, c->vertex_bufs[0].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
 -      surface_verts,
 -      sizeof(struct vertex2f) * 4
 -   );
 -
 -   pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[0].buffer);
 -
     c->vertex_elems[0].src_offset = 0;
+    c->vertex_elems[0].instance_divisor = 0;
     c->vertex_elems[0].vertex_buffer_index = 0;
     c->vertex_elems[0].nr_components = 2;
     c->vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
 -
 -   /*
 -    * Create our texcoord buffer and texcoord buffer element
 -    * Texcoord buffer contains the TCs for mapping the rendered surface to the 4 vertices
 -    */
 -   c->vertex_bufs[1].stride = sizeof(struct vertex2f);
 -   c->vertex_bufs[1].max_index = 3;
 -   c->vertex_bufs[1].buffer_offset = 0;
 -   c->vertex_bufs[1].buffer = pipe_buffer_create
 -   (
 -      c->pipe->screen,
 -      1,
 -      PIPE_BUFFER_USAGE_VERTEX,
 -      sizeof(struct vertex2f) * 4
 -   );
 -
 -   memcpy
 -   (
 -      pipe_buffer_map(c->pipe->screen, c->vertex_bufs[1].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
 -      surface_texcoords,
 -      sizeof(struct vertex2f) * 4
 -   );
 -
 -   pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[1].buffer);
 -
 -   c->vertex_elems[1].src_offset = 0;
 +   c->vertex_elems[1].src_offset = sizeof(struct vertex2f);
+    c->vertex_elems[1].instance_divisor = 0;
 -   c->vertex_elems[1].vertex_buffer_index = 1;
 +   c->vertex_elems[1].vertex_buffer_index = 0;
     c->vertex_elems[1].nr_components = 2;
     c->vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
  
  static void
  cleanup_buffers(struct vl_compositor *c)
  {
 -   unsigned i;
 -
     assert(c);
 -      
 -   for (i = 0; i < 2; ++i)
 -      pipe_buffer_reference(&c->vertex_bufs[i].buffer, NULL);
  
 -   pipe_buffer_reference(&c->vs_const_buf, NULL);
 +   pipe_buffer_reference(&c->vertex_buf.buffer, NULL);
-    pipe_buffer_reference(&c->fs_const_buf.buffer, NULL);
+    pipe_buffer_reference(&c->fs_const_buf, NULL);
  }
  
  bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
@@@ -504,18 -472,49 +505,18 @@@ void vl_compositor_render(struct vl_com
     compositor->viewport.translate[2] = 0;
     compositor->viewport.translate[3] = 0;
  
 -   compositor->scissor.maxx = compositor->fb_state.width;
 -   compositor->scissor.maxy = compositor->fb_state.height;
 -
     compositor->pipe->set_framebuffer_state(compositor->pipe, &compositor->fb_state);
     compositor->pipe->set_viewport_state(compositor->pipe, &compositor->viewport);
 -   compositor->pipe->set_scissor_state(compositor->pipe, &compositor->scissor);
     compositor->pipe->bind_fragment_sampler_states(compositor->pipe, 1, &compositor->sampler);
 -   compositor->pipe->set_fragment_sampler_textures(compositor->pipe, 1, &src_surface);
     compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
     compositor->pipe->bind_fs_state(compositor->pipe, compositor->fragment_shader);
 -   compositor->pipe->set_vertex_buffers(compositor->pipe, 2, compositor->vertex_bufs);
 +   compositor->pipe->set_vertex_buffers(compositor->pipe, 1, &compositor->vertex_buf);
     compositor->pipe->set_vertex_elements(compositor->pipe, 2, compositor->vertex_elems);
-    compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, &compositor->fs_const_buf);
 -   compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_VERTEX, 0, compositor->vs_const_buf);
+    compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, compositor->fs_const_buf);
  
 -   vs_consts = pipe_buffer_map
 -   (
 -      compositor->pipe->screen,
 -      compositor->vs_const_buf,
 -      PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
 -   );
 +   draw_layers(compositor, src_surface, src_area, dst_area);
  
 -   vs_consts->dst_scale.x = dst_area->w / (float)compositor->fb_state.cbufs[0]->width;
 -   vs_consts->dst_scale.y = dst_area->h / (float)compositor->fb_state.cbufs[0]->height;
 -   vs_consts->dst_scale.z = 1;
 -   vs_consts->dst_scale.w = 1;
 -   vs_consts->dst_trans.x = dst_area->x / (float)compositor->fb_state.cbufs[0]->width;
 -   vs_consts->dst_trans.y = dst_area->y / (float)compositor->fb_state.cbufs[0]->height;
 -   vs_consts->dst_trans.z = 0;
 -   vs_consts->dst_trans.w = 0;
 -
 -   vs_consts->src_scale.x = src_area->w / (float)src_surface->width0;
 -   vs_consts->src_scale.y = src_area->h / (float)src_surface->height0;
 -   vs_consts->src_scale.z = 1;
 -   vs_consts->src_scale.w = 1;
 -   vs_consts->src_trans.x = src_area->x / (float)src_surface->width0;
 -   vs_consts->src_trans.y = src_area->y / (float)src_surface->height0;
 -   vs_consts->src_trans.z = 0;
 -   vs_consts->src_trans.w = 0;
 -
 -   pipe_buffer_unmap(compositor->pipe->screen, compositor->vs_const_buf);
 -
 -   compositor->pipe->draw_arrays(compositor->pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
 +   assert(!compositor->dirty_bg && !compositor->dirty_layers);
     compositor->pipe->flush(compositor->pipe, PIPE_FLUSH_RENDER_CACHE, fence);
  
     pipe_surface_reference(&compositor->fb_state.cbufs[0], NULL);
@@@ -527,8 -526,7 +528,8 @@@ void vl_compositor_set_csc_matrix(struc
  
     memcpy
     (
-       pipe_buffer_map(compositor->pipe->screen, compositor->fs_const_buf.buffer,
 -      pipe_buffer_map(compositor->pipe->screen, compositor->fs_const_buf, PIPE_BUFFER_USAGE_CPU_WRITE),
++      pipe_buffer_map(compositor->pipe->screen, compositor->fs_const_buf,
 +                      PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD),
        mat,
        sizeof(struct fragment_shader_consts)
     );
@@@ -48,17 -44,10 +48,17 @@@ struct vl_composito
     void *vertex_shader;
     void *fragment_shader;
     struct pipe_viewport_state viewport;
 -   struct pipe_scissor_state scissor;
 -   struct pipe_vertex_buffer vertex_bufs[2];
 +   struct pipe_vertex_buffer vertex_buf;
     struct pipe_vertex_element vertex_elems[2];
-    struct pipe_constant_buffer fs_const_buf;
 -   struct pipe_buffer *vs_const_buf, *fs_const_buf;
++   struct pipe_buffer *fs_const_buf;
 +
 +   struct pipe_texture *bg;
 +   struct pipe_video_rect bg_src_rect;
 +   bool dirty_bg;
 +   struct pipe_texture *layers[VL_COMPOSITOR_MAX_LAYERS];
 +   struct pipe_video_rect layer_src_rects[VL_COMPOSITOR_MAX_LAYERS];
 +   struct pipe_video_rect layer_dst_rects[VL_COMPOSITOR_MAX_LAYERS];
 +   unsigned dirty_layers;
  };
  
  bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
  #include "vl_mpeg12_mc_renderer.h"
  #include <assert.h>
  #include <pipe/p_context.h>
- #include <pipe/p_inlines.h>
+ #include <util/u_inlines.h>
+ #include <util/u_format.h>
  #include <util/u_math.h>
  #include <util/u_memory.h>
 -#include <tgsi/tgsi_parse.h>
 -#include <tgsi/tgsi_build.h>
 -#include "vl_shader_build.h"
 +#include <tgsi/tgsi_ureg.h>
  
  #define DEFAULT_BUF_ALIGNMENT 1
  #define MACROBLOCK_WIDTH 16
@@@ -74,287 -97,574 +75,294 @@@ enum MACROBLOCK_TYP
     NUM_MACROBLOCK_TYPES
  };
  
 -static void
 +static bool
  create_intra_vert_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 50;
 -
 -   struct pipe_shader_state vs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src vpos, vtex[3];
 +   struct ureg_dst o_vpos, o_vtex[3];
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0              ; Vertex pos
 -    * decl i1              ; Luma texcoords
 -    * decl i2              ; Chroma Cb texcoords
 -    * decl i3              ; Chroma Cr texcoords
 -    */
 -   for (i = 0; i < 4; i++) {
 -      decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 +   shader = ureg_create(TGSI_PROCESSOR_VERTEX);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * decl o0              ; Vertex pos
 -    * decl o1              ; Luma texcoords
 -    * decl o2              ; Chroma Cb texcoords
 -    * decl o3              ; Chroma Cr texcoords
 -    */
 -   for (i = 0; i < 4; i++) {
 -      decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 +   vpos = ureg_DECL_vs_input(shader, 0);
 +   for (i = 0; i < 3; ++i)
 +      vtex[i] = ureg_DECL_vs_input(shader, i + 1);
 +   o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
 +   for (i = 0; i < 3; ++i)
 +      o_vtex[i] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, i + 1);
  
     /*
 -    * mov o0, i0           ; Move input vertex pos to output
 -    * mov o1, i1           ; Move input luma texcoords to output
 -    * mov o2, i2           ; Move input chroma Cb texcoords to output
 -    * mov o3, i3           ; Move input chroma Cr texcoords to output
 +    * o_vpos = vpos
 +    * o_vtex[0..2] = vtex[0..2]
      */
 -   for (i = 0; i < 4; ++i) {
 -      inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -   }
 +   ureg_MOV(shader, o_vpos, vpos);
 +   for (i = 0; i < 3; ++i)
 +      ureg_MOV(shader, o_vtex[i], vtex[i]);
  
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_END(shader);
  
 -   assert(ti <= max_tokens);
 +   r->i_vs = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->i_vs)
 +      return false;
  
 -   vs.tokens = tokens;
 -   r->i_vs = r->pipe->create_vs_state(r->pipe, &vs);
 -   free(tokens);
 +   return true;
  }
  
 -static void
 +static bool
  create_intra_frag_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 100;
 -
 -   struct pipe_shader_state fs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src tc[3];
 +   struct ureg_src sampler[3];
 +   struct ureg_dst texel, temp;
 +   struct ureg_dst fragment;
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0                      ; Luma texcoords
 -    * decl i1                      ; Chroma Cb texcoords
 -    * decl i2                      ; Chroma Cr texcoords
 -    */
 -   for (i = 0; i < 3; ++i) {
 -      decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /* decl c0                      ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */
 -   decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl o0                      ; Fragment color */
 -   decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl t0, t1 */
 -   decl = vl_decl_temps(0, 1);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * decl s0                      ; Sampler for luma texture
 -    * decl s1                      ; Sampler for chroma Cb texture
 -    * decl s2                      ; Sampler for chroma Cr texture
 -    */
 -   for (i = 0; i < 3; ++i) {
 -      decl = vl_decl_samplers(i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   for (i = 0; i < 3; ++i)  {
 +      tc[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, i + 1, TGSI_INTERPOLATE_LINEAR);
 +      sampler[i] = ureg_DECL_sampler(shader, i);
     }
 +   texel = ureg_DECL_temporary(shader);
 +   temp = ureg_DECL_temporary(shader);
 +   fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
  
     /*
 -    * tex2d t1, i0, s0             ; Read texel from luma texture
 -    * mov t0.x, t1.x               ; Move luma sample into .x component
 -    * tex2d t1, i1, s1             ; Read texel from chroma Cb texture
 -    * mov t0.y, t1.x               ; Move Cb sample into .y component
 -    * tex2d t1, i2, s2             ; Read texel from chroma Cr texture
 -    * mov t0.z, t1.x               ; Move Cr sample into .z component
 +    * texel.r = tex(tc[0], sampler[0])
 +    * texel.g = tex(tc[1], sampler[1])
 +    * texel.b = tex(tc[2], sampler[2])
 +    * fragment = texel * scale
      */
     for (i = 0; i < 3; ++i) {
 -      inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -      inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
 -      inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
 -      inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +      /* Nouveau can't writemask tex dst regs (yet?), do in two steps */
 +      ureg_TEX(shader, temp, TGSI_TEXTURE_2D, tc[i], sampler[i]);
 +      ureg_MOV(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), ureg_scalar(ureg_src(temp), TGSI_SWIZZLE_X));
     }
 +   ureg_MUL(shader, fragment, ureg_src(texel), ureg_scalar(ureg_imm1f(shader, SCALE_FACTOR_16_TO_9), TGSI_SWIZZLE_X));
  
 -   /* mul o0, t0, c0               ; Rescale texel to correct range */
 -   inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_release_temporary(shader, texel);
 +   ureg_release_temporary(shader, temp);
 +   ureg_END(shader);
  
 -   assert(ti <= max_tokens);
 +   r->i_fs = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->i_fs)
 +      return false;
  
 -   fs.tokens = tokens;
 -   r->i_fs = r->pipe->create_fs_state(r->pipe, &fs);
 -   free(tokens);
 +   return true;
  }
  
 -static void
 +static bool
  create_frame_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 100;
 -
 -   struct pipe_shader_state vs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src vpos, vtex[4];
 +   struct ureg_dst o_vpos, o_vtex[4];
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0              ; Vertex pos
 -    * decl i1              ; Luma texcoords
 -    * decl i2              ; Chroma Cb texcoords
 -    * decl i3              ; Chroma Cr texcoords
 -    * decl i4              ; Ref surface top field texcoords
 -    * decl i5              ; Ref surface bottom field texcoords (unused, packed in the same stream)
 -    */
 -   for (i = 0; i < 6; i++) {
 -      decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 +   shader = ureg_create(TGSI_PROCESSOR_VERTEX);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * decl o0              ; Vertex pos
 -    * decl o1              ; Luma texcoords
 -    * decl o2              ; Chroma Cb texcoords
 -    * decl o3              ; Chroma Cr texcoords
 -    * decl o4              ; Ref macroblock texcoords
 -    */
 -   for (i = 0; i < 5; i++) {
 -      decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 +   vpos = ureg_DECL_vs_input(shader, 0);
 +   for (i = 0; i < 4; ++i)
 +      vtex[i] = ureg_DECL_vs_input(shader, i + 1);
 +   o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
 +   for (i = 0; i < 4; ++i)
 +      o_vtex[i] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, i + 1);
  
     /*
 -    * mov o0, i0           ; Move input vertex pos to output
 -    * mov o1, i1           ; Move input luma texcoords to output
 -    * mov o2, i2           ; Move input chroma Cb texcoords to output
 -    * mov o3, i3           ; Move input chroma Cr texcoords to output
 +    * o_vpos = vpos
 +    * o_vtex[0..2] = vtex[0..2]
 +    * o_vtex[3] = vpos + vtex[3] // Apply motion vector
      */
 -   for (i = 0; i < 4; ++i) {
 -        inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
 -        ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /* add o4, i0, i4       ; Translate vertex pos by motion vec to form ref macroblock texcoords */
 -   inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, 4);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_MOV(shader, o_vpos, vpos);
 +   for (i = 0; i < 3; ++i)
 +      ureg_MOV(shader, o_vtex[i], vtex[i]);
 +   ureg_ADD(shader, o_vtex[3], vpos, vtex[3]);
  
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_END(shader);
  
 -   assert(ti <= max_tokens);
 +   r->p_vs[0] = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->p_vs[0])
 +      return false;
  
 -   vs.tokens = tokens;
 -   r->p_vs[0] = r->pipe->create_vs_state(r->pipe, &vs);
 -   free(tokens);
 +   return true;
  }
  
+ #if 0
  static void
  create_field_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
  {
     assert(false);
  }
+ #endif
  
 -static void
 +static bool
  create_frame_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 100;
 -
 -   struct pipe_shader_state fs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src tc[4];
 +   struct ureg_src sampler[4];
 +   struct ureg_dst texel, ref;
 +   struct ureg_dst fragment;
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0                      ; Luma texcoords
 -    * decl i1                      ; Chroma Cb texcoords
 -    * decl i2                      ; Chroma Cr texcoords
 -    * decl i3                      ; Ref macroblock texcoords
 -    */
 -   for (i = 0; i < 4; ++i) {
 -      decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /* decl c0                      ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */
 -   decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl o0                      ; Fragment color */
 -   decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl t0, t1 */
 -   decl = vl_decl_temps(0, 1);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * decl s0                      ; Sampler for luma texture
 -    * decl s1                      ; Sampler for chroma Cb texture
 -    * decl s2                      ; Sampler for chroma Cr texture
 -    * decl s3                      ; Sampler for ref surface texture
 -    */
 -   for (i = 0; i < 4; ++i) {
 -      decl = vl_decl_samplers(i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   for (i = 0; i < 4; ++i)  {
 +      tc[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, i + 1, TGSI_INTERPOLATE_LINEAR);
 +      sampler[i] = ureg_DECL_sampler(shader, i);
     }
 +   texel = ureg_DECL_temporary(shader);
 +   ref = ureg_DECL_temporary(shader);
 +   fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
  
     /*
 -    * tex2d t1, i0, s0             ; Read texel from luma texture
 -    * mov t0.x, t1.x               ; Move luma sample into .x component
 -    * tex2d t1, i1, s1             ; Read texel from chroma Cb texture
 -    * mov t0.y, t1.x               ; Move Cb sample into .y component
 -    * tex2d t1, i2, s2             ; Read texel from chroma Cr texture
 -    * mov t0.z, t1.x               ; Move Cr sample into .z component
 +    * texel.r = tex(tc[0], sampler[0])
 +    * texel.g = tex(tc[1], sampler[1])
 +    * texel.b = tex(tc[2], sampler[2])
 +    * ref = tex(tc[3], sampler[3])
 +    * fragment = texel * scale + ref
      */
     for (i = 0; i < 3; ++i) {
 -      inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -      inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
 -      inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
 -      inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +      /* Nouveau can't writemask tex dst regs (yet?), do in two steps */
 +      ureg_TEX(shader, ref, TGSI_TEXTURE_2D, tc[i], sampler[i]);
 +      ureg_MOV(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), ureg_scalar(ureg_src(ref), TGSI_SWIZZLE_X));
     }
 +   ureg_TEX(shader, ref, TGSI_TEXTURE_2D, tc[3], sampler[3]);
 +   ureg_MAD(shader, fragment, ureg_src(texel), ureg_scalar(ureg_imm1f(shader, SCALE_FACTOR_16_TO_9), TGSI_SWIZZLE_X), ureg_src(ref));
  
 -   /* mul t0, t0, c0               ; Rescale texel to correct range */
 -   inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   /* tex2d t1, i3, s3             ; Read texel from ref macroblock */
 -   inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, 3, TGSI_FILE_SAMPLER, 3);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   /* add o0, t0, t1               ; Add ref and differential to form final output */
 -   inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_release_temporary(shader, texel);
 +   ureg_release_temporary(shader, ref);
 +   ureg_END(shader);
  
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   assert(ti <= max_tokens);
 +   r->p_fs[0] = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->p_fs[0])
 +      return false;
  
 -   fs.tokens = tokens;
 -   r->p_fs[0] = r->pipe->create_fs_state(r->pipe, &fs);
 -   free(tokens);
 +   return true;
  }
  
+ #if 0
  static void
  create_field_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
  {
     assert(false);
  }
+ #endif
  
 -static void
 +static bool
  create_frame_bi_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 100;
 -
 -   struct pipe_shader_state vs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src vpos, vtex[5];
 +   struct ureg_dst o_vpos, o_vtex[5];
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0              ; Vertex pos
 -    * decl i1              ; Luma texcoords
 -    * decl i2              ; Chroma Cb texcoords
 -    * decl i3              ; Chroma Cr texcoords
 -    * decl i4              ; First ref macroblock top field texcoords
 -    * decl i5              ; First ref macroblock bottom field texcoords (unused, packed in the same stream)
 -    * decl i6              ; Second ref macroblock top field texcoords
 -    * decl i7              ; Second ref macroblock bottom field texcoords (unused, packed in the same stream)
 -    */
 -   for (i = 0; i < 8; i++) {
 -      decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /*
 -    * decl o0              ; Vertex pos
 -    * decl o1              ; Luma texcoords
 -    * decl o2              ; Chroma Cb texcoords
 -    * decl o3              ; Chroma Cr texcoords
 -    * decl o4              ; First ref macroblock texcoords
 -    * decl o5              ; Second ref macroblock texcoords
 -    */
 -   for (i = 0; i < 6; i++) {
 -      decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 +   shader = ureg_create(TGSI_PROCESSOR_VERTEX);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * mov o0, i0           ; Move input vertex pos to output
 -    * mov o1, i1           ; Move input luma texcoords to output
 -    * mov o2, i2           ; Move input chroma Cb texcoords to output
 -    * mov o3, i3           ; Move input chroma Cr texcoords to output
 -    */
 -   for (i = 0; i < 4; ++i) {
 -      inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -   }
 +   vpos = ureg_DECL_vs_input(shader, 0);
 +   for (i = 0; i < 4; ++i)
 +      vtex[i] = ureg_DECL_vs_input(shader, i + 1);
 +   /* Skip input 5 */
 +   vtex[4] = ureg_DECL_vs_input(shader, 6);
 +   o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, 0);
 +   for (i = 0; i < 5; ++i)
 +      o_vtex[i] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, i + 1);
  
     /*
 -    * add o4, i0, i4       ; Translate vertex pos by motion vec to form first ref macroblock texcoords
 -    * add o5, i0, i6       ; Translate vertex pos by motion vec to form second ref macroblock texcoords
 +    * o_vpos = vpos
 +    * o_vtex[0..2] = vtex[0..2]
 +    * o_vtex[3..4] = vpos + vtex[3..4] // Apply motion vector
      */
 -   for (i = 0; i < 2; ++i) {
 -      inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, i + 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, (i + 2) * 2);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -   }
 +   ureg_MOV(shader, o_vpos, vpos);
 +   for (i = 0; i < 3; ++i)
 +      ureg_MOV(shader, o_vtex[i], vtex[i]);
 +   for (i = 3; i < 5; ++i)
 +      ureg_ADD(shader, o_vtex[i], vpos, vtex[i]);
  
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_END(shader);
  
 -   assert(ti <= max_tokens);
 +   r->b_vs[0] = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->b_vs[0])
 +      return false;
  
 -   vs.tokens = tokens;
 -   r->b_vs[0] = r->pipe->create_vs_state(r->pipe, &vs);
 -   free(tokens);
 +   return true;
  }
  
+ #if 0
  static void
  create_field_bi_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
  {
     assert(false);
  }
+ #endif
  
 -static void
 +static bool
  create_frame_bi_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
  {
 -   const unsigned max_tokens = 100;
 -
 -   struct pipe_shader_state fs;
 -   struct tgsi_token *tokens;
 -   struct tgsi_header *header;
 -
 -   struct tgsi_full_declaration decl;
 -   struct tgsi_full_instruction inst;
 -
 -   unsigned ti;
 -
 +   struct ureg_program *shader;
 +   struct ureg_src tc[5];
 +   struct ureg_src sampler[5];
 +   struct ureg_dst texel, ref[2];
 +   struct ureg_dst fragment;
     unsigned i;
  
 -   assert(r);
 -
 -   tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
 -   header = (struct tgsi_header *) &tokens[0];
 -   *header = tgsi_build_header();
 -   *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
 -
 -   ti = 2;
 -
 -   /*
 -    * decl i0                      ; Luma texcoords
 -    * decl i1                      ; Chroma Cb texcoords
 -    * decl i2                      ; Chroma Cr texcoords
 -    * decl i3                      ; First ref macroblock texcoords
 -    * decl i4                      ; Second ref macroblock texcoords
 -    */
 -   for (i = 0; i < 5; ++i) {
 -      decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /*
 -    * decl c0                      ; Scaling factor, rescales 16-bit snorm to 9-bit snorm
 -    * decl c1                      ; Constant 1/2 in .x channel to use as weight to blend past and future texels
 -    */
 -   decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl o0                      ; Fragment color */
 -   decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 -
 -   /* decl t0-t2 */
 -   decl = vl_decl_temps(0, 2);
 -   ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
 +   if (!shader)
 +      return false;
  
 -   /*
 -    * decl s0                      ; Sampler for luma texture
 -    * decl s1                      ; Sampler for chroma Cb texture
 -    * decl s2                      ; Sampler for chroma Cr texture
 -    * decl s3                      ; Sampler for first ref surface texture
 -    * decl s4                      ; Sampler for second ref surface texture
 -    */
 -   for (i = 0; i < 5; ++i) {
 -      decl = vl_decl_samplers(i, i);
 -      ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
 +   for (i = 0; i < 5; ++i)  {
 +      tc[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, i + 1, TGSI_INTERPOLATE_LINEAR);
 +      sampler[i] = ureg_DECL_sampler(shader, i);
     }
 +   texel = ureg_DECL_temporary(shader);
 +   ref[0] = ureg_DECL_temporary(shader);
 +   ref[1] = ureg_DECL_temporary(shader);
 +   fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
  
     /*
 -    * tex2d t1, i0, s0             ; Read texel from luma texture
 -    * mov t0.x, t1.x               ; Move luma sample into .x component
 -    * tex2d t1, i1, s1             ; Read texel from chroma Cb texture
 -    * mov t0.y, t1.x               ; Move Cb sample into .y component
 -    * tex2d t1, i2, s2             ; Read texel from chroma Cr texture
 -    * mov t0.z, t1.x               ; Move Cr sample into .z component
 +    * texel.r = tex(tc[0], sampler[0])
 +    * texel.g = tex(tc[1], sampler[1])
 +    * texel.b = tex(tc[2], sampler[2])
 +    * ref[0..1 = tex(tc[3..4], sampler[3..4])
 +    * ref[0] = lerp(ref[0], ref[1], 0.5)
 +    * fragment = texel * scale + ref[0]
      */
     for (i = 0; i < 3; ++i) {
 -      inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -      inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
 -      inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
 -      inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
 -      inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -   }
 -
 -   /* mul t0, t0, c0               ; Rescale texel to correct range */
 -   inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   /*
 -    * tex2d t1, i3, s3             ; Read texel from first ref macroblock
 -    * tex2d t2, i4, s4             ; Read texel from second ref macroblock
 -    */
 -   for (i = 0; i < 2; ++i) {
 -      inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 1, TGSI_FILE_INPUT, i + 3, TGSI_FILE_SAMPLER, i + 3);
 -      ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +      /* Nouveau can't writemask tex dst regs (yet?), do in two steps */
 +      ureg_TEX(shader, ref[0], TGSI_TEXTURE_2D, tc[i], sampler[i]);
 +      ureg_MOV(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), ureg_scalar(ureg_src(ref[0]), TGSI_SWIZZLE_X));
     }
 +   ureg_TEX(shader, ref[0], TGSI_TEXTURE_2D, tc[3], sampler[3]);
 +   ureg_TEX(shader, ref[1], TGSI_TEXTURE_2D, tc[4], sampler[4]);
 +   ureg_LRP(shader, ref[0], ureg_scalar(ureg_imm1f(shader, 0.5f), TGSI_SWIZZLE_X), ureg_src(ref[0]), ureg_src(ref[1]));
  
 -   /* lerp t1, c1.x, t1, t2        ; Blend past and future texels */
 -   inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_CONSTANT, 1, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2);
 -   inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
 -   inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
 -   inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
 -   inst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_X;
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_MAD(shader, fragment, ureg_src(texel), ureg_scalar(ureg_imm1f(shader, SCALE_FACTOR_16_TO_9), TGSI_SWIZZLE_X), ureg_src(ref[0]));
  
 -   /* add o0, t0, t1               ; Add past/future ref and differential to form final output */
 -   inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 +   ureg_release_temporary(shader, texel);
 +   ureg_release_temporary(shader, ref[0]);
 +   ureg_release_temporary(shader, ref[1]);
 +   ureg_END(shader);
  
 -   /* end */
 -   inst = vl_end();
 -   ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
 -
 -   assert(ti <= max_tokens);
 +   r->b_fs[0] = ureg_create_shader_and_destroy(shader, r->pipe);
 +   if (!r->b_fs[0])
 +      return false;
  
 -   fs.tokens = tokens;
 -   r->b_fs[0] = r->pipe->create_fs_state(r->pipe, &fs);
 -   free(tokens);
 +   return true;
  }
  
+ #if 0
  static void
  create_field_bi_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
  {
@@@ -413,11 -724,11 +422,6 @@@ init_pipe_state(struct vl_mpeg12_mc_ren
     r->viewport.translate[2] = 0;
     r->viewport.translate[3] = 0;
  
--   r->scissor.maxx = r->pot_buffers ?
--      util_next_power_of_two(r->picture_width) : r->picture_width;
--   r->scissor.maxy = r->pot_buffers ?
--      util_next_power_of_two(r->picture_height) : r->picture_height;
--
     r->fb_state.width = r->pot_buffers ?
        util_next_power_of_two(r->picture_width) : r->picture_width;
     r->fb_state.height = r->pot_buffers ?
@@@ -644,7 -977,8 +655,7 @@@ cleanup_buffers(struct vl_mpeg12_mc_ren
  
     assert(r);
  
-    pipe_buffer_reference(&r->vs_const_buf.buffer, NULL);
+    pipe_buffer_reference(&r->vs_const_buf, NULL);
 -   pipe_buffer_reference(&r->fs_const_buf, NULL);
  
     for (i = 0; i < 3; ++i)
        pipe_buffer_reference(&r->vertex_bufs.all[i].buffer, NULL);
@@@ -991,7 -1287,7 +1005,6 @@@ flush(struct vl_mpeg12_mc_renderer *r
  
     r->pipe->set_framebuffer_state(r->pipe, &r->fb_state);
     r->pipe->set_viewport_state(r->pipe, &r->viewport);
--   r->pipe->set_scissor_state(r->pipe, &r->scissor);
  
     vs_consts = pipe_buffer_map
     (
     vs_consts->denorm.x = r->surface->width0;
     vs_consts->denorm.y = r->surface->height0;
  
-    pipe_buffer_unmap(r->pipe->screen, r->vs_const_buf.buffer);
+    pipe_buffer_unmap(r->pipe->screen, r->vs_const_buf);
  
     r->pipe->set_constant_buffer(r->pipe, PIPE_SHADER_VERTEX, 0,
-                                 &r->vs_const_buf);
+                                 r->vs_const_buf);
 -   r->pipe->set_constant_buffer(r->pipe, PIPE_SHADER_FRAGMENT, 0,
 -                                r->fs_const_buf);
  
     if (num_macroblocks[MACROBLOCK_TYPE_INTRA] > 0) {
        r->pipe->set_vertex_buffers(r->pipe, 1, r->vertex_bufs.all);
@@@ -1336,7 -1629,7 +1349,7 @@@ vl_mpeg12_mc_renderer_render_macroblock
              xfer_buffers_unmap(renderer);
              flush(renderer);
           }
--         
++
           new_surface = true;
        }
  
@@@ -1,8 -1,8 +1,8 @@@
  /**************************************************************************
-- * 
++ *
   * Copyright 2009 Younes Manton.
   * All Rights Reserved.
-- * 
++ *
   * Permission is hereby granted, free of charge, to any person obtaining a
   * copy of this software and associated documentation files (the
   * "Software"), to deal in the Software without restriction, including
   * distribute, sub license, and/or sell copies of the Software, and to
   * permit persons to whom the Software is furnished to do so, subject to
   * the following conditions:
-- * 
++ *
   * The above copyright notice and this permission notice (including the
   * next paragraph) shall be included in all copies or substantial portions
   * of the Software.
-- * 
++ *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@@@ -22,7 -22,7 +22,7 @@@
   * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- * 
++ *
   **************************************************************************/
  
  #ifndef vl_mpeg12_mc_renderer_h
@@@ -63,20 -62,21 +63,19 @@@ struct vl_mpeg12_mc_rendere
     unsigned macroblocks_per_batch;
  
     struct pipe_viewport_state viewport;
--   struct pipe_scissor_state scissor;
-    struct pipe_constant_buffer vs_const_buf;
+    struct pipe_buffer *vs_const_buf;
 -   struct pipe_buffer *fs_const_buf;
     struct pipe_framebuffer_state fb_state;
     struct pipe_vertex_element vertex_elems[8];
--      
++
     union
     {
        void *all[5];
        struct { void *y, *cb, *cr, *ref[2]; } individual;
     } samplers;
--      
++
     void *i_vs, *p_vs[2], *b_vs[2];
     void *i_fs, *p_fs[2], *b_fs[2];
--      
++
     union
     {
        struct pipe_texture *all[5];
@@@ -88,7 -88,7 +87,7 @@@
        struct pipe_vertex_buffer all[3];
        struct { struct pipe_vertex_buffer ycbcr, ref[2]; } individual;
     } vertex_bufs;
--      
++
     struct pipe_texture *surface, *past, *future;
     struct pipe_fence_handle **fence;
     unsigned num_macroblocks;
   * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 - * 
 + *
   **************************************************************************/
  
+ #include "util/u_inlines.h"
+ #include "util/u_memory.h"
  #include "sp_video_context.h"
- #include <pipe/p_inlines.h>
++#include <util/u_inlines.h>
 +#include <util/u_memory.h>
 +#include <util/u_rect.h>
 +#include <util/u_video.h>
 +#include "sp_winsys.h"
  #include "sp_texture.h"
  
 -
  static void
  sp_mpeg12_destroy(struct pipe_video_context *vpipe)
  {
@@@ -230,8 -182,6 +233,7 @@@ init_pipe_state(struct sp_mpeg12_contex
     rast.point_size = 1;
     rast.offset_units = 1;
     rast.offset_scale = 1;
-    /*rast.sprite_coord_mode[i] = ;*/
 +   rast.gl_rasterization_rules = 1;
     ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
     ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
  
@@@ -343,38 -293,11 +345,38 @@@ sp_video_create(struct pipe_screen *scr
     assert(screen);
     assert(width && height);
  
-    pipe = softpipe_create(screen);
++   pipe = screen->context_create(screen, NULL);
 +   if (!pipe)
 +      return NULL;
 +
 +   /* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture with softpipe */
 +   /* TODO: Use XFER_NONE when implemented */
 +   return sp_video_create_ex(pipe, profile,
 +                             chroma_format,
 +                             width, height,
 +                             VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
 +                             VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE,
 +                             true);
 +}
 +
 +struct pipe_video_context *
 +sp_video_create_ex(struct pipe_context *pipe, enum pipe_video_profile profile,
 +                   enum pipe_video_chroma_format chroma_format,
 +                   unsigned width, unsigned height,
 +                   enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
 +                   enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling,
 +                   bool pot_buffers)
 +{
 +   assert(pipe);
 +   assert(width && height);
 +
     switch (u_reduce_video_profile(profile)) {
        case PIPE_VIDEO_CODEC_MPEG12:
 -         return sp_mpeg12_create(screen, profile,
 +         return sp_mpeg12_create(pipe, profile,
                                   chroma_format,
 -                                 width, height);
 +                                 width, height,
 +                                 bufmode, eb_handling,
 +                                 pot_buffers);
        default:
           return NULL;
     }
  #ifndef PIPE_VIDEO_STATE_H
  #define PIPE_VIDEO_STATE_H
  
 -/* u_reduce_video_profile() needs these */
 -#include <pipe/p_compiler.h>
 -
  #include <pipe/p_defines.h>
  #include <pipe/p_format.h>
- #include <pipe/p_refcnt.h>
+ #include <pipe/p_state.h>
  #include <pipe/p_screen.h>
+ #include <util/u_inlines.h>
  
  #ifdef __cplusplus
  extern "C" {
@@@ -74,7 -109,7 +76,7 @@@ enum pipe_mpeg12_macroblock_typ
     PIPE_MPEG12_MACROBLOCK_TYPE_FWD,
     PIPE_MPEG12_MACROBLOCK_TYPE_BKWD,
     PIPE_MPEG12_MACROBLOCK_TYPE_BI,
--      
++
     PIPE_MPEG12_MACROBLOCK_NUM_TYPES
  };
  
@@@ -31,7 -30,6 +31,7 @@@
  #include <pipe/p_video_context.h>
  #include <pipe/p_video_state.h>
  #include <pipe/p_state.h>
- #include <pipe/p_inlines.h>
++#include <util/u_inlines.h>
  #include <util/u_memory.h>
  #include "xvmc_private.h"
  
@@@ -119,37 -148,9 +148,27 @@@ struct pipe_screen* radeon_create_scree
      }
  }
  
- /* Create a pipe_context. */
- struct pipe_context* radeon_create_context(struct drm_api* api,
-                                            struct pipe_screen* screen)
- {
-     if (debug_get_bool_option("RADEON_SOFTPIPE", FALSE)) {
-         return radeon_create_softpipe(screen->winsys);
-     } else {
-         return r300_create_context(screen,
-                                    (struct radeon_winsys*)screen->winsys);
-     }
- }
  
 +
 +static struct pipe_video_context *
 +radeon_create_video_context(struct drm_api *api, struct pipe_screen *pscreen,
 +                            enum pipe_video_profile profile,
 +                            enum pipe_video_chroma_format chroma_format,
 +                            unsigned width, unsigned height)
 +{
 +    struct radeon_winsys *winsys = (struct radeon_winsys*)pscreen->winsys;
 +    struct pipe_context *pipe;
 +    struct pipe_video_context *pvctx;
 +
 +    pipe = radeon_create_context(api, pscreen);
 +    if (!pipe)
 +        return NULL;
 +
 +    pvctx = r300_video_create(pipe, profile, chroma_format, width, height, 0);
 +}
 +
  boolean radeon_buffer_from_texture(struct drm_api* api,
+                                    struct pipe_screen* screen,
                                     struct pipe_texture* texture,
                                     struct pipe_buffer** buffer,
                                     unsigned* stride)
  #include <softpipe/sp_video_context.h>
  #include <softpipe/sp_texture.h>
  
 -/* pipe_winsys implementation */
 +/* TODO: Find a good way to calculate this */
 +static enum pipe_format VisualToPipe(Visual *visual)
 +{
 +   assert(visual);
-    return PIPE_FORMAT_X8R8G8B8_UNORM;
++   return PIPE_FORMAT_B8G8R8X8_UNORM;
 +}
  
  struct xsp_pipe_winsys
  {