summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/egl/drivers/dri2/Makefile19
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c951
-rw-r--r--src/egl/drivers/glx/egl_glx.c39
-rw-r--r--src/egl/drivers/xdri/Makefile28
-rw-r--r--src/egl/drivers/xdri/driinit.c85
-rw-r--r--src/egl/drivers/xdri/driinit.h9
-rw-r--r--src/egl/drivers/xdri/egl_xdri.c655
-rw-r--r--src/egl/main/eglconfig.c34
-rw-r--r--src/egl/main/eglconfig.h23
-rw-r--r--src/egl/main/eglcontext.c119
-rw-r--r--src/egl/main/eglcontext.h8
-rw-r--r--src/egl/main/eglcurrent.c1
-rw-r--r--src/egl/main/egldisplay.c1
-rw-r--r--src/egl/main/egldisplay.h7
-rw-r--r--src/egl/main/egldriver.c309
-rw-r--r--src/egl/main/egldriver.h27
-rw-r--r--src/egl/main/eglimage.c59
-rw-r--r--src/egl/main/eglimage.h4
-rw-r--r--src/egl/main/eglmisc.c54
-rw-r--r--src/egl/main/eglsurface.c427
-rw-r--r--src/egl/main/eglsurface.h37
-rw-r--r--src/gallium/auxiliary/Makefile7
-rw-r--r--src/gallium/auxiliary/SConscript7
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c1
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c30
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe.c1
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aaline.c19
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aapoint.c34
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_pstipple.c18
-rw-r--r--src/gallium/auxiliary/draw/draw_private.h4
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_util.c1
-rw-r--r--src/gallium/auxiliary/draw/draw_vertex.h2
-rw-r--r--src/gallium/auxiliary/os/os_memory.h (renamed from src/gallium/include/pipe/p_refcnt.h)99
-rw-r--r--src/gallium/auxiliary/os/os_memory_aligned.h (renamed from src/gallium/drivers/nv10/nv10_surface.c)69
-rw-r--r--src/gallium/auxiliary/os/os_memory_debug.h83
-rw-r--r--src/gallium/auxiliary/os/os_memory_stdc.h (renamed from src/gallium/drivers/nv20/nv20_surface.c)77
-rw-r--r--src/gallium/auxiliary/os/os_memory_win32k.h123
-rw-r--r--src/gallium/auxiliary/os/os_misc.c188
-rw-r--r--src/gallium/auxiliary/os/os_misc.h99
-rw-r--r--src/gallium/auxiliary/os/os_stream.h (renamed from src/gallium/auxiliary/util/u_stream.h)22
-rw-r--r--src/gallium/auxiliary/os/os_stream_stdc.c (renamed from src/gallium/auxiliary/util/u_stream_stdc.c)39
-rw-r--r--src/gallium/auxiliary/os/os_stream_wd.c (renamed from src/gallium/auxiliary/util/u_stream_wd.c)76
-rw-r--r--src/gallium/auxiliary/os/os_thread.h (renamed from src/gallium/include/pipe/p_thread.h)25
-rw-r--r--src/gallium/auxiliary/os/os_time.c128
-rw-r--r--src/gallium/auxiliary/os/os_time.h (renamed from src/gallium/drivers/nv04/nv04_surface.c)101
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_buffer.h1
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c2
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c2
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c2
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c2
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c2
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c2
-rw-r--r--src/gallium/auxiliary/rtasm/rtasm_execmem.c4
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_exec.c39
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_parse.c11
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_parse.h4
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_text.c2
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_ureg.c19
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_ureg.h5
-rw-r--r--src/gallium/auxiliary/util/u_atomic.h271
-rw-r--r--src/gallium/auxiliary/util/u_blit.c2
-rw-r--r--src/gallium/auxiliary/util/u_blitter.c2
-rw-r--r--src/gallium/auxiliary/util/u_debug.c223
-rw-r--r--src/gallium/auxiliary/util/u_debug.h44
-rw-r--r--src/gallium/auxiliary/util/u_debug_memory.c33
-rw-r--r--src/gallium/auxiliary/util/u_dl.c10
-rw-r--r--src/gallium/auxiliary/util/u_draw_quad.c2
-rw-r--r--src/gallium/auxiliary/util/u_format.h1
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c2
-rw-r--r--src/gallium/auxiliary/util/u_inlines.h (renamed from src/gallium/include/pipe/p_inlines.h)92
-rw-r--r--src/gallium/auxiliary/util/u_keymap.c1
-rw-r--r--src/gallium/auxiliary/util/u_memory.h158
-rw-r--r--src/gallium/auxiliary/util/u_prim.h5
-rw-r--r--src/gallium/auxiliary/util/u_ringbuffer.c2
-rw-r--r--src/gallium/auxiliary/util/u_simple_screen.c2
-rw-r--r--src/gallium/auxiliary/util/u_simple_screen.h139
-rw-r--r--src/gallium/auxiliary/util/u_simple_shaders.c1
-rw-r--r--src/gallium/auxiliary/util/u_surface.c1
-rw-r--r--src/gallium/auxiliary/util/u_texture.c1
-rw-r--r--src/gallium/auxiliary/util/u_tile.c2
-rw-r--r--src/gallium/auxiliary/util/u_time.c225
-rw-r--r--src/gallium/auxiliary/util/u_time.h96
-rw-r--r--src/gallium/auxiliary/util/u_timed_winsys.c2
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.c2
-rw-r--r--src/gallium/auxiliary/vl/vl_compositor.c2
-rw-r--r--src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c2
-rw-r--r--src/gallium/docs/source/conf.py4
-rw-r--r--src/gallium/docs/source/distro.rst31
-rw-r--r--src/gallium/docs/source/exts/tgsi.py17
-rw-r--r--src/gallium/docs/source/screen.rst4
-rw-r--r--src/gallium/docs/source/tgsi.rst512
-rw-r--r--src/gallium/drivers/cell/ppu/cell_clear.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_context.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_draw_arrays.c4
-rw-r--r--src/gallium/drivers/cell/ppu/cell_fence.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_pipe_state.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_screen.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_state_emit.c2
-rw-r--r--src/gallium/drivers/cell/ppu/cell_state_shader.c4
-rw-r--r--src/gallium/drivers/cell/ppu/cell_texture.c4
-rw-r--r--src/gallium/drivers/cell/ppu/cell_vertex_shader.c2
-rw-r--r--src/gallium/drivers/failover/fo_context.c2
-rw-r--r--src/gallium/drivers/failover/fo_state.c2
-rw-r--r--src/gallium/drivers/i915/i915_buffer.c1
-rw-r--r--src/gallium/drivers/i915/i915_context.c2
-rw-r--r--src/gallium/drivers/i915/i915_context.h2
-rw-r--r--src/gallium/drivers/i915/i915_debug.h2
-rw-r--r--src/gallium/drivers/i915/i915_debug_fp.c3
-rw-r--r--src/gallium/drivers/i915/i915_prim_vbuf.c2
-rw-r--r--src/gallium/drivers/i915/i915_screen.c2
-rw-r--r--src/gallium/drivers/i915/i915_state.c2
-rw-r--r--src/gallium/drivers/i915/i915_state_inlines.h1
-rw-r--r--src/gallium/drivers/i915/i915_texture.c2
-rw-r--r--src/gallium/drivers/i965/brw_context.c1
-rw-r--r--src/gallium/drivers/i965/brw_disasm.c1
-rw-r--r--src/gallium/drivers/i965/brw_draw.c1
-rw-r--r--src/gallium/drivers/i965/brw_draw_upload.c1
-rw-r--r--src/gallium/drivers/i965/brw_pipe_fb.c1
-rw-r--r--src/gallium/drivers/i965/brw_pipe_sampler.c1
-rw-r--r--src/gallium/drivers/i965/brw_pipe_shader.c1
-rw-r--r--src/gallium/drivers/i965/brw_screen.c2
-rw-r--r--src/gallium/drivers/i965/brw_screen_buffers.c2
-rw-r--r--src/gallium/drivers/i965/brw_winsys.h2
-rw-r--r--src/gallium/drivers/identity/id_objects.c2
-rw-r--r--src/gallium/drivers/llvmpipe/SConscript29
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_logic.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_buffer.c2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_context.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_fence.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_fence.h4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_rast.c11
-rw-r--r--src/gallium/drivers/llvmpipe/lp_rast_priv.h2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_scene.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_scene.h2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_setup.c2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_fs.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_sampler.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_surface.c1
-rw-r--r--src/gallium/drivers/llvmpipe/lp_texture.c2
-rw-r--r--src/gallium/drivers/nouveau/Makefile3
-rw-r--r--src/gallium/drivers/nouveau/nouveau_screen.c2
-rw-r--r--src/gallium/drivers/nouveau/nouveau_winsys.h20
-rw-r--r--src/gallium/drivers/nouveau/nv04_surface_2d.c (renamed from src/gallium/drivers/nv04/nv04_surface_2d.c)40
-rw-r--r--src/gallium/drivers/nouveau/nv04_surface_2d.h (renamed from src/gallium/drivers/nv04/nv04_surface_2d.h)0
-rw-r--r--src/gallium/drivers/nv04/Makefile21
-rw-r--r--src/gallium/drivers/nv04/nv04_clear.c12
-rw-r--r--src/gallium/drivers/nv04/nv04_context.c112
-rw-r--r--src/gallium/drivers/nv04/nv04_context.h148
-rw-r--r--src/gallium/drivers/nv04/nv04_fragprog.c21
-rw-r--r--src/gallium/drivers/nv04/nv04_fragtex.c73
-rw-r--r--src/gallium/drivers/nv04/nv04_miptree.c146
-rw-r--r--src/gallium/drivers/nv04/nv04_prim_vbuf.c339
-rw-r--r--src/gallium/drivers/nv04/nv04_screen.c222
-rw-r--r--src/gallium/drivers/nv04/nv04_screen.h30
-rw-r--r--src/gallium/drivers/nv04/nv04_state.c459
-rw-r--r--src/gallium/drivers/nv04/nv04_state.h72
-rw-r--r--src/gallium/drivers/nv04/nv04_state_emit.c246
-rw-r--r--src/gallium/drivers/nv04/nv04_transfer.c178
-rw-r--r--src/gallium/drivers/nv04/nv04_vbo.c78
-rw-r--r--src/gallium/drivers/nv10/Makefile20
-rw-r--r--src/gallium/drivers/nv10/nv10_clear.c14
-rw-r--r--src/gallium/drivers/nv10/nv10_context.c298
-rw-r--r--src/gallium/drivers/nv10/nv10_context.h151
-rw-r--r--src/gallium/drivers/nv10/nv10_fragprog.c21
-rw-r--r--src/gallium/drivers/nv10/nv10_fragtex.c130
-rw-r--r--src/gallium/drivers/nv10/nv10_miptree.c165
-rw-r--r--src/gallium/drivers/nv10/nv10_prim_vbuf.c267
-rw-r--r--src/gallium/drivers/nv10/nv10_screen.c208
-rw-r--r--src/gallium/drivers/nv10/nv10_screen.h28
-rw-r--r--src/gallium/drivers/nv10/nv10_state.c590
-rw-r--r--src/gallium/drivers/nv10/nv10_state.h140
-rw-r--r--src/gallium/drivers/nv10/nv10_state_emit.c333
-rw-r--r--src/gallium/drivers/nv10/nv10_transfer.c178
-rw-r--r--src/gallium/drivers/nv10/nv10_vbo.c78
-rw-r--r--src/gallium/drivers/nv20/Makefile21
-rw-r--r--src/gallium/drivers/nv20/nv20_clear.c14
-rw-r--r--src/gallium/drivers/nv20/nv20_context.h150
-rw-r--r--src/gallium/drivers/nv20/nv20_fragprog.c21
-rw-r--r--src/gallium/drivers/nv20/nv20_fragtex.c130
-rw-r--r--src/gallium/drivers/nv20/nv20_miptree.c226
-rw-r--r--src/gallium/drivers/nv20/nv20_prim_vbuf.c440
-rw-r--r--src/gallium/drivers/nv20/nv20_screen.c204
-rw-r--r--src/gallium/drivers/nv20/nv20_screen.h28
-rw-r--r--src/gallium/drivers/nv20/nv20_state.c583
-rw-r--r--src/gallium/drivers/nv20/nv20_state.h140
-rw-r--r--src/gallium/drivers/nv20/nv20_state_emit.c426
-rw-r--r--src/gallium/drivers/nv20/nv20_transfer.c178
-rw-r--r--src/gallium/drivers/nv20/nv20_vbo.c79
-rw-r--r--src/gallium/drivers/nv20/nv20_vertprog.c841
-rw-r--r--src/gallium/drivers/nv30/nv30_context.c2
-rw-r--r--src/gallium/drivers/nv30/nv30_context.h3
-rw-r--r--src/gallium/drivers/nv30/nv30_fragprog.c2
-rw-r--r--src/gallium/drivers/nv30/nv30_miptree.c4
-rw-r--r--src/gallium/drivers/nv30/nv30_screen.c6
-rw-r--r--src/gallium/drivers/nv30/nv30_screen.h2
-rw-r--r--src/gallium/drivers/nv30/nv30_state.c2
-rw-r--r--src/gallium/drivers/nv30/nv30_surface.c4
-rw-r--r--src/gallium/drivers/nv30/nv30_transfer.c2
-rw-r--r--src/gallium/drivers/nv30/nv30_vbo.c2
-rw-r--r--src/gallium/drivers/nv30/nv30_vertprog.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_context.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_context.h3
-rw-r--r--src/gallium/drivers/nv40/nv40_draw.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_fragprog.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_miptree.c4
-rw-r--r--src/gallium/drivers/nv40/nv40_screen.c6
-rw-r--r--src/gallium/drivers/nv40/nv40_screen.h2
-rw-r--r--src/gallium/drivers/nv40/nv40_state.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_surface.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_transfer.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_vbo.c2
-rw-r--r--src/gallium/drivers/nv40/nv40_vertprog.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_context.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_context.h2
-rw-r--r--src/gallium/drivers/nv50/nv50_miptree.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_program.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_query.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_screen.c3
-rw-r--r--src/gallium/drivers/nv50/nv50_state.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_surface.c4
-rw-r--r--src/gallium/drivers/nv50/nv50_transfer.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_vbo.c2
-rw-r--r--src/gallium/drivers/r300/r300_context.h2
-rw-r--r--src/gallium/drivers/r300/r300_fs.c10
-rw-r--r--src/gallium/drivers/r300/r300_render.c4
-rw-r--r--src/gallium/drivers/r300/r300_screen.c7
-rw-r--r--src/gallium/drivers/r300/r300_texture.h13
-rw-r--r--src/gallium/drivers/r300/r300_tgsi_to_rc.c63
-rw-r--r--src/gallium/drivers/r300/r300_tgsi_to_rc.h7
-rw-r--r--src/gallium/drivers/r300/r300_winsys.h2
-rw-r--r--src/gallium/drivers/softpipe/sp_context.c1
-rw-r--r--src/gallium/drivers/softpipe/sp_draw_arrays.c4
-rw-r--r--src/gallium/drivers/softpipe/sp_screen.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_state_derived.c3
-rw-r--r--src/gallium/drivers/softpipe/sp_state_fs.c1
-rw-r--r--src/gallium/drivers/softpipe/sp_state_surface.c1
-rw-r--r--src/gallium/drivers/softpipe/sp_tex_tile_cache.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_texture.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_tile_cache.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_video_context.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_winsys.c3
-rw-r--r--src/gallium/drivers/svga/svga_context.c3
-rw-r--r--src/gallium/drivers/svga/svga_context.h4
-rw-r--r--src/gallium/drivers/svga/svga_draw.c2
-rw-r--r--src/gallium/drivers/svga/svga_draw_arrays.c2
-rw-r--r--src/gallium/drivers/svga/svga_draw_elements.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_blend.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_constants.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_depthstencil.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_draw.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_fs.c3
-rw-r--r--src/gallium/drivers/svga/svga_pipe_misc.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_rasterizer.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_sampler.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_vertex.c2
-rw-r--r--src/gallium/drivers/svga/svga_pipe_vs.c2
-rw-r--r--src/gallium/drivers/svga/svga_screen.c2
-rw-r--r--src/gallium/drivers/svga/svga_screen.h2
-rw-r--r--src/gallium/drivers/svga/svga_screen_buffer.c4
-rw-r--r--src/gallium/drivers/svga/svga_screen_cache.h2
-rw-r--r--src/gallium/drivers/svga/svga_screen_texture.c4
-rw-r--r--src/gallium/drivers/svga/svga_screen_texture.h1
-rw-r--r--src/gallium/drivers/svga/svga_state_constants.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_framebuffer.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_fs.c128
-rw-r--r--src/gallium/drivers/svga/svga_state_need_swtnl.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_rss.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_tss.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_vdecl.c2
-rw-r--r--src/gallium/drivers/svga/svga_state_vs.c2
-rw-r--r--src/gallium/drivers/svga/svga_swtnl_backend.c2
-rw-r--r--src/gallium/drivers/svga/svga_swtnl_draw.c2
-rw-r--r--src/gallium/drivers/svga/svga_swtnl_state.c2
-rw-r--r--src/gallium/drivers/svga/svga_tgsi.h1
-rw-r--r--src/gallium/drivers/svga/svga_tgsi_decl_sm30.c15
-rw-r--r--src/gallium/drivers/svga/svga_tgsi_emit.h19
-rw-r--r--src/gallium/drivers/svga/svga_tgsi_insn.c271
-rw-r--r--src/gallium/drivers/trace/tr_buffer.c1
-rw-r--r--src/gallium/drivers/trace/tr_dump.c14
-rw-r--r--src/gallium/drivers/trace/tr_dump_state.c2
-rw-r--r--src/gallium/drivers/trace/tr_rbug.c13
-rw-r--r--src/gallium/drivers/trace/tr_screen.c2
-rw-r--r--src/gallium/drivers/trace/tr_screen.h2
-rw-r--r--src/gallium/drivers/trace/tr_texture.c1
-rw-r--r--src/gallium/include/pipe/internal/p_winsys_screen.h190
-rw-r--r--src/gallium/include/pipe/p_atomic.h353
-rw-r--r--src/gallium/include/pipe/p_compiler.h13
-rw-r--r--src/gallium/include/pipe/p_config.h8
-rw-r--r--src/gallium/include/pipe/p_format.h4
-rw-r--r--src/gallium/include/pipe/p_state.h39
-rw-r--r--src/gallium/include/pipe/p_video_state.h4
-rw-r--r--src/gallium/state_trackers/dri/dri_drawable.c1
-rw-r--r--src/gallium/state_trackers/dri/dri_screen.c4
-rw-r--r--src/gallium/state_trackers/egl/Makefile4
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c34
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.h39
-rw-r--r--src/gallium/state_trackers/egl/kms/native_kms.c2
-rw-r--r--src/gallium/state_trackers/egl/x11/glxinit.c (renamed from src/egl/drivers/xdri/glxinit.c)0
-rw-r--r--src/gallium/state_trackers/egl/x11/glxinit.h (renamed from src/egl/drivers/xdri/glxinit.h)0
-rw-r--r--src/gallium/state_trackers/egl/x11/native_dri2.c1
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.c1
-rw-r--r--src/gallium/state_trackers/egl/x11/native_ximage.c3
-rw-r--r--src/gallium/state_trackers/egl/x11/sw_winsys.c4
-rw-r--r--src/gallium/state_trackers/egl/x11/x11_screen.c2
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_api.h2
-rw-r--r--src/gallium/state_trackers/python/gallium.i2
-rw-r--r--src/gallium/state_trackers/python/st_device.c2
-rw-r--r--src/gallium/state_trackers/python/st_llvmpipe_winsys.c2
-rw-r--r--src/gallium/state_trackers/python/st_sample.c2
-rw-r--r--src/gallium/state_trackers/vega/api_filters.c2
-rw-r--r--src/gallium/state_trackers/vega/api_images.c2
-rw-r--r--src/gallium/state_trackers/vega/api_masks.c2
-rw-r--r--src/gallium/state_trackers/vega/api_path.c2
-rw-r--r--src/gallium/state_trackers/vega/asm_fill.h551
-rw-r--r--src/gallium/state_trackers/vega/image.c2
-rw-r--r--src/gallium/state_trackers/vega/mask.c2
-rw-r--r--src/gallium/state_trackers/vega/paint.c2
-rw-r--r--src/gallium/state_trackers/vega/polygon.c2
-rw-r--r--src/gallium/state_trackers/vega/renderer.c2
-rw-r--r--src/gallium/state_trackers/vega/shader.c2
-rw-r--r--src/gallium/state_trackers/vega/shaders_cache.c151
-rw-r--r--src/gallium/state_trackers/vega/st_inlines.h2
-rw-r--r--src/gallium/state_trackers/vega/vg_context.c2
-rw-r--r--src/gallium/state_trackers/vega/vg_tracker.c2
-rw-r--r--src/gallium/state_trackers/wgl/stw_device.h2
-rw-r--r--src/gallium/state_trackers/wgl/stw_framebuffer.h2
-rw-r--r--src/gallium/state_trackers/xorg/xorg_crtc.c2
-rw-r--r--src/gallium/state_trackers/xorg/xorg_dri2.c2
-rw-r--r--src/gallium/state_trackers/xorg/xorg_renderer.c2
-rw-r--r--src/gallium/state_trackers/xorg/xorg_tracker.h2
-rw-r--r--src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c1
-rw-r--r--src/gallium/winsys/drm/intel/gem/intel_drm_api.c1
-rw-r--r--src/gallium/winsys/drm/intel/gem/intel_drm_fence.c3
-rw-r--r--src/gallium/winsys/drm/nouveau/dri/Makefile3
-rw-r--r--src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c18
-rw-r--r--src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h2
-rw-r--r--src/gallium/winsys/drm/nouveau/egl/Makefile3
-rw-r--r--src/gallium/winsys/drm/nouveau/xorg/Makefile3
-rw-r--r--src/gallium/winsys/drm/radeon/core/radeon_buffer.h4
-rw-r--r--src/gallium/winsys/drm/radeon/core/radeon_winsys.h2
-rw-r--r--src/gallium/winsys/drm/vmware/core/vmw_buffer.c2
-rw-r--r--src/gallium/winsys/drm/vmware/core/vmw_buffer.h2
-rw-r--r--src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c3
-rw-r--r--src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c2
-rw-r--r--src/gallium/winsys/drm/vmware/core/vmw_surface.h6
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/Makefile5
-rw-r--r--src/gallium/winsys/g3dvl/xlib/xsp_winsys.c4
-rw-r--r--src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c2
-rw-r--r--src/gallium/winsys/gdi/gdi_softpipe_winsys.c4
-rw-r--r--src/gallium/winsys/xlib/xlib_brw_context.c4
-rw-r--r--src/gallium/winsys/xlib/xlib_cell.c4
-rw-r--r--src/gallium/winsys/xlib/xlib_llvmpipe.c4
-rw-r--r--src/gallium/winsys/xlib/xlib_softpipe.c4
-rw-r--r--src/glut/glx/SConscript2
-rw-r--r--src/glut/glx/glut_fullscrn.c1
-rw-r--r--src/glut/glx/glut_gamemode.c1
-rw-r--r--src/glut/glx/glut_init.c1
-rw-r--r--src/glut/glx/glut_menu2.c1
-rw-r--r--src/glut/glx/glut_overlay.c1
-rw-r--r--src/glut/glx/layerutil.c1
-rw-r--r--src/glx/x11/compsize.c1
-rw-r--r--src/glx/x11/dri2_glx.c1
-rw-r--r--src/glx/x11/dri_glx.c1
-rw-r--r--src/glx/x11/drisw_glx.c1
-rw-r--r--src/glx/x11/glx_pbuffer.c2
-rw-r--r--src/glx/x11/glxcurrent.c4
-rw-r--r--src/glx/x11/glxext.c1
-rw-r--r--src/glx/x11/glxextensions.c1
-rw-r--r--src/mesa/drivers/directfb/idirectfbgl_mesa.c2
-rw-r--r--src/mesa/drivers/dri/i915/i915_fragprog.c7
-rw-r--r--src/mesa/drivers/dri/i965/brw_program.c10
-rw-r--r--src/mesa/drivers/dri/i965/brw_vs_emit.c2
-rw-r--r--src/mesa/drivers/dri/intel/intel_screen.c2
-rw-r--r--src/mesa/drivers/dri/nouveau/Makefile59
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_bo_state.c184
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_bo_state.h107
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c172
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h39
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_context.c273
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_context.h105
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_driver.c140
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_driver.h89
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_fbo.c277
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_fbo.h51
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_gldefs.h263
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_render.h98
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_render_t.c361
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_screen.c269
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_screen.h54
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_span.c174
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_state.c532
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_state.h119
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_surface.c81
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_surface.h58
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c354
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_texture.c456
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_texture.h49
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_util.h176
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c409
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_context.c118
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_context.h52
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_driver.h97
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_render.c212
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_screen.c211
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_state_fb.c116
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_state_frag.c261
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_state_raster.c314
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_state_tex.c162
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_surface.c547
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_context.c91
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_driver.h192
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_render.c201
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_screen.c364
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_fb.c190
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_frag.c416
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_polygon.c126
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_raster.c186
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_tex.c142
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_tnl.c514
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_context.c61
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_driver.h112
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_render.c225
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_screen.c (renamed from src/gallium/drivers/nv20/nv20_context.c)375
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_fb.c123
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_polygon.c44
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_raster.c42
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_tex.c167
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_tnl.c396
-rw-r--r--src/mesa/drivers/dri/r200/r200_cmdbuf.c5
-rw-r--r--src/mesa/drivers/dri/r200/r200_context.c5
-rw-r--r--src/mesa/drivers/dri/r200/r200_ioctl.c4
-rw-r--r--src/mesa/drivers/dri/r200/r200_maos_arrays.c4
-rw-r--r--src/mesa/drivers/dri/r200/r200_sanity.c1
-rw-r--r--src/mesa/drivers/dri/r200/r200_state.c8
-rw-r--r--src/mesa/drivers/dri/r200/r200_state_init.c4
-rw-r--r--src/mesa/drivers/dri/r200/r200_swtcl.c1
-rw-r--r--src/mesa/drivers/dri/r200/r200_tcl.c1
-rw-r--r--src/mesa/drivers/dri/r200/r200_tex.c2
-rw-r--r--src/mesa/drivers/dri/r200/r200_vertprog.c7
-rw-r--r--src/mesa/drivers/dri/r300/compiler/r300_fragprog.c4
-rw-r--r--src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c7
-rw-r--r--src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c5
-rw-r--r--src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c3
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_compiler.h4
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_pair_translate.c21
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h2
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_program_print.c4
-rw-r--r--src/mesa/drivers/dri/r300/r300_blit.c2
-rw-r--r--src/mesa/drivers/dri/r300/r300_emit.c2
-rw-r--r--src/mesa/drivers/dri/r300/r300_fragprog_common.c3
-rw-r--r--src/mesa/drivers/dri/r300/r300_shader.c7
-rw-r--r--src/mesa/drivers/dri/r600/r600_blit.c1
-rw-r--r--src/mesa/drivers/dri/r600/r600_cmdbuf.c2
-rw-r--r--src/mesa/drivers/dri/r600/r600_context.c5
-rw-r--r--src/mesa/drivers/dri/r600/r600_emit.c2
-rw-r--r--src/mesa/drivers/dri/r600/r600_tex.c4
-rw-r--r--src/mesa/drivers/dri/r600/r600_texstate.c1
-rw-r--r--src/mesa/drivers/dri/r600/r700_chip.c2
-rw-r--r--src/mesa/drivers/dri/r600/r700_clear.c1
-rw-r--r--src/mesa/drivers/dri/r600/r700_ioctl.c2
-rw-r--r--src/mesa/drivers/dri/r600/r700_oglprog.c4
-rw-r--r--src/mesa/drivers/dri/r600/r700_render.c6
-rw-r--r--src/mesa/drivers/dri/r600/r700_shader.c1
-rw-r--r--src/mesa/drivers/dri/r600/r700_state.c3
-rw-r--r--src/mesa/drivers/dri/r600/r700_vertprog.c2
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_common_context.c5
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_context.c5
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_debug.h6
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_ioctl.c15
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_lock.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_sanity.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_screen.c4
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_state.c2
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_state_init.c4
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_swtcl.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_tcl.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_tex.c2
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_tex_copy.c1
-rw-r--r--src/mesa/drivers/dri/swrast/swrast.c2
-rw-r--r--src/mesa/drivers/fbdev/glfbdev.c2
-rw-r--r--src/mesa/drivers/glslcompiler/Makefile1
-rw-r--r--src/mesa/drivers/windows/gdi/wmesa.c2
-rw-r--r--src/mesa/drivers/x11/xm_api.c2
-rw-r--r--src/mesa/es/state_tracker/st_cb_drawtex.c2
-rw-r--r--src/mesa/main/api_exec.c6
-rw-r--r--src/mesa/main/api_validate.c1
-rw-r--r--src/mesa/main/bitset.h25
-rw-r--r--src/mesa/main/context.c10
-rw-r--r--src/mesa/main/dd.h10
-rw-r--r--src/mesa/main/dlist.c2
-rw-r--r--src/mesa/main/framebuffer.c41
-rw-r--r--src/mesa/main/framebuffer.h6
-rw-r--r--src/mesa/main/get.c196
-rw-r--r--src/mesa/main/get_gen.py53
-rw-r--r--src/mesa/main/getstring.c1
-rw-r--r--src/mesa/main/matrix.c8
-rw-r--r--src/mesa/main/mtypes.h6
-rw-r--r--src/mesa/main/points.c2
-rw-r--r--src/mesa/main/rastpos.c3
-rw-r--r--src/mesa/main/texenvprogram.c11
-rw-r--r--src/mesa/main/texparam.c4
-rw-r--r--src/mesa/main/texstate.c31
-rw-r--r--src/mesa/main/varray.c2
-rw-r--r--src/mesa/shader/arbprogram.c9
-rw-r--r--src/mesa/shader/atifragshader.c16
-rw-r--r--src/mesa/shader/prog_print.c41
-rw-r--r--src/mesa/shader/prog_print.h6
-rw-r--r--src/mesa/shader/prog_statevars.c8
-rw-r--r--src/mesa/shader/program.c72
-rw-r--r--src/mesa/shader/program.h8
-rw-r--r--src/mesa/shader/programopt.c11
-rw-r--r--src/mesa/shader/shader_api.c6
-rw-r--r--src/mesa/shader/slang/slang_link.c17
-rw-r--r--src/mesa/state_tracker/st_atom_constbuf.c2
-rw-r--r--src/mesa/state_tracker/st_atom_framebuffer.c1
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c20
-rw-r--r--src/mesa/state_tracker/st_atom_texture.c1
-rw-r--r--src/mesa/state_tracker/st_atom_viewport.c7
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c2
-rw-r--r--src/mesa/state_tracker/st_cb_bitmap.c4
-rw-r--r--src/mesa/state_tracker/st_cb_blit.c3
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.c2
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c2
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c6
-rw-r--r--src/mesa/state_tracker/st_cb_fbo.c1
-rw-r--r--src/mesa/state_tracker/st_cb_feedback.c1
-rw-r--r--src/mesa/state_tracker/st_cb_program.c10
-rw-r--r--src/mesa/state_tracker/st_cb_readpixels.c2
-rw-r--r--src/mesa/state_tracker/st_cb_strings.c3
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c24
-rw-r--r--src/mesa/state_tracker/st_context.c1
-rw-r--r--src/mesa/state_tracker/st_draw.c2
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c2
-rw-r--r--src/mesa/state_tracker/st_framebuffer.c3
-rw-r--r--src/mesa/state_tracker/st_gen_mipmap.c2
-rw-r--r--src/mesa/state_tracker/st_inlines.h2
-rw-r--r--src/mesa/state_tracker/st_mesa_to_tgsi.c1
-rw-r--r--src/mesa/state_tracker/st_program.c28
-rw-r--r--src/mesa/state_tracker/st_program.h9
-rw-r--r--src/mesa/state_tracker/st_texture.c2
-rw-r--r--src/mesa/tnl/t_vb_program.c3
-rw-r--r--src/mesa/tnl/tnl.h2
-rw-r--r--src/mesa/vbo/vbo_split_inplace.c114
-rw-r--r--src/mesa/x86/sse_xform2.S2
-rw-r--r--src/mesa/x86/sse_xform3.S2
549 files changed, 16390 insertions, 12624 deletions
diff --git a/src/egl/drivers/dri2/Makefile b/src/egl/drivers/dri2/Makefile
new file mode 100644
index 0000000000..95f9574531
--- /dev/null
+++ b/src/egl/drivers/dri2/Makefile
@@ -0,0 +1,19 @@
+# src/egl/drivers/dri2/Makefile
+
+TOP = ../../../..
+include $(TOP)/configs/current
+
+EGL_DRIVER = egl_dri2.so
+EGL_SOURCES = egl_dri2.c
+
+EGL_INCLUDES = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/egl/main \
+ -I$(TOP)/src/mesa \
+ -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" \
+ $(shell pkg-config --cflags xcb-dri2 xcb-xfixes x11-xcb libdrm)
+
+EGL_CFLAGS =
+EGL_LIBS = $(shell pkg-config --libs xcb-dri2 xcb-xfixes x11-xcb libdrm)
+
+include ../Makefile.template
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
new file mode 100644
index 0000000000..d53f137530
--- /dev/null
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -0,0 +1,951 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * 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 without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * 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
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR 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.
+ *
+ * Authors:
+ * Kristian Høgsberg <krh@bitplanet.net>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <xf86drm.h>
+#include <GL/gl.h>
+#include <GL/internal/dri_interface.h>
+#include <xcb/xcb.h>
+#include <xcb/dri2.h>
+#include <xcb/xfixes.h>
+#include <X11/Xlib-xcb.h>
+
+#include <glapi/glapi.h>
+#include "eglconfigutil.h"
+#include "eglconfig.h"
+#include "eglcontext.h"
+#include "egldisplay.h"
+#include "egldriver.h"
+#include "eglcurrent.h"
+#include "egllog.h"
+#include "eglsurface.h"
+
+struct dri2_egl_driver
+{
+ _EGLDriver base;
+};
+
+struct dri2_egl_display
+{
+ xcb_connection_t *conn;
+ int dri2_major;
+ int dri2_minor;
+ __DRIscreen *dri_screen;
+ void *driver;
+ __DRIcoreExtension *core;
+ __DRIdri2Extension *dri2;
+ __DRI2flushExtension *flush;
+ int fd;
+
+ __DRIdri2LoaderExtension loader_extension;
+ const __DRIextension *extensions[2];
+};
+
+struct dri2_egl_context
+{
+ _EGLContext base;
+ __DRIcontext *dri_context;
+};
+
+struct dri2_egl_surface
+{
+ _EGLSurface base;
+ __DRIdrawable *dri_drawable;
+ xcb_drawable_t drawable;
+ __DRIbuffer buffers[5];
+ int buffer_count;
+ xcb_xfixes_region_t region;
+ int have_back;
+ int have_fake_front;
+ int swap_interval;
+};
+
+struct dri2_egl_config
+{
+ _EGLConfig base;
+ const __DRIconfig *dri_config;
+};
+
+/* standard typecasts */
+_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
+
+EGLint dri2_to_egl_attribute_map[] = {
+ 0,
+ EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */
+ EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */
+ EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */
+ EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */
+ EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */
+ 0, /* __DRI_ATTRIB_LUMINANCE_SIZE */
+ EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */
+ 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */
+ EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */
+ EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */
+ 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */
+ 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */
+ 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */
+ 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */
+ EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */
+ EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */
+ 0, /* __DRI_ATTRIB_RENDER_TYPE, */
+ 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */
+ 0, /* __DRI_ATTRIB_CONFORMANT */
+ 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */
+ 0, /* __DRI_ATTRIB_STEREO */
+ 0, /* __DRI_ATTRIB_AUX_BUFFERS */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */
+ 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */
+ 0, /* __DRI_ATTRIB_FLOAT_MODE */
+ 0, /* __DRI_ATTRIB_RED_MASK */
+ 0, /* __DRI_ATTRIB_GREEN_MASK */
+ 0, /* __DRI_ATTRIB_BLUE_MASK */
+ 0, /* __DRI_ATTRIB_ALPHA_MASK */
+ EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */
+ EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */
+ EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */
+ 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */
+ 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */
+ 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */
+ 0, /* __DRI_ATTRIB_SWAP_METHOD */
+ EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */
+ EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */
+ 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */
+ 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */
+ 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */
+ 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
+ 0, /* __DRI_ATTRIB_YINVERTED */
+};
+
+static void
+dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id)
+{
+ struct dri2_egl_config *conf;
+ struct dri2_egl_display *dri2_dpy;
+ unsigned int attrib, value, double_buffer;
+ EGLint key, bind_to_texture_rgb, bind_to_texture_rgba;
+ int i;
+
+ dri2_dpy = disp->DriverData;
+ conf = malloc(sizeof *conf);
+ if (conf == NULL)
+ return;
+
+ conf->dri_config = dri_config;
+ _eglInitConfig(&conf->base, disp, id);
+
+ i = 0;
+ while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) {
+ switch (attrib) {
+ case 0:
+ break;
+
+ case __DRI_ATTRIB_RENDER_TYPE:
+ if (value & __DRI_ATTRIB_RGBA_BIT)
+ value = EGL_RGB_BUFFER;
+ else if (value & __DRI_ATTRIB_LUMINANCE_BIT)
+ value = EGL_LUMINANCE_BUFFER;
+ else
+ /* not valid */;
+ _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE, value);
+ break;
+
+ case __DRI_ATTRIB_CONFIG_CAVEAT:
+ if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
+ value = EGL_NON_CONFORMANT_CONFIG;
+ else if (value & __DRI_ATTRIB_SLOW_BIT)
+ value = EGL_SLOW_CONFIG;
+ else
+ value = EGL_NONE;
+ _eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, value);
+ break;
+
+ case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB:
+ bind_to_texture_rgb = value;
+ break;
+
+ case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA:
+ bind_to_texture_rgba = value;
+ break;
+
+ case __DRI_ATTRIB_DOUBLE_BUFFER:
+ double_buffer = value;
+ break;
+
+ default:
+ key = dri2_to_egl_attribute_map[attrib];
+ if (key != 0)
+ _eglSetConfigKey(&conf->base, key, value);
+ break;
+ }
+ }
+
+ /* EGL_SWAP_BEHAVIOR_PRESERVED_BIT */
+
+ if (double_buffer) {
+ /* FIXME: Figure out how to get the visual ID and types */
+ _eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
+ _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID, 0x21);
+ _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE,
+ XCB_VISUAL_CLASS_TRUE_COLOR);
+ } else {
+ _eglSetConfigKey(&conf->base,
+ EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_PBUFFER_BIT);
+ _eglSetConfigKey(&conf->base,
+ EGL_BIND_TO_TEXTURE_RGB, bind_to_texture_rgb);
+ _eglSetConfigKey(&conf->base,
+ EGL_BIND_TO_TEXTURE_RGBA, bind_to_texture_rgba);
+ }
+
+ /* EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT, EGL_OPENGL_ES2_BIT */
+ _eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT);
+ _eglSetConfigKey(&conf->base, EGL_CONFORMANT, EGL_OPENGL_BIT);
+
+ if (!_eglValidateConfig(&conf->base, EGL_FALSE)) {
+ _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id);
+ free(conf);
+ return;
+ }
+
+ _eglAddConfig(disp, &conf->base);
+}
+
+/**
+ * Process list of buffer received from the server
+ *
+ * Processes the list of buffers received in a reply from the server to either
+ * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
+ */
+static void
+dri2_process_buffers(struct dri2_egl_surface *dri2_surf,
+ xcb_dri2_dri2_buffer_t *buffers, unsigned count)
+{
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+ xcb_rectangle_t rectangle;
+ int i;
+
+ dri2_surf->buffer_count = count;
+ dri2_surf->have_fake_front = 0;
+ dri2_surf->have_back = 0;
+
+ /* This assumes the DRI2 buffer attachment tokens matches the
+ * __DRIbuffer tokens. */
+ for (i = 0; i < count; i++) {
+ dri2_surf->buffers[i].attachment = buffers[i].attachment;
+ dri2_surf->buffers[i].name = buffers[i].name;
+ dri2_surf->buffers[i].pitch = buffers[i].pitch;
+ dri2_surf->buffers[i].cpp = buffers[i].cpp;
+ dri2_surf->buffers[i].flags = buffers[i].flags;
+ if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
+ dri2_surf->have_fake_front = 1;
+ if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
+ dri2_surf->have_back = 1;
+ }
+
+ if (dri2_surf->region != XCB_NONE)
+ xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region);
+
+ rectangle.x = 0;
+ rectangle.y = 0;
+ rectangle.width = dri2_surf->base.Width;
+ rectangle.height = dri2_surf->base.Height;
+ dri2_surf->region = xcb_generate_id(dri2_dpy->conn);
+ xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle);
+}
+
+static __DRIbuffer *
+dri2_get_buffers(__DRIdrawable * driDrawable,
+ int *width, int *height,
+ unsigned int *attachments, int count,
+ int *out_count, void *loaderPrivate)
+{
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+ xcb_dri2_dri2_buffer_t *buffers;
+ xcb_dri2_get_buffers_reply_t *reply;
+ xcb_dri2_get_buffers_cookie_t cookie;
+
+ cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn,
+ dri2_surf->drawable,
+ count, count, attachments);
+ reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL);
+ buffers = xcb_dri2_get_buffers_buffers (reply);
+ if (buffers == NULL)
+ return NULL;
+
+ *out_count = reply->count;
+ dri2_surf->base.Width = *width = reply->width;
+ dri2_surf->base.Height = *height = reply->height;
+ dri2_process_buffers(dri2_surf, buffers, *out_count);
+
+ free(reply);
+
+ return dri2_surf->buffers;
+}
+
+static void
+dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
+{
+ /* FIXME: Does EGL support front buffer rendering at all? */
+
+#if 0
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+
+ dri2WaitGL(dri2_surf);
+#endif
+}
+
+static __DRIbuffer *
+dri2_get_buffers_with_format(__DRIdrawable * driDrawable,
+ int *width, int *height,
+ unsigned int *attachments, int count,
+ int *out_count, void *loaderPrivate)
+{
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+ xcb_dri2_dri2_buffer_t *buffers;
+ xcb_dri2_get_buffers_with_format_reply_t *reply;
+ xcb_dri2_get_buffers_with_format_cookie_t cookie;
+ xcb_dri2_attach_format_t *format_attachments;
+
+ format_attachments = (xcb_dri2_attach_format_t *) attachments;
+ cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn,
+ dri2_surf->drawable,
+ count, count,
+ format_attachments);
+
+ reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn,
+ cookie, NULL);
+ if (reply == NULL)
+ return NULL;
+
+ buffers = xcb_dri2_get_buffers_with_format_buffers (reply);
+ dri2_surf->base.Width = *width = reply->width;
+ dri2_surf->base.Height = *height = reply->height;
+ *out_count = reply->count;
+ dri2_process_buffers(dri2_surf, buffers, *out_count);
+
+ free(reply);
+
+ return dri2_surf->buffers;
+}
+
+#ifdef GLX_USE_TLS
+static const char dri_driver_format[] = "%.*s/tls/%.*s_dri.so";
+#else
+static const char dri_driver_format[] = "%.*s/%.*s_dri.so";
+#endif
+
+static const char dri_driver_path[] = DEFAULT_DRIVER_DIR;
+
+/**
+ * Called via eglInitialize(), GLX_drv->API.Initialize().
+ */
+static EGLBoolean
+dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp,
+ EGLint *major, EGLint *minor)
+{
+ const __DRIextension **extensions;
+ const __DRIconfig **driver_configs;
+ struct dri2_egl_display *dri2_dpy;
+ char path[PATH_MAX], *search_paths, *p, *next, *end;
+ xcb_xfixes_query_version_reply_t *xfixes_query;
+ xcb_xfixes_query_version_cookie_t xfixes_query_cookie;
+ xcb_dri2_query_version_reply_t *dri2_query;
+ xcb_dri2_query_version_cookie_t dri2_query_cookie;
+ xcb_dri2_connect_reply_t *connect = NULL;
+ xcb_dri2_connect_cookie_t connect_cookie;
+ xcb_dri2_authenticate_reply_t *authenticate;
+ xcb_dri2_authenticate_cookie_t authenticate_cookie;
+ xcb_generic_error_t *error;
+ drm_magic_t magic;
+ xcb_screen_iterator_t s;
+ int i;
+
+ dri2_dpy = malloc(sizeof *dri2_dpy);
+ if (!dri2_dpy)
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+
+ disp->DriverData = (void *) dri2_dpy;
+ dri2_dpy->conn = XGetXCBConnection(disp->NativeDisplay);
+ if (!dri2_dpy->conn) {
+ dri2_dpy->conn = xcb_connect(0, 0);
+ if (!dri2_dpy->conn) {
+ _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed");
+ free(dri2_dpy);
+ return EGL_FALSE;
+ }
+ }
+
+ xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id);
+ xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id);
+
+ xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn,
+ XCB_XFIXES_MAJOR_VERSION,
+ XCB_XFIXES_MINOR_VERSION);
+
+ dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn,
+ XCB_DRI2_MAJOR_VERSION,
+ XCB_DRI2_MINOR_VERSION);
+
+ s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
+ connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn,
+ s.data->root,
+ XCB_DRI2_DRIVER_TYPE_DRI);
+
+ xfixes_query =
+ xcb_xfixes_query_version_reply (dri2_dpy->conn,
+ xfixes_query_cookie, &error);
+ if (xfixes_query == NULL ||
+ error != NULL || xfixes_query->major_version < 2) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version");
+ free(error);
+ goto handle_error;
+ }
+ free(xfixes_query);
+
+ dri2_query =
+ xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error);
+ if (dri2_query == NULL || error != NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to query version");
+ free(error);
+ goto handle_error;
+ }
+ dri2_dpy->dri2_major = dri2_query->major_version;
+ dri2_dpy->dri2_minor = dri2_query->minor_version;
+ free(dri2_query);
+
+ connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL);
+ if (connect->driver_name_length == 0 && connect->device_name_length == 0) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to authenticate");
+ goto handle_error;
+ }
+
+ search_paths = NULL;
+ if (geteuid() == getuid()) {
+ /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
+ search_paths = getenv("LIBGL_DRIVERS_PATH");
+ }
+ if (search_paths == NULL)
+ search_paths = DEFAULT_DRIVER_DIR;
+
+ dri2_dpy->driver = NULL;
+ end = search_paths + strlen(search_paths);
+ for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) {
+ int path_len;
+
+ next = strchr(p, ':');
+ if (next == NULL)
+ next = end;
+ path_len = next - p;
+
+ snprintf(path, sizeof path,
+ dri_driver_format,
+ path_len, p,
+ xcb_dri2_connect_driver_name_length (connect),
+ xcb_dri2_connect_driver_name (connect));
+
+ dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+ }
+
+ if (dri2_dpy->driver == NULL) {
+ _eglLog(_EGL_FATAL,
+ "DRI2: failed to open any driver (search paths %s)",
+ search_paths);
+ goto handle_error;
+ }
+
+ _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
+ extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS);
+ if (extensions == NULL) {
+ _eglLog(_EGL_FATAL,
+ "DRI2: driver exports no extensions (%s)", dlerror());
+ goto handle_error;
+ }
+
+ for (i = 0; extensions[i]; i++) {
+ if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
+ dri2_dpy->core = (__DRIcoreExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
+ dri2_dpy->dri2 = (__DRIdri2Extension *) extensions[i];
+ }
+
+ if (dri2_dpy->core == NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: driver has no core extension");
+ goto handle_error;
+ }
+
+ if (dri2_dpy->dri2 == NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: driver has no dri2 extension");
+ goto handle_error;
+ }
+
+ snprintf(path, sizeof path, "%.*s",
+ xcb_dri2_connect_device_name_length (connect),
+ xcb_dri2_connect_device_name (connect));
+ dri2_dpy->fd = open (path, O_RDWR);
+ if (dri2_dpy->fd == -1) {
+ _eglLog(_EGL_FATAL,
+ "DRI2: could not open %s (%s)", path, strerror(errno));
+ goto handle_error;
+ }
+
+ if (drmGetMagic(dri2_dpy->fd, &magic)) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic");
+ goto handle_error;
+ }
+
+ authenticate_cookie = xcb_dri2_authenticate_unchecked (dri2_dpy->conn,
+ s.data->root, magic);
+ authenticate = xcb_dri2_authenticate_reply (dri2_dpy->conn,
+ authenticate_cookie, NULL);
+ if (authenticate == NULL || !authenticate->authenticated) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to authenticate");
+ goto handle_error;
+ }
+
+ if (dri2_dpy->dri2_minor >= 1) {
+ dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER;
+ dri2_dpy->loader_extension.base.version = 3;
+ dri2_dpy->loader_extension.getBuffers = dri2_get_buffers;
+ dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer;
+ dri2_dpy->loader_extension.getBuffersWithFormat =
+ dri2_get_buffers_with_format;
+ } else {
+ dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER;
+ dri2_dpy->loader_extension.base.version = 2;
+ dri2_dpy->loader_extension.getBuffers = dri2_get_buffers;
+ dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer;
+ dri2_dpy->loader_extension.getBuffersWithFormat = NULL;
+ }
+
+ dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base;
+ dri2_dpy->extensions[1] = NULL;
+
+ dri2_dpy->dri_screen =
+ dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions,
+ &driver_configs, dri2_dpy);
+
+ if (dri2_dpy->dri_screen == NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: failed to create dri screen");
+ free(dri2_dpy);
+ goto handle_error;
+ }
+
+ extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen);
+ for (i = 0; extensions[i]; i++) {
+ _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name);
+ if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0))
+ dri2_dpy->flush = (__DRI2flushExtension *) extensions[i];
+ }
+
+ if (dri2_dpy->flush == NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: driver doesn't support the flush extension");
+ free(dri2_dpy);
+ goto handle_error;
+ }
+
+ for (i = 0; driver_configs[i]; i++)
+ dri2_add_config(disp, driver_configs[i], i + 1);
+ if (!disp->NumConfigs) {
+ _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
+ goto handle_error;
+ }
+
+ disp->ClientAPIsMask = EGL_OPENGL_BIT;
+
+ /* we're supporting EGL 1.4 */
+ *major = 1;
+ *minor = 4;
+
+ free (connect);
+ return EGL_TRUE;
+
+ handle_error:
+ free(connect);
+ free(dri2_dpy);
+ return EGL_FALSE;
+}
+
+/**
+ * Called via eglTerminate(), drv->API.Terminate().
+ */
+static EGLBoolean
+dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+ _eglReleaseDisplayResources(drv, disp);
+ _eglCleanupDisplay(disp);
+
+ close(dri2_dpy->fd);
+ dlclose(dri2_dpy->driver);
+ free(dri2_dpy);
+
+ disp->DriverData = NULL;
+
+ return EGL_TRUE;
+}
+
+
+/**
+ * Called via eglCreateContext(), drv->API.CreateContext().
+ */
+static _EGLContext *
+dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
+ _EGLContext *share_list, const EGLint *attrib_list)
+{
+ struct dri2_egl_context *dri2_ctx;
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list);
+ struct dri2_egl_config *dri2_config = dri2_egl_config(conf);
+
+ dri2_ctx = malloc(sizeof *dri2_ctx);
+ if (!dri2_ctx) {
+ _eglError(EGL_BAD_ALLOC, "eglCreateContext");
+ return NULL;
+ }
+
+ if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) {
+ free(dri2_ctx);
+ return NULL;
+ }
+
+ dri2_ctx->dri_context =
+ dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen,
+ dri2_config->dri_config,
+ dri2_ctx_shared ?
+ dri2_ctx_shared->dri_context : NULL,
+ dri2_ctx);
+
+ if (!dri2_ctx->dri_context) {
+ free(dri2_ctx);
+ return NULL;
+ }
+
+ return &dri2_ctx->base;
+}
+
+static EGLBoolean
+dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+ if (_eglIsSurfaceBound(surf))
+ return EGL_TRUE;
+
+ (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable);
+
+ xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable);
+
+ if (surf->Type == EGL_PBUFFER_BIT)
+ xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable);
+
+ free(surf);
+
+ return EGL_TRUE;
+}
+
+/**
+ * Called via eglMakeCurrent(), drv->API.MakeCurrent().
+ */
+static EGLBoolean
+dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
+ _EGLSurface *rsurf, _EGLContext *ctx)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf);
+ struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf);
+ struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+ __DRIdrawable *ddraw, *rdraw;
+ __DRIcontext *cctx;
+
+ /* bind the new context and return the "orphaned" one */
+ if (!_eglBindContext(&ctx, &dsurf, &rsurf))
+ return EGL_FALSE;
+
+ ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL;
+ rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL;
+ cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
+
+ if ((cctx == NULL && ddraw == NULL && rdraw == NULL) ||
+ dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) {
+ if (dsurf && !_eglIsSurfaceLinked(dsurf))
+ dri2_destroy_surface(drv, disp, dsurf);
+ if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(dsurf))
+ dri2_destroy_surface(drv, disp, rsurf);
+ if (ctx != NULL && !_eglIsContextLinked(ctx))
+ dri2_dpy->core->unbindContext(dri2_egl_context(ctx)->dri_context);
+
+ return EGL_TRUE;
+ } else {
+ _eglBindContext(&ctx, &dsurf, &rsurf);
+
+ return EGL_FALSE;
+ }
+}
+
+/**
+ * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
+ */
+static _EGLSurface *
+dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
+ _EGLConfig *conf, EGLNativeWindowType window,
+ const EGLint *attrib_list)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
+ struct dri2_egl_surface *dri2_surf;
+ xcb_get_geometry_cookie_t cookie;
+ xcb_get_geometry_reply_t *reply;
+ xcb_screen_iterator_t s;
+ xcb_generic_error_t *error;
+
+ dri2_surf = malloc(sizeof *dri2_surf);
+ if (!dri2_surf) {
+ _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
+ return NULL;
+ }
+
+ if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) {
+ free(dri2_surf);
+ return NULL;
+ }
+
+ dri2_surf->region = XCB_NONE;
+ if (type == EGL_PBUFFER_BIT) {
+ dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
+ s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
+ xcb_create_pixmap(dri2_dpy->conn,
+ _eglGetConfigKey(conf, EGL_BUFFER_SIZE),
+ dri2_surf->drawable, s.data->root,
+ dri2_surf->base.Width, dri2_surf->base.Height);
+ } else {
+ dri2_surf->drawable = window;
+ }
+
+ dri2_surf->dri_drawable =
+ (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen,
+ dri2_conf->dri_config, dri2_surf);
+ if (dri2_surf == NULL) {
+ _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
+ free(dri2_surf);
+ return NULL;
+ }
+
+ xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable);
+
+ cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable);
+ reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error);
+ if (reply == NULL || error != NULL) {
+ _eglError(EGL_BAD_ALLOC, "xcb_get_geometry");
+ free(dri2_surf);
+ free(error);
+ return NULL;
+ }
+ dri2_surf->base.Width = reply->width;
+ dri2_surf->base.Height = reply->height;
+ free(reply);
+
+ return &dri2_surf->base;
+}
+
+/**
+ * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
+ */
+static _EGLSurface *
+dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, EGLNativeWindowType window,
+ const EGLint *attrib_list)
+{
+ return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf,
+ window, attrib_list);
+}
+
+static _EGLSurface *
+dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, EGLNativePixmapType pixmap,
+ const EGLint *attrib_list)
+{
+ return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf,
+ pixmap, attrib_list);
+}
+
+static _EGLSurface *
+dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, const EGLint *attrib_list)
+{
+ return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf,
+ XCB_WINDOW_NONE, attrib_list);
+}
+
+static EGLBoolean
+dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
+ xcb_dri2_copy_region_cookie_t cookie;
+
+ (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+
+#if 0
+ /* FIXME: Add support for dri swapbuffers, that'll give us swap
+ * interval and page flipping (at least for fullscreen windows) as
+ * well as the page flip event. */
+#if __DRI2_FLUSH_VERSION >= 2
+ if (pdraw->psc->f)
+ (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable);
+#endif
+#endif
+
+ if (!dri2_surf->have_back)
+ return EGL_TRUE;
+
+ cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn,
+ dri2_surf->drawable,
+ dri2_surf->region,
+ XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
+ XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
+ free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL));
+
+ return EGL_TRUE;
+}
+
+/*
+ * Called from eglGetProcAddress() via drv->API.GetProcAddress().
+ */
+static _EGLProc
+dri2_get_proc_address(_EGLDriver *drv, const char *procname)
+{
+ /* FIXME: Do we need to support lookup of EGL symbols too? */
+
+ return (_EGLProc) _glapi_get_proc_address(procname);
+}
+
+static EGLBoolean
+dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface);
+
+ /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
+ * we need to copy fake to real here.*/
+
+ (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+
+ return EGL_TRUE;
+}
+
+static EGLBoolean
+dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine)
+{
+ if (engine != EGL_CORE_NATIVE_ENGINE)
+ return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
+ /* glXWaitX(); */
+
+ return EGL_TRUE;
+}
+
+static void
+dri2_unload(_EGLDriver *drv)
+{
+ struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
+ free(dri2_drv);
+}
+
+static EGLBoolean
+dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
+ EGLNativePixmapType target)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+ xcb_gcontext_t gc;
+
+ (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+
+ gc = xcb_generate_id(dri2_dpy->conn);
+ xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL);
+ xcb_copy_area(dri2_dpy->conn,
+ dri2_surf->drawable,
+ target,
+ gc,
+ 0, 0,
+ 0, 0,
+ dri2_surf->base.Width,
+ dri2_surf->base.Height);
+ xcb_free_gc(dri2_dpy->conn, gc);
+
+ return EGL_TRUE;
+}
+
+/**
+ * This is the main entrypoint into the driver, called by libEGL.
+ * Create a new _EGLDriver object and init its dispatch table.
+ */
+_EGLDriver *
+_eglMain(const char *args)
+{
+ struct dri2_egl_driver *dri2_drv;
+
+ dri2_drv = malloc(sizeof *dri2_drv);
+ if (!dri2_drv)
+ return NULL;
+
+ _eglInitDriverFallbacks(&dri2_drv->base);
+ dri2_drv->base.API.Initialize = dri2_initialize;
+ dri2_drv->base.API.Terminate = dri2_terminate;
+ dri2_drv->base.API.CreateContext = dri2_create_context;
+ dri2_drv->base.API.MakeCurrent = dri2_make_current;
+ dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface;
+ dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface;
+ dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface;
+ dri2_drv->base.API.DestroySurface = dri2_destroy_surface;
+ dri2_drv->base.API.SwapBuffers = dri2_swap_buffers;
+ dri2_drv->base.API.GetProcAddress = dri2_get_proc_address;
+ dri2_drv->base.API.WaitClient = dri2_wait_client;
+ dri2_drv->base.API.WaitNative = dri2_wait_native;
+ dri2_drv->base.API.CopyBuffers = dri2_copy_buffers;
+
+ dri2_drv->base.Name = "DRI2";
+ dri2_drv->base.Unload = dri2_unload;
+
+ return &dri2_drv->base;
+}
diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c
index af653b86ee..3cbfebe488 100644
--- a/src/egl/drivers/glx/egl_glx.c
+++ b/src/egl/drivers/glx/egl_glx.c
@@ -116,35 +116,14 @@ struct GLX_egl_config
int index;
};
-/** cast wrapper */
-static struct GLX_egl_driver *
-GLX_egl_driver(_EGLDriver *drv)
-{
- return (struct GLX_egl_driver *) drv;
-}
-
-static struct GLX_egl_display *
-GLX_egl_display(_EGLDisplay *dpy)
-{
- return (struct GLX_egl_display *) dpy->DriverData;
-}
-
-static struct GLX_egl_context *
-GLX_egl_context(_EGLContext *ctx)
-{
- return (struct GLX_egl_context *) ctx;
-}
-
-static struct GLX_egl_surface *
-GLX_egl_surface(_EGLSurface *surf)
-{
- return (struct GLX_egl_surface *) surf;
-}
+/* standard typecasts */
+_EGL_DRIVER_STANDARD_TYPECASTS(GLX_egl)
static int
GLX_egl_config_index(_EGLConfig *conf)
{
- return ((struct GLX_egl_config *) conf)->index;
+ struct GLX_egl_config *GLX_conf = GLX_egl_config(conf);
+ return GLX_conf->index;
}
@@ -422,7 +401,7 @@ create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy,
EGLBoolean ok;
memset(&template, 0, sizeof(template));
- _eglInitConfig(&template.Base, id);
+ _eglInitConfig(&template.Base, dpy, id);
if (GLX_dpy->have_fbconfig)
ok = convert_fbconfig(GLX_dpy->dpy, GLX_dpy->fbconfigs[i], &template);
else
@@ -605,7 +584,7 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
return NULL;
}
- if (!_eglInitContext(drv, &GLX_ctx->Base, conf, attrib_list)) {
+ if (!_eglInitContext(&GLX_ctx->Base, disp, conf, attrib_list)) {
free(GLX_ctx);
return NULL;
}
@@ -720,7 +699,7 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp,
return NULL;
}
- if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_WINDOW_BIT,
+ if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_WINDOW_BIT,
conf, attrib_list)) {
free(GLX_surf);
return NULL;
@@ -766,7 +745,7 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
return NULL;
}
- if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PIXMAP_BIT,
+ if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PIXMAP_BIT,
conf, attrib_list)) {
free(GLX_surf);
return NULL;
@@ -826,7 +805,7 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
return NULL;
}
- if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PBUFFER_BIT,
+ if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PBUFFER_BIT,
conf, attrib_list)) {
free(GLX_surf);
return NULL;
diff --git a/src/egl/drivers/xdri/Makefile b/src/egl/drivers/xdri/Makefile
deleted file mode 100644
index 9120620dc5..0000000000
--- a/src/egl/drivers/xdri/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
-# src/egl/drivers/xdri/Makefile
-
-TOP = ../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER = egl_xdri.so
-
-# steal sources from GLX
-GLX_SOURCES = dri_common.c XF86dri.c dri2.c dri2_glx.c dri_glx.c drisw_glx.c
-GLX_SOURCES := $(addprefix ../../../glx/x11/,$(GLX_SOURCES))
-GLX_INCLUDES = \
- $(shell pkg-config --cflags-only-I libdrm) \
- -I$(TOP)/include/GL/internal \
- -I$(TOP)/src/glx/x11 \
- -I$(TOP)/src/mesa/glapi \
- -I$(TOP)/src/mesa
-GLX_CFLAGS = -DGLX_DIRECT_RENDERING
-
-EGL_SOURCES = egl_xdri.c glxinit.c driinit.c $(GLX_SOURCES)
-EGL_INCLUDES = \
- -I$(TOP)/include \
- -I$(TOP)/src/egl/main \
- $(GLX_INCLUDES)
-
-EGL_CFLAGS = $(GLX_CFLAGS)
-EGL_LIBS = -lX11 -lGL
-
-include ../Makefile.template
diff --git a/src/egl/drivers/xdri/driinit.c b/src/egl/drivers/xdri/driinit.c
deleted file mode 100644
index 3e54f0bd4d..0000000000
--- a/src/egl/drivers/xdri/driinit.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * DRI initialization. The DRI loaders are defined in src/glx/x11/.
- */
-
-#include <stdlib.h>
-#include <sys/time.h>
-
-#include "glxclient.h"
-#include "driinit.h"
-
-/* for __DRI_SYSTEM_TIME extension */
-_X_HIDDEN int
-__glXGetUST(int64_t * ust)
-{
- struct timeval tv;
-
- if (ust == NULL) {
- return -EFAULT;
- }
-
- if (gettimeofday(&tv, NULL) == 0) {
- ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
- return 0;
- }
- else {
- return -errno;
- }
-}
-
-_X_HIDDEN GLboolean
-__driGetMscRateOML(__DRIdrawable * draw,
- int32_t * numerator, int32_t * denominator, void *private)
-{
- return GL_FALSE;
-}
-
-/* ignore glx extensions */
-_X_HIDDEN void
-__glXEnableDirectExtension(__GLXscreenConfigs * psc, const char *name)
-{
-}
-
-_X_HIDDEN __GLXDRIdisplay *
-__driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version)
-{
- __GLXDRIdisplay *driDisplay = NULL;
- int ver = 0;
- char *env;
- int force_sw;
-
- env = getenv("EGL_SOFTWARE");
- force_sw = (env && *env != '0');
-
- /* try DRI2 first */
- if (!force_sw) {
- driDisplay = dri2CreateDisplay(dpyPriv->dpy);
- if (driDisplay) {
- /* fill in the required field */
- dpyPriv->dri2Display = driDisplay;
- ver = 2;
- }
- }
-
- /* and then DRI */
- if (!force_sw && !driDisplay) {
- driDisplay = driCreateDisplay(dpyPriv->dpy);
- if (driDisplay) {
- dpyPriv->driDisplay = driDisplay;
- ver = 1;
- }
- }
-
- /* and then DRISW */
- if (!driDisplay) {
- driDisplay = driswCreateDisplay(dpyPriv->dpy);
- if (driDisplay) {
- dpyPriv->driDisplay = driDisplay;
- ver = 0;
- }
- }
-
- if (version)
- *version = ver;
- return driDisplay;
-}
diff --git a/src/egl/drivers/xdri/driinit.h b/src/egl/drivers/xdri/driinit.h
deleted file mode 100644
index 6ea05cebef..0000000000
--- a/src/egl/drivers/xdri/driinit.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef DRIINIT_INCLUDED
-#define DRIINIT_INCLUDED
-
-#include "glxclient.h"
-
-extern __GLXDRIdisplay *
-__driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version);
-
-#endif /* DRIINIT_INCLUDED */
diff --git a/src/egl/drivers/xdri/egl_xdri.c b/src/egl/drivers/xdri/egl_xdri.c
deleted file mode 100644
index 9c21576539..0000000000
--- a/src/egl/drivers/xdri/egl_xdri.c
+++ /dev/null
@@ -1,655 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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
- * without limitation the rights to use, copy, modify, merge, publish,
- * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * 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.
- *
- **************************************************************************/
-
-
-/**
- * Code to interface a DRI driver to libEGL.
- * Note that unlike previous DRI/EGL interfaces, this one is meant to
- * be used _with_ X. Applications will use eglCreateWindowSurface()
- * to render into X-created windows.
- *
- * This is an EGL driver that, in turn, loads a regular DRI driver.
- * There are some dependencies on code in libGL, but those could be
- * removed with some effort.
- *
- * Authors: Brian Paul
- */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <X11/Xlib.h>
-
-#include "glxinit.h"
-#include "driinit.h"
-#include "glapi/glapi.h" /* for glapi functions */
-
-#include "eglconfig.h"
-#include "eglconfigutil.h"
-#include "eglcontext.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglcurrent.h"
-#include "egllog.h"
-#include "eglsurface.h"
-
-#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
-
-/** subclass of _EGLDriver */
-struct xdri_egl_driver
-{
- _EGLDriver Base; /**< base class */
- void (*FlushCurrentContext)(void);
-};
-
-
-/** driver data of _EGLDisplay */
-struct xdri_egl_display
-{
- Display *dpy;
- __GLXdisplayPrivate *dpyPriv;
- __GLXDRIdisplay *driDisplay;
- int driVersion;
-
- __GLXscreenConfigs *psc;
- EGLint scr;
-};
-
-
-/** subclass of _EGLContext */
-struct xdri_egl_context
-{
- _EGLContext Base; /**< base class */
-
- /* just enough info to create dri contexts */
- GLXContext dummy_gc;
-
- __GLXDRIcontext *driContext;
-};
-
-
-/** subclass of _EGLSurface */
-struct xdri_egl_surface
-{
- _EGLSurface Base; /**< base class */
-
- Drawable drawable;
- __GLXDRIdrawable *driDrawable;
-};
-
-
-/** subclass of _EGLConfig */
-struct xdri_egl_config
-{
- _EGLConfig Base; /**< base class */
-
- const __GLcontextModes *mode; /**< corresponding GLX mode */
- EGLint window_render_buffer;
-};
-
-
-
-/** cast wrapper */
-static INLINE struct xdri_egl_driver *
-xdri_egl_driver(_EGLDriver *drv)
-{
- return (struct xdri_egl_driver *) drv;
-}
-
-
-static INLINE struct xdri_egl_display *
-lookup_display(_EGLDisplay *dpy)
-{
- return (struct xdri_egl_display *) dpy->DriverData;
-}
-
-
-/** Map EGLSurface handle to xdri_egl_surface object */
-static INLINE struct xdri_egl_surface *
-lookup_surface(_EGLSurface *surface)
-{
- return (struct xdri_egl_surface *) surface;
-}
-
-
-/** Map EGLContext handle to xdri_egl_context object */
-static INLINE struct xdri_egl_context *
-lookup_context(_EGLContext *context)
-{
- return (struct xdri_egl_context *) context;
-}
-
-
-/** Map EGLConfig handle to xdri_egl_config object */
-static INLINE struct xdri_egl_config *
-lookup_config(_EGLConfig *conf)
-{
- return (struct xdri_egl_config *) conf;
-}
-
-
-/** Get size of given window */
-static Status
-get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height)
-{
- Window root;
- Status stat;
- int xpos, ypos;
- unsigned int w, h, bw, depth;
- stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth);
- *width = w;
- *height = h;
- return stat;
-}
-
-
-static EGLBoolean
-convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m)
-{
- EGLint val;
-
- _eglInitConfig(conf, id);
- if (!_eglConfigFromContextModesRec(conf, m, EGL_OPENGL_BIT, EGL_OPENGL_BIT))
- return EGL_FALSE;
-
- if (m->doubleBufferMode) {
- /* pixmap and pbuffer surfaces are always single-buffered */
- val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
- val &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT);
- SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, val);
- }
- else {
- /* EGL requires OpenGL ES context to be double-buffered */
- val = GET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE);
- val &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT);
- SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, val);
- }
- /* skip "empty" config */
- if (!val)
- return EGL_FALSE;
-
- val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
- if (!(val & EGL_PBUFFER_BIT)) {
- /* bind-to-texture cannot be EGL_TRUE without pbuffer bit */
- SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE);
- SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE);
- }
-
- /* EGL_NATIVE_RENDERABLE is a boolean */
- val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE);
- if (val != EGL_TRUE)
- SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, EGL_FALSE);
-
- return _eglValidateConfig(conf, EGL_FALSE);
-}
-
-
-/**
- * Produce a set of EGL configs.
- */
-static EGLint
-create_configs(_EGLDisplay *disp, const __GLcontextModes *m, EGLint first_id)
-{
- struct xdri_egl_display *xdri_dpy = lookup_display(disp);
- int id = first_id;
-
- for (; m; m = m->next) {
- struct xdri_egl_config *xdri_conf;
- _EGLConfig conf;
- EGLint rb;
-
- if (!convert_config(&conf, id, m))
- continue;
- if (m->doubleBufferMode) {
- rb = EGL_BACK_BUFFER;
- }
- else {
- /* ignore single-buffered mode for DRISW */
- if (xdri_dpy->driVersion == 0)
- continue;
- rb = EGL_SINGLE_BUFFER;
- }
-
- xdri_conf = CALLOC_STRUCT(xdri_egl_config);
- if (xdri_conf) {
- memcpy(&xdri_conf->Base, &conf, sizeof(conf));
- xdri_conf->mode = m;
- xdri_conf->window_render_buffer = rb;
- _eglAddConfig(disp, &xdri_conf->Base);
- id++;
- }
- }
-
- return id;
-}
-
-
-/**
- * Called via eglInitialize(), xdri_dpy->API.Initialize().
- */
-static EGLBoolean
-xdri_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
- EGLint *minor, EGLint *major)
-{
- struct xdri_egl_display *xdri_dpy;
- __GLXdisplayPrivate *dpyPriv;
- __GLXDRIdisplay *driDisplay;
- __GLXscreenConfigs *psc;
- EGLint first_id = 1;
- int scr;
-
- xdri_dpy = CALLOC_STRUCT(xdri_egl_display);
- if (!xdri_dpy)
- return _eglError(EGL_BAD_ALLOC, "eglInitialize");
-
- xdri_dpy->dpy = (Display *) dpy->NativeDisplay;
- if (!xdri_dpy->dpy) {
- xdri_dpy->dpy = XOpenDisplay(NULL);
- if (!xdri_dpy->dpy) {
- free(xdri_dpy);
- return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
- }
- }
-
- dpyPriv = __glXInitialize(xdri_dpy->dpy);
- if (!dpyPriv) {
- _eglLog(_EGL_WARNING, "failed to create GLX display");
- free(xdri_dpy);
- return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
- }
-
- driDisplay = __driCreateDisplay(dpyPriv, &xdri_dpy->driVersion);
- if (!driDisplay) {
- _eglLog(_EGL_WARNING, "failed to create DRI display");
- free(xdri_dpy);
- return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
- }
-
- scr = DefaultScreen(xdri_dpy->dpy);
- psc = &dpyPriv->screenConfigs[scr];
-
- xdri_dpy->dpyPriv = dpyPriv;
- xdri_dpy->driDisplay = driDisplay;
- xdri_dpy->psc = psc;
- xdri_dpy->scr = scr;
-
- psc->driScreen = driDisplay->createScreen(psc, scr, dpyPriv);
- if (!psc->driScreen) {
- _eglLog(_EGL_WARNING, "failed to create DRI screen #%d", scr);
- free(xdri_dpy);
- return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
- }
-
- dpy->DriverData = xdri_dpy;
- dpy->ClientAPIsMask = EGL_OPENGL_BIT;
-
- /* add visuals and fbconfigs */
- first_id = create_configs(dpy, psc->visuals, first_id);
- create_configs(dpy, psc->configs, first_id);
-
- /* we're supporting EGL 1.4 */
- *minor = 1;
- *major = 4;
-
- return EGL_TRUE;
-}
-
-
-/**
- * Called via eglTerminate(), drv->API.Terminate().
- */
-static EGLBoolean
-xdri_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy)
-{
- struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
- __GLXscreenConfigs *psc;
-
- _eglReleaseDisplayResources(drv, dpy);
- _eglCleanupDisplay(dpy);
-
- psc = xdri_dpy->psc;
- if (psc->driver_configs) {
- unsigned int i;
- for (i = 0; psc->driver_configs[i]; i++)
- free((__DRIconfig *) psc->driver_configs[i]);
- free(psc->driver_configs);
- psc->driver_configs = NULL;
- }
- if (psc->driScreen) {
- psc->driScreen->destroyScreen(psc);
- free(psc->driScreen);
- psc->driScreen = NULL;
- }
-
- xdri_dpy->driDisplay->destroyDisplay(xdri_dpy->driDisplay);
-
- free(xdri_dpy);
- dpy->DriverData = NULL;
-
- return EGL_TRUE;
-}
-
-
-/*
- * Called from eglGetProcAddress() via drv->API.GetProcAddress().
- */
-static _EGLProc
-xdri_eglGetProcAddress(_EGLDriver *drv, const char *procname)
-{
- /* the symbol is defined in libGL.so */
- return (_EGLProc) _glapi_get_proc_address(procname);
-}
-
-
-/**
- * Called via eglCreateContext(), drv->API.CreateContext().
- */
-static _EGLContext *
-xdri_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- _EGLContext *share_list, const EGLint *attrib_list)
-{
- struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
- struct xdri_egl_config *xdri_config = lookup_config(conf);
- struct xdri_egl_context *shared = lookup_context(share_list);
- __GLXscreenConfigs *psc = xdri_dpy->psc;
- int renderType = GLX_RGBA_BIT;
- struct xdri_egl_context *xdri_ctx;
-
- xdri_ctx = CALLOC_STRUCT(xdri_egl_context);
- if (!xdri_ctx) {
- _eglError(EGL_BAD_ALLOC, "eglCreateContext");
- return NULL;
- }
-
- xdri_ctx->dummy_gc = CALLOC_STRUCT(__GLXcontextRec);
- if (!xdri_ctx->dummy_gc) {
- _eglError(EGL_BAD_ALLOC, "eglCreateContext");
- free(xdri_ctx);
- return NULL;
- }
-
- if (!_eglInitContext(drv, &xdri_ctx->Base, &xdri_config->Base, attrib_list)) {
- free(xdri_ctx->dummy_gc);
- free(xdri_ctx);
- return NULL;
- }
-
- /* the config decides the render buffer for the context */
- xdri_ctx->Base.WindowRenderBuffer = xdri_config->window_render_buffer;
-
- xdri_ctx->driContext =
- psc->driScreen->createContext(psc,
- xdri_config->mode,
- xdri_ctx->dummy_gc,
- (shared) ? shared->dummy_gc : NULL,
- renderType);
- if (!xdri_ctx->driContext) {
- free(xdri_ctx->dummy_gc);
- free(xdri_ctx);
- return NULL;
- }
-
- /* fill in the required field */
- xdri_ctx->dummy_gc->driContext = xdri_ctx->driContext;
-
- return &xdri_ctx->Base;
-}
-
-
-/**
- * Destroy a context.
- */
-static void
-destroy_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
- struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
- struct xdri_egl_context *xdri_ctx = lookup_context(ctx);
-
- /* FIXME a context might live longer than its display */
- if (!dpy->Initialized)
- _eglLog(_EGL_FATAL, "destroy a context with an unitialized display");
-
- xdri_ctx->driContext->destroyContext(xdri_ctx->driContext,
- xdri_dpy->psc, xdri_dpy->dpy);
- free(xdri_ctx->dummy_gc);
- free(xdri_ctx);
-}
-
-
-/**
- * Destroy a surface.
- */
-static void
-destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
-{
- struct xdri_egl_surface *xdri_surf = lookup_surface(surf);
-
- if (!dpy->Initialized)
- _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display");
-
- xdri_surf->driDrawable->destroyDrawable(xdri_surf->driDrawable);
- free(xdri_surf);
-}
-
-
-static EGLBoolean
-xdri_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
-{
- if (!_eglIsContextBound(ctx))
- destroy_context(dpy, ctx);
- return EGL_TRUE;
-}
-
-
-/**
- * Called via eglMakeCurrent(), drv->API.MakeCurrent().
- */
-static EGLBoolean
-xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
- _EGLSurface *r, _EGLContext *context)
-{
- struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
- struct xdri_egl_context *xdri_ctx = lookup_context(context);
- struct xdri_egl_surface *draw = lookup_surface(d);
- struct xdri_egl_surface *read = lookup_surface(r);
-
- /* bind the new context and return the "orphaned" one */
- if (!_eglBindContext(&context, &d, &r))
- return EGL_FALSE;
-
- /* flush before context switch */
- if (context && xdri_driver->FlushCurrentContext)
- xdri_driver->FlushCurrentContext();
-
- /* the symbol is defined in libGL.so */
- _glapi_check_multithread();
-
- if (xdri_ctx) {
- if (!xdri_ctx->driContext->bindContext(xdri_ctx->driContext,
- draw->driDrawable,
- read->driDrawable)) {
- return EGL_FALSE;
- }
- }
- else if (context) {
- xdri_ctx = lookup_context(context);
- xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
- }
-
- if (context && !_eglIsContextLinked(context))
- destroy_context(dpy, context);
- if (d && !_eglIsSurfaceLinked(d))
- destroy_surface(dpy, d);
- if (r && r != d && !_eglIsSurfaceLinked(r))
- destroy_surface(dpy, r);
-
- return EGL_TRUE;
-}
-
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-xdri_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- EGLNativeWindowType window,
- const EGLint *attrib_list)
-{
- struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
- struct xdri_egl_config *xdri_config = lookup_config(conf);
- struct xdri_egl_surface *xdri_surf;
- uint width, height;
-
- xdri_surf = CALLOC_STRUCT(xdri_egl_surface);
- if (!xdri_surf) {
- _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
- return NULL;
- }
-
- if (!_eglInitSurface(drv, &xdri_surf->Base, EGL_WINDOW_BIT,
- &xdri_config->Base, attrib_list)) {
- free(xdri_surf);
- return NULL;
- }
-
- xdri_surf->driDrawable =
- xdri_dpy->psc->driScreen->createDrawable(xdri_dpy->psc,
- (XID) window,
- (GLXDrawable) window,
- xdri_config->mode);
- if (!xdri_surf->driDrawable) {
- free(xdri_surf);
- return NULL;
- }
-
- xdri_surf->drawable = (Drawable) window;
-
- get_drawable_size(xdri_dpy->dpy, window, &width, &height);
- xdri_surf->Base.Width = width;
- xdri_surf->Base.Height = height;
-
- return &xdri_surf->Base;
-}
-
-
-/**
- * Called via eglCreatePbufferSurface(), drv->API.CreatePbufferSurface().
- */
-static _EGLSurface *
-xdri_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- const EGLint *attrib_list)
-{
- return NULL;
-}
-
-
-
-static EGLBoolean
-xdri_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
-{
- if (!_eglIsSurfaceBound(surface))
- destroy_surface(dpy, surface);
- return EGL_TRUE;
-}
-
-
-static EGLBoolean
-xdri_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
- EGLint buffer)
-{
- return EGL_FALSE;
-}
-
-
-static EGLBoolean
-xdri_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
- EGLint buffer)
-{
- return EGL_FALSE;
-}
-
-
-static EGLBoolean
-xdri_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
-{
- struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
- struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
- struct xdri_egl_surface *xdri_surf = lookup_surface(draw);
-
- /* swapBuffers does not flush commands */
- if (draw->CurrentContext && xdri_driver->FlushCurrentContext)
- xdri_driver->FlushCurrentContext();
-
- xdri_dpy->psc->driScreen->swapBuffers(xdri_surf->driDrawable, 0, 0, 0);
-
- return EGL_TRUE;
-}
-
-
-static void
-xdri_Unload(_EGLDriver *drv)
-{
- struct xdri_egl_driver *xdri_drv = xdri_egl_driver(drv);
- free(xdri_drv);
-}
-
-
-/**
- * This is the main entrypoint into the driver, called by libEGL.
- * Create a new _EGLDriver object and init its dispatch table.
- */
-_EGLDriver *
-_eglMain(const char *args)
-{
- struct xdri_egl_driver *xdri_drv = CALLOC_STRUCT(xdri_egl_driver);
- if (!xdri_drv)
- return NULL;
-
- _eglInitDriverFallbacks(&xdri_drv->Base);
- xdri_drv->Base.API.Initialize = xdri_eglInitialize;
- xdri_drv->Base.API.Terminate = xdri_eglTerminate;
-
- xdri_drv->Base.API.GetProcAddress = xdri_eglGetProcAddress;
-
- xdri_drv->Base.API.CreateContext = xdri_eglCreateContext;
- xdri_drv->Base.API.DestroyContext = xdri_eglDestroyContext;
- xdri_drv->Base.API.MakeCurrent = xdri_eglMakeCurrent;
- xdri_drv->Base.API.CreateWindowSurface = xdri_eglCreateWindowSurface;
- xdri_drv->Base.API.CreatePbufferSurface = xdri_eglCreatePbufferSurface;
- xdri_drv->Base.API.DestroySurface = xdri_eglDestroySurface;
- xdri_drv->Base.API.BindTexImage = xdri_eglBindTexImage;
- xdri_drv->Base.API.ReleaseTexImage = xdri_eglReleaseTexImage;
- xdri_drv->Base.API.SwapBuffers = xdri_eglSwapBuffers;
-
- xdri_drv->Base.Name = "X/DRI";
- xdri_drv->Base.Unload = xdri_Unload;
-
- /* we need a way to flush commands */
- xdri_drv->FlushCurrentContext =
- (void (*)(void)) xdri_eglGetProcAddress(&xdri_drv->Base, "glFlush");
-
- return &xdri_drv->Base;
-}
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index b974e40cce..1190f8cdd5 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -25,10 +25,12 @@
* IDs are from 1 to N respectively.
*/
void
-_eglInitConfig(_EGLConfig *config, EGLint id)
+_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id)
{
memset(config, 0, sizeof(*config));
+ config->Display = dpy;
+
/* some attributes take non-zero default values */
SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id);
SET_CONFIG_ATTRIB(config, EGL_CONFIG_CAVEAT, EGL_NONE);
@@ -323,11 +325,12 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
mask = EGL_PBUFFER_BIT |
EGL_PIXMAP_BIT |
EGL_WINDOW_BIT |
- EGL_SCREEN_BIT_MESA | /* XXX should check the extension */
EGL_VG_COLORSPACE_LINEAR_BIT |
EGL_VG_ALPHA_FORMAT_PRE_BIT |
EGL_MULTISAMPLE_RESOLVE_BOX_BIT |
EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
+ if (conf->Display->Extensions.MESA_screen_surface)
+ mask |= EGL_SCREEN_BIT_MESA;
break;
case EGL_RENDERABLE_TYPE:
case EGL_CONFORMANT:
@@ -363,8 +366,11 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_SPECIAL)
valid = EGL_TRUE;
}
- if (!valid)
+ if (!valid) {
+ _eglLog(_EGL_DEBUG,
+ "attribute 0x%04x has an invalid value 0x%x", attr, val);
break;
+ }
}
/* any invalid attribute value should have been catched */
@@ -387,10 +393,18 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
valid = EGL_FALSE;
break;
}
+ if (!valid) {
+ _eglLog(_EGL_DEBUG, "conflicting color buffer type and channel sizes");
+ return EGL_FALSE;
+ }
val = GET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS);
if (!val && GET_CONFIG_ATTRIB(conf, EGL_SAMPLES))
valid = EGL_FALSE;
+ if (!valid) {
+ _eglLog(_EGL_DEBUG, "conflicting samples and sample buffers");
+ return EGL_FALSE;
+ }
val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
if (!(val & EGL_WINDOW_BIT)) {
@@ -403,6 +417,10 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA))
valid = EGL_FALSE;
}
+ if (!valid) {
+ _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding");
+ return EGL_FALSE;
+ }
return valid;
}
@@ -454,8 +472,14 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
break;
}
- if (!matched)
+ if (!matched) {
+#ifdef DEBUG
+ _eglLog(_EGL_DEBUG,
+ "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)",
+ val, attr, cmp);
+#endif
break;
+ }
}
return matched;
@@ -730,7 +754,7 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
if (!num_configs)
return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs");
- _eglInitConfig(&criteria, 0);
+ _eglInitConfig(&criteria, disp, 0);
if (!_eglParseConfigAttribList(&criteria, attrib_list))
return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h
index 799bf4ee24..56ec95fe9a 100644
--- a/src/egl/main/eglconfig.h
+++ b/src/egl/main/eglconfig.h
@@ -21,6 +21,9 @@ struct _egl_config
};
+/**
+ * Macros for source level compatibility.
+ */
#define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL)
#define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR)
@@ -55,6 +58,10 @@ _eglResetConfigKeys(_EGLConfig *conf, EGLint val)
/**
* Update a config for a given key.
+ *
+ * Note that a valid key is not necessarily a valid attribute. There are gaps
+ * in the attribute enums. The separation is to catch application errors.
+ * Drivers should never set a key that is an invalid attribute.
*/
static INLINE void
_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
@@ -77,22 +84,8 @@ _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
}
-/**
- * Set a given attribute.
- *
- * Because _eglGetConfigAttrib is already used as a fallback driver
- * function, this function is not considered to have a good name.
- * SET_CONFIG_ATTRIB is preferred over this function.
- */
-static INLINE void
-_eglSetConfigAttrib(_EGLConfig *conf, EGLint attr, EGLint val)
-{
- SET_CONFIG_ATTRIB(conf, attr, val);
-}
-
-
PUBLIC void
-_eglInitConfig(_EGLConfig *config, EGLint id);
+_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id);
PUBLIC EGLConfig
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index d0c6b1b64c..012d8dfe1f 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -4,9 +4,96 @@
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldisplay.h"
-#include "egldriver.h"
#include "eglcurrent.h"
#include "eglsurface.h"
+#include "egllog.h"
+
+
+/**
+ * Return the API bit (one of EGL_xxx_BIT) of the context.
+ */
+static EGLint
+_eglGetContextAPIBit(_EGLContext *ctx)
+{
+ EGLint bit = 0;
+
+ switch (ctx->ClientAPI) {
+ case EGL_OPENGL_ES_API:
+ switch (ctx->ClientVersion) {
+ case 1:
+ bit = EGL_OPENGL_ES_BIT;
+ break;
+ case 2:
+ bit = EGL_OPENGL_ES2_BIT;
+ break;
+ default:
+ break;
+ }
+ break;
+ case EGL_OPENVG_API:
+ bit = EGL_OPENVG_BIT;
+ break;
+ case EGL_OPENGL_API:
+ bit = EGL_OPENGL_BIT;
+ break;
+ default:
+ break;
+ }
+
+ return bit;
+}
+
+
+/**
+ * Parse the list of context attributes and return the proper error code.
+ */
+static EGLint
+_eglParseContextAttribList(_EGLContext *ctx, const EGLint *attrib_list)
+{
+ EGLenum api = ctx->ClientAPI;
+ EGLint i, err = EGL_SUCCESS;
+
+ if (!attrib_list)
+ return EGL_SUCCESS;
+
+ for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+ EGLint attr = attrib_list[i++];
+ EGLint val = attrib_list[i];
+
+ switch (attr) {
+ case EGL_CONTEXT_CLIENT_VERSION:
+ if (api != EGL_OPENGL_ES_API) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (val != 1 && val != 2) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ ctx->ClientVersion = val;
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+
+ if (err != EGL_SUCCESS) {
+ _eglLog(_EGL_DEBUG, "bad context attribute 0x%04x", attr);
+ break;
+ }
+ }
+
+ if (err == EGL_SUCCESS) {
+ EGLint renderable_type, api_bit;
+
+ renderable_type = GET_CONFIG_ATTRIB(ctx->Config, EGL_RENDERABLE_TYPE);
+ api_bit = _eglGetContextAPIBit(ctx);
+ if (!(renderable_type & api_bit))
+ err = EGL_BAD_CONFIG;
+ }
+
+ return err;
+}
/**
@@ -14,11 +101,11 @@
* in the attrib_list.
*/
EGLBoolean
-_eglInitContext(_EGLDriver *drv, _EGLContext *ctx,
- _EGLConfig *conf, const EGLint *attrib_list)
+_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf,
+ const EGLint *attrib_list)
{
- EGLint i;
const EGLenum api = eglQueryAPI();
+ EGLint err;
if (api == EGL_NONE) {
_eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)");
@@ -26,26 +113,16 @@ _eglInitContext(_EGLDriver *drv, _EGLContext *ctx,
}
memset(ctx, 0, sizeof(_EGLContext));
+ ctx->Resource.Display = dpy;
+ ctx->ClientAPI = api;
+ ctx->Config = conf;
+ ctx->WindowRenderBuffer = EGL_NONE;
ctx->ClientVersion = 1; /* the default, per EGL spec */
- for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
- switch (attrib_list[i]) {
- case EGL_CONTEXT_CLIENT_VERSION:
- i++;
- ctx->ClientVersion = attrib_list[i];
- break;
- default:
- _eglError(EGL_BAD_ATTRIBUTE, "_eglInitContext");
- return EGL_FALSE;
- }
- }
-
- ctx->Config = conf;
- ctx->DrawSurface = EGL_NO_SURFACE;
- ctx->ReadSurface = EGL_NO_SURFACE;
- ctx->ClientAPI = api;
- ctx->WindowRenderBuffer = EGL_NONE;
+ err = _eglParseContextAttribList(ctx, attrib_list);
+ if (err != EGL_SUCCESS)
+ return _eglError(err, "eglCreateContext");
return EGL_TRUE;
}
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index ebb50aa60e..cfe92dd9f5 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -30,7 +30,7 @@ struct _egl_context
PUBLIC EGLBoolean
-_eglInitContext(_EGLDriver *drv, _EGLContext *ctx,
+_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
_EGLConfig *config, const EGLint *attrib_list);
@@ -60,6 +60,9 @@ _eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLConte
/**
* Return true if the context is bound to a thread.
+ *
+ * The binding is considered a reference to the context. Drivers should not
+ * destroy a context when it is bound.
*/
static INLINE EGLBoolean
_eglIsContextBound(_EGLContext *ctx)
@@ -119,6 +122,9 @@ _eglGetContextHandle(_EGLContext *ctx)
/**
* Return true if the context is linked to a display.
+ *
+ * The link is considered a reference to the context (the display is owning the
+ * context). Drivers should not destroy a context when it is linked.
*/
static INLINE EGLBoolean
_eglIsContextLinked(_EGLContext *ctx)
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index a19dcf4096..989c19a2fa 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include "eglglobals.h"
-#include "eglcontext.h"
#include "egllog.h"
#include "eglmutex.h"
#include "eglcurrent.h"
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 5897372fc5..d7a8d14292 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -10,7 +10,6 @@
#include "egldisplay.h"
#include "egldriver.h"
#include "eglglobals.h"
-#include "eglcurrent.h"
#include "eglmutex.h"
#include "egllog.h"
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index b04b094d84..03903290fd 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -38,6 +38,11 @@ struct _egl_extensions
EGLBoolean MESA_copy_context;
EGLBoolean KHR_image_base;
EGLBoolean KHR_image_pixmap;
+ EGLBoolean KHR_vg_parent_image;
+ EGLBoolean KHR_gl_texture_2D_image;
+ EGLBoolean KHR_gl_texture_cubemap_image;
+ EGLBoolean KHR_gl_texture_3D_image;
+ EGLBoolean KHR_gl_renderbuffer_image;
char String[_EGL_MAX_EXTENSIONS_LEN];
};
@@ -63,8 +68,6 @@ struct _egl_display
_EGLExtensions Extensions;
- int LargestPbuffer;
-
EGLint NumScreens;
_EGLScreen **Screens; /* array [NumScreens] */
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index df36369ac2..a87c697b11 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -13,7 +13,6 @@
#include "egldisplay.h"
#include "egldriver.h"
#include "eglglobals.h"
-#include "eglcurrent.h"
#include "egllog.h"
#include "eglmisc.h"
#include "eglmode.h"
@@ -26,6 +25,7 @@
#include <dlfcn.h>
#include <sys/types.h>
#include <dirent.h>
+#include <unistd.h>
#endif
@@ -56,21 +56,7 @@ close_library(HMODULE lib)
static const char *
library_suffix(void)
{
- return "dll";
-}
-
-
-static EGLBoolean
-make_library_path(char *buf, unsigned int size, const char *name)
-{
- EGLBoolean need_suffix;
- const char *suffix = ".dll";
- int ret;
-
- need_suffix = (strchr(name, '.') == NULL);
- ret = snprintf(buf, size, "%s%s", name, (need_suffix) ? suffix : "");
-
- return ((unsigned int) ret < size);
+ return ".dll";
}
@@ -97,30 +83,13 @@ close_library(void *lib)
static const char *
library_suffix(void)
{
- return "so";
-}
-
-
-static EGLBoolean
-make_library_path(char *buf, unsigned int size, const char *name)
-{
- EGLBoolean need_dir, need_suffix;
- const char *suffix = ".so";
- int ret;
-
- need_dir = (strchr(name, '/') == NULL);
- need_suffix = (strchr(name, '.') == NULL);
-
- ret = snprintf(buf, size, "%s%s%s",
- (need_dir) ? _EGL_DRIVER_SEARCH_DIR"/" : "", name,
- (need_suffix) ? suffix : "");
-
- return ((unsigned int) ret < size);
+ return ".so";
}
#else /* _EGL_PLATFORM_NO_OS */
+
static const char DefaultDriverName[] = "builtin";
typedef void *lib_handle;
@@ -144,14 +113,6 @@ library_suffix(void)
}
-static EGLBoolean
-make_library_path(char *buf, unsigned int size, const char *name)
-{
- int ret = snprintf(buf, size, name);
- return ((unsigned int) ret < size);
-}
-
-
#endif
@@ -300,122 +261,260 @@ _eglMatchDriver(_EGLDisplay *dpy)
/**
- * Preload a user driver.
- *
- * A user driver can be specified by EGL_DRIVER.
+ * A loader function for use with _eglPreloadForEach. The loader data is the
+ * filename of the driver. This function stops on the first valid driver.
*/
static EGLBoolean
-_eglPreloadUserDriver(void)
+_eglLoaderFile(const char *dir, size_t len, void *loader_data)
{
-#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS)
_EGLDriver *drv;
char path[1024];
- char *env;
-
- env = getenv("EGL_DRIVER");
- if (!env)
- return EGL_FALSE;
+ const char *filename = (const char *) loader_data;
+ size_t flen = strlen(filename);
- if (!make_library_path(path, sizeof(path), env))
- return EGL_FALSE;
+ /* make a full path */
+ if (len + flen + 2 > sizeof(path))
+ return EGL_TRUE;
+ if (len) {
+ memcpy(path, dir, len);
+ path[len++] = '/';
+ }
+ memcpy(path + len, filename, flen);
+ len += flen;
+ path[len] = '\0';
drv = _eglLoadDriver(path, NULL);
- if (!drv) {
- _eglLog(_EGL_WARNING, "EGL_DRIVER is set to an invalid driver");
- return EGL_FALSE;
+ /* fix the path and load again */
+ if (!drv && library_suffix()) {
+ const char *suffix = library_suffix();
+ size_t slen = strlen(suffix);
+ const char *p;
+ EGLBoolean need_suffix;
+
+ p = filename + flen - slen;
+ need_suffix = (p < filename || strcmp(p, suffix) != 0);
+ if (need_suffix && len + slen + 1 <= sizeof(path)) {
+ strcpy(path + len, suffix);
+ drv = _eglLoadDriver(path, NULL);
+ }
}
+ if (!drv)
+ return EGL_TRUE;
+ /* remember the driver and stop */
_eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
-
- return EGL_TRUE;
-#else /* _EGL_PLATFORM_POSIX || _EGL_PLATFORM_WINDOWS */
return EGL_FALSE;
-#endif
}
/**
- * Preload display drivers.
- *
- * Display drivers are a set of drivers that support a certain display system.
- * The display system may be specified by EGL_DISPLAY.
- *
- * FIXME This makes libEGL a memory hog if an user driver is not specified and
- * there are many display drivers.
+ * A loader function for use with _eglPreloadForEach. The loader data is the
+ * pattern (prefix) of the files to look for.
*/
static EGLBoolean
-_eglPreloadDisplayDrivers(void)
+_eglLoaderPattern(const char *dir, size_t len, void *loader_data)
{
#if defined(_EGL_PLATFORM_POSIX)
- const char *dpy, *suffix;
- char path[1024], prefix[32];
+ const char *prefix, *suffix;
+ size_t prefix_len, suffix_len;
DIR *dirp;
struct dirent *dirent;
+ char path[1024];
- dpy = getenv("EGL_DISPLAY");
- if (!dpy || !dpy[0])
- dpy = _EGL_DEFAULT_DISPLAY;
- if (!dpy || !dpy[0])
- return EGL_FALSE;
-
- snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
- suffix = library_suffix();
+ if (len + 2 > sizeof(path))
+ return EGL_TRUE;
+ if (len) {
+ memcpy(path, dir, len);
+ path[len++] = '/';
+ }
+ path[len] = '\0';
- dirp = opendir(_EGL_DRIVER_SEARCH_DIR);
+ dirp = opendir(path);
if (!dirp)
- return EGL_FALSE;
+ return EGL_TRUE;
+
+ prefix = (const char *) loader_data;
+ prefix_len = strlen(prefix);
+ suffix = library_suffix();
+ suffix_len = (suffix) ? strlen(suffix) : 0;
while ((dirent = readdir(dirp))) {
_EGLDriver *drv;
+ size_t dirent_len = strlen(dirent->d_name);
const char *p;
/* match the prefix */
- if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
+ if (strncmp(dirent->d_name, prefix, prefix_len) != 0)
continue;
-
/* match the suffix */
- p = strrchr(dirent->d_name, '.');
- if ((p && !suffix) || (!p && suffix))
- continue;
- else if (p && suffix && strcmp(p + 1, suffix) != 0)
- continue;
-
- snprintf(path, sizeof(path),
- _EGL_DRIVER_SEARCH_DIR"/%s", dirent->d_name);
+ if (suffix) {
+ p = dirent->d_name + dirent_len - suffix_len;
+ if (p < dirent->d_name || strcmp(p, suffix) != 0)
+ continue;
+ }
- drv = _eglLoadDriver(path, NULL);
- if (drv)
- _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+ /* make a full path and load the driver */
+ if (len + dirent_len + 1 <= sizeof(path)) {
+ strcpy(path + len, dirent->d_name);
+ drv = _eglLoadDriver(path, NULL);
+ if (drv)
+ _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+ }
}
closedir(dirp);
- return (_eglGlobal.NumDrivers > 0);
+ return EGL_TRUE;
#else /* _EGL_PLATFORM_POSIX */
+ /* stop immediately */
return EGL_FALSE;
#endif
}
/**
- * Preload the default driver.
+ * Run the preload function on each driver directory and return the number of
+ * drivers loaded.
+ *
+ * The process may end prematurely if the callback function returns false.
+ */
+static EGLint
+_eglPreloadForEach(const char *search_path,
+ EGLBoolean (*loader)(const char *, size_t, void *),
+ void *loader_data)
+{
+ const char *cur, *next;
+ size_t len;
+ EGLint num_drivers = _eglGlobal.NumDrivers;
+
+ cur = search_path;
+ while (cur) {
+ next = strchr(cur, ':');
+ len = (next) ? next - cur : strlen(cur);
+
+ if (!loader(cur, len, loader_data))
+ break;
+
+ cur = (next) ? next + 1 : NULL;
+ }
+
+ return (_eglGlobal.NumDrivers - num_drivers);
+}
+
+
+/**
+ * Return a list of colon-separated driver directories.
+ */
+static const char *
+_eglGetSearchPath(void)
+{
+ static const char *search_path;
+
+#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS)
+ if (!search_path) {
+ static char buffer[1024];
+ const char *p;
+ int ret;
+
+ p = getenv("EGL_DRIVERS_PATH");
+#if defined(_EGL_PLATFORM_POSIX)
+ if (p && (geteuid() != getuid() || getegid() != getgid())) {
+ _eglLog(_EGL_DEBUG,
+ "ignore EGL_DRIVERS_PATH for setuid/setgid binaries");
+ p = NULL;
+ }
+#endif /* _EGL_PLATFORM_POSIX */
+
+ if (p) {
+ ret = snprintf(buffer, sizeof(buffer),
+ "%s:%s", p, _EGL_DRIVER_SEARCH_DIR);
+ if (ret > 0 && ret < sizeof(buffer))
+ search_path = buffer;
+ }
+ }
+ if (!search_path)
+ search_path = _EGL_DRIVER_SEARCH_DIR;
+#else
+ search_path = "";
+#endif
+
+ return search_path;
+}
+
+
+/**
+ * Preload a user driver.
+ *
+ * A user driver can be specified by EGL_DRIVER.
*/
static EGLBoolean
-_eglPreloadDefaultDriver(void)
+_eglPreloadUserDriver(void)
{
- _EGLDriver *drv;
- char path[1024];
+ const char *search_path = _eglGetSearchPath();
+ char *env;
+
+ env = getenv("EGL_DRIVER");
+#if defined(_EGL_PLATFORM_POSIX)
+ if (env && strchr(env, '/')) {
+ search_path = "";
+ if ((geteuid() != getuid() || getegid() != getgid())) {
+ _eglLog(_EGL_DEBUG,
+ "ignore EGL_DRIVER for setuid/setgid binaries");
+ env = NULL;
+ }
+ }
+#endif /* _EGL_PLATFORM_POSIX */
+ if (!env)
+ return EGL_FALSE;
- if (!make_library_path(path, sizeof(path), DefaultDriverName))
+ if (!_eglPreloadForEach(search_path, _eglLoaderFile, (void *) env)) {
+ _eglLog(_EGL_WARNING, "EGL_DRIVER is set to an invalid driver");
return EGL_FALSE;
+ }
- drv = _eglLoadDriver(path, NULL);
- if (!drv)
+ return EGL_TRUE;
+}
+
+
+/**
+ * Preload display drivers.
+ *
+ * Display drivers are a set of drivers that support a certain display system.
+ * The display system may be specified by EGL_DISPLAY.
+ *
+ * FIXME This makes libEGL a memory hog if an user driver is not specified and
+ * there are many display drivers.
+ */
+static EGLBoolean
+_eglPreloadDisplayDrivers(void)
+{
+ const char *dpy;
+ char prefix[32];
+ int ret;
+
+ dpy = getenv("EGL_DISPLAY");
+ if (!dpy || !dpy[0])
+ dpy = _EGL_DEFAULT_DISPLAY;
+ if (!dpy || !dpy[0])
return EGL_FALSE;
- _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+ ret = snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
+ if (ret < 0 || ret >= sizeof(prefix))
+ return EGL_FALSE;
- return EGL_TRUE;
+ return (_eglPreloadForEach(_eglGetSearchPath(),
+ _eglLoaderPattern, (void *) prefix) > 0);
+}
+
+
+/**
+ * Preload the default driver.
+ */
+static EGLBoolean
+_eglPreloadDefaultDriver(void)
+{
+ return (_eglPreloadForEach(_eglGetSearchPath(),
+ _eglLoaderFile, (void *) DefaultDriverName) > 0);
}
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 5149acd964..55686681dc 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -6,6 +6,33 @@
#include "eglapi.h"
+/**
+ * Define an inline driver typecast function.
+ *
+ * Note that this macro defines a function and should not be ended with a
+ * semicolon when used.
+ */
+#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \
+ static INLINE struct drvtype *drvtype(const egltype *obj) \
+ { return (struct drvtype *) code; }
+
+
+/**
+ * Define the driver typecast functions for _EGLDriver, _EGLDisplay,
+ * _EGLContext, _EGLSurface, and _EGLConfig.
+ *
+ * Note that this macro defines several functions and should not be ended with
+ * a semicolon when used.
+ */
+#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \
+ _EGL_DRIVER_TYPECAST(drvname ## _driver, _EGLDriver, obj) \
+ /* note that this is not a direct cast */ \
+ _EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) \
+ _EGL_DRIVER_TYPECAST(drvname ## _context, _EGLContext, obj) \
+ _EGL_DRIVER_TYPECAST(drvname ## _surface, _EGLSurface, obj) \
+ _EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj)
+
+
typedef _EGLDriver *(*_EGLMain_t)(const char *args);
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index 5044112fa8..5732ef35ec 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -1,31 +1,70 @@
#include <assert.h>
+#include <string.h>
#include "eglimage.h"
-#include "egldisplay.h"
+#include "eglcurrent.h"
+#include "egllog.h"
#ifdef EGL_KHR_image_base
-EGLBoolean
-_eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list)
+/**
+ * Parse the list of image attributes and return the proper error code.
+ */
+static EGLint
+_eglParseImageAttribList(_EGLImage *img, const EGLint *attrib_list)
{
- EGLint i;
+ EGLint i, err = EGL_SUCCESS;
- img->Preserved = EGL_FALSE;
+ if (!attrib_list)
+ return EGL_SUCCESS;
+
+ for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+ EGLint attr = attrib_list[i++];
+ EGLint val = attrib_list[i];
- for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
- switch (attrib_list[i]) {
+ switch (attr) {
case EGL_IMAGE_PRESERVED_KHR:
- i++;
- img->Preserved = attrib_list[i];
+ img->Preserved = val;
+ break;
+ case EGL_GL_TEXTURE_LEVEL_KHR:
+ img->GLTextureLevel = val;
+ break;
+ case EGL_GL_TEXTURE_ZOFFSET_KHR:
+ img->GLTextureZOffset = val;
break;
default:
- /* not an error */
+ /* unknown attrs are ignored */
+ break;
+ }
+
+ if (err != EGL_SUCCESS) {
+ _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
break;
}
}
+ return err;
+}
+
+
+EGLBoolean
+_eglInitImage(_EGLImage *img, _EGLDisplay *dpy, const EGLint *attrib_list)
+{
+ EGLint err;
+
+ memset(img, 0, sizeof(_EGLImage));
+ img->Resource.Display = dpy;
+
+ img->Preserved = EGL_FALSE;
+ img->GLTextureLevel = 0;
+ img->GLTextureZOffset = 0;
+
+ err = _eglParseImageAttribList(img, attrib_list);
+ if (err != EGL_SUCCESS)
+ return _eglError(err, "eglCreateImageKHR");
+
return EGL_TRUE;
}
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 43107c23e9..2c0fb16d1d 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -15,11 +15,13 @@ struct _egl_image
_EGLResource Resource;
EGLBoolean Preserved;
+ EGLint GLTextureLevel;
+ EGLint GLTextureZOffset;
};
PUBLIC EGLBoolean
-_eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list);
+_eglInitImage(_EGLImage *img, _EGLDisplay *dpy, const EGLint *attrib_list);
extern _EGLImage *
diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
index 907a057b44..984e426686 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -39,30 +39,64 @@
/**
+ * Copy the extension into the string and update the string pointer.
+ */
+static EGLint
+_eglAppendExtension(char **str, const char *ext)
+{
+ char *s = *str;
+ EGLint len = strlen(ext);
+
+ if (s) {
+ memcpy(s, ext, len);
+ s[len++] = ' ';
+ s[len] = '\0';
+
+ *str += len;
+ }
+ else {
+ len++;
+ }
+
+ return len;
+}
+
+
+/**
* Examine the individual extension enable/disable flags and recompute
* the driver's Extensions string.
*/
static void
_eglUpdateExtensionsString(_EGLDisplay *dpy)
{
+#define _EGL_CHECK_EXTENSION(ext) \
+ do { \
+ if (dpy->Extensions.ext) { \
+ _eglAppendExtension(&exts, "EGL_" #ext); \
+ assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \
+ } \
+ } while (0)
+
char *exts = dpy->Extensions.String;
if (exts[0])
return;
- if (dpy->Extensions.MESA_screen_surface)
- strcat(exts, "EGL_MESA_screen_surface ");
- if (dpy->Extensions.MESA_copy_context)
- strcat(exts, "EGL_MESA_copy_context ");
+ _EGL_CHECK_EXTENSION(MESA_screen_surface);
+ _EGL_CHECK_EXTENSION(MESA_copy_context);
- if (dpy->Extensions.KHR_image_base)
- strcat(exts, "EGL_KHR_image_base ");
- if (dpy->Extensions.KHR_image_pixmap)
- strcat(exts, "EGL_KHR_image_pixmap ");
+ _EGL_CHECK_EXTENSION(KHR_image_base);
+ _EGL_CHECK_EXTENSION(KHR_image_pixmap);
if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
- strcat(exts, "EGL_KHR_image ");
+ _eglAppendExtension(&exts, "EGL_KHR_image");
+
+ _EGL_CHECK_EXTENSION(KHR_vg_parent_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
+ _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
- assert(strlen(exts) < _EGL_MAX_EXTENSIONS_LEN);
+#undef _EGL_CHECK_EXTENSION
}
diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c
index aa2da9dd09..8026a6314d 100644
--- a/src/egl/main/eglsurface.c
+++ b/src/egl/main/eglsurface.c
@@ -31,23 +31,168 @@ _eglClampSwapInterval(_EGLSurface *surf, EGLint interval)
/**
+ * Parse the list of surface attributes and return the proper error code.
+ */
+static EGLint
+_eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
+{
+ EGLint type = surf->Type;
+ EGLint i, err = EGL_SUCCESS;
+
+ if (!attrib_list)
+ return EGL_SUCCESS;
+
+ for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+ EGLint attr = attrib_list[i++];
+ EGLint val = attrib_list[i];
+
+ switch (attr) {
+ /* common (except for screen surfaces) attributes */
+ case EGL_VG_COLORSPACE:
+ if (type == EGL_SCREEN_BIT_MESA) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ switch (val) {
+ case EGL_VG_COLORSPACE_sRGB:
+ case EGL_VG_COLORSPACE_LINEAR:
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surf->VGColorspace = val;
+ break;
+ case EGL_VG_ALPHA_FORMAT:
+ if (type == EGL_SCREEN_BIT_MESA) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ switch (val) {
+ case EGL_VG_ALPHA_FORMAT_NONPRE:
+ case EGL_VG_ALPHA_FORMAT_PRE:
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surf->VGAlphaFormat = val;
+ break;
+ /* window surface attributes */
+ case EGL_RENDER_BUFFER:
+ if (type != EGL_WINDOW_BIT) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (val != EGL_BACK_BUFFER && val != EGL_SINGLE_BUFFER) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ surf->RenderBuffer = val;
+ break;
+ /* pbuffer surface attributes */
+ case EGL_WIDTH:
+ if (type != EGL_PBUFFER_BIT && type != EGL_SCREEN_BIT_MESA) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (val < 0) {
+ err = EGL_BAD_PARAMETER;
+ break;
+ }
+ surf->Width = val;
+ break;
+ case EGL_HEIGHT:
+ if (type != EGL_PBUFFER_BIT && type != EGL_SCREEN_BIT_MESA) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (val < 0) {
+ err = EGL_BAD_PARAMETER;
+ break;
+ }
+ surf->Height = val;
+ break;
+ case EGL_LARGEST_PBUFFER:
+ if (type != EGL_PBUFFER_BIT) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ surf->LargestPbuffer = !!val;
+ break;
+ case EGL_TEXTURE_FORMAT:
+ if (type != EGL_PBUFFER_BIT) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ switch (val) {
+ case EGL_TEXTURE_RGB:
+ case EGL_TEXTURE_RGBA:
+ case EGL_NO_TEXTURE:
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surf->TextureFormat = val;
+ break;
+ case EGL_TEXTURE_TARGET:
+ if (type != EGL_PBUFFER_BIT) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ switch (val) {
+ case EGL_TEXTURE_2D:
+ case EGL_NO_TEXTURE:
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surf->TextureTarget = val;
+ break;
+ case EGL_MIPMAP_TEXTURE:
+ if (type != EGL_PBUFFER_BIT) {
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ surf->MipmapTexture = !!val;
+ break;
+ /* no pixmap surface specific attributes */
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+
+ if (err != EGL_SUCCESS) {
+ _eglLog(_EGL_WARNING, "bad surface attribute 0x%04x", attr);
+ break;
+ }
+ }
+
+ return err;
+}
+
+
+/**
* Do error check on parameters and initialize the given _EGLSurface object.
* \return EGL_TRUE if no errors, EGL_FALSE otherwise.
*/
EGLBoolean
-_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
+_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
_EGLConfig *conf, const EGLint *attrib_list)
{
const char *func;
- EGLint width = 0, height = 0, largest = 0;
- EGLint texFormat = EGL_NO_TEXTURE, texTarget = EGL_NO_TEXTURE;
- EGLint mipmapTex = EGL_FALSE;
EGLint renderBuffer = EGL_BACK_BUFFER;
-#ifdef EGL_VERSION_1_2
- EGLint colorspace = EGL_COLORSPACE_sRGB;
- EGLint alphaFormat = EGL_ALPHA_FORMAT_NONPRE;
-#endif
- EGLint i;
+ EGLint err;
switch (type) {
case EGL_WINDOW_BIT:
@@ -69,158 +214,41 @@ _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
return EGL_FALSE;
}
- if (!conf) {
- _eglError(EGL_BAD_CONFIG, func);
- return EGL_FALSE;
- }
-
if ((GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE) & type) == 0) {
/* The config can't be used to create a surface of this type */
_eglError(EGL_BAD_CONFIG, func);
return EGL_FALSE;
}
- /*
- * Parse attribute list. Different kinds of surfaces support different
- * attributes.
- */
- for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
- switch (attrib_list[i]) {
- case EGL_WIDTH:
- if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) {
- width = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_HEIGHT:
- if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) {
- height = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_LARGEST_PBUFFER:
- if (type == EGL_PBUFFER_BIT) {
- largest = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_TEXTURE_FORMAT:
- if (type == EGL_PBUFFER_BIT) {
- texFormat = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_TEXTURE_TARGET:
- if (type == EGL_PBUFFER_BIT) {
- texTarget = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_MIPMAP_TEXTURE:
- if (type == EGL_PBUFFER_BIT) {
- mipmapTex = attrib_list[++i];
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
-#ifdef EGL_VERSION_1_2
- case EGL_RENDER_BUFFER:
- if (type == EGL_WINDOW_BIT) {
- renderBuffer = attrib_list[++i];
- if (renderBuffer != EGL_BACK_BUFFER &&
- renderBuffer != EGL_SINGLE_BUFFER) {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_COLORSPACE:
- if (type == EGL_WINDOW_BIT ||
- type == EGL_PBUFFER_BIT ||
- type == EGL_PIXMAP_BIT) {
- colorspace = attrib_list[++i];
- if (colorspace != EGL_COLORSPACE_sRGB &&
- colorspace != EGL_COLORSPACE_LINEAR) {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
- case EGL_ALPHA_FORMAT:
- if (type == EGL_WINDOW_BIT ||
- type == EGL_PBUFFER_BIT ||
- type == EGL_PIXMAP_BIT) {
- alphaFormat = attrib_list[++i];
- if (alphaFormat != EGL_ALPHA_FORMAT_NONPRE &&
- alphaFormat != EGL_ALPHA_FORMAT_PRE) {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- }
- else {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- break;
-
-#endif /* EGL_VERSION_1_2 */
- default:
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
- }
-
- if (width < 0 || height < 0) {
- _eglError(EGL_BAD_ATTRIBUTE, func);
- return EGL_FALSE;
- }
-
memset(surf, 0, sizeof(_EGLSurface));
- surf->Config = conf;
+ surf->Resource.Display = dpy;
surf->Type = type;
- surf->Width = width;
- surf->Height = height;
- surf->TextureFormat = texFormat;
- surf->TextureTarget = texTarget;
- surf->MipmapTexture = mipmapTex;
+ surf->Config = conf;
+
+ surf->Width = 0;
+ surf->Height = 0;
+ surf->TextureFormat = EGL_NO_TEXTURE;
+ surf->TextureTarget = EGL_NO_TEXTURE;
+ surf->MipmapTexture = EGL_FALSE;
+ surf->LargestPbuffer = EGL_FALSE;
+ surf->RenderBuffer = renderBuffer;
+ surf->VGAlphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
+ surf->VGColorspace = EGL_VG_COLORSPACE_sRGB;
+
surf->MipmapLevel = 0;
+ surf->MultisampleResolve = EGL_MULTISAMPLE_RESOLVE_DEFAULT;
+ surf->SwapBehavior = EGL_BUFFER_DESTROYED;
+
+ surf->HorizontalResolution = EGL_UNKNOWN;
+ surf->VerticalResolution = EGL_UNKNOWN;
+ surf->AspectRatio = EGL_UNKNOWN;
+
/* the default swap interval is 1 */
_eglClampSwapInterval(surf, 1);
-#ifdef EGL_VERSION_1_2
- surf->SwapBehavior = EGL_BUFFER_DESTROYED; /* XXX ok? */
- surf->HorizontalResolution = EGL_UNKNOWN; /* set by caller */
- surf->VerticalResolution = EGL_UNKNOWN; /* set by caller */
- surf->AspectRatio = EGL_UNKNOWN; /* set by caller */
- surf->RenderBuffer = renderBuffer;
- surf->AlphaFormat = alphaFormat;
- surf->Colorspace = colorspace;
-#endif
+ err = _eglParseSurfaceAttribList(surf, attrib_list);
+ if (err != EGL_SUCCESS)
+ return _eglError(err, func);
return EGL_TRUE;
}
@@ -251,65 +279,63 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface,
switch (attribute) {
case EGL_WIDTH:
*value = surface->Width;
- return EGL_TRUE;
+ break;
case EGL_HEIGHT:
*value = surface->Height;
- return EGL_TRUE;
+ break;
case EGL_CONFIG_ID:
*value = GET_CONFIG_ATTRIB(surface->Config, EGL_CONFIG_ID);
- return EGL_TRUE;
+ break;
case EGL_LARGEST_PBUFFER:
- *value = dpy->LargestPbuffer;
- return EGL_TRUE;
- case EGL_SURFACE_TYPE:
- *value = surface->Type;
- return EGL_TRUE;
-#ifdef EGL_VERSION_1_1
+ *value = surface->LargestPbuffer;
+ break;
case EGL_TEXTURE_FORMAT:
/* texture attributes: only for pbuffers, no error otherwise */
if (surface->Type == EGL_PBUFFER_BIT)
*value = surface->TextureFormat;
- return EGL_TRUE;
+ break;
case EGL_TEXTURE_TARGET:
if (surface->Type == EGL_PBUFFER_BIT)
*value = surface->TextureTarget;
- return EGL_TRUE;
+ break;
case EGL_MIPMAP_TEXTURE:
if (surface->Type == EGL_PBUFFER_BIT)
*value = surface->MipmapTexture;
- return EGL_TRUE;
+ break;
case EGL_MIPMAP_LEVEL:
if (surface->Type == EGL_PBUFFER_BIT)
*value = surface->MipmapLevel;
- return EGL_TRUE;
-#endif /* EGL_VERSION_1_1 */
-#ifdef EGL_VERSION_1_2
+ break;
case EGL_SWAP_BEHAVIOR:
*value = surface->SwapBehavior;
- return EGL_TRUE;
+ break;
case EGL_RENDER_BUFFER:
*value = surface->RenderBuffer;
- return EGL_TRUE;
+ break;
case EGL_PIXEL_ASPECT_RATIO:
*value = surface->AspectRatio;
- return EGL_TRUE;
+ break;
case EGL_HORIZONTAL_RESOLUTION:
*value = surface->HorizontalResolution;
- return EGL_TRUE;
+ break;
case EGL_VERTICAL_RESOLUTION:
*value = surface->VerticalResolution;
- return EGL_TRUE;
- case EGL_ALPHA_FORMAT:
- *value = surface->AlphaFormat;
- return EGL_TRUE;
- case EGL_COLORSPACE:
- *value = surface->Colorspace;
- return EGL_TRUE;
-#endif /* EGL_VERSION_1_2 */
+ break;
+ case EGL_MULTISAMPLE_RESOLVE:
+ *value = surface->MultisampleResolve;
+ break;
+ case EGL_VG_ALPHA_FORMAT:
+ *value = surface->VGAlphaFormat;
+ break;
+ case EGL_VG_COLORSPACE:
+ *value = surface->VGColorspace;
+ break;
default:
_eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
return EGL_FALSE;
}
+
+ return EGL_TRUE;
}
@@ -365,14 +391,59 @@ EGLBoolean
_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface,
EGLint attribute, EGLint value)
{
+ EGLint confval;
+ EGLint err = EGL_SUCCESS;
+
switch (attribute) {
case EGL_MIPMAP_LEVEL:
+ confval = GET_CONFIG_ATTRIB(surface->Config, EGL_RENDERABLE_TYPE);
+ if (!(confval & (EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT))) {
+ err = EGL_BAD_PARAMETER;
+ break;
+ }
surface->MipmapLevel = value;
break;
+ case EGL_MULTISAMPLE_RESOLVE:
+ switch (value) {
+ case EGL_MULTISAMPLE_RESOLVE_DEFAULT:
+ break;
+ case EGL_MULTISAMPLE_RESOLVE_BOX:
+ confval = GET_CONFIG_ATTRIB(surface->Config, EGL_SURFACE_TYPE);
+ if (!(confval & EGL_MULTISAMPLE_RESOLVE_BOX_BIT))
+ err = EGL_BAD_MATCH;
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surface->MultisampleResolve = value;
+ break;
+ case EGL_SWAP_BEHAVIOR:
+ switch (value) {
+ case EGL_BUFFER_DESTROYED:
+ break;
+ case EGL_BUFFER_PRESERVED:
+ confval = GET_CONFIG_ATTRIB(surface->Config, EGL_SURFACE_TYPE);
+ if (!(confval & EGL_SWAP_BEHAVIOR_PRESERVED_BIT))
+ err = EGL_BAD_MATCH;
+ break;
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+ if (err != EGL_SUCCESS)
+ break;
+ surface->SwapBehavior = value;
+ break;
default:
- _eglError(EGL_BAD_ATTRIBUTE, "eglSurfaceAttrib");
- return EGL_FALSE;
+ err = EGL_BAD_ATTRIBUTE;
+ break;
}
+
+ if (err != EGL_SUCCESS)
+ return _eglError(err, "eglSurfaceAttrib");
return EGL_TRUE;
}
diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h
index 0d64d20dd4..0a00035730 100644
--- a/src/egl/main/eglsurface.h
+++ b/src/egl/main/eglsurface.h
@@ -20,27 +20,34 @@ struct _egl_surface
_EGLConfig *Config;
EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
+
+ /* attributes set by attribute list */
EGLint Width, Height;
- EGLint TextureFormat, TextureTarget;
- EGLint MipmapTexture, MipmapLevel;
+ EGLenum TextureFormat;
+ EGLenum TextureTarget;
+ EGLBoolean MipmapTexture;
+ EGLBoolean LargestPbuffer;
+ EGLenum RenderBuffer;
+ EGLenum VGAlphaFormat;
+ EGLenum VGColorspace;
+
+ /* attributes set by eglSurfaceAttrib */
+ EGLint MipmapLevel;
+ EGLenum MultisampleResolve;
+ EGLenum SwapBehavior;
+
+ EGLint HorizontalResolution, VerticalResolution;
+ EGLint AspectRatio;
+
EGLint SwapInterval;
/* True if the surface is bound to an OpenGL ES texture */
EGLBoolean BoundToTexture;
-
-#ifdef EGL_VERSION_1_2
- EGLint SwapBehavior; /* one of EGL_BUFFER_PRESERVED/DESTROYED */
- EGLint HorizontalResolution, VerticalResolution;
- EGLint AspectRatio;
- EGLint RenderBuffer; /* EGL_BACK_BUFFER or EGL_SINGLE_BUFFER */
- EGLint AlphaFormat; /* EGL_ALPHA_FORMAT_NONPRE or EGL_ALPHA_FORMAT_PRE */
- EGLint Colorspace; /* EGL_COLORSPACE_sRGB or EGL_COLORSPACE_LINEAR */
-#endif /* EGL_VERSION_1_2 */
};
PUBLIC EGLBoolean
-_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
+_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
_EGLConfig *config, const EGLint *attrib_list);
@@ -100,6 +107,9 @@ _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy,
/**
* Return true if there is a context bound to the surface.
+ *
+ * The binding is considered a reference to the surface. Drivers should not
+ * destroy a surface when it is bound.
*/
static INLINE EGLBoolean
_eglIsSurfaceBound(_EGLSurface *surf)
@@ -159,6 +169,9 @@ _eglGetSurfaceHandle(_EGLSurface *surf)
/**
* Return true if the surface is linked to a display.
+ *
+ * The link is considered a reference to the surface (the display is owning the
+ * surface). Drivers should not destroy a surface when it is linked.
*/
static INLINE EGLBoolean
_eglIsSurfaceLinked(_EGLSurface *surf)
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile
index da1fb6b299..66cfe9d89d 100644
--- a/src/gallium/auxiliary/Makefile
+++ b/src/gallium/auxiliary/Makefile
@@ -48,6 +48,10 @@ C_SOURCES = \
draw/draw_vs_sse.c \
indices/u_indices_gen.c \
indices/u_unfilled_gen.c \
+ os/os_misc.c \
+ os/os_stream_stdc.c \
+ os/os_stream_wd.c \
+ os/os_time.c \
pipebuffer/pb_buffer_malloc.c \
pipebuffer/pb_bufmgr_alt.c \
pipebuffer/pb_bufmgr_cache.c \
@@ -113,12 +117,9 @@ C_SOURCES = \
util/u_ringbuffer.c \
util/u_simple_shaders.c \
util/u_snprintf.c \
- util/u_stream_stdc.c \
- util/u_stream_wd.c \
util/u_surface.c \
util/u_texture.c \
util/u_tile.c \
- util/u_time.c \
util/u_timed_winsys.c \
util/u_upload_mgr.c \
util/u_simple_screen.c \
diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript
index 3aa782f81e..255739b0a2 100644
--- a/src/gallium/auxiliary/SConscript
+++ b/src/gallium/auxiliary/SConscript
@@ -82,6 +82,10 @@ source = [
#'indices/u_unfilled_indices.c',
'indices/u_indices_gen.c',
'indices/u_unfilled_gen.c',
+ 'os/os_misc.c',
+ 'os/os_stream_stdc.c',
+ 'os/os_stream_wd.c',
+ 'os/os_time.c',
'pipebuffer/pb_buffer_fenced.c',
'pipebuffer/pb_buffer_malloc.c',
'pipebuffer/pb_bufmgr_alt.c',
@@ -149,12 +153,9 @@ source = [
'util/u_ringbuffer.c',
'util/u_simple_shaders.c',
'util/u_snprintf.c',
- 'util/u_stream_stdc.c',
- 'util/u_stream_wd.c',
'util/u_surface.c',
'util/u_texture.c',
'util/u_tile.c',
- 'util/u_time.c',
'util/u_timed_winsys.c',
'util/u_upload_mgr.c',
'util/u_simple_screen.c',
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index dec830ba93..c638239e80 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -36,6 +36,7 @@
*/
#include "pipe/p_state.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index d3084fd428..d5ddc4a6a9 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -352,7 +352,10 @@ draw_find_shader_output(const struct draw_context *draw,
/**
- * Return number of the shader outputs.
+ * Return total number of the shader outputs. This function is similar to
+ * draw_current_shader_outputs() but this function also counts any extra
+ * vertex/geometry output attributes that may be filled in by some draw
+ * stages (such as AA point, AA line).
*
* If geometry shader is present, its output will be returned,
* if not vertex shader is used.
@@ -362,8 +365,9 @@ draw_num_shader_outputs(const struct draw_context *draw)
{
uint count = draw->vs.vertex_shader->info.num_outputs;
- /* if geometry shader is present, its outputs go to te
- * driver, not the vertex shaders */
+ /* If a geometry shader is present, its outputs go to the
+ * driver, else the vertex shader's outputs.
+ */
if (draw->gs.geometry_shader)
count = draw->gs.geometry_shader->info.num_outputs;
@@ -374,7 +378,8 @@ draw_num_shader_outputs(const struct draw_context *draw)
/**
- * Provide TGSI sampler objects for vertex/geometry shaders that use texture fetches.
+ * Provide TGSI sampler objects for vertex/geometry shaders that use
+ * texture fetches.
* This might only be used by software drivers for the time being.
*/
void
@@ -454,14 +459,27 @@ void draw_do_flush( struct draw_context *draw, unsigned flags )
}
-int draw_current_shader_outputs(struct draw_context *draw)
+/**
+ * Return the number of output attributes produced by the geometry
+ * shader, if present. If no geometry shader, return the number of
+ * outputs from the vertex shader.
+ * \sa draw_num_shader_outputs
+ */
+uint
+draw_current_shader_outputs(const struct draw_context *draw)
{
if (draw->gs.geometry_shader)
return draw->gs.num_gs_outputs;
return draw->vs.num_vs_outputs;
}
-int draw_current_shader_position_output(struct draw_context *draw)
+
+/**
+ * Return the index of the shader output which will contain the
+ * vertex position.
+ */
+uint
+draw_current_shader_position_output(const struct draw_context *draw)
{
if (draw->gs.geometry_shader)
return draw->gs.position_output;
diff --git a/src/gallium/auxiliary/draw/draw_pipe.c b/src/gallium/auxiliary/draw/draw_pipe.c
index 11d6485dcf..83dc1a35f4 100644
--- a/src/gallium/auxiliary/draw/draw_pipe.c
+++ b/src/gallium/auxiliary/draw/draw_pipe.c
@@ -32,6 +32,7 @@
#include "draw/draw_private.h"
#include "draw/draw_pipe.h"
+#include "util/u_debug.h"
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
index 4585dcdb48..8f6ca15dfa 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
@@ -35,6 +35,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
@@ -48,6 +49,10 @@
#include "draw_pipe.h"
+/** Approx number of new tokens for instructions in aa_transform_inst() */
+#define NUM_NEW_TOKENS 50
+
+
/**
* Max texture level for the alpha texture used for antialiasing
*/
@@ -178,12 +183,7 @@ aa_transform_decl(struct tgsi_transform_context *ctx,
static int
free_bit(uint bitfield)
{
- int i;
- for (i = 0; i < 32; i++) {
- if ((bitfield & (1 << i)) == 0)
- return i;
- }
- return -1;
+ return ffs(~bitfield) - 1;
}
@@ -342,11 +342,10 @@ generate_aaline_fs(struct aaline_stage *aaline)
const struct pipe_shader_state *orig_fs = &aaline->fs->state;
struct pipe_shader_state aaline_fs;
struct aa_transform_context transform;
-
-#define MAX 1000
+ const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS;
aaline_fs = *orig_fs; /* copy to init */
- aaline_fs.tokens = MALLOC(sizeof(struct tgsi_token) * MAX);
+ aaline_fs.tokens = tgsi_alloc_tokens(newLen);
if (aaline_fs.tokens == NULL)
return FALSE;
@@ -362,7 +361,7 @@ generate_aaline_fs(struct aaline_stage *aaline)
tgsi_transform_shader(orig_fs->tokens,
(struct tgsi_token *) aaline_fs.tokens,
- MAX, &transform.base);
+ newLen, &transform.base);
#if 0 /* DEBUG */
tgsi_dump(orig_fs->tokens, 0);
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
index d86717e518..97f3480879 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
@@ -53,6 +53,10 @@
#include "draw_pipe.h"
+/** Approx number of new tokens for instructions in aa_transform_inst() */
+#define NUM_NEW_TOKENS 200
+
+
/*
* Enabling NORMALIZE might give _slightly_ better results.
* Basically, it controls whether we compute distance as d=sqrt(x*x+y*y) or
@@ -81,16 +85,19 @@ struct aapoint_stage
{
struct draw_stage stage;
- int psize_slot;
+ /** half of pipe_rasterizer_state::point_size */
float radius;
+ /** vertex attrib slot containing point size */
+ int psize_slot;
+
/** this is the vertex attrib slot for the new texcoords */
uint tex_slot;
+
+ /** vertex attrib slot containing position */
uint pos_slot;
- /*
- * Currently bound state
- */
+ /** Currently bound fragment shader */
struct aapoint_fragment_shader *fs;
/*
@@ -491,11 +498,10 @@ generate_aapoint_fs(struct aapoint_stage *aapoint)
const struct pipe_shader_state *orig_fs = &aapoint->fs->state;
struct pipe_shader_state aapoint_fs;
struct aa_transform_context transform;
-
-#define MAX 1000
+ const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS;
aapoint_fs = *orig_fs; /* copy to init */
- aapoint_fs.tokens = MALLOC(sizeof(struct tgsi_token) * MAX);
+ aapoint_fs.tokens = tgsi_alloc_tokens(newLen);
if (aapoint_fs.tokens == NULL)
return FALSE;
@@ -511,7 +517,7 @@ generate_aapoint_fs(struct aapoint_stage *aapoint)
tgsi_transform_shader(orig_fs->tokens,
(struct tgsi_token *) aapoint_fs.tokens,
- MAX, &transform.base);
+ newLen, &transform.base);
#if 0 /* DEBUG */
printf("draw_aapoint, orig shader:\n");
@@ -575,8 +581,8 @@ aapoint_point(struct draw_stage *stage, struct prim_header *header)
const struct aapoint_stage *aapoint = aapoint_stage(stage);
struct prim_header tri;
struct vertex_header *v[4];
- uint texPos = aapoint->tex_slot;
- uint pos_slot = aapoint->pos_slot;
+ const uint tex_slot = aapoint->tex_slot;
+ const uint pos_slot = aapoint->pos_slot;
float radius, *pos, *tex;
uint i;
float k;
@@ -643,16 +649,16 @@ aapoint_point(struct draw_stage *stage, struct prim_header *header)
pos[1] += radius;
/* new texcoords */
- tex = v[0]->data[texPos];
+ tex = v[0]->data[tex_slot];
ASSIGN_4V(tex, -1, -1, k, 1);
- tex = v[1]->data[texPos];
+ tex = v[1]->data[tex_slot];
ASSIGN_4V(tex, 1, -1, k, 1);
- tex = v[2]->data[texPos];
+ tex = v[2]->data[tex_slot];
ASSIGN_4V(tex, 1, 1, k, 1);
- tex = v[3]->data[texPos];
+ tex = v[3]->data[tex_slot];
ASSIGN_4V(tex, -1, 1, k, 1);
/* emit 2 tris for the quad strip */
diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
index 0cc2b71864..d0d99aa331 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
@@ -37,6 +37,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
@@ -49,6 +50,9 @@
#include "draw_pipe.h"
+/** Approx number of new tokens for instructions in pstip_transform_inst() */
+#define NUM_NEW_TOKENS 50
+
/**
* Subclass of pipe_shader_state to carry extra fragment shader info.
@@ -171,12 +175,7 @@ pstip_transform_immed(struct tgsi_transform_context *ctx,
static int
free_bit(uint bitfield)
{
- int i;
- for (i = 0; i < 32; i++) {
- if ((bitfield & (1 << i)) == 0)
- return i;
- }
- return -1;
+ return ffs(~bitfield) - 1;
}
@@ -332,11 +331,10 @@ generate_pstip_fs(struct pstip_stage *pstip)
/*struct draw_context *draw = pstip->stage.draw;*/
struct pipe_shader_state pstip_fs;
struct pstip_transform_context transform;
-
-#define MAX 1000
+ const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS;
pstip_fs = *orig_fs; /* copy to init */
- pstip_fs.tokens = MALLOC(sizeof(struct tgsi_token) * MAX);
+ pstip_fs.tokens = tgsi_alloc_tokens(newLen);
if (pstip_fs.tokens == NULL)
return FALSE;
@@ -351,7 +349,7 @@ generate_pstip_fs(struct pstip_stage *pstip)
tgsi_transform_shader(orig_fs->tokens,
(struct tgsi_token *) pstip_fs.tokens,
- MAX, &transform.base);
+ newLen, &transform.base);
#if 0 /* DEBUG */
tgsi_dump(orig_fs->tokens, 0);
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index 6a7190e975..69466d8749 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -280,8 +280,8 @@ void draw_gs_destroy( struct draw_context *draw );
/*******************************************************************************
* Common shading code:
*/
-int draw_current_shader_outputs(struct draw_context *draw);
-int draw_current_shader_position_output(struct draw_context *draw);
+uint draw_current_shader_outputs(const struct draw_context *draw);
+uint draw_current_shader_position_output(const struct draw_context *draw);
/*******************************************************************************
* Vertex processing (was passthrough) code:
diff --git a/src/gallium/auxiliary/draw/draw_pt_util.c b/src/gallium/auxiliary/draw/draw_pt_util.c
index 17c3b8cec2..3236d38e6a 100644
--- a/src/gallium/auxiliary/draw/draw_pt_util.c
+++ b/src/gallium/auxiliary/draw/draw_pt_util.c
@@ -33,6 +33,7 @@
#include "draw/draw_context.h"
#include "draw/draw_private.h"
#include "draw/draw_pt.h"
+#include "util/u_debug.h"
void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr)
{
diff --git a/src/gallium/auxiliary/draw/draw_vertex.h b/src/gallium/auxiliary/draw/draw_vertex.h
index 554f4ac3c1..8c3c7befbc 100644
--- a/src/gallium/auxiliary/draw/draw_vertex.h
+++ b/src/gallium/auxiliary/draw/draw_vertex.h
@@ -39,7 +39,9 @@
#define DRAW_VERTEX_H
+#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
+#include "util/u_debug.h"
/**
diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/auxiliary/os/os_memory.h
index c1c7415e02..556662d35e 100644
--- a/src/gallium/include/pipe/p_refcnt.h
+++ b/src/gallium/auxiliary/os/os_memory.h
@@ -1,8 +1,8 @@
/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
+ *
+ * Copyright 2010 Vmware, Inc.
* 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
@@ -10,86 +10,75 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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 P_REFCNT_H
-#define P_REFCNT_H
+
+/*
+ * OS memory management abstractions
+ */
+
+
+#ifndef _OS_MEMORY_H_
+#define _OS_MEMORY_H_
-#include "p_defines.h"
-#include "p_atomic.h"
+#include "pipe/p_config.h"
+#include "pipe/p_compiler.h"
+#if defined(PIPE_OS_EMBEDDED)
+
#ifdef __cplusplus
extern "C" {
#endif
+void *
+os_malloc(size_t size);
-struct pipe_reference
-{
- struct pipe_atomic count;
-};
+void *
+os_calloc(size_t count, size_t size);
+void
+os_free(void *ptr);
-static INLINE void
-pipe_reference_init(struct pipe_reference *reference, unsigned count)
-{
- p_atomic_set(&reference->count, count);
-}
+void *
+os_realloc(void *ptr, size_t old_size, size_t new_size);
+void *
+os_malloc_aligned(size_t size, size_t alignment);
-static INLINE boolean
-pipe_is_referenced(struct pipe_reference *reference)
-{
- return p_atomic_read(&reference->count) != 0;
+void
+os_free_aligned(void *ptr);
+
+#ifdef __cplusplus
}
+#endif
+#elif defined(PIPE_OS_WINDOWS) && defined(DEBUG) && !defined(DEBUG_MEMORY_IMPLEMENTATION)
-/**
- * Update reference counting.
- * The old thing pointed to, if any, will be unreferenced.
- * Both 'ptr' and 'reference' may be NULL.
- * \return TRUE if the object's refcount hits zero and should be destroyed.
- */
-static INLINE boolean
-pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference)
-{
- boolean destroy = FALSE;
-
- if(ptr != reference) {
- /* bump the reference.count first */
- if (reference) {
- assert(pipe_is_referenced(reference));
- p_atomic_inc(&reference->count);
- }
-
- if (ptr) {
- assert(pipe_is_referenced(ptr));
- if (p_atomic_dec_zero(&ptr->count)) {
- destroy = TRUE;
- }
- }
- }
-
- return destroy;
-}
+# include "os_memory_debug.h"
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+
+# include "os_memory_win32k.h"
+
+#else
+
+# include "os_memory_stdc.h"
-#ifdef __cplusplus
-}
#endif
-#endif /* P_REFCNT_H */
+#endif /* _OS_MEMORY_H_ */
diff --git a/src/gallium/drivers/nv10/nv10_surface.c b/src/gallium/auxiliary/os/os_memory_aligned.h
index 5b52246a9c..72c5cf65b6 100644
--- a/src/gallium/drivers/nv10/nv10_surface.c
+++ b/src/gallium/auxiliary/os/os_memory_aligned.h
@@ -1,7 +1,6 @@
-
/**************************************************************************
*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -19,45 +18,55 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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 "nv10_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
-#include "util/u_tile.h"
-
-static void
-nv10_surface_copy(struct pipe_context *pipe,
- struct pipe_surface *dest, unsigned destx, unsigned desty,
- struct pipe_surface *src, unsigned srcx, unsigned srcy,
- unsigned width, unsigned height)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct nv04_surface_2d *eng2d = nv10->screen->eng2d;
- eng2d->copy(eng2d, dest, destx, desty, src, srcx, srcy, width, height);
-}
+/*
+ * Memory alignment wrappers.
+ */
+
+
+#ifndef _OS_MEMORY_H_
+#error "Must not be included directly. Include os_memory.h instead"
+#endif
+
-static void
-nv10_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
- unsigned destx, unsigned desty, unsigned width,
- unsigned height, unsigned value)
+#include "pipe/p_compiler.h"
+
+
+/**
+ * Return memory on given byte alignment
+ */
+static INLINE void *
+os_malloc_aligned(size_t size, size_t alignment)
{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct nv04_surface_2d *eng2d = nv10->screen->eng2d;
+ char *ptr, *buf;
+
+ ptr = (char *) os_malloc(size + alignment + sizeof(void *));
+ if (!ptr)
+ return NULL;
- eng2d->fill(eng2d, dest, destx, desty, width, height, value);
+ buf = (char *)(((uintptr_t)ptr + sizeof(void *) + alignment - 1) & ~((uintptr_t)(alignment - 1)));
+ *(char **)(buf - sizeof(void *)) = ptr;
+
+ return buf;
}
-void
-nv10_init_surface_functions(struct nv10_context *nv10)
+
+/**
+ * Free memory returned by align_malloc().
+ */
+static INLINE void
+os_free_aligned(void *ptr)
{
- nv10->pipe.surface_copy = nv10_surface_copy;
- nv10->pipe.surface_fill = nv10_surface_fill;
+ if (ptr) {
+ void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
+ void *realAddr = *cubbyHole;
+ os_free(realAddr);
+ }
}
diff --git a/src/gallium/auxiliary/os/os_memory_debug.h b/src/gallium/auxiliary/os/os_memory_debug.h
new file mode 100644
index 0000000000..c664be9aad
--- /dev/null
+++ b/src/gallium/auxiliary/os/os_memory_debug.h
@@ -0,0 +1,83 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 VMware, Inc.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
+ *
+ **************************************************************************/
+
+
+/*
+ * Debugging wrappers for OS memory management abstractions.
+ */
+
+
+#ifndef _OS_MEMORY_H_
+#error "Must not be included directly. Include os_memory.h instead"
+#endif
+
+
+#include "pipe/p_compiler.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+void *
+debug_malloc(const char *file, unsigned line, const char *function,
+ size_t size);
+
+void *
+debug_calloc(const char *file, unsigned line, const char *function,
+ size_t count, size_t size );
+
+void
+debug_free(const char *file, unsigned line, const char *function,
+ void *ptr);
+
+void *
+debug_realloc(const char *file, unsigned line, const char *function,
+ void *old_ptr, size_t old_size, size_t new_size );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#ifndef DEBUG_MEMORY_IMPLEMENTATION
+
+#define os_malloc( _size ) \
+ debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
+#define os_calloc( _count, _size ) \
+ debug_calloc(__FILE__, __LINE__, __FUNCTION__, _count, _size )
+#define os_free( _ptr ) \
+ debug_free( __FILE__, __LINE__, __FUNCTION__, _ptr )
+#define os_realloc( _ptr, _old_size, _new_size ) \
+ debug_realloc( __FILE__, __LINE__, __FUNCTION__, _ptr, _old_size, _new_size )
+
+/* TODO: wrap os_malloc_aligned() and os_free_aligned() too */
+#include "os_memory_aligned.h"
+
+#endif /* !DEBUG_MEMORY_IMPLEMENTATION */
diff --git a/src/gallium/drivers/nv20/nv20_surface.c b/src/gallium/auxiliary/os/os_memory_stdc.h
index 4224bdd6af..806e536356 100644
--- a/src/gallium/drivers/nv20/nv20_surface.c
+++ b/src/gallium/auxiliary/os/os_memory_stdc.h
@@ -1,7 +1,6 @@
-
/**************************************************************************
*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -19,45 +18,59 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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 "nv20_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
-#include "util/u_tile.h"
-
-static void
-nv20_surface_copy(struct pipe_context *pipe,
- struct pipe_surface *dest, unsigned destx, unsigned desty,
- struct pipe_surface *src, unsigned srcx, unsigned srcy,
- unsigned width, unsigned height)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct nv04_surface_2d *eng2d = nv20->screen->eng2d;
- eng2d->copy(eng2d, dest, destx, desty, src, srcx, srcy, width, height);
-}
+/*
+ * OS memory management abstractions for the standard C library.
+ */
-static void
-nv20_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
- unsigned destx, unsigned desty, unsigned width,
- unsigned height, unsigned value)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct nv04_surface_2d *eng2d = nv20->screen->eng2d;
- eng2d->fill(eng2d, dest, destx, desty, width, height, value);
-}
+#ifndef _OS_MEMORY_H_
+#error "Must not be included directly. Include os_memory.h instead"
+#endif
+
+#include <stdlib.h>
+
+#include "pipe/p_compiler.h"
+
+
+#define os_malloc(_size) malloc(_size)
+#define os_calloc(_count, _size ) calloc(_count, _size )
+#define os_free(_ptr) free(_ptr)
+
+#define os_realloc( _old_ptr, _old_size, _new_size) \
+ realloc(_old_ptr, _new_size + 0*(_old_size))
-void
-nv20_init_surface_functions(struct nv20_context *nv20)
+
+#if defined(HAVE_POSIX_MEMALIGN)
+
+static INLINE void *
+os_malloc_aligned(size_t size, size_t alignment)
{
- nv20->pipe.surface_copy = nv20_surface_copy;
- nv20->pipe.surface_fill = nv20_surface_fill;
+ void *ptr;
+ alignment = (alignment + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
+ if(posix_memalign(&ptr, alignment, size) != 0)
+ return NULL;
+ return ptr;
}
+
+#define os_free_aligned(_ptr) free(_ptr)
+
+#elif defined(PIPE_OS_WINDOWS)
+
+#include <malloc.h>
+
+#define os_malloc_aligned(_size, _align) _aligned_malloc(_size, _align)
+#define os_free_aligned(_ptr) _aligned_free(_ptr)
+
+#else
+
+#include "os_memory_aligned.h"
+
+#endif
diff --git a/src/gallium/auxiliary/os/os_memory_win32k.h b/src/gallium/auxiliary/os/os_memory_win32k.h
new file mode 100644
index 0000000000..d56d690872
--- /dev/null
+++ b/src/gallium/auxiliary/os/os_memory_win32k.h
@@ -0,0 +1,123 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 VMware, Inc.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
+ *
+ **************************************************************************/
+
+
+/*
+ * OS memory management abstractions for Windows kernel.
+ */
+
+
+#ifndef _OS_MEMORY_H_
+#error "Must not be included directly. Include os_memory.h instead"
+#endif
+
+
+#include "pipe/p_compiler.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+
+void * __stdcall
+EngAllocMem(unsigned long Flags,
+ unsigned long MemSize,
+ unsigned long Tag);
+
+void __stdcall
+EngFreeMem(void *Mem);
+
+#define os_malloc(_size) EngAllocMem(0, _size, 'D3AG')
+#define os_calloc(_count, _size) EngAllocMem(1, (_count)*(_size), 'D3AG')
+#define _os_free(_ptr) EngFreeMem(_ptr)
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+
+void *
+ExAllocatePool(unsigned long PoolType,
+ size_t NumberOfBytes);
+
+void
+ExFreePool(void *P);
+
+#define os_malloc(_size) ExAllocatePool(0, _size)
+#define _os_free(_ptr) ExFreePool(_ptr)
+
+static INLINE void *
+os_calloc(unsigned count, unsigned size)
+{
+ void *ptr = os_malloc(count * size);
+ if (ptr) {
+ memset(ptr, 0, count * size);
+ }
+ return ptr;
+}
+
+#else
+
+#error "Unsupported subsystem"
+
+#endif
+
+
+static INLINE void
+os_free( void *ptr )
+{
+ if (ptr) {
+ _os_free(ptr);
+ }
+}
+
+
+static INLINE void *
+os_realloc(void *old_ptr, unsigned old_size, unsigned new_size)
+{
+ void *new_ptr = NULL;
+
+ if (new_size != 0) {
+ unsigned copy_size = old_size < new_size ? old_size : new_size;
+ new_ptr = os_malloc( new_size );
+ if (new_ptr && old_ptr && copy_size) {
+ memcpy(new_ptr, old_ptr, copy_size);
+ }
+ }
+
+ os_free(old_ptr);
+
+ return new_ptr;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#include "os_memory_aligned.h"
diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
new file mode 100644
index 0000000000..384988017b
--- /dev/null
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -0,0 +1,188 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 Vmware, Inc.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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 "os_misc.h"
+
+#include <stdarg.h>
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+
+#include <windows.h>
+#include <winddi.h>
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <types.h>
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#endif
+#include <windows.h>
+#include <stdio.h>
+
+#else
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#endif
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+static INLINE void
+_EngDebugPrint(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ EngDebugPrint("", (PCHAR)format, ap);
+ va_end(ap);
+}
+#endif
+
+
+void
+os_log_message(const char *message)
+{
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+ _EngDebugPrint("%s", message);
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+ OutputDebugStringA(message);
+ if(GetConsoleWindow() && !IsDebuggerPresent()) {
+ fflush(stdout);
+ fputs(message, stderr);
+ fflush(stderr);
+ }
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+ wchar_t *wide_format;
+ long wide_str_len;
+ /* Format is ascii - needs to be converted to wchar_t for printing */
+ wide_str_len = MultiByteToWideChar(CP_ACP, 0, message, -1, NULL, 0);
+ wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));
+ if (wide_format) {
+ MultiByteToWideChar(CP_ACP, 0, message, -1,
+ wide_format, wide_str_len);
+ NKDbgPrintfW(wide_format, wide_format);
+ free(wide_format);
+ }
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+ /* TODO */
+#else /* !PIPE_SUBSYSTEM_WINDOWS */
+ fflush(stdout);
+ fputs(message, stderr);
+#endif
+}
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+static const char *
+find(const char *start, const char *end, char c)
+{
+ const char *p;
+ for(p = start; !end || p != end; ++p) {
+ if(*p == c)
+ return p;
+ if(*p < 32)
+ break;
+ }
+ return NULL;
+}
+
+static int
+compare(const char *start, const char *end, const char *s)
+{
+ const char *p, *q;
+ for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
+ if(*p != *q)
+ return 0;
+ }
+ return p == end && *q == '\0';
+}
+
+static void
+copy(char *dst, const char *start, const char *end, size_t n)
+{
+ const char *p;
+ char *q;
+ for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
+ *q = *p;
+ *q = '\0';
+}
+#endif
+
+
+const char *
+os_get_option(const char *name)
+{
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+ /* EngMapFile creates the file if it does not exists, so it must either be
+ * disabled on release versions (or put in a less conspicuous place). */
+#ifdef DEBUG
+ const char *result = NULL;
+ ULONG_PTR iFile = 0;
+ const void *pMap = NULL;
+ const char *sol, *eol, *sep;
+ static char output[1024];
+
+ pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
+ if(pMap) {
+ sol = (const char *)pMap;
+ while(1) {
+ /* TODO: handle LF line endings */
+ eol = find(sol, NULL, '\r');
+ if(!eol || eol == sol)
+ break;
+ sep = find(sol, eol, '=');
+ if(!sep)
+ break;
+ if(compare(sol, sep, name)) {
+ copy(output, sep + 1, eol, sizeof(output));
+ result = output;
+ break;
+ }
+ sol = eol + 2;
+ }
+ EngUnmapFile(iFile);
+ }
+ return result;
+#else
+ return NULL;
+#endif
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+ /* TODO: implement */
+ return NULL;
+#else
+ return getenv(name);
+#endif
+}
+
diff --git a/src/gallium/auxiliary/os/os_misc.h b/src/gallium/auxiliary/os/os_misc.h
new file mode 100644
index 0000000000..d59f9819fe
--- /dev/null
+++ b/src/gallium/auxiliary/os/os_misc.h
@@ -0,0 +1,99 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Vmware, Inc.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
+ *
+ **************************************************************************/
+
+
+/*
+ * Miscellaneous OS services.
+ */
+
+
+#ifndef _OS_MISC_H_
+#define _OS_MISC_H_
+
+
+#include "pipe/p_compiler.h"
+
+
+#if defined(PIPE_OS_UNIX)
+# include <signal.h> /* for kill() */
+# include <unistd.h> /* getpid() */
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * Trap into the debugger.
+ */
+#if (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) && defined(PIPE_CC_GCC)
+# define os_break() __asm("int3")
+#elif defined(PIPE_CC_MSVC)
+# define os_break() __debugbreak()
+#elif defined(PIPE_OS_UNIX)
+# define os_break() kill(getpid(), SIGTRAP)
+#elif defined(PIPE_OS_EMBEDDED)
+void os_break(void);
+#else
+# define os_break() abort()
+#endif
+
+
+/*
+ * Abort the program.
+ */
+#if defined(DEBUG) || defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+# define os_abort() os_break()
+#elif defined(PIPE_OS_EMBEDDED)
+void os_abort(void);
+#else
+# define os_abort() abort()
+#endif
+
+
+/*
+ * Output a message. Message should preferably end in a newline.
+ */
+void
+os_log_message(const char *message);
+
+
+/*
+ * Get an option. Should return NULL if specified option is not set.
+ */
+const char *
+os_get_option(const char *name);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _OS_MISC_H_ */
diff --git a/src/gallium/auxiliary/util/u_stream.h b/src/gallium/auxiliary/os/os_stream.h
index a9d0f0121a..bf30e6542d 100644
--- a/src/gallium/auxiliary/util/u_stream.h
+++ b/src/gallium/auxiliary/os/os_stream.h
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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.
@@ -30,14 +30,14 @@
* Cross-platform sequential access stream abstraction.
*/
-#ifndef U_STREAM_H
-#define U_STREAM_H
+#ifndef _OS_STREAM_H_
+#define _OS_STREAM_H_
#include "pipe/p_compiler.h"
-struct util_stream;
+struct os_stream;
/**
@@ -45,17 +45,17 @@ struct util_stream;
* @param filename relative or absolute path (necessary for windows)
* @param optional maximum file size (0 for a growable size).
*/
-struct util_stream *
-util_stream_create(const char *filename, size_t max_size);
+struct os_stream *
+os_stream_create(const char *filename, size_t max_size);
boolean
-util_stream_write(struct util_stream *stream, const void *data, size_t size);
+os_stream_write(struct os_stream *stream, const void *data, size_t size);
void
-util_stream_flush(struct util_stream *stream);
+os_stream_flush(struct os_stream *stream);
void
-util_stream_close(struct util_stream *stream);
+os_stream_close(struct os_stream *stream);
-#endif /* U_STREAM_H */
+#endif /* _OS_STREAM_H_ */
diff --git a/src/gallium/auxiliary/util/u_stream_stdc.c b/src/gallium/auxiliary/os/os_stream_stdc.c
index 4d976d6dca..caa60c0b50 100644
--- a/src/gallium/auxiliary/util/u_stream_stdc.c
+++ b/src/gallium/auxiliary/os/os_stream_stdc.c
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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.
@@ -32,47 +32,46 @@
#include "pipe/p_config.h"
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_APPLE)
+#if defined(PIPE_OS_UNIX) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+#include <stdlib.h>
#include <stdio.h>
-#include "util/u_memory.h"
+#include "os_stream.h"
-#include "u_stream.h"
-
-struct util_stream
+struct os_stream
{
FILE *file;
};
-struct util_stream *
-util_stream_create(const char *filename, size_t max_size)
+struct os_stream *
+os_stream_create(const char *filename, size_t max_size)
{
- struct util_stream *stream;
+ struct os_stream *stream;
(void)max_size;
- stream = CALLOC_STRUCT(util_stream);
+ stream = (struct os_stream *)calloc(1, sizeof(struct os_stream));
if(!stream)
- goto error1;
+ goto no_stream;
stream->file = fopen(filename, "w");
if(!stream->file)
- goto error2;
+ goto no_file;
return stream;
-error2:
- FREE(stream);
-error1:
+no_file:
+ free(stream);
+no_stream:
return NULL;
}
boolean
-util_stream_write(struct util_stream *stream, const void *data, size_t size)
+os_stream_write(struct os_stream *stream, const void *data, size_t size)
{
if(!stream)
return FALSE;
@@ -82,7 +81,7 @@ util_stream_write(struct util_stream *stream, const void *data, size_t size)
void
-util_stream_flush(struct util_stream *stream)
+os_stream_flush(struct os_stream *stream)
{
if(!stream)
return;
@@ -92,14 +91,14 @@ util_stream_flush(struct util_stream *stream)
void
-util_stream_close(struct util_stream *stream)
+os_stream_close(struct os_stream *stream)
{
if(!stream)
return;
fclose(stream->file);
- FREE(stream);
+ free(stream);
}
diff --git a/src/gallium/auxiliary/util/u_stream_wd.c b/src/gallium/auxiliary/os/os_stream_wd.c
index 864489e775..a64cbcab4c 100644
--- a/src/gallium/auxiliary/util/u_stream_wd.c
+++ b/src/gallium/auxiliary/os/os_stream_wd.c
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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.
@@ -37,16 +37,14 @@
#include <windows.h>
#include <winddi.h>
-#include "util/u_memory.h"
-#include "util/u_string.h"
-
-#include "u_stream.h"
+#include "os_memory.h"
+#include "os_stream.h"
#define MAP_FILE_SIZE (4*1024*1024)
-struct util_stream
+struct os_stream
{
char filename[MAX_PATH + 1];
WCHAR wFileName[MAX_PATH + 1];
@@ -60,23 +58,23 @@ struct util_stream
static INLINE boolean
-util_stream_map(struct util_stream *stream)
+os_stream_map(struct os_stream *stream)
{
ULONG BytesInUnicodeString;
static char filename[MAX_PATH + 1];
unsigned filename_len;
if(stream->growable)
- filename_len = util_snprintf(filename,
- sizeof(filename),
- "%s.%04x",
- stream->filename,
- stream->suffix++);
+ filename_len = snprintf(filename,
+ sizeof(filename),
+ "%s.%04x",
+ stream->filename,
+ stream->suffix++);
else
- filename_len = util_snprintf(filename,
- sizeof(filename),
- "%s",
- stream->filename);
+ filename_len = snprintf(filename,
+ sizeof(filename),
+ "%s",
+ stream->filename);
EngMultiByteToUnicodeN(
stream->wFileName,
@@ -97,7 +95,7 @@ util_stream_map(struct util_stream *stream)
static INLINE void
-util_stream_unmap(struct util_stream *stream)
+os_stream_unmap(struct os_stream *stream)
{
EngUnmapFile(stream->iFile);
if(stream->written < stream->map_size) {
@@ -112,7 +110,7 @@ util_stream_unmap(struct util_stream *stream)
static INLINE void
-util_stream_full_qualified_filename(char *dst, size_t size, const char *src)
+os_stream_full_qualified_filename(char *dst, size_t size, const char *src)
{
boolean need_drive, need_root;
@@ -125,24 +123,24 @@ util_stream_full_qualified_filename(char *dst, size_t size, const char *src)
need_root = src[0] == '\\' ? FALSE : TRUE;
}
- util_snprintf(dst, size,
- "\\??\\%s%s%s",
- need_drive ? "C:" : "",
- need_root ? "\\" : "",
- src);
+ snprintf(dst, size,
+ "\\??\\%s%s%s",
+ need_drive ? "C:" : "",
+ need_root ? "\\" : "",
+ src);
}
-struct util_stream *
-util_stream_create(const char *filename, size_t max_size)
+struct os_stream *
+os_stream_create(const char *filename, size_t max_size)
{
- struct util_stream *stream;
+ struct os_stream *stream;
- stream = CALLOC_STRUCT(util_stream);
+ stream = CALLOC_STRUCT(os_stream);
if(!stream)
goto error1;
- util_stream_full_qualified_filename(stream->filename,
+ os_stream_full_qualified_filename(stream->filename,
sizeof(stream->filename),
filename);
@@ -155,7 +153,7 @@ util_stream_create(const char *filename, size_t max_size)
stream->map_size = MAP_FILE_SIZE;
}
- if(!util_stream_map(stream))
+ if(!os_stream_map(stream))
goto error2;
return stream;
@@ -168,7 +166,7 @@ error1:
static INLINE void
-util_stream_copy(struct util_stream *stream, const char *data, size_t size)
+os_stream_copy(struct os_stream *stream, const char *data, size_t size)
{
assert(stream->written + size <= stream->map_size);
memcpy(stream->pMap + stream->written, data, size);
@@ -177,7 +175,7 @@ util_stream_copy(struct util_stream *stream, const char *data, size_t size)
boolean
-util_stream_write(struct util_stream *stream, const void *data, size_t size)
+os_stream_write(struct os_stream *stream, const void *data, size_t size)
{
if(!stream)
return FALSE;
@@ -187,35 +185,35 @@ util_stream_write(struct util_stream *stream, const void *data, size_t size)
while(stream->written + size > stream->map_size) {
size_t step = stream->map_size - stream->written;
- util_stream_copy(stream, data, step);
+ os_stream_copy(stream, data, step);
data = (const char *)data + step;
size -= step;
- util_stream_unmap(stream);
- if(!stream->growable || !util_stream_map(stream))
+ os_stream_unmap(stream);
+ if(!stream->growable || !os_stream_map(stream))
return FALSE;
}
- util_stream_copy(stream, data, size);
+ os_stream_copy(stream, data, size);
return TRUE;
}
void
-util_stream_flush(struct util_stream *stream)
+os_stream_flush(struct os_stream *stream)
{
(void)stream;
}
void
-util_stream_close(struct util_stream *stream)
+os_stream_close(struct os_stream *stream)
{
if(!stream)
return;
- util_stream_unmap(stream);
+ os_stream_unmap(stream);
FREE(stream);
}
diff --git a/src/gallium/include/pipe/p_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 8119c1f571..24a2309976 100644
--- a/src/gallium/include/pipe/p_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -32,8 +32,8 @@
*/
-#ifndef _P_THREAD2_H_
-#define _P_THREAD2_H_
+#ifndef OS_THREAD_H_
+#define OS_THREAD_H_
#include "pipe/p_compiler.h"
@@ -235,6 +235,25 @@ static INLINE void pipe_barrier_wait(pipe_barrier *barrier)
/** Dummy definitions */
typedef unsigned pipe_thread;
+
+#define PIPE_THREAD_ROUTINE( name, param ) \
+ void * name( void *param )
+
+static INLINE pipe_thread pipe_thread_create( void *(* routine)( void *), void *param )
+{
+ return 0;
+}
+
+static INLINE int pipe_thread_wait( pipe_thread thread )
+{
+ return -1;
+}
+
+static INLINE int pipe_thread_destroy( pipe_thread thread )
+{
+ return -1;
+}
+
typedef unsigned pipe_mutex;
typedef unsigned pipe_condvar;
typedef unsigned pipe_barrier;
@@ -413,4 +432,4 @@ pipe_tsd_set(pipe_tsd *tsd, void *value)
-#endif /* _P_THREAD2_H_ */
+#endif /* OS_THREAD_H_ */
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
new file mode 100644
index 0000000000..6259142bec
--- /dev/null
+++ b/src/gallium/auxiliary/os/os_time.c
@@ -0,0 +1,128 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2010 VMware, Inc.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * OS independent time-manipulation functions.
+ *
+ * @author Jose Fonseca <jfonseca@vmware.com>
+ */
+
+
+#include "pipe/p_config.h"
+
+#if !defined(PIPE_OS_EMBEDDED)
+
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
+# include <sys/time.h> /* timeval */
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+# include <windows.h>
+# include <winddi.h>
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+# include <windows.h>
+extern VOID KeQuerySystemTime(PLARGE_INTEGER);
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+# include <windows.h>
+#else
+# error Unsupported OS
+#endif
+
+#include "os_time.h"
+
+
+int64_t
+os_time_get(void)
+{
+#if defined(PIPE_OS_UNIX)
+
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_usec + tv.tv_sec*1000000LL;
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+
+ static LONGLONG frequency;
+ LONGLONG counter;
+ if(!frequency)
+ EngQueryPerformanceFrequency(&frequency);
+ EngQueryPerformanceCounter(&counter);
+ return counter*INT64_C(1000000)/frequency;
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+
+ static LARGE_INTEGER frequency;
+ LARGE_INTEGER counter;
+ if(!frequency.QuadPart)
+ QueryPerformanceFrequency(&frequency);
+ QueryPerformanceCounter(&counter);
+ return counter.QuadPart*INT64_C(1000000)/frequency.QuadPart;
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+
+ /* Updated every 10 miliseconds, measured in units of 100 nanoseconds.
+ * http://msdn.microsoft.com/en-us/library/ms801642.aspx */
+ LARGE_INTEGER counter;
+ KeQuerySystemTime(&counter);
+ return counter.QuadPart/10;
+
+#endif
+}
+
+
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+
+void
+os_time_sleep(int64_t usecs)
+{
+ static LONGLONG frequency;
+ LONGLONG start, curr, end;
+
+ EngQueryPerformanceCounter(&start);
+
+ if(!frequency)
+ EngQueryPerformanceFrequency(&frequency);
+
+ end = start + (usecs * frequency + 999999LL)/1000000LL;
+
+ do {
+ EngQueryPerformanceCounter(&curr);
+ } while(start <= curr && curr < end ||
+ end < start && (curr < end || start <= curr));
+}
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+
+void
+os_time_sleep(int64_t usecs)
+{
+ Sleep((usecs + 999) / 1000);
+}
+
+#endif
+
+
+#endif /* !PIPE_OS_EMBEDDED */
diff --git a/src/gallium/drivers/nv04/nv04_surface.c b/src/gallium/auxiliary/os/os_time.h
index 0387ff4e78..5b55c1b374 100644
--- a/src/gallium/drivers/nv04/nv04_surface.c
+++ b/src/gallium/auxiliary/os/os_time.h
@@ -1,9 +1,8 @@
-
/**************************************************************************
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ *
+ * Copyright 2008-2010 VMware, Inc.
* 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
@@ -11,53 +10,83 @@
* 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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 "nv04_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
-#include "util/u_tile.h"
-
-static void
-nv04_surface_copy(struct pipe_context *pipe,
- struct pipe_surface *dest, unsigned destx, unsigned desty,
- struct pipe_surface *src, unsigned srcx, unsigned srcy,
- unsigned width, unsigned height)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_surface_2d *eng2d = nv04->screen->eng2d;
+/**
+ * @file
+ * OS independent time-manipulation functions.
+ *
+ * @author Jose Fonseca <jfonseca@vmware.com>
+ */
- eng2d->copy(eng2d, dest, destx, desty, src, srcx, srcy, width, height);
-}
+#ifndef _OS_TIME_H_
+#define _OS_TIME_H_
-static void
-nv04_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
- unsigned destx, unsigned desty, unsigned width,
- unsigned height, unsigned value)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_surface_2d *eng2d = nv04->screen->eng2d;
- eng2d->fill(eng2d, dest, destx, desty, width, height, value);
-}
+#include "pipe/p_config.h"
+
+#if defined(PIPE_OS_UNIX)
+# include <unistd.h> /* usleep */
+#endif
+#include "pipe/p_compiler.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * Get the current time in microseconds from an unknown base.
+ */
+int64_t
+os_time_get(void);
+
+
+/*
+ * Sleep.
+ */
+#if defined(PIPE_OS_UNIX)
+#define os_time_sleep(_usecs) usleep(_usecs)
+#else
void
-nv04_init_surface_functions(struct nv04_context *nv04)
+os_time_sleep(int64_t usecs);
+#endif
+
+
+/*
+ * Helper function for detecting time outs, taking in account overflow.
+ *
+ * Returns true the the current time has elapsed beyond the specified interval.
+ */
+static INLINE boolean
+os_time_timeout(int64_t start,
+ int64_t end,
+ int64_t curr)
{
- nv04->pipe.surface_copy = nv04_surface_copy;
- nv04->pipe.surface_fill = nv04_surface_fill;
+ if(start <= end)
+ return !(start <= curr && curr < end);
+ else
+ return !((start <= curr) || (curr < end));
+}
+
+
+#ifdef __cplusplus
}
+#endif
+
+#endif /* _OS_TIME_H_ */
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h
index eb7e84be84..34b1b77df4 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h
+++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h
@@ -46,6 +46,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
index ba087ac0f3..95eb5f6563 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
@@ -44,7 +44,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_defines.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
index 7b34c8e357..c1498318df 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
@@ -36,7 +36,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
#include "util/u_time.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
index 8f74180a11..93f8960641 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
@@ -35,7 +35,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
index 6400fc5b0a..63195715d6 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
@@ -35,7 +35,7 @@
#include "pipe/p_defines.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
#include "util/u_mm.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
index 7fd65ed226..fea234ae8c 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
@@ -37,7 +37,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "pipe/p_defines.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
index d21910d0bf..c445cb578b 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
@@ -38,7 +38,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "pipe/p_defines.h"
#include "util/u_memory.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/auxiliary/rtasm/rtasm_execmem.c b/src/gallium/auxiliary/rtasm/rtasm_execmem.c
index ffed768f97..65d5ce795b 100644
--- a/src/gallium/auxiliary/rtasm/rtasm_execmem.c
+++ b/src/gallium/auxiliary/rtasm/rtasm_execmem.c
@@ -32,7 +32,7 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include "rtasm_execmem.h"
@@ -58,7 +58,7 @@
#include <unistd.h>
#include <sys/mman.h>
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_mm.h"
#define EXEC_HEAP_SIZE (10*1024*1024)
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index fbb9aa0e63..f7a1bb74a9 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -264,6 +264,12 @@ static void
micro_rcp(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src)
{
+#if 0 /* for debugging */
+ assert(src->f[0] != 0.0f);
+ assert(src->f[1] != 0.0f);
+ assert(src->f[2] != 0.0f);
+ assert(src->f[3] != 0.0f);
+#endif
dst->f[0] = 1.0f / src->f[0];
dst->f[1] = 1.0f / src->f[1];
dst->f[2] = 1.0f / src->f[2];
@@ -284,6 +290,12 @@ static void
micro_rsq(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src)
{
+#if 0 /* for debugging */
+ assert(src->f[0] != 0.0f);
+ assert(src->f[1] != 0.0f);
+ assert(src->f[2] != 0.0f);
+ assert(src->f[3] != 0.0f);
+#endif
dst->f[0] = 1.0f / sqrtf(fabsf(src->f[0]));
dst->f[1] = 1.0f / sqrtf(fabsf(src->f[1]));
dst->f[2] = 1.0f / sqrtf(fabsf(src->f[2]));
@@ -450,12 +462,20 @@ static const union tgsi_exec_channel ZeroVec =
{ { 0.0, 0.0, 0.0, 0.0 } };
-#define CHECK_INF_OR_NAN(chan) do {\
- assert(!util_is_inf_or_nan((chan)->f[0]));\
- assert(!util_is_inf_or_nan((chan)->f[1]));\
- assert(!util_is_inf_or_nan((chan)->f[2]));\
- assert(!util_is_inf_or_nan((chan)->f[3]));\
- } while (0)
+/**
+ * Assert that none of the float values in 'chan' are infinite or NaN.
+ * NaN and Inf may occur normally during program execution and should
+ * not lead to crashes, etc. But when debugging, it's helpful to catch
+ * them.
+ */
+static INLINE void
+check_inf_or_nan(const union tgsi_exec_channel *chan)
+{
+ assert(!util_is_inf_or_nan((chan)->f[0]));
+ assert(!util_is_inf_or_nan((chan)->f[1]));
+ assert(!util_is_inf_or_nan((chan)->f[2]));
+ assert(!util_is_inf_or_nan((chan)->f[3]));
+}
#ifdef DEBUG
@@ -1219,8 +1239,9 @@ store_dest(struct tgsi_exec_machine *mach,
int offset = 0; /* indirection offset */
int index;
- if (dst_datatype == TGSI_EXEC_DATA_FLOAT) {
- CHECK_INF_OR_NAN(chan);
+ /* for debugging */
+ if (0 && dst_datatype == TGSI_EXEC_DATA_FLOAT) {
+ check_inf_or_nan(chan);
}
/* There is an extra source register that indirectly subscripts
@@ -1478,7 +1499,7 @@ emit_primitive(struct tgsi_exec_machine *mach)
}
/*
- * Fetch a four texture samples using STR texture coordinates.
+ * Fetch four texture samples using STR texture coordinates.
*/
static void
fetch_texel( struct tgsi_sampler *sampler,
diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.c b/src/gallium/auxiliary/tgsi/tgsi_parse.c
index fd37fc3079..7e19e1fe36 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_parse.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_parse.c
@@ -284,3 +284,14 @@ tgsi_dup_tokens(const struct tgsi_token *tokens)
memcpy(new_tokens, tokens, bytes);
return new_tokens;
}
+
+
+/**
+ * Allocate memory for num_tokens tokens.
+ */
+struct tgsi_token *
+tgsi_alloc_tokens(unsigned num_tokens)
+{
+ unsigned bytes = num_tokens * sizeof(struct tgsi_token);
+ return (struct tgsi_token *) MALLOC(bytes);
+}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.h b/src/gallium/auxiliary/tgsi/tgsi_parse.h
index 8150e3cd29..b45ccee2f6 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_parse.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_parse.h
@@ -130,6 +130,10 @@ tgsi_num_tokens(const struct tgsi_token *tokens);
struct tgsi_token *
tgsi_dup_tokens(const struct tgsi_token *tokens);
+struct tgsi_token *
+tgsi_alloc_tokens(unsigned num_tokens);
+
+
#if defined __cplusplus
}
#endif
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index 96be353e26..f918151daa 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -29,7 +29,7 @@
#include "util/u_memory.h"
#include "util/u_prim.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "tgsi_text.h"
#include "tgsi_build.h"
#include "tgsi_info.h"
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 0ae46785bb..27960bac22 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -33,6 +33,7 @@
#include "tgsi/tgsi_info.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_sanity.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "util/u_math.h"
@@ -103,6 +104,8 @@ struct ureg_program
struct {
unsigned index;
+ unsigned semantic_name;
+ unsigned semantic_index;
} gs_input[UREG_MAX_INPUT];
unsigned nr_gs_inputs;
@@ -325,10 +328,14 @@ ureg_DECL_vs_input( struct ureg_program *ureg,
struct ureg_src
ureg_DECL_gs_input(struct ureg_program *ureg,
- unsigned index)
+ unsigned index,
+ unsigned semantic_name,
+ unsigned semantic_index)
{
if (ureg->nr_gs_inputs < UREG_MAX_INPUT) {
ureg->gs_input[ureg->nr_gs_inputs].index = index;
+ ureg->gs_input[ureg->nr_gs_inputs].semantic_name = semantic_name;
+ ureg->gs_input[ureg->nr_gs_inputs].semantic_index = semantic_index;
ureg->nr_gs_inputs++;
} else {
set_bad(ureg);
@@ -1251,10 +1258,12 @@ static void emit_decls( struct ureg_program *ureg )
}
} else {
for (i = 0; i < ureg->nr_gs_inputs; i++) {
- emit_decl_range(ureg,
- TGSI_FILE_INPUT,
- ureg->gs_input[i].index,
- 1);
+ emit_decl(ureg,
+ TGSI_FILE_INPUT,
+ ureg->gs_input[i].index,
+ ureg->gs_input[i].semantic_name,
+ ureg->gs_input[i].semantic_index,
+ TGSI_INTERPOLATE_CONSTANT);
}
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index e25f35c6dc..6be66d0694 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -30,6 +30,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_shader_tokens.h"
+#include "util/u_debug.h"
#ifdef __cplusplus
extern "C" {
@@ -160,7 +161,9 @@ ureg_DECL_vs_input( struct ureg_program *,
struct ureg_src
ureg_DECL_gs_input(struct ureg_program *,
- unsigned index);
+ unsigned index,
+ unsigned semantic_name,
+ unsigned semantic_index);
struct ureg_src
ureg_DECL_system_value(struct ureg_program *,
diff --git a/src/gallium/auxiliary/util/u_atomic.h b/src/gallium/auxiliary/util/u_atomic.h
new file mode 100644
index 0000000000..540112f7f3
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_atomic.h
@@ -0,0 +1,271 @@
+/**
+ * Many similar implementations exist. See for example libwsbm
+ * or the linux kernel include/atomic.h
+ *
+ * No copyright claimed on this file.
+ *
+ */
+
+#ifndef U_ATOMIC_H
+#define U_ATOMIC_H
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_defines.h"
+
+/* Favor OS-provided implementations.
+ *
+ * Where no OS-provided implementation is available, fall back to
+ * locally coded assembly, compiler intrinsic or ultimately a
+ * mutex-based implementation.
+ */
+#if (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \
+ defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT))
+#define PIPE_ATOMIC_OS_UNLOCKED
+#elif defined(PIPE_CC_MSVC)
+#define PIPE_ATOMIC_MSVC_INTRINSIC
+#elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86))
+#define PIPE_ATOMIC_ASM_MSVC_X86
+#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86))
+#define PIPE_ATOMIC_ASM_GCC_X86
+#elif defined(PIPE_CC_GCC)
+#define PIPE_ATOMIC_GCC_INTRINSIC
+#else
+#error "Unsupported platform"
+#endif
+
+
+
+#if defined(PIPE_ATOMIC_ASM_GCC_X86)
+
+#define PIPE_ATOMIC "GCC x86 assembly"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+
+static INLINE boolean
+p_atomic_dec_zero(int32_t *v)
+{
+ unsigned char c;
+
+ __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
+ ::"memory");
+
+ return c != 0;
+}
+
+static INLINE void
+p_atomic_inc(int32_t *v)
+{
+ __asm__ __volatile__("lock; incl %0":"+m"(*v));
+}
+
+static INLINE void
+p_atomic_dec(int32_t *v)
+{
+ __asm__ __volatile__("lock; decl %0":"+m"(*v));
+}
+
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+ return __sync_val_compare_and_swap(v, old, _new);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+/* Implementation using GCC-provided synchronization intrinsics
+ */
+#if defined(PIPE_ATOMIC_GCC_INTRINSIC)
+
+#define PIPE_ATOMIC "GCC Sync Intrinsics"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+
+static INLINE boolean
+p_atomic_dec_zero(int32_t *v)
+{
+ return (__sync_sub_and_fetch(v, 1) == 0);
+}
+
+static INLINE void
+p_atomic_inc(int32_t *v)
+{
+ (void) __sync_add_and_fetch(v, 1);
+}
+
+static INLINE void
+p_atomic_dec(int32_t *v)
+{
+ (void) __sync_sub_and_fetch(v, 1);
+}
+
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+ return __sync_val_compare_and_swap(v, old, _new);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+/* Unlocked version for single threaded environments, such as some
+ * windows kernel modules.
+ */
+#if defined(PIPE_ATOMIC_OS_UNLOCKED)
+
+#define PIPE_ATOMIC "Unlocked"
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+#define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
+#define p_atomic_inc(_v) ((void) (*(_v))++)
+#define p_atomic_dec(_v) ((void) (*(_v))--)
+#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
+
+#endif
+
+
+/* Locally coded assembly for MSVC on x86:
+ */
+#if defined(PIPE_ATOMIC_ASM_MSVC_X86)
+
+#define PIPE_ATOMIC "MSVC x86 assembly"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+
+static INLINE boolean
+p_atomic_dec_zero(int32_t *v)
+{
+ unsigned char c;
+
+ __asm {
+ mov eax, [v]
+ lock dec dword ptr [eax]
+ sete byte ptr [c]
+ }
+
+ return c != 0;
+}
+
+static INLINE void
+p_atomic_inc(int32_t *v)
+{
+ __asm {
+ mov eax, [v]
+ lock inc dword ptr [eax]
+ }
+}
+
+static INLINE void
+p_atomic_dec(int32_t *v)
+{
+ __asm {
+ mov eax, [v]
+ lock dec dword ptr [eax]
+ }
+}
+
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+ int32_t orig;
+
+ __asm {
+ mov ecx, [v]
+ mov eax, [old]
+ mov edx, [_new]
+ lock cmpxchg [ecx], edx
+ mov [orig], eax
+ }
+
+ return orig;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+#if defined(PIPE_ATOMIC_MSVC_INTRINSIC)
+
+#define PIPE_ATOMIC "MSVC Intrinsics"
+
+#include <intrin.h>
+
+#pragma intrinsic(_InterlockedIncrement)
+#pragma intrinsic(_InterlockedDecrement)
+#pragma intrinsic(_InterlockedCompareExchange)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+
+static INLINE boolean
+p_atomic_dec_zero(int32_t *v)
+{
+ return _InterlockedDecrement((long *)v) == 0;
+}
+
+static INLINE void
+p_atomic_inc(int32_t *v)
+{
+ _InterlockedIncrement((long *)v);
+}
+
+static INLINE void
+p_atomic_dec(int32_t *v)
+{
+ _InterlockedDecrement((long *)v);
+}
+
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+ return _InterlockedCompareExchange((long *)v, _new, old);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+#ifndef PIPE_ATOMIC
+#error "No pipe_atomic implementation selected"
+#endif
+
+
+
+#endif /* U_ATOMIC_H */
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index eb63bec7b5..f0bc58a558 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -36,7 +36,7 @@
#include "pipe/p_context.h"
#include "util/u_debug.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 935e11c5d8..f3b4491d17 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -34,7 +34,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 7ee0864d29..4821b8a143 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -29,125 +29,30 @@
#include "pipe/p_config.h"
-#include <stdarg.h>
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-
-#include <windows.h>
-#include <winddi.h>
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <windows.h>
-#include <types.h>
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
-#endif
-#include <windows.h>
-#include <stdio.h>
-
-#else
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#endif
-
-#include "pipe/p_compiler.h"
+#include "pipe/p_compiler.h"
+#include "os/os_stream.h"
#include "util/u_debug.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_string.h"
-#include "util/u_stream.h"
#include "util/u_math.h"
#include "util/u_tile.h"
#include "util/u_prim.h"
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static INLINE void
-_EngDebugPrint(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- EngDebugPrint("", (PCHAR)format, ap);
- va_end(ap);
-}
-#endif
-
-
void _debug_vprintf(const char *format, va_list ap)
{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- /* EngDebugPrint does not handle float point arguments, so we need to use
- * our own vsnprintf implementation. It is also very slow, so buffer until
- * we find a newline. */
- static char buf[512] = {'\0'};
- size_t len = strlen(buf);
- int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
- if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
- _EngDebugPrint("%s", buf);
- buf[0] = '\0';
- }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
- /* OutputDebugStringA can be very slow, so buffer until we find a newline. */
+ /* We buffer until we find a newline. */
static char buf[4096] = {'\0'};
size_t len = strlen(buf);
int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
- OutputDebugStringA(buf);
+ os_log_message(buf);
buf[0] = '\0';
}
-
- if(GetConsoleWindow() && !IsDebuggerPresent()) {
- fflush(stdout);
- vfprintf(stderr, format, ap);
- fflush(stderr);
- }
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- wchar_t *wide_format;
- long wide_str_len;
- char buf[512];
- int ret;
-#if (_WIN32_WCE < 600)
- ret = vsprintf(buf, format, ap);
- if(ret < 0){
- sprintf(buf, "Cant handle debug print!");
- ret = 25;
- }
-#else
- ret = vsprintf_s(buf, 512, format, ap);
- if(ret < 0){
- sprintf_s(buf, 512, "Cant handle debug print!");
- ret = 25;
- }
-#endif
- buf[ret] = '\0';
- /* Format is ascii - needs to be converted to wchar_t for printing */
- wide_str_len = MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1, NULL, 0);
- wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));
- if (wide_format) {
- MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1,
- wide_format, wide_str_len);
- NKDbgPrintfW(wide_format, wide_format);
- free(wide_format);
- }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* TODO */
-#else /* !PIPE_SUBSYSTEM_WINDOWS */
- fflush(stdout);
- vfprintf(stderr, format, ap);
-#endif
}
@@ -169,108 +74,12 @@ void debug_print_blob( const char *name,
#endif
-#ifndef debug_break
-void debug_break(void)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
- DebugBreak();
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- EngDebugBreak();
-#else
- abort();
-#endif
-}
-#endif
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static const char *
-find(const char *start, const char *end, char c)
-{
- const char *p;
- for(p = start; !end || p != end; ++p) {
- if(*p == c)
- return p;
- if(*p < 32)
- break;
- }
- return NULL;
-}
-
-static int
-compare(const char *start, const char *end, const char *s)
-{
- const char *p, *q;
- for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
- if(*p != *q)
- return 0;
- }
- return p == end && *q == '\0';
-}
-
-static void
-copy(char *dst, const char *start, const char *end, size_t n)
-{
- const char *p;
- char *q;
- for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
- *q = *p;
- *q = '\0';
-}
-#endif
-
-
-static INLINE const char *
-_debug_get_option(const char *name)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- /* EngMapFile creates the file if it does not exists, so it must either be
- * disabled on release versions (or put in a less conspicuous place). */
-#ifdef DEBUG
- const char *result = NULL;
- ULONG_PTR iFile = 0;
- const void *pMap = NULL;
- const char *sol, *eol, *sep;
- static char output[1024];
-
- pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
- if(pMap) {
- sol = (const char *)pMap;
- while(1) {
- /* TODO: handle LF line endings */
- eol = find(sol, NULL, '\r');
- if(!eol || eol == sol)
- break;
- sep = find(sol, eol, '=');
- if(!sep)
- break;
- if(compare(sol, sep, name)) {
- copy(output, sep + 1, eol, sizeof(output));
- result = output;
- break;
- }
- sol = eol + 2;
- }
- EngUnmapFile(iFile);
- }
- return result;
-#else
- return NULL;
-#endif
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* TODO: implement */
- return NULL;
-#else
- return getenv(name);
-#endif
-}
-
const char *
debug_get_option(const char *name, const char *dfault)
{
const char *result;
- result = _debug_get_option(name);
+ result = os_get_option(name);
if(!result)
result = dfault;
@@ -282,7 +91,7 @@ debug_get_option(const char *name, const char *dfault)
boolean
debug_get_bool_option(const char *name, boolean dfault)
{
- const char *str = _debug_get_option(name);
+ const char *str = os_get_option(name);
boolean result;
if(str == NULL)
@@ -312,7 +121,7 @@ debug_get_num_option(const char *name, long dfault)
long result;
const char *str;
- str = _debug_get_option(name);
+ str = os_get_option(name);
if(!str)
result = dfault;
else {
@@ -348,7 +157,7 @@ debug_get_flags_option(const char *name,
unsigned long result;
const char *str;
- str = _debug_get_option(name);
+ str = os_get_option(name);
if(!str)
result = dfault;
else if (!util_strcmp(str, "help")) {
@@ -389,7 +198,7 @@ void _debug_assert_fail(const char *expr,
#else
if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
#endif
- debug_break();
+ os_abort();
else
_debug_printf("continuing...\n");
}
@@ -872,7 +681,7 @@ debug_dump_float_rgba_bmp(const char *filename,
float *rgba, unsigned stride)
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
- struct util_stream *stream;
+ struct os_stream *stream;
struct bmp_file_header bmfh;
struct bmp_info_header bmih;
unsigned x, y;
@@ -898,12 +707,12 @@ debug_dump_float_rgba_bmp(const char *filename,
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
- stream = util_stream_create(filename, bmfh.bfSize);
+ stream = os_stream_create(filename, bmfh.bfSize);
if(!stream)
goto error1;
- util_stream_write(stream, &bmfh, 14);
- util_stream_write(stream, &bmih, 40);
+ os_stream_write(stream, &bmfh, 14);
+ os_stream_write(stream, &bmih, 40);
y = height;
while(y--) {
@@ -915,11 +724,11 @@ debug_dump_float_rgba_bmp(const char *filename,
pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]);
pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]);
pixel.rgbAlpha = 255;
- util_stream_write(stream, &pixel, 4);
+ os_stream_write(stream, &pixel, 4);
}
}
- util_stream_close(stream);
+ os_stream_close(stream);
error1:
;
#endif
diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index 131c991539..efcf065d27 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -39,9 +39,7 @@
#define U_DEBUG_H_
-#include <stdarg.h>
-
-#include "pipe/p_compiler.h"
+#include "os/os_misc.h"
#ifdef __cplusplus
@@ -49,22 +47,6 @@ extern "C" {
#endif
-#if defined(DBG) || defined(DEBUG)
-#ifndef DEBUG
-#define DEBUG 1
-#endif
-#else
-#ifndef NDEBUG
-#define NDEBUG 1
-#endif
-#endif
-
-
-/* MSVC bebore VC7 does not have the __FUNCTION__ macro */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-#define __FUNCTION__ "???"
-#endif
-
#if defined(__GNUC__)
#define _util_printf_format(fmt, list) __attribute__ ((format (printf, fmt, list)))
#else
@@ -155,13 +137,7 @@ void debug_print_format(const char *msg, unsigned fmt );
* Hard-coded breakpoint.
*/
#ifdef DEBUG
-#if (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) && defined(PIPE_CC_GCC)
-#define debug_break() __asm("int3")
-#elif defined(PIPE_CC_MSVC)
-#define debug_break() __debugbreak()
-#else
-void debug_break(void);
-#endif
+#define debug_break() os_break()
#else /* !DEBUG */
#define debug_break() ((void)0)
#endif /* !DEBUG */
@@ -328,22 +304,6 @@ debug_get_flags_option(const char *name,
unsigned long dfault);
-void *
-debug_malloc(const char *file, unsigned line, const char *function,
- size_t size);
-
-void
-debug_free(const char *file, unsigned line, const char *function,
- void *ptr);
-
-void *
-debug_calloc(const char *file, unsigned line, const char *function,
- size_t count, size_t size );
-
-void *
-debug_realloc(const char *file, unsigned line, const char *function,
- void *old_ptr, size_t old_size, size_t new_size );
-
unsigned long
debug_memory_begin(void);
diff --git a/src/gallium/auxiliary/util/u_debug_memory.c b/src/gallium/auxiliary/util/u_debug_memory.c
index d6484f4ad5..f1baa62f89 100644
--- a/src/gallium/auxiliary/util/u_debug_memory.c
+++ b/src/gallium/auxiliary/util/u_debug_memory.c
@@ -34,15 +34,10 @@
#include "pipe/p_config.h"
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-#include <windows.h>
-#include <winddi.h>
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-#include <wdm.h>
-#else
-#include <stdio.h>
-#include <stdlib.h>
-#endif
+#define DEBUG_MEMORY_IMPLEMENTATION
+
+#include "os/os_memory.h"
+#include "os/os_memory_debug.h"
#include "util/u_debug.h"
#include "util/u_debug_stack.h"
@@ -53,18 +48,6 @@
#define DEBUG_MEMORY_STACK 0 /* XXX: disabled until we have symbol lookup */
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) && !defined(WINCE)
-#define real_malloc(_size) EngAllocMem(0, _size, 'D3AG')
-#define real_free(_ptr) EngFreeMem(_ptr)
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-#define real_malloc(_size) ExAllocatePool(0, _size)
-#define real_free(_ptr) ExFreePool(_ptr)
-#else
-#define real_malloc(_size) malloc(_size)
-#define real_free(_ptr) free(_ptr)
-#endif
-
-
struct debug_memory_header
{
struct list_head head;
@@ -127,7 +110,7 @@ debug_malloc(const char *file, unsigned line, const char *function,
struct debug_memory_header *hdr;
struct debug_memory_footer *ftr;
- hdr = real_malloc(sizeof(*hdr) + size + sizeof(*ftr));
+ hdr = os_malloc(sizeof(*hdr) + size + sizeof(*ftr));
if(!hdr) {
debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
file, line, function,
@@ -185,7 +168,7 @@ debug_free(const char *file, unsigned line, const char *function,
hdr->magic = 0;
ftr->magic = 0;
- real_free(hdr);
+ os_free(hdr);
}
void *
@@ -232,7 +215,7 @@ debug_realloc(const char *file, unsigned line, const char *function,
}
/* alloc new */
- new_hdr = real_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr));
+ new_hdr = os_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr));
if(!new_hdr) {
debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
file, line, function,
@@ -258,7 +241,7 @@ debug_realloc(const char *file, unsigned line, const char *function,
/* free old */
old_hdr->magic = 0;
old_ftr->magic = 0;
- real_free(old_hdr);
+ os_free(old_hdr);
return new_ptr;
}
diff --git a/src/gallium/auxiliary/util/u_dl.c b/src/gallium/auxiliary/util/u_dl.c
index d8803f77fa..37ed789f95 100644
--- a/src/gallium/auxiliary/util/u_dl.c
+++ b/src/gallium/auxiliary/util/u_dl.c
@@ -26,8 +26,9 @@
*
**************************************************************************/
+
#include "pipe/p_config.h"
-#include "util/u_debug.h"
+#include "pipe/p_compiler.h"
#if defined(PIPE_OS_UNIX)
#include <dlfcn.h>
@@ -43,12 +44,7 @@ struct util_dl_library *
util_dl_open(const char *filename)
{
#if defined(PIPE_OS_UNIX)
- struct util_dl_library *lib;
- lib = (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
- if (!lib) {
- debug_printf("gallium: dlopen() failed: %s\n", dlerror());
- }
- return lib;
+ return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
#elif defined(PIPE_OS_WINDOWS)
return (struct util_dl_library *)LoadLibraryA(filename);
#else
diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c
index e2e23c3cdd..14506e8451 100644
--- a/src/gallium/auxiliary/util/u_draw_quad.c
+++ b/src/gallium/auxiliary/util/u_draw_quad.c
@@ -28,7 +28,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index a558923b2e..4323bc881b 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -31,6 +31,7 @@
#include "pipe/p_format.h"
+#include "util/u_debug.h"
#ifdef __cplusplus
extern "C" {
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 8611231ed7..4e358d3938 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -37,7 +37,7 @@
#include "pipe/p_context.h"
#include "util/u_debug.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index 72f5c1dc2a..e95d58ea86 100644
--- a/src/gallium/include/pipe/p_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -25,12 +25,15 @@
*
**************************************************************************/
-#ifndef P_INLINES_H
-#define P_INLINES_H
+#ifndef U_INLINES_H
+#define U_INLINES_H
-#include "p_context.h"
-#include "p_defines.h"
-#include "p_screen.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_state.h"
+#include "pipe/p_screen.h"
+#include "util/u_debug.h"
+#include "util/u_atomic.h"
#ifdef __cplusplus
@@ -38,7 +41,84 @@ extern "C" {
#endif
+/*
+ * Reference counting helper functions.
+ */
+
+
+static INLINE void
+pipe_reference_init(struct pipe_reference *reference, unsigned count)
+{
+ p_atomic_set(&reference->count, count);
+}
+
+static INLINE boolean
+pipe_is_referenced(struct pipe_reference *reference)
+{
+ return p_atomic_read(&reference->count) != 0;
+}
+
/**
+ * Update reference counting.
+ * The old thing pointed to, if any, will be unreferenced.
+ * Both 'ptr' and 'reference' may be NULL.
+ * \return TRUE if the object's refcount hits zero and should be destroyed.
+ */
+static INLINE boolean
+pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference)
+{
+ boolean destroy = FALSE;
+
+ if(ptr != reference) {
+ /* bump the reference.count first */
+ if (reference) {
+ assert(pipe_is_referenced(reference));
+ p_atomic_inc(&reference->count);
+ }
+
+ if (ptr) {
+ assert(pipe_is_referenced(ptr));
+ if (p_atomic_dec_zero(&ptr->count)) {
+ destroy = TRUE;
+ }
+ }
+ }
+
+ return destroy;
+}
+
+static INLINE void
+pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf)
+{
+ struct pipe_buffer *old_buf = *ptr;
+
+ if (pipe_reference(&(*ptr)->reference, &buf->reference))
+ old_buf->screen->buffer_destroy(old_buf);
+ *ptr = buf;
+}
+
+static INLINE void
+pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
+{
+ struct pipe_surface *old_surf = *ptr;
+
+ if (pipe_reference(&(*ptr)->reference, &surf->reference))
+ old_surf->texture->screen->tex_surface_destroy(old_surf);
+ *ptr = surf;
+}
+
+static INLINE void
+pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex)
+{
+ struct pipe_texture *old_tex = *ptr;
+
+ if (pipe_reference(&(*ptr)->reference, &tex->reference))
+ old_tex->screen->texture_destroy(old_tex);
+ *ptr = tex;
+}
+
+
+/*
* Convenience wrappers for screen buffer functions.
*/
@@ -221,4 +301,4 @@ pipe_transfer_buffer_flags( struct pipe_transfer *transf )
}
#endif
-#endif /* P_INLINES_H */
+#endif /* U_INLINES_H */
diff --git a/src/gallium/auxiliary/util/u_keymap.c b/src/gallium/auxiliary/util/u_keymap.c
index c4b9eb3d9b..e161ccd88e 100644
--- a/src/gallium/auxiliary/util/u_keymap.c
+++ b/src/gallium/auxiliary/util/u_keymap.c
@@ -36,7 +36,6 @@
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
-#include "pipe/p_defines.h"
#include "cso_cache/cso_hash.h"
diff --git a/src/gallium/auxiliary/util/u_memory.h b/src/gallium/auxiliary/util/u_memory.h
index c3f8c91833..a2fc597356 100644
--- a/src/gallium/auxiliary/util/u_memory.h
+++ b/src/gallium/auxiliary/util/u_memory.h
@@ -26,7 +26,7 @@
**************************************************************************/
-/**
+/*
* Memory functions
*/
@@ -37,6 +37,7 @@
#include "util/u_pointer.h"
#include "util/u_debug.h"
+#include "os/os_memory.h"
#ifdef __cplusplus
@@ -44,114 +45,13 @@ extern "C" {
#endif
-/* Define ENOMEM for WINCE */
-#if (_WIN32_WCE < 600)
-#ifndef ENOMEM
-#define ENOMEM 12
-#endif
-#endif
-
-
-#if defined(PIPE_OS_WINDOWS) && defined(DEBUG)
-
-/* memory debugging */
-
-#include "util/u_debug.h"
-
-#define MALLOC( _size ) \
- debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
-#define CALLOC( _count, _size ) \
- debug_calloc(__FILE__, __LINE__, __FUNCTION__, _count, _size )
-#define FREE( _ptr ) \
- debug_free( __FILE__, __LINE__, __FUNCTION__, _ptr )
-#define REALLOC( _ptr, _old_size, _size ) \
- debug_realloc( __FILE__, __LINE__, __FUNCTION__, _ptr, _old_size, _size )
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-
-void * __stdcall
-EngAllocMem(
- unsigned long Flags,
- unsigned long MemSize,
- unsigned long Tag );
-
-void __stdcall
-EngFreeMem(
- void *Mem );
-
-#define MALLOC( _size ) EngAllocMem( 0, _size, 'D3AG' )
-#define _FREE( _ptr ) EngFreeMem( _ptr )
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-
-void *
-ExAllocatePool(
- unsigned long PoolType,
- size_t NumberOfBytes);
-
-void
-ExFreePool(void *P);
-
-#define MALLOC(_size) ExAllocatePool(0, _size)
-#define _FREE(_ptr) ExFreePool(_ptr)
-
-#else
-
-#define MALLOC( SIZE ) malloc( SIZE )
-#define CALLOC( COUNT, SIZE ) calloc( COUNT, SIZE )
-#define FREE( PTR ) free( PTR )
-
-static INLINE void *
-_REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
-{
- (void) old_size;
- return realloc(old_ptr, new_size);
-}
-#define REALLOC( a, b, c ) _REALLOC( a, b, c )
-#endif
-
-
-#ifndef CALLOC
-static INLINE void *
-CALLOC( unsigned count, unsigned size )
-{
- void *ptr = MALLOC( count * size );
- if( ptr ) {
- memset( ptr, 0, count * size );
- }
- return ptr;
-}
-#endif /* !CALLOC */
+#define MALLOC(_size) os_malloc(_size)
-#ifndef FREE
-static INLINE void
-FREE( void *ptr )
-{
- if( ptr ) {
- _FREE( ptr );
- }
-}
-#endif /* !FREE */
+#define CALLOC(_count, _size) os_calloc(_count, _size)
-#ifndef REALLOC
-static INLINE void *
-REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
-{
- void *new_ptr = NULL;
-
- if (new_size != 0) {
- unsigned copy_size = old_size < new_size ? old_size : new_size;
- new_ptr = MALLOC( new_size );
- if (new_ptr && old_ptr && copy_size) {
- memcpy( new_ptr, old_ptr, copy_size );
- }
- }
-
- FREE( old_ptr );
- return new_ptr;
-}
-#endif /* !REALLOC */
+#define FREE(_ptr ) os_free(_ptr)
+#define REALLOC(_ptr, _old_size, _size) os_realloc(_ptr, _old_size, _size)
#define MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T))
@@ -160,50 +60,8 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
#define CALLOC_VARIANT_LENGTH_STRUCT(T,more_size) ((struct T *) CALLOC(1, sizeof(struct T) + more_size))
-/**
- * Return memory on given byte alignment
- */
-static INLINE void *
-align_malloc(size_t bytes, uint alignment)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- void *mem;
- alignment = (alignment + (uint)sizeof(void*) - 1) & ~((uint)sizeof(void*) - 1);
- if(posix_memalign(& mem, alignment, bytes) != 0)
- return NULL;
- return mem;
-#else
- char *ptr, *buf;
-
- assert( alignment > 0 );
-
- ptr = (char *) MALLOC(bytes + alignment + sizeof(void *));
- if (!ptr)
- return NULL;
-
- buf = (char *) align_pointer( ptr + sizeof(void *), alignment );
- *(char **)(buf - sizeof(void *)) = ptr;
-
- return buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
-
-/**
- * Free memory returned by align_malloc().
- */
-static INLINE void
-align_free(void *ptr)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- FREE(ptr);
-#else
- if (ptr) {
- void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
- void *realAddr = *cubbyHole;
- FREE(realAddr);
- }
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
+#define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment)
+#define align_free(_ptr) os_free_aligned(_ptr)
/**
diff --git a/src/gallium/auxiliary/util/u_prim.h b/src/gallium/auxiliary/util/u_prim.h
index 10a874f341..64390e1385 100644
--- a/src/gallium/auxiliary/util/u_prim.h
+++ b/src/gallium/auxiliary/util/u_prim.h
@@ -30,12 +30,13 @@
#define U_BLIT_H
+#include "pipe/p_defines.h"
+#include "util/u_debug.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#include "pipe/p_defines.h"
-
static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
{
boolean ok = TRUE;
diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c
index e73ba0b348..648b105b13 100644
--- a/src/gallium/auxiliary/util/u_ringbuffer.c
+++ b/src/gallium/auxiliary/util/u_ringbuffer.c
@@ -1,5 +1,5 @@
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "pipe/p_defines.h"
#include "util/u_ringbuffer.h"
#include "util/u_math.h"
diff --git a/src/gallium/auxiliary/util/u_simple_screen.c b/src/gallium/auxiliary/util/u_simple_screen.c
index 5238299015..53f3c16dbc 100644
--- a/src/gallium/auxiliary/util/u_simple_screen.c
+++ b/src/gallium/auxiliary/util/u_simple_screen.c
@@ -29,7 +29,7 @@
#include "pipe/p_screen.h"
#include "pipe/p_state.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
static struct pipe_buffer *
diff --git a/src/gallium/auxiliary/util/u_simple_screen.h b/src/gallium/auxiliary/util/u_simple_screen.h
index 6612a8a7c0..bb3f5ba102 100644
--- a/src/gallium/auxiliary/util/u_simple_screen.h
+++ b/src/gallium/auxiliary/util/u_simple_screen.h
@@ -28,8 +28,145 @@
#ifndef U_SIMPLE_SCREEN_H
#define U_SIMPLE_SCREEN_H
+#include "pipe/p_format.h"
+
struct pipe_screen;
-struct pipe_winsys;
+struct pipe_fence_handle;
+struct pipe_surface;
+struct pipe_buffer;
+
+/**
+ * Gallium3D drivers are (meant to be!) independent of both GL and the
+ * window system. The window system provides a buffer manager and a
+ * set of additional hooks for things like command buffer submission,
+ * etc.
+ *
+ * There clearly has to be some agreement between the window system
+ * driver and the hardware driver about the format of command buffers,
+ * etc.
+ */
+struct pipe_winsys
+{
+ void (*destroy)( struct pipe_winsys *ws );
+
+ /** Returns name of this winsys interface */
+ const char *(*get_name)( struct pipe_winsys *ws );
+
+ /**
+ * Do any special operations to ensure buffer size is correct
+ */
+ void (*update_buffer)( struct pipe_winsys *ws,
+ void *context_private );
+ /**
+ * Do any special operations to ensure frontbuffer contents are
+ * displayed, eg copy fake frontbuffer.
+ */
+ void (*flush_frontbuffer)( struct pipe_winsys *ws,
+ struct pipe_surface *surf,
+ void *context_private );
+
+
+ /**
+ * Buffer management. Buffer attributes are mostly fixed over its lifetime.
+ *
+ * Remember that gallium gets to choose the interface it needs, and the
+ * window systems must then implement that interface (rather than the
+ * other way around...).
+ *
+ * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
+ * usage argument is only an optimization hint, not a guarantee, therefore
+ * proper behavior must be observed in all circumstances.
+ *
+ * alignment indicates the client's alignment requirements, eg for
+ * SSE instructions.
+ */
+ struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,
+ unsigned alignment,
+ unsigned usage,
+ unsigned size );
+
+ /**
+ * Create a buffer that wraps user-space data.
+ *
+ * Effectively this schedules a delayed call to buffer_create
+ * followed by an upload of the data at *some point in the future*,
+ * or perhaps never. Basically the allocate/upload is delayed
+ * until the buffer is actually passed to hardware.
+ *
+ * The intention is to provide a quick way to turn regular data
+ * into a buffer, and secondly to avoid a copy operation if that
+ * data subsequently turns out to be only accessed by the CPU.
+ *
+ * Common example is OpenGL vertex buffers that are subsequently
+ * processed either by software TNL in the driver or by passing to
+ * hardware.
+ *
+ * XXX: What happens if the delayed call to buffer_create() fails?
+ *
+ * Note that ptr may be accessed at any time upto the time when the
+ * buffer is destroyed, so the data must not be freed before then.
+ */
+ struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,
+ void *ptr,
+ unsigned bytes);
+
+ /**
+ * Allocate storage for a display target surface.
+ *
+ * Often surfaces which are meant to be blitted to the front screen (i.e.,
+ * display targets) must be allocated with special characteristics, memory
+ * pools, or obtained directly from the windowing system.
+ *
+ * This callback is invoked by the pipe_screenwhen creating a texture marked
+ * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
+ * buffer storage.
+ */
+ struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
+ unsigned width, unsigned height,
+ enum pipe_format format,
+ unsigned usage,
+ unsigned tex_usage,
+ unsigned *stride);
+
+
+ /**
+ * Map the entire data store of a buffer object into the client's address.
+ * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
+ */
+ void *(*buffer_map)( struct pipe_winsys *ws,
+ struct pipe_buffer *buf,
+ unsigned usage );
+
+ void (*buffer_unmap)( struct pipe_winsys *ws,
+ struct pipe_buffer *buf );
+
+ void (*buffer_destroy)( struct pipe_buffer *buf );
+
+
+ /** Set ptr = fence, with reference counting */
+ void (*fence_reference)( struct pipe_winsys *ws,
+ struct pipe_fence_handle **ptr,
+ struct pipe_fence_handle *fence );
+
+ /**
+ * Checks whether the fence has been signalled.
+ * \param flags driver-specific meaning
+ * \return zero on success.
+ */
+ int (*fence_signalled)( struct pipe_winsys *ws,
+ struct pipe_fence_handle *fence,
+ unsigned flag );
+
+ /**
+ * Wait for the fence to finish.
+ * \param flags driver-specific meaning
+ * \return zero on success.
+ */
+ int (*fence_finish)( struct pipe_winsys *ws,
+ struct pipe_fence_handle *fence,
+ unsigned flag );
+
+};
/**
* The following function initializes a simple passthrough screen.
diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c
index b751e29ab6..019dda767d 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.c
+++ b/src/gallium/auxiliary/util/u_simple_shaders.c
@@ -38,6 +38,7 @@
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_simple_shaders.h"
+#include "util/u_debug.h"
#include "tgsi/tgsi_ureg.h"
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index 70de140ec9..c9f1c9c210 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -35,6 +35,7 @@
#include "pipe/p_screen.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_surface.h"
diff --git a/src/gallium/auxiliary/util/u_texture.c b/src/gallium/auxiliary/util/u_texture.c
index cd477ab640..d97e57a790 100644
--- a/src/gallium/auxiliary/util/u_texture.c
+++ b/src/gallium/auxiliary/util/u_texture.c
@@ -37,6 +37,7 @@
#include "pipe/p_defines.h"
+#include "util/u_debug.h"
#include "util/u_texture.h"
void util_map_texcoords2d_onto_cubemap(unsigned face,
diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c
index c25e1e52e9..0051258e22 100644
--- a/src/gallium/auxiliary/util/u_tile.c
+++ b/src/gallium/auxiliary/util/u_tile.c
@@ -32,7 +32,7 @@
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
diff --git a/src/gallium/auxiliary/util/u_time.c b/src/gallium/auxiliary/util/u_time.c
deleted file mode 100644
index b958a98635..0000000000
--- a/src/gallium/auxiliary/util/u_time.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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
- * without limitation the rights to use, copy, modify, merge, publish,
- * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * OS independent time-manipulation functions.
- *
- * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-
-#include "pipe/p_config.h"
-
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
-#include <sys/time.h>
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-#include <windows.h>
-#include <winddi.h>
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-#include <windows.h>
-extern VOID KeQuerySystemTime(PLARGE_INTEGER);
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-#include <windows.h>
-#else
-#error Unsupported OS
-#endif
-
-#include "util/u_time.h"
-
-
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-
-static int64_t frequency = 0;
-
-static INLINE void
-util_time_get_frequency(void)
-{
- if(!frequency) {
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- LONGLONG temp;
- EngQueryPerformanceFrequency(&temp);
- frequency = temp;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- LARGE_INTEGER temp;
- QueryPerformanceFrequency(&temp);
- frequency = temp.QuadPart;
-#endif
- }
-}
-#endif
-
-
-void
-util_time_get(struct util_time *t)
-{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- gettimeofday(&t->tv, NULL);
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- LONGLONG temp;
- EngQueryPerformanceCounter(&temp);
- t->counter = temp;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* Updated every 10 miliseconds, measured in units of 100 nanoseconds.
- * http://msdn.microsoft.com/en-us/library/ms801642.aspx */
- LARGE_INTEGER temp;
- KeQuerySystemTime(&temp);
- t->counter = temp.QuadPart;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- LARGE_INTEGER temp;
- QueryPerformanceCounter(&temp);
- t->counter = temp.QuadPart;
-#endif
-}
-
-
-void
-util_time_add(const struct util_time *t1,
- int64_t usecs,
- struct util_time *t2)
-{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- t2->tv.tv_sec = t1->tv.tv_sec + usecs / 1000000;
- t2->tv.tv_usec = t1->tv.tv_usec + usecs % 1000000;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- util_time_get_frequency();
- t2->counter = t1->counter + (usecs * frequency + INT64_C(999999))/INT64_C(1000000);
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* 1 tick = 100 nano seconds. */
- t2->counter = t1->counter + usecs * 10;
-#else
- LARGE_INTEGER temp;
- LONGLONG freq;
- freq = temp.QuadPart;
- t2->counter = t1->counter + (usecs * freq)/1000000L;
-#endif
-}
-
-
-int64_t
-util_time_diff(const struct util_time *t1,
- const struct util_time *t2)
-{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- return (t2->tv.tv_usec - t1->tv.tv_usec) +
- (t2->tv.tv_sec - t1->tv.tv_sec)*1000000;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- util_time_get_frequency();
- return (t2->counter - t1->counter)*INT64_C(1000000)/frequency;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- return (t2->counter - t1->counter)/10;
-#endif
-}
-
-
-
-uint64_t
-util_time_micros( void )
-{
- struct util_time t1;
-
- util_time_get(&t1);
-
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- return t1.tv.tv_usec + t1.tv.tv_sec*1000000LL;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- util_time_get_frequency();
- return t1.counter*INT64_C(1000000)/frequency;
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- return t1.counter/10;
-#endif
-}
-
-
-
-/**
- * Compare two time values.
- *
- * Not publicly available because it does not take in account wrap-arounds.
- * Use util_time_timeout instead.
- */
-static INLINE int
-util_time_compare(const struct util_time *t1,
- const struct util_time *t2)
-{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- if (t1->tv.tv_sec < t2->tv.tv_sec)
- return -1;
- else if(t1->tv.tv_sec > t2->tv.tv_sec)
- return 1;
- else if (t1->tv.tv_usec < t2->tv.tv_usec)
- return -1;
- else if(t1->tv.tv_usec > t2->tv.tv_usec)
- return 1;
- else
- return 0;
-#elif defined(PIPE_OS_WINDOWS)
- if (t1->counter < t2->counter)
- return -1;
- else if(t1->counter > t2->counter)
- return 1;
- else
- return 0;
-#endif
-}
-
-
-boolean
-util_time_timeout(const struct util_time *start,
- const struct util_time *end,
- const struct util_time *curr)
-{
- if(util_time_compare(start, end) <= 0)
- return !(util_time_compare(start, curr) <= 0 && util_time_compare(curr, end) < 0);
- else
- return !(util_time_compare(start, curr) <= 0 || util_time_compare(curr, end) < 0);
-}
-
-
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-void util_time_sleep(unsigned usecs)
-{
- LONGLONG start, curr, end;
-
- EngQueryPerformanceCounter(&start);
-
- if(!frequency)
- EngQueryPerformanceFrequency(&frequency);
-
- end = start + (usecs * frequency + 999999LL)/1000000LL;
-
- do {
- EngQueryPerformanceCounter(&curr);
- } while(start <= curr && curr < end ||
- end < start && (curr < end || start <= curr));
-}
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-void util_time_sleep(unsigned usecs)
-{
- Sleep((usecs + 999)/ 1000);
-}
-#endif
diff --git a/src/gallium/auxiliary/util/u_time.h b/src/gallium/auxiliary/util/u_time.h
index 29fd1cbc67..15899c2c88 100644
--- a/src/gallium/auxiliary/util/u_time.h
+++ b/src/gallium/auxiliary/util/u_time.h
@@ -38,15 +38,7 @@
#include "pipe/p_config.h"
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE)
-#include <time.h> /* timeval */
-#include <unistd.h> /* usleep */
-#endif
-
-#if defined(PIPE_OS_HAIKU)
-#include <sys/time.h> /* timeval */
-#include <unistd.h>
-#endif
+#include "os/os_time.h"
#include "pipe/p_compiler.h"
@@ -63,52 +55,92 @@ extern "C" {
*/
struct util_time
{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
- struct timeval tv;
-#else
int64_t counter;
-#endif
};
-void
-util_time_get(struct util_time *t);
+PIPE_DEPRECATED
+static INLINE void
+util_time_get(struct util_time *t)
+{
+ t->counter = os_time_get();
+}
+
/**
* Return t2 = t1 + usecs
*/
-void
+PIPE_DEPRECATED
+static INLINE void
util_time_add(const struct util_time *t1,
int64_t usecs,
- struct util_time *t2);
+ struct util_time *t2)
+{
+ t2->counter = t1->counter + usecs;
+}
-/**
- * Return current time in microseconds
- */
-uint64_t
-util_time_micros( void );
/**
* Return difference between times, in microseconds
*/
-int64_t
+PIPE_DEPRECATED
+static INLINE int64_t
util_time_diff(const struct util_time *t1,
- const struct util_time *t2);
+ const struct util_time *t2)
+{
+ return t2->counter - t1->counter;
+}
+
+
+/**
+ * Compare two time values.
+ *
+ * Not publicly available because it does not take in account wrap-arounds.
+ * Use util_time_timeout instead.
+ */
+static INLINE int
+_util_time_compare(const struct util_time *t1,
+ const struct util_time *t2)
+{
+ if (t1->counter < t2->counter)
+ return -1;
+ else if(t1->counter > t2->counter)
+ return 1;
+ else
+ return 0;
+}
+
/**
* Returns non-zero when the timeout expires.
*/
-boolean
+PIPE_DEPRECATED
+static INLINE boolean
util_time_timeout(const struct util_time *start,
const struct util_time *end,
- const struct util_time *curr);
+ const struct util_time *curr)
+{
+ return os_time_timeout(start->counter, end->counter, curr->counter);
+}
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU)
-#define util_time_sleep usleep
-#else
-void
-util_time_sleep(unsigned usecs);
-#endif
+
+/**
+ * Return current time in microseconds
+ */
+PIPE_DEPRECATED
+static INLINE int64_t
+util_time_micros(void)
+{
+ return os_time_get();
+}
+
+
+PIPE_DEPRECATED
+static INLINE void
+util_time_sleep(int64_t usecs)
+{
+ os_time_sleep(usecs);
+}
#ifdef __cplusplus
diff --git a/src/gallium/auxiliary/util/u_timed_winsys.c b/src/gallium/auxiliary/util/u_timed_winsys.c
index 178acdca4d..59bdcd2c45 100644
--- a/src/gallium/auxiliary/util/u_timed_winsys.c
+++ b/src/gallium/auxiliary/util/u_timed_winsys.c
@@ -30,7 +30,7 @@
*/
#include "pipe/p_state.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "u_timed_winsys.h"
#include "util/u_memory.h"
#include "util/u_time.h"
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index 55a65375c8..012b2ae233 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -30,7 +30,7 @@
*/
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "util/u_memory.h"
#include "util/u_math.h"
diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c
index a524e2fdfb..6c5298daab 100644
--- a/src/gallium/auxiliary/vl/vl_compositor.c
+++ b/src/gallium/auxiliary/vl/vl_compositor.c
@@ -28,7 +28,7 @@
#include "vl_compositor.h"
#include <assert.h>
#include <pipe/p_context.h>
-#include <pipe/p_inlines.h>
+#include <util/u_inlines.h>
#include <tgsi/tgsi_parse.h>
#include <tgsi/tgsi_build.h>
#include <util/u_memory.h>
diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
index e43187545c..c2552f40b4 100644
--- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
+++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
@@ -28,7 +28,7 @@
#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>
diff --git a/src/gallium/docs/source/conf.py b/src/gallium/docs/source/conf.py
index 9b0c86babd..59c19ed98d 100644
--- a/src/gallium/docs/source/conf.py
+++ b/src/gallium/docs/source/conf.py
@@ -16,13 +16,13 @@ import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+sys.path.append(os.path.abspath('exts'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.pngmath']
+extensions = ['sphinx.ext.pngmath', 'tgsi']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
diff --git a/src/gallium/docs/source/distro.rst b/src/gallium/docs/source/distro.rst
index 0ef9fe2645..100afe3397 100644
--- a/src/gallium/docs/source/distro.rst
+++ b/src/gallium/docs/source/distro.rst
@@ -31,21 +31,6 @@ Wrapper driver.
LLVM Softpipe
^^^^^^^^^^^^^
-nVidia nv04
-^^^^^^^^^^^
-
-Deprecated.
-
-nVidia nv10
-^^^^^^^^^^^
-
-Deprecated.
-
-nVidia nv20
-^^^^^^^^^^^
-
-Deprecated.
-
nVidia nv30
^^^^^^^^^^^
@@ -103,6 +88,22 @@ Xorg XFree86 DDX
Auxiliary
---------
+OS
+^^
+
+The OS module contains the abstractions for basic operating system services:
+
+* memory allocation
+* simple message logging
+* obtaining run-time configuration option
+* threading primitives
+
+This is the bare minimum required to port Gallium to a new platform.
+
+The OS module already provides the implementations of these abstractions for
+the most common platforms. When targeting an embedded platform no
+implementation will be provided -- these must be provided separately.
+
CSO Cache
^^^^^^^^^
diff --git a/src/gallium/docs/source/exts/tgsi.py b/src/gallium/docs/source/exts/tgsi.py
new file mode 100644
index 0000000000..e92cd5c4d1
--- /dev/null
+++ b/src/gallium/docs/source/exts/tgsi.py
@@ -0,0 +1,17 @@
+# tgsi.py
+# Sphinx extension providing formatting for TGSI opcodes
+# (c) Corbin Simpson 2010
+
+import docutils.nodes
+import sphinx.addnodes
+
+def parse_opcode(env, sig, signode):
+ opcode, desc = sig.split("-", 1)
+ opcode = opcode.strip().upper()
+ desc = " (%s)" % desc.strip()
+ signode += sphinx.addnodes.desc_name(opcode, opcode)
+ signode += sphinx.addnodes.desc_annotation(desc, desc)
+ return opcode
+
+def setup(app):
+ app.add_description_unit("opcode", "opcode", "%s (TGSI opcode)", parse_opcode)
diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
index 3e57a282fd..55a4c6990d 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -227,7 +227,7 @@ buffer_map
Map a buffer into memory.
-**usage** is a bitmask of :ref:`PIPE_TEXTURE_USAGE` flags.
+**usage** is a bitmask of :ref:`PIPE_BUFFER_USAGE` flags.
Returns a pointer to the map, or NULL if the mapping failed.
@@ -248,7 +248,7 @@ Flush a range of mapped memory into a buffer.
The buffer must have been mapped with ``PIPE_BUFFER_USAGE_FLUSH_EXPLICIT``.
-**usage** is a bitmask of :ref:`PIPE_TEXTURE_USAGE` flags.
+**usage** is a bitmask of :ref:`PIPE_BUFFER_USAGE` flags.
buffer_unmap
^^^^^^^^^^^^
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 3e702ceeda..5478d86667 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -6,6 +6,23 @@ for describing shaders. Since Gallium is inherently shaderful, shaders are
an important part of the API. TGSI is the only intermediate representation
used by all drivers.
+Basics
+------
+
+All TGSI instructions, known as *opcodes*, operate on arbitrary-precision
+floating-point four-component vectors. An opcode may have up to one
+destination register, known as *dst*, and between zero and three source
+registers, called *src0* through *src2*, or simply *src* if there is only
+one.
+
+Some instructions, like :opcode:`I2F`, permit re-interpretation of vector
+components as integers. Other instructions permit using registers as
+two-component vectors with double precision; see :ref:`Double Opcodes`.
+
+When an instruction has a scalar result, the result is usually copied into
+each of the components of *dst*. When this happens, the result is said to be
+*replicated* to *dst*. :opcode:`RCP` is one such instruction.
+
Instruction Set
---------------
@@ -13,7 +30,7 @@ From GL_NV_vertex_program
^^^^^^^^^^^^^^^^^^^^^^^^^
-ARL - Address Register Load
+.. opcode:: ARL - Address Register Load
.. math::
@@ -26,7 +43,7 @@ ARL - Address Register Load
dst.w = \lfloor src.w\rfloor
-MOV - Move
+.. opcode:: MOV - Move
.. math::
@@ -39,7 +56,7 @@ MOV - Move
dst.w = src.w
-LIT - Light Coefficients
+.. opcode:: LIT - Light Coefficients
.. math::
@@ -52,33 +69,25 @@ LIT - Light Coefficients
dst.w = 1
-RCP - Reciprocal
-
-.. math::
+.. opcode:: RCP - Reciprocal
- dst.x = \frac{1}{src.x}
+This instruction replicates its result.
- dst.y = \frac{1}{src.x}
+.. math::
- dst.z = \frac{1}{src.x}
+ dst = \frac{1}{src.x}
- dst.w = \frac{1}{src.x}
+.. opcode:: RSQ - Reciprocal Square Root
-RSQ - Reciprocal Square Root
+This instruction replicates its result.
.. math::
- dst.x = \frac{1}{\sqrt{|src.x|}}
-
- dst.y = \frac{1}{\sqrt{|src.x|}}
-
- dst.z = \frac{1}{\sqrt{|src.x|}}
+ dst = \frac{1}{\sqrt{|src.x|}}
- dst.w = \frac{1}{\sqrt{|src.x|}}
-
-EXP - Approximate Exponential Base 2
+.. opcode:: EXP - Approximate Exponential Base 2
.. math::
@@ -91,7 +100,7 @@ EXP - Approximate Exponential Base 2
dst.w = 1
-LOG - Approximate Logarithm Base 2
+.. opcode:: LOG - Approximate Logarithm Base 2
.. math::
@@ -104,7 +113,7 @@ LOG - Approximate Logarithm Base 2
dst.w = 1
-MUL - Multiply
+.. opcode:: MUL - Multiply
.. math::
@@ -117,7 +126,7 @@ MUL - Multiply
dst.w = src0.w \times src1.w
-ADD - Add
+.. opcode:: ADD - Add
.. math::
@@ -130,33 +139,25 @@ ADD - Add
dst.w = src0.w + src1.w
-DP3 - 3-component Dot Product
-
-.. math::
+.. opcode:: DP3 - 3-component Dot Product
- dst.x = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
+This instruction replicates its result.
- dst.y = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
+.. math::
- dst.z = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
+ dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
- dst.w = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
+.. opcode:: DP4 - 4-component Dot Product
-DP4 - 4-component Dot Product
+This instruction replicates its result.
.. math::
- dst.x = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
-
- dst.y = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
+ dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
- dst.z = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
- dst.w = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
-
-
-DST - Distance Vector
+.. opcode:: DST - Distance Vector
.. math::
@@ -169,7 +170,7 @@ DST - Distance Vector
dst.w = src1.w
-MIN - Minimum
+.. opcode:: MIN - Minimum
.. math::
@@ -182,7 +183,7 @@ MIN - Minimum
dst.w = min(src0.w, src1.w)
-MAX - Maximum
+.. opcode:: MAX - Maximum
.. math::
@@ -195,7 +196,7 @@ MAX - Maximum
dst.w = max(src0.w, src1.w)
-SLT - Set On Less Than
+.. opcode:: SLT - Set On Less Than
.. math::
@@ -208,7 +209,7 @@ SLT - Set On Less Than
dst.w = (src0.w < src1.w) ? 1 : 0
-SGE - Set On Greater Equal Than
+.. opcode:: SGE - Set On Greater Equal Than
.. math::
@@ -221,7 +222,7 @@ SGE - Set On Greater Equal Than
dst.w = (src0.w >= src1.w) ? 1 : 0
-MAD - Multiply And Add
+.. opcode:: MAD - Multiply And Add
.. math::
@@ -234,7 +235,7 @@ MAD - Multiply And Add
dst.w = src0.w \times src1.w + src2.w
-SUB - Subtract
+.. opcode:: SUB - Subtract
.. math::
@@ -247,7 +248,7 @@ SUB - Subtract
dst.w = src0.w - src1.w
-LRP - Linear Interpolate
+.. opcode:: LRP - Linear Interpolate
.. math::
@@ -260,7 +261,7 @@ LRP - Linear Interpolate
dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
-CND - Condition
+.. opcode:: CND - Condition
.. math::
@@ -273,7 +274,7 @@ CND - Condition
dst.w = (src2.w > 0.5) ? src0.w : src1.w
-DP2A - 2-component Dot Product And Add
+.. opcode:: DP2A - 2-component Dot Product And Add
.. math::
@@ -286,7 +287,7 @@ DP2A - 2-component Dot Product And Add
dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
-FRAC - Fraction
+.. opcode:: FRAC - Fraction
.. math::
@@ -299,7 +300,7 @@ FRAC - Fraction
dst.w = src.w - \lfloor src.w\rfloor
-CLAMP - Clamp
+.. opcode:: CLAMP - Clamp
.. math::
@@ -312,9 +313,9 @@ CLAMP - Clamp
dst.w = clamp(src0.w, src1.w, src2.w)
-FLR - Floor
+.. opcode:: FLR - Floor
-This is identical to ARL.
+This is identical to :opcode:`ARL`.
.. math::
@@ -327,7 +328,7 @@ This is identical to ARL.
dst.w = \lfloor src.w\rfloor
-ROUND - Round
+.. opcode:: ROUND - Round
.. math::
@@ -340,45 +341,33 @@ ROUND - Round
dst.w = round(src.w)
-EX2 - Exponential Base 2
+.. opcode:: EX2 - Exponential Base 2
-.. math::
+This instruction replicates its result.
- dst.x = 2^{src.x}
-
- dst.y = 2^{src.x}
+.. math::
- dst.z = 2^{src.x}
+ dst = 2^{src.x}
- dst.w = 2^{src.x}
+.. opcode:: LG2 - Logarithm Base 2
-LG2 - Logarithm Base 2
+This instruction replicates its result.
.. math::
- dst.x = \log_2{src.x}
-
- dst.y = \log_2{src.x}
-
- dst.z = \log_2{src.x}
+ dst = \log_2{src.x}
- dst.w = \log_2{src.x}
+.. opcode:: POW - Power
-POW - Power
+This instruction replicates its result.
.. math::
- dst.x = src0.x^{src1.x}
+ dst = src0.x^{src1.x}
- dst.y = src0.x^{src1.x}
-
- dst.z = src0.x^{src1.x}
-
- dst.w = src0.x^{src1.x}
-
-XPD - Cross Product
+.. opcode:: XPD - Cross Product
.. math::
@@ -391,7 +380,7 @@ XPD - Cross Product
dst.w = 1
-ABS - Absolute
+.. opcode:: ABS - Absolute
.. math::
@@ -404,48 +393,36 @@ ABS - Absolute
dst.w = |src.w|
-RCC - Reciprocal Clamped
+.. opcode:: RCC - Reciprocal Clamped
+
+This instruction replicates its result.
XXX cleanup on aisle three
.. math::
- dst.x = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
-
- dst.y = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
-
- dst.z = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
+ dst = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
- dst.w = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
+.. opcode:: DPH - Homogeneous Dot Product
-DPH - Homogeneous Dot Product
+This instruction replicates its result.
.. math::
- dst.x = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
+ dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
- dst.y = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
- dst.z = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
+.. opcode:: COS - Cosine
- dst.w = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
-
-
-COS - Cosine
+This instruction replicates its result.
.. math::
- dst.x = \cos{src.x}
-
- dst.y = \cos{src.x}
-
- dst.z = \cos{src.x}
+ dst = \cos{src.x}
- dst.w = \cos{src.x}
-
-DDX - Derivative Relative To X
+.. opcode:: DDX - Derivative Relative To X
.. math::
@@ -458,7 +435,7 @@ DDX - Derivative Relative To X
dst.w = partialx(src.w)
-DDY - Derivative Relative To Y
+.. opcode:: DDY - Derivative Relative To Y
.. math::
@@ -471,32 +448,32 @@ DDY - Derivative Relative To Y
dst.w = partialy(src.w)
-KILP - Predicated Discard
+.. opcode:: KILP - Predicated Discard
discard
-PK2H - Pack Two 16-bit Floats
+.. opcode:: PK2H - Pack Two 16-bit Floats
TBD
-PK2US - Pack Two Unsigned 16-bit Scalars
+.. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
TBD
-PK4B - Pack Four Signed 8-bit Scalars
+.. opcode:: PK4B - Pack Four Signed 8-bit Scalars
TBD
-PK4UB - Pack Four Unsigned 8-bit Scalars
+.. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
TBD
-RFL - Reflection Vector
+.. opcode:: RFL - Reflection Vector
.. math::
@@ -508,10 +485,12 @@ RFL - Reflection Vector
dst.w = 1
-Considered for removal.
+.. note::
+
+ Considered for removal.
-SEQ - Set On Equal
+.. opcode:: SEQ - Set On Equal
.. math::
@@ -524,21 +503,20 @@ SEQ - Set On Equal
dst.w = (src0.w == src1.w) ? 1 : 0
-SFL - Set On False
+.. opcode:: SFL - Set On False
-.. math::
+This instruction replicates its result.
- dst.x = 0
+.. math::
- dst.y = 0
+ dst = 0
- dst.z = 0
+.. note::
- dst.w = 0
+ Considered for removal.
-Considered for removal.
-SGT - Set On Greater Than
+.. opcode:: SGT - Set On Greater Than
.. math::
@@ -551,20 +529,16 @@ SGT - Set On Greater Than
dst.w = (src0.w > src1.w) ? 1 : 0
-SIN - Sine
+.. opcode:: SIN - Sine
-.. math::
+This instruction replicates its result.
- dst.x = \sin{src.x}
-
- dst.y = \sin{src.x}
-
- dst.z = \sin{src.x}
+.. math::
- dst.w = \sin{src.x}
+ dst = \sin{src.x}
-SLE - Set On Less Equal Than
+.. opcode:: SLE - Set On Less Equal Than
.. math::
@@ -577,7 +551,7 @@ SLE - Set On Less Equal Than
dst.w = (src0.w <= src1.w) ? 1 : 0
-SNE - Set On Not Equal
+.. opcode:: SNE - Set On Not Equal
.. math::
@@ -590,59 +564,63 @@ SNE - Set On Not Equal
dst.w = (src0.w != src1.w) ? 1 : 0
-STR - Set On True
+.. opcode:: STR - Set On True
-.. math::
+This instruction replicates its result.
- dst.x = 1
-
- dst.y = 1
-
- dst.z = 1
+.. math::
- dst.w = 1
+ dst = 1
-TEX - Texture Lookup
+.. opcode:: TEX - Texture Lookup
TBD
-TXD - Texture Lookup with Derivatives
+.. opcode:: TXD - Texture Lookup with Derivatives
TBD
-TXP - Projective Texture Lookup
+.. opcode:: TXP - Projective Texture Lookup
TBD
-UP2H - Unpack Two 16-Bit Floats
+.. opcode:: UP2H - Unpack Two 16-Bit Floats
TBD
- Considered for removal.
+.. note::
-UP2US - Unpack Two Unsigned 16-Bit Scalars
+ Considered for removal.
+
+.. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
TBD
- Considered for removal.
+.. note::
+
+ Considered for removal.
-UP4B - Unpack Four Signed 8-Bit Values
+.. opcode:: UP4B - Unpack Four Signed 8-Bit Values
TBD
- Considered for removal.
+.. note::
+
+ Considered for removal.
-UP4UB - Unpack Four Unsigned 8-Bit Scalars
+.. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
TBD
- Considered for removal.
+.. note::
-X2D - 2D Coordinate Transformation
+ Considered for removal.
+
+.. opcode:: X2D - 2D Coordinate Transformation
.. math::
@@ -654,20 +632,24 @@ X2D - 2D Coordinate Transformation
dst.w = src0.y + src1.x \times src2.z + src1.y \times src2.w
-Considered for removal.
+.. note::
+
+ Considered for removal.
From GL_NV_vertex_program2
^^^^^^^^^^^^^^^^^^^^^^^^^^
-ARA - Address Register Add
+.. opcode:: ARA - Address Register Add
TBD
- Considered for removal.
+.. note::
-ARR - Address Register Load With Round
+ Considered for removal.
+
+.. opcode:: ARR - Address Register Load With Round
.. math::
@@ -680,26 +662,28 @@ ARR - Address Register Load With Round
dst.w = round(src.w)
-BRA - Branch
+.. opcode:: BRA - Branch
pc = target
- Considered for removal.
+.. note::
+
+ Considered for removal.
-CAL - Subroutine Call
+.. opcode:: CAL - Subroutine Call
push(pc)
pc = target
-RET - Subroutine Call Return
+.. opcode:: RET - Subroutine Call Return
pc = pop()
Potential restrictions:
* Only occurs at end of function.
-SSG - Set Sign
+.. opcode:: SSG - Set Sign
.. math::
@@ -712,7 +696,7 @@ SSG - Set Sign
dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
-CMP - Compare
+.. opcode:: CMP - Compare
.. math::
@@ -725,7 +709,7 @@ CMP - Compare
dst.w = (src0.w < 0) ? src1.w : src2.w
-KIL - Conditional Discard
+.. opcode:: KIL - Conditional Discard
.. math::
@@ -734,7 +718,7 @@ KIL - Conditional Discard
endif
-SCS - Sine Cosine
+.. opcode:: SCS - Sine Cosine
.. math::
@@ -747,12 +731,12 @@ SCS - Sine Cosine
dst.y = 1
-TXB - Texture Lookup With Bias
+.. opcode:: TXB - Texture Lookup With Bias
TBD
-NRM - 3-component Vector Normalise
+.. opcode:: NRM - 3-component Vector Normalise
.. math::
@@ -765,7 +749,7 @@ NRM - 3-component Vector Normalise
dst.w = 1
-DIV - Divide
+.. opcode:: DIV - Divide
.. math::
@@ -778,35 +762,31 @@ DIV - Divide
dst.w = \frac{src0.w}{src1.w}
-DP2 - 2-component Dot Product
-
-.. math::
-
- dst.x = src0.x \times src1.x + src0.y \times src1.y
+.. opcode:: DP2 - 2-component Dot Product
- dst.y = src0.x \times src1.x + src0.y \times src1.y
+This instruction replicates its result.
- dst.z = src0.x \times src1.x + src0.y \times src1.y
+.. math::
- dst.w = src0.x \times src1.x + src0.y \times src1.y
+ dst = src0.x \times src1.x + src0.y \times src1.y
-TXL - Texture Lookup With LOD
+.. opcode:: TXL - Texture Lookup With LOD
TBD
-BRK - Break
+.. opcode:: BRK - Break
TBD
-IF - If
+.. opcode:: IF - If
TBD
-BGNFOR - Begin a For-Loop
+.. opcode:: BGNFOR - Begin a For-Loop
dst.x = floor(src.x)
dst.y = floor(src.y)
@@ -819,25 +799,31 @@ BGNFOR - Begin a For-Loop
Note: The destination must be a loop register.
The source must be a constant register.
- Considered for cleanup / removal.
+.. note::
+ Considered for cleanup.
-REP - Repeat
+.. note::
+
+ Considered for removal.
+
+
+.. opcode:: REP - Repeat
TBD
-ELSE - Else
+.. opcode:: ELSE - Else
TBD
-ENDIF - End If
+.. opcode:: ENDIF - End If
TBD
-ENDFOR - End a For-Loop
+.. opcode:: ENDFOR - End a For-Loop
dst.x = dst.x + dst.z
dst.y = dst.y - 1.0
@@ -848,30 +834,48 @@ ENDFOR - End a For-Loop
Note: The destination must be a loop register.
- Considered for cleanup / removal.
+.. note::
+
+ Considered for cleanup.
+
+.. note::
-ENDREP - End Repeat
+ Considered for removal.
+
+.. opcode:: ENDREP - End Repeat
TBD
-PUSHA - Push Address Register On Stack
+.. opcode:: PUSHA - Push Address Register On Stack
push(src.x)
push(src.y)
push(src.z)
push(src.w)
- Considered for cleanup / removal.
+.. note::
+
+ Considered for cleanup.
+
+.. note::
-POPA - Pop Address Register From Stack
+ Considered for removal.
+
+.. opcode:: POPA - Pop Address Register From Stack
dst.w = pop()
dst.z = pop()
dst.y = pop()
dst.x = pop()
- Considered for cleanup / removal.
+.. note::
+
+ Considered for cleanup.
+
+.. note::
+
+ Considered for removal.
From GL_NV_gpu_program4
@@ -879,7 +883,7 @@ From GL_NV_gpu_program4
Support for these opcodes indicated by a special pipe capability bit (TBD).
-CEIL - Ceiling
+.. opcode:: CEIL - Ceiling
.. math::
@@ -892,7 +896,7 @@ CEIL - Ceiling
dst.w = \lceil src.w\rceil
-I2F - Integer To Float
+.. opcode:: I2F - Integer To Float
.. math::
@@ -905,7 +909,7 @@ I2F - Integer To Float
dst.w = (float) src.w
-NOT - Bitwise Not
+.. opcode:: NOT - Bitwise Not
.. math::
@@ -918,7 +922,7 @@ NOT - Bitwise Not
dst.w = ~src.w
-TRUNC - Truncate
+.. opcode:: TRUNC - Truncate
.. math::
@@ -931,7 +935,7 @@ TRUNC - Truncate
dst.w = trunc(src.w)
-SHL - Shift Left
+.. opcode:: SHL - Shift Left
.. math::
@@ -944,7 +948,7 @@ SHL - Shift Left
dst.w = src0.w << src1.x
-SHR - Shift Right
+.. opcode:: SHR - Shift Right
.. math::
@@ -957,7 +961,7 @@ SHR - Shift Right
dst.w = src0.w >> src1.x
-AND - Bitwise And
+.. opcode:: AND - Bitwise And
.. math::
@@ -970,7 +974,7 @@ AND - Bitwise And
dst.w = src0.w & src1.w
-OR - Bitwise Or
+.. opcode:: OR - Bitwise Or
.. math::
@@ -983,7 +987,7 @@ OR - Bitwise Or
dst.w = src0.w | src1.w
-MOD - Modulus
+.. opcode:: MOD - Modulus
.. math::
@@ -996,7 +1000,7 @@ MOD - Modulus
dst.w = src0.w \bmod src1.w
-XOR - Bitwise Xor
+.. opcode:: XOR - Bitwise Xor
.. math::
@@ -1009,7 +1013,7 @@ XOR - Bitwise Xor
dst.w = src0.w \oplus src1.w
-SAD - Sum Of Absolute Differences
+.. opcode:: SAD - Sum Of Absolute Differences
.. math::
@@ -1022,17 +1026,17 @@ SAD - Sum Of Absolute Differences
dst.w = |src0.w - src1.w| + src2.w
-TXF - Texel Fetch
+.. opcode:: TXF - Texel Fetch
TBD
-TXQ - Texture Size Query
+.. opcode:: TXQ - Texture Size Query
TBD
-CONT - Continue
+.. opcode:: CONT - Continue
TBD
@@ -1041,12 +1045,12 @@ From GL_NV_geometry_program4
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-EMIT - Emit
+.. opcode:: EMIT - Emit
TBD
-ENDPRIM - End Primitive
+.. opcode:: ENDPRIM - End Primitive
TBD
@@ -1055,66 +1059,64 @@ From GLSL
^^^^^^^^^^
-BGNLOOP - Begin a Loop
+.. opcode:: BGNLOOP - Begin a Loop
TBD
-BGNSUB - Begin Subroutine
+.. opcode:: BGNSUB - Begin Subroutine
TBD
-ENDLOOP - End a Loop
+.. opcode:: ENDLOOP - End a Loop
TBD
-ENDSUB - End Subroutine
+.. opcode:: ENDSUB - End Subroutine
TBD
-NOP - No Operation
+.. opcode:: NOP - No Operation
Do nothing.
-NRM4 - 4-component Vector Normalise
-
-.. math::
+.. opcode:: NRM4 - 4-component Vector Normalise
- dst.x = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
+This instruction replicates its result.
- dst.y = \frac{src.y}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
-
- dst.z = \frac{src.z}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
+.. math::
- dst.w = \frac{src.w}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
+ dst = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
ps_2_x
^^^^^^^^^^^^
-CALLNZ - Subroutine Call If Not Zero
+.. opcode:: CALLNZ - Subroutine Call If Not Zero
TBD
-IFC - If
+.. opcode:: IFC - If
TBD
-BREAKC - Break Conditional
+.. opcode:: BREAKC - Break Conditional
TBD
+.. _doubleopcodes:
+
Double Opcodes
^^^^^^^^^^^^^^^
-DADD - Add Double
+.. opcode:: DADD - Add Double
.. math::
@@ -1123,7 +1125,7 @@ DADD - Add Double
dst.zw = src0.zw + src1.zw
-DDIV - Divide Double
+.. opcode:: DDIV - Divide Double
.. math::
@@ -1131,7 +1133,7 @@ DDIV - Divide Double
dst.zw = src0.zw / src1.zw
-DSEQ - Set Double on Equal
+.. opcode:: DSEQ - Set Double on Equal
.. math::
@@ -1139,7 +1141,7 @@ DSEQ - Set Double on Equal
dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
-DSLT - Set Double on Less than
+.. opcode:: DSLT - Set Double on Less than
.. math::
@@ -1147,7 +1149,7 @@ DSLT - Set Double on Less than
dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
-DFRAC - Double Fraction
+.. opcode:: DFRAC - Double Fraction
.. math::
@@ -1156,7 +1158,7 @@ DFRAC - Double Fraction
dst.zw = src.zw - \lfloor src.zw\rfloor
-DFRACEXP - Convert Double Number to Fractional and Integral Components
+.. opcode:: DFRACEXP - Convert Double Number to Fractional and Integral Components
.. math::
@@ -1164,7 +1166,7 @@ DFRACEXP - Convert Double Number to Fractional and Integral Components
dst0.zw = frexp(src.zw, dst1.zw)
-DLDEXP - Multiple Double Number by Integral Power of 2
+.. opcode:: DLDEXP - Multiple Double Number by Integral Power of 2
.. math::
@@ -1172,7 +1174,7 @@ DLDEXP - Multiple Double Number by Integral Power of 2
dst.zw = ldexp(src0.zw, src1.zw)
-DMIN - Minimum Double
+.. opcode:: DMIN - Minimum Double
.. math::
@@ -1180,7 +1182,7 @@ DMIN - Minimum Double
dst.zw = min(src0.zw, src1.zw)
-DMAX - Maximum Double
+.. opcode:: DMAX - Maximum Double
.. math::
@@ -1188,7 +1190,7 @@ DMAX - Maximum Double
dst.zw = max(src0.zw, src1.zw)
-DMUL - Multiply Double
+.. opcode:: DMUL - Multiply Double
.. math::
@@ -1197,7 +1199,7 @@ DMUL - Multiply Double
dst.zw = src0.zw \times src1.zw
-DMAD - Multiply And Add Doubles
+.. opcode:: DMAD - Multiply And Add Doubles
.. math::
@@ -1206,7 +1208,7 @@ DMAD - Multiply And Add Doubles
dst.zw = src0.zw \times src1.zw + src2.zw
-DRCP - Reciprocal Double
+.. opcode:: DRCP - Reciprocal Double
.. math::
@@ -1214,7 +1216,7 @@ DRCP - Reciprocal Double
dst.zw = \frac{1}{src.zw}
-DSQRT - Square root double
+.. opcode:: DSQRT - Square root double
.. math::
@@ -1269,20 +1271,8 @@ Keywords
discard Discard fragment.
- dst First destination register.
-
- dst0 First destination register.
-
pc Program counter.
- src First source register.
-
- src0 First source register.
-
- src1 Second source register.
-
- src2 Third source register.
-
target Label of target instruction.
@@ -1441,3 +1431,43 @@ GL_ARB_fragment_coord_conventions extension.
DirectX 9 uses INTEGER.
DirectX 10 uses HALF_INTEGER.
+
+
+
+Texture Sampling and Texture Formats
+------------------------------------
+
+This table shows how texture image components are returned as (x,y,z,w) tuples
+by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
+:opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
+well.
+
++--------------------+--------------+--------------------+--------------+
+| Texture Components | Gallium | OpenGL | Direct3D 9 |
++====================+==============+====================+==============+
+| R | XXX TBD | (r, 0, 0, 1) | (r, 1, 1, 1) |
++--------------------+--------------+--------------------+--------------+
+| RG | XXX TBD | (r, g, 0, 1) | (r, g, 1, 1) |
++--------------------+--------------+--------------------+--------------+
+| RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
++--------------------+--------------+--------------------+--------------+
+| RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
++--------------------+--------------+--------------------+--------------+
+| A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
++--------------------+--------------+--------------------+--------------+
+| L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
++--------------------+--------------+--------------------+--------------+
+| LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
++--------------------+--------------+--------------------+--------------+
+| I | (i, i, i, i) | (i, i, i, i) | N/A |
++--------------------+--------------+--------------------+--------------+
+| UV | XXX TBD | (0, 0, 0, 1) | (u, v, 1, 1) |
+| | | [#envmap-bumpmap]_ | |
++--------------------+--------------+--------------------+--------------+
+| Z | XXX TBD | (z, z, z, 1) | (0, z, 0, 1) |
+| | | [#depth-tex-mode]_ | |
++--------------------+--------------+--------------------+--------------+
+
+.. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
+.. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
+ or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.
diff --git a/src/gallium/drivers/cell/ppu/cell_clear.c b/src/gallium/drivers/cell/ppu/cell_clear.c
index 3a3f968a49..246fe21054 100644
--- a/src/gallium/drivers/cell/ppu/cell_clear.c
+++ b/src/gallium/drivers/cell/ppu/cell_clear.c
@@ -33,7 +33,7 @@
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_pack_color.h"
#include "cell/common.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_context.c b/src/gallium/drivers/cell/ppu/cell_context.c
index ebb7a7acc4..30aa04482e 100644
--- a/src/gallium/drivers/cell/ppu/cell_context.c
+++ b/src/gallium/drivers/cell/ppu/cell_context.c
@@ -36,7 +36,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_format.h"
#include "util/u_memory.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_screen.h"
#include "draw/draw_context.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_draw_arrays.c b/src/gallium/drivers/cell/ppu/cell_draw_arrays.c
index c674d0be63..bffd0fac6f 100644
--- a/src/gallium/drivers/cell/ppu/cell_draw_arrays.c
+++ b/src/gallium/drivers/cell/ppu/cell_draw_arrays.c
@@ -33,8 +33,8 @@
#include "pipe/p_defines.h"
#include "pipe/p_context.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "cell_context.h"
#include "cell_draw_arrays.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_fence.c b/src/gallium/drivers/cell/ppu/cell_fence.c
index 13125a9fa3..e10071529a 100644
--- a/src/gallium/drivers/cell/ppu/cell_fence.c
+++ b/src/gallium/drivers/cell/ppu/cell_fence.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include "util/u_memory.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "cell_context.h"
#include "cell_batch.h"
#include "cell_fence.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_pipe_state.c b/src/gallium/drivers/cell/ppu/cell_pipe_state.c
index c18a5d0635..3259c58687 100644
--- a/src/gallium/drivers/cell/ppu/cell_pipe_state.c
+++ b/src/gallium/drivers/cell/ppu/cell_pipe_state.c
@@ -31,7 +31,7 @@
*/
#include "util/u_memory.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "draw/draw_context.h"
#include "cell_context.h"
#include "cell_flush.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c
index 37b04396b3..c329c6682d 100644
--- a/src/gallium/drivers/cell/ppu/cell_screen.c
+++ b/src/gallium/drivers/cell/ppu/cell_screen.c
@@ -28,7 +28,7 @@
#include "util/u_memory.h"
#include "util/u_simple_screen.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_state_emit.c b/src/gallium/drivers/cell/ppu/cell_state_emit.c
index f1e1dcb9eb..282f05ba08 100644
--- a/src/gallium/drivers/cell/ppu/cell_state_emit.c
+++ b/src/gallium/drivers/cell/ppu/cell_state_emit.c
@@ -25,7 +25,7 @@
*
**************************************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "cell_context.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_state_shader.c b/src/gallium/drivers/cell/ppu/cell_state_shader.c
index 1b09cf7f7d..9b2f86fdfb 100644
--- a/src/gallium/drivers/cell/ppu/cell_state_shader.c
+++ b/src/gallium/drivers/cell/ppu/cell_state_shader.c
@@ -27,8 +27,8 @@
#include "pipe/p_defines.h"
#include "util/u_memory.h"
-#include "pipe/p_inlines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_inlines.h"
+#include "util/u_simple_screen.h"
#include "draw/draw_context.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c
index 998944f77a..fad290dfa0 100644
--- a/src/gallium/drivers/cell/ppu/cell_texture.c
+++ b/src/gallium/drivers/cell/ppu/cell_texture.c
@@ -33,8 +33,8 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_inlines.h"
+#include "util/u_simple_screen.h"
#include "util/u_format.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/cell/ppu/cell_vertex_shader.c b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c
index 403cf6d50f..cf8cd41159 100644
--- a/src/gallium/drivers/cell/ppu/cell_vertex_shader.c
+++ b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c
@@ -31,7 +31,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_context.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "util/u_math.h"
#include "cell_context.h"
diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c
index 46e4338d98..2ccc5d3e60 100644
--- a/src/gallium/drivers/failover/fo_context.c
+++ b/src/gallium/drivers/failover/fo_context.c
@@ -27,7 +27,7 @@
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "util/u_memory.h"
#include "pipe/p_context.h"
diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c
index d6ec4d1313..c189d1d82c 100644
--- a/src/gallium/drivers/failover/fo_state.c
+++ b/src/gallium/drivers/failover/fo_state.c
@@ -28,6 +28,8 @@
/* Authors: Keith Whitwell <keith@tungstengraphics.com>
*/
+#include "util/u_inlines.h"
+
#include "fo_context.h"
diff --git a/src/gallium/drivers/i915/i915_buffer.c b/src/gallium/drivers/i915/i915_buffer.c
index 669964770d..0f76a59e93 100644
--- a/src/gallium/drivers/i915/i915_buffer.c
+++ b/src/gallium/drivers/i915/i915_buffer.c
@@ -23,6 +23,7 @@
*
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "i915_screen.h"
#include "i915_buffer.h"
diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c
index a0c80d0228..f8219c9f29 100644
--- a/src/gallium/drivers/i915/i915_context.c
+++ b/src/gallium/drivers/i915/i915_context.c
@@ -32,7 +32,7 @@
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "pipe/p_screen.h"
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h
index 37cbd56036..6ec5566d5d 100644
--- a/src/gallium/drivers/i915/i915_context.h
+++ b/src/gallium/drivers/i915/i915_context.h
@@ -167,7 +167,7 @@ struct i915_depth_stencil_state {
};
struct i915_rasterizer_state {
- int light_twoside : 1;
+ unsigned light_twoside : 1;
unsigned st;
enum interp_mode color_interp;
diff --git a/src/gallium/drivers/i915/i915_debug.h b/src/gallium/drivers/i915/i915_debug.h
index dd9b86e17b..8f7484797d 100644
--- a/src/gallium/drivers/i915/i915_debug.h
+++ b/src/gallium/drivers/i915/i915_debug.h
@@ -72,7 +72,7 @@ void i915_print_ureg(const char *msg, unsigned ureg);
#if defined(DEBUG) && defined(FILE_DEBUG_FLAG)
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
static INLINE void
I915_DBG(
diff --git a/src/gallium/drivers/i915/i915_debug_fp.c b/src/gallium/drivers/i915/i915_debug_fp.c
index f9c40d8a11..066e7392d1 100644
--- a/src/gallium/drivers/i915/i915_debug_fp.c
+++ b/src/gallium/drivers/i915/i915_debug_fp.c
@@ -28,7 +28,8 @@
#include "i915_reg.h"
#include "i915_debug.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
+#include "util/u_debug.h"
static void
diff --git a/src/gallium/drivers/i915/i915_prim_vbuf.c b/src/gallium/drivers/i915/i915_prim_vbuf.c
index 6b832140a8..cad4109ee6 100644
--- a/src/gallium/drivers/i915/i915_prim_vbuf.c
+++ b/src/gallium/drivers/i915/i915_prim_vbuf.c
@@ -41,7 +41,7 @@
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
#include "util/u_debug.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_fifo.h"
diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
index 7b8d66b8aa..e6b560bc21 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -26,7 +26,7 @@
**************************************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_string.h"
diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c
index 23e4d6b993..beb26e996a 100644
--- a/src/gallium/drivers/i915/i915_state.c
+++ b/src/gallium/drivers/i915/i915_state.c
@@ -30,7 +30,7 @@
#include "draw/draw_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/i915/i915_state_inlines.h b/src/gallium/drivers/i915/i915_state_inlines.h
index 378de8f9c4..b589117fbf 100644
--- a/src/gallium/drivers/i915/i915_state_inlines.h
+++ b/src/gallium/drivers/i915/i915_state_inlines.h
@@ -30,6 +30,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_defines.h"
+#include "util/u_debug.h"
#include "i915_reg.h"
diff --git a/src/gallium/drivers/i915/i915_texture.c b/src/gallium/drivers/i915/i915_texture.c
index 612e5c1cdd..e101c8683e 100644
--- a/src/gallium/drivers/i915/i915_texture.c
+++ b/src/gallium/drivers/i915/i915_texture.c
@@ -33,7 +33,7 @@
#include "pipe/p_state.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.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"
diff --git a/src/gallium/drivers/i965/brw_context.c b/src/gallium/drivers/i965/brw_context.c
index d60b7b99b6..7cbda05ac5 100644
--- a/src/gallium/drivers/i965/brw_context.c
+++ b/src/gallium/drivers/i965/brw_context.c
@@ -31,6 +31,7 @@
#include "pipe/p_context.h"
+#include "util/u_inlines.h"
#include "util/u_simple_list.h"
#include "brw_context.h"
diff --git a/src/gallium/drivers/i965/brw_disasm.c b/src/gallium/drivers/i965/brw_disasm.c
index 65db27248b..9c2ccfff65 100644
--- a/src/gallium/drivers/i965/brw_disasm.c
+++ b/src/gallium/drivers/i965/brw_disasm.c
@@ -366,6 +366,7 @@ static int format (FILE *f, char *format, ...)
va_start (args, format);
vsnprintf (buf, sizeof (buf) - 1, format, args);
+ va_end (args);
string (f, buf);
return 0;
}
diff --git a/src/gallium/drivers/i965/brw_draw.c b/src/gallium/drivers/i965/brw_draw.c
index 1b5cd23995..9bad61ef72 100644
--- a/src/gallium/drivers/i965/brw_draw.c
+++ b/src/gallium/drivers/i965/brw_draw.c
@@ -26,6 +26,7 @@
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_prim.h"
#include "util/u_upload_mgr.h"
diff --git a/src/gallium/drivers/i965/brw_draw_upload.c b/src/gallium/drivers/i965/brw_draw_upload.c
index a27da5f1c1..d59261557b 100644
--- a/src/gallium/drivers/i965/brw_draw_upload.c
+++ b/src/gallium/drivers/i965/brw_draw_upload.c
@@ -26,6 +26,7 @@
**************************************************************************/
#include "pipe/p_context.h"
+#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/i965/brw_pipe_fb.c b/src/gallium/drivers/i965/brw_pipe_fb.c
index c1f049272a..a90b7c73f6 100644
--- a/src/gallium/drivers/i965/brw_pipe_fb.c
+++ b/src/gallium/drivers/i965/brw_pipe_fb.c
@@ -1,6 +1,7 @@
#include "util/u_math.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
+#include "util/u_inlines.h"
#include "brw_context.h"
diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c
index ef6c1bb315..6aab561004 100644
--- a/src/gallium/drivers/i965/brw_pipe_sampler.c
+++ b/src/gallium/drivers/i965/brw_pipe_sampler.c
@@ -4,6 +4,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
+#include "util/u_inlines.h"
#include "brw_context.h"
#include "brw_defines.h"
diff --git a/src/gallium/drivers/i965/brw_pipe_shader.c b/src/gallium/drivers/i965/brw_pipe_shader.c
index e389587f3e..c2b1839110 100644
--- a/src/gallium/drivers/i965/brw_pipe_shader.c
+++ b/src/gallium/drivers/i965/brw_pipe_shader.c
@@ -29,6 +29,7 @@
* Keith Whitwell <keith@tungstengraphics.com>
*/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/i965/brw_screen.c b/src/gallium/drivers/i965/brw_screen.c
index a8f9892d71..1d79d84dc6 100644
--- a/src/gallium/drivers/i965/brw_screen.c
+++ b/src/gallium/drivers/i965/brw_screen.c
@@ -26,7 +26,7 @@
**************************************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_string.h"
diff --git a/src/gallium/drivers/i965/brw_screen_buffers.c b/src/gallium/drivers/i965/brw_screen_buffers.c
index d8141a3f5b..0b38885f40 100644
--- a/src/gallium/drivers/i965/brw_screen_buffers.c
+++ b/src/gallium/drivers/i965/brw_screen_buffers.c
@@ -4,7 +4,7 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "brw_screen.h"
#include "brw_winsys.h"
diff --git a/src/gallium/drivers/i965/brw_winsys.h b/src/gallium/drivers/i965/brw_winsys.h
index a242e31218..8841de2611 100644
--- a/src/gallium/drivers/i965/brw_winsys.h
+++ b/src/gallium/drivers/i965/brw_winsys.h
@@ -28,7 +28,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_defines.h"
-#include "pipe/p_refcnt.h"
+#include "util/u_inlines.h"
struct brw_winsys;
struct pipe_fence_handle;
diff --git a/src/gallium/drivers/identity/id_objects.c b/src/gallium/drivers/identity/id_objects.c
index bc9bc7121d..2b1a60c1bf 100644
--- a/src/gallium/drivers/identity/id_objects.c
+++ b/src/gallium/drivers/identity/id_objects.c
@@ -25,9 +25,9 @@
*
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
-#include "id_public.h"
#include "id_screen.h"
#include "id_objects.h"
diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript
index d7a396292c..840cb0950e 100644
--- a/src/gallium/drivers/llvmpipe/SConscript
+++ b/src/gallium/drivers/llvmpipe/SConscript
@@ -80,21 +80,22 @@ llvmpipe = env.ConvenienceLibrary(
])
-env = env.Clone()
+if env['platform'] != 'embedded':
+ env = env.Clone()
-env.Prepend(LIBS = [llvmpipe] + gallium)
+ env.Prepend(LIBS = [llvmpipe] + gallium)
-tests = [
- 'format',
- 'blend',
- 'conv',
-]
+ tests = [
+ 'format',
+ 'blend',
+ 'conv',
+ ]
-for test in tests:
- target = env.Program(
- target = 'lp_test_' + test,
- source = ['lp_test_' + test + '.c', 'lp_test_main.c'],
- )
- env.InstallProgram(target)
+ for test in tests:
+ target = env.Program(
+ target = 'lp_test_' + test,
+ source = ['lp_test_' + test + '.c', 'lp_test_main.c'],
+ )
+ env.InstallProgram(target)
-Export('llvmpipe')
+ Export('llvmpipe')
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c
index ad1dbbc9b1..0215bb72ac 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c
@@ -44,6 +44,7 @@
#include "pipe/p_state.h"
+#include "util/u_debug.h"
#include "lp_bld_type.h"
#include "lp_bld_const.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c
index 88321f62a2..1eac0a5c89 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c
@@ -35,6 +35,7 @@
#include "pipe/p_state.h"
+#include "util/u_debug.h"
#include "lp_bld_blend.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c
index a73d1158e7..6d5a45db7a 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c
@@ -69,6 +69,7 @@
#include "pipe/p_state.h"
+#include "util/u_debug.h"
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_logic.c b/src/gallium/drivers/llvmpipe/lp_bld_logic.c
index d094a040d6..d23de4f0ef 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_logic.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_logic.c
@@ -34,6 +34,7 @@
#include "util/u_cpu_detect.h"
+#include "util/u_debug.h"
#include "lp_bld_type.h"
#include "lp_bld_const.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_buffer.c b/src/gallium/drivers/llvmpipe/lp_buffer.c
index a5ef221a21..9eda972081 100644
--- a/src/gallium/drivers/llvmpipe/lp_buffer.c
+++ b/src/gallium/drivers/llvmpipe/lp_buffer.c
@@ -26,12 +26,12 @@
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "lp_winsys.h"
#include "lp_screen.h"
-#include "lp_texture.h"
#include "lp_buffer.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c
index 51de6f93ca..a76bde3905 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -33,6 +33,7 @@
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "lp_clear.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_fence.c b/src/gallium/drivers/llvmpipe/lp_fence.c
index 97c46087da..525c117f31 100644
--- a/src/gallium/drivers/llvmpipe/lp_fence.c
+++ b/src/gallium/drivers/llvmpipe/lp_fence.c
@@ -28,6 +28,7 @@
#include "pipe/p_screen.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "lp_fence.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_fence.h b/src/gallium/drivers/llvmpipe/lp_fence.h
index d45318f9e4..c90e6de423 100644
--- a/src/gallium/drivers/llvmpipe/lp_fence.h
+++ b/src/gallium/drivers/llvmpipe/lp_fence.h
@@ -30,8 +30,8 @@
#define LP_FENCE_H
-#include "pipe/p_refcnt.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
+#include "pipe/p_state.h"
struct pipe_screen;
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index e27b6528ea..54af850467 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -808,12 +808,12 @@ lp_rasterize_scene( struct lp_rasterizer *rast,
if (debug) {
unsigned x, y;
- printf("rasterize scene:\n");
- printf(" data size: %u\n", lp_scene_data_size(scene));
+ debug_printf("rasterize scene:\n");
+ debug_printf(" data size: %u\n", lp_scene_data_size(scene));
for (y = 0; y < scene->tiles_y; y++) {
for (x = 0; x < scene->tiles_x; x++) {
- printf(" bin %u, %u size: %u\n", x, y,
- lp_scene_bin_size(scene, x, y));
+ debug_printf(" bin %u, %u size: %u\n", x, y,
+ lp_scene_bin_size(scene, x, y));
}
}
}
@@ -864,8 +864,7 @@ lp_rasterize_scene( struct lp_rasterizer *rast,
* 2. do work
* 3. signal that we're done
*/
-static void *
-thread_func( void *init_data )
+static PIPE_THREAD_ROUTINE( thread_func, init_data )
{
struct lp_rasterizer_task *task = (struct lp_rasterizer_task *) init_data;
struct lp_rasterizer *rast = task->rast;
diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
index 607968e345..71e3a301e6 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
@@ -28,7 +28,7 @@
#ifndef LP_RAST_PRIV_H
#define LP_RAST_PRIV_H
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "lp_rast.h"
#include "lp_tile_soa.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c
index 191122de7d..0421c506d8 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.c
+++ b/src/gallium/drivers/llvmpipe/lp_scene.c
@@ -27,6 +27,7 @@
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "util/u_simple_list.h"
#include "lp_scene.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h b/src/gallium/drivers/llvmpipe/lp_scene.h
index 86facf8eac..7db2165cf1 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.h
+++ b/src/gallium/drivers/llvmpipe/lp_scene.h
@@ -35,7 +35,7 @@
#ifndef LP_SCENE_H
#define LP_SCENE_H
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "lp_tile_soa.h"
#include "lp_rast.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index f8fc912fa1..2e3ef4ae5c 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -33,7 +33,7 @@
*/
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_pack_color.h"
#include "util/u_surface.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 0602e940d9..c5f6df23a1 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -62,6 +62,7 @@
#include <limits.h>
#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_format.h"
#include "util/u_debug_dump.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
index 976f81113f..43649febf2 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
@@ -29,6 +29,7 @@
* Brian Paul
*/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "draw/draw_context.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_state_surface.c b/src/gallium/drivers/llvmpipe/lp_state_surface.c
index aa4241a80d..048ac5b968 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_surface.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_surface.c
@@ -29,6 +29,7 @@
*/
#include "pipe/p_state.h"
+#include "util/u_inlines.h"
#include "util/u_surface.h"
#include "lp_context.h"
#include "lp_state.h"
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index c9b6eb180f..605200396b 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -32,7 +32,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/nouveau/Makefile b/src/gallium/drivers/nouveau/Makefile
index 0cb66041d5..0e02680bc6 100644
--- a/src/gallium/drivers/nouveau/Makefile
+++ b/src/gallium/drivers/nouveau/Makefile
@@ -4,6 +4,7 @@ include $(TOP)/configs/current
LIBNAME = nouveau
C_SOURCES = nouveau_screen.c \
- nouveau_context.c
+ nouveau_context.c \
+ nv04_surface_2d.c
include ../../Makefile.template
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
index 1ad539d285..156cb2d229 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.c
+++ b/src/gallium/drivers/nouveau/nouveau_screen.c
@@ -3,7 +3,9 @@
#include <pipe/p_state.h>
#include <util/u_memory.h>
+#include <util/u_inlines.h>
+#include <stdio.h>
#include <errno.h>
#include "nouveau/nouveau_bo.h"
diff --git a/src/gallium/drivers/nouveau/nouveau_winsys.h b/src/gallium/drivers/nouveau/nouveau_winsys.h
index 4c3e08a43f..4c5d2f8b1c 100644
--- a/src/gallium/drivers/nouveau/nouveau_winsys.h
+++ b/src/gallium/drivers/nouveau/nouveau_winsys.h
@@ -2,7 +2,7 @@
#define NOUVEAU_WINSYS_H
#include <stdint.h>
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_defines.h"
#include "nouveau/nouveau_bo.h"
@@ -27,24 +27,6 @@
#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19)
extern struct pipe_screen *
-nv04_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
-
-extern struct pipe_context *
-nv04_create(struct pipe_screen *, unsigned pctx_id);
-
-extern struct pipe_screen *
-nv10_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
-
-extern struct pipe_context *
-nv10_create(struct pipe_screen *, unsigned pctx_id);
-
-extern struct pipe_screen *
-nv20_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
-
-extern struct pipe_context *
-nv20_create(struct pipe_screen *, unsigned pctx_id);
-
-extern struct pipe_screen *
nv30_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_context *
diff --git a/src/gallium/drivers/nv04/nv04_surface_2d.c b/src/gallium/drivers/nouveau/nv04_surface_2d.c
index b24a9cee5a..42c2ca932d 100644
--- a/src/gallium/drivers/nv04/nv04_surface_2d.c
+++ b/src/gallium/drivers/nouveau/nv04_surface_2d.c
@@ -60,17 +60,17 @@ nv04_scaled_image_format(enum pipe_format format)
case PIPE_FORMAT_A8_UNORM:
case PIPE_FORMAT_L8_UNORM:
case PIPE_FORMAT_I8_UNORM:
- return NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_Y8;
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_Y8;
case PIPE_FORMAT_A1R5G5B5_UNORM:
- return NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A1R5G5B5;
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A1R5G5B5;
case PIPE_FORMAT_A8R8G8B8_UNORM:
- return NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8;
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8;
case PIPE_FORMAT_X8R8G8B8_UNORM:
- return NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8;
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8;
case PIPE_FORMAT_R5G6B5_UNORM:
case PIPE_FORMAT_R16_SNORM:
case PIPE_FORMAT_A8L8_UNORM:
- return NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5;
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5;
default:
return -1;
}
@@ -155,7 +155,7 @@ nv04_surface_copy_swizzle(struct nv04_surface_2d *ctx,
log2i(dst->width) << NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_U_SHIFT |
log2i(dst->height) << NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_V_SHIFT);
- BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 1);
+ BEGIN_RING(chan, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 1);
OUT_RELOCo(chan, src_bo,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE, 1);
@@ -173,22 +173,22 @@ nv04_surface_copy_swizzle(struct nv04_surface_2d *ctx,
OUT_RELOCl(chan, dst_bo, dst->offset,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 9);
- OUT_RING (chan, NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE);
+ BEGIN_RING(chan, sifm, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 9);
+ OUT_RING (chan, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE);
OUT_RING (chan, nv04_scaled_image_format(src->format));
- OUT_RING (chan, NV04_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
- OUT_RING (chan, (x + dx) | ((y + dy) << NV04_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_Y_SHIFT));
- OUT_RING (chan, sub_h << NV04_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_H_SHIFT | sub_w);
- OUT_RING (chan, (x + dx) | ((y + dy) << NV04_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_Y_SHIFT));
- OUT_RING (chan, sub_h << NV04_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_H_SHIFT | sub_w);
+ OUT_RING (chan, NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
+ OUT_RING (chan, (x + dx) | ((y + dy) << NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_Y_SHIFT));
+ OUT_RING (chan, sub_h << NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_H_SHIFT | sub_w);
+ OUT_RING (chan, (x + dx) | ((y + dy) << NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_Y_SHIFT));
+ OUT_RING (chan, sub_h << NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_H_SHIFT | sub_w);
OUT_RING (chan, 1 << 20);
OUT_RING (chan, 1 << 20);
- BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SIZE, 4);
- OUT_RING (chan, sub_h << NV04_SCALED_IMAGE_FROM_MEMORY_SIZE_H_SHIFT | sub_w);
+ BEGIN_RING(chan, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_SIZE, 4);
+ OUT_RING (chan, sub_h << NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_H_SHIFT | sub_w);
OUT_RING (chan, src_pitch |
- NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
- NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE);
+ NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
+ NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE);
OUT_RELOCl(chan, src_bo, src->offset + (sy+y) * src_pitch + (sx+x) * util_format_get_blocksize(src->texture->format),
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
OUT_RING (chan, 0);
@@ -421,12 +421,12 @@ nv04_surface_2d_init(struct nouveau_screen *screen)
return NULL;
}
- BEGIN_RING(chan, ctx->blit, NV04_IMAGE_BLIT_DMA_NOTIFY, 1);
+ BEGIN_RING(chan, ctx->blit, NV01_IMAGE_BLIT_DMA_NOTIFY, 1);
OUT_RING (chan, ctx->ntfy->handle);
BEGIN_RING(chan, ctx->blit, NV04_IMAGE_BLIT_SURFACE, 1);
OUT_RING (chan, ctx->surf2d->handle);
- BEGIN_RING(chan, ctx->blit, NV04_IMAGE_BLIT_OPERATION, 1);
- OUT_RING (chan, NV04_IMAGE_BLIT_OPERATION_SRCCOPY);
+ BEGIN_RING(chan, ctx->blit, NV01_IMAGE_BLIT_OPERATION, 1);
+ OUT_RING (chan, NV01_IMAGE_BLIT_OPERATION_SRCCOPY);
ret = nouveau_grobj_alloc(chan, handle++, NV04_GDI_RECTANGLE_TEXT,
&ctx->rect);
diff --git a/src/gallium/drivers/nv04/nv04_surface_2d.h b/src/gallium/drivers/nouveau/nv04_surface_2d.h
index ce696a11a3..ce696a11a3 100644
--- a/src/gallium/drivers/nv04/nv04_surface_2d.h
+++ b/src/gallium/drivers/nouveau/nv04_surface_2d.h
diff --git a/src/gallium/drivers/nv04/Makefile b/src/gallium/drivers/nv04/Makefile
deleted file mode 100644
index 7c14bacb1d..0000000000
--- a/src/gallium/drivers/nv04/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-TOP = ../../../..
-include $(TOP)/configs/current
-
-LIBNAME = nv04
-
-C_SOURCES = \
- nv04_surface_2d.c \
- nv04_clear.c \
- nv04_context.c \
- nv04_fragprog.c \
- nv04_fragtex.c \
- nv04_miptree.c \
- nv04_prim_vbuf.c \
- nv04_screen.c \
- nv04_state.c \
- nv04_state_emit.c \
- nv04_surface.c \
- nv04_transfer.c \
- nv04_vbo.c
-
-include ../../Makefile.template
diff --git a/src/gallium/drivers/nv04/nv04_clear.c b/src/gallium/drivers/nv04/nv04_clear.c
deleted file mode 100644
index 01cacd36fe..0000000000
--- a/src/gallium/drivers/nv04/nv04_clear.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-
-#include "nv04_context.h"
-
-void
-nv04_clear(struct pipe_context *pipe, struct pipe_surface *ps,
- unsigned clearValue)
-{
- pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
-}
diff --git a/src/gallium/drivers/nv04/nv04_context.c b/src/gallium/drivers/nv04/nv04_context.c
deleted file mode 100644
index edd96859cf..0000000000
--- a/src/gallium/drivers/nv04/nv04_context.c
+++ /dev/null
@@ -1,112 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-
-#include "nv04_context.h"
-#include "nv04_screen.h"
-
-static void
-nv04_flush(struct pipe_context *pipe, unsigned flags,
- struct pipe_fence_handle **fence)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
-
- draw_flush(nv04->draw);
-
- FIRE_RING(chan);
- if (fence)
- *fence = NULL;
-}
-
-static void
-nv04_destroy(struct pipe_context *pipe)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- if (nv04->draw)
- draw_destroy(nv04->draw);
-
- FREE(nv04);
-}
-
-static boolean
-nv04_init_hwctx(struct nv04_context *nv04)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
-
- // requires a valid handle
-// BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_NOTIFY, 1);
-// OUT_RING(0);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_NOP, 1);
- OUT_RING(chan, 0);
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_CONTROL, 1);
- OUT_RING(chan, 0x40182800);
-// OUT_RING(1<<20/*no cull*/);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_BLEND, 1);
-// OUT_RING(0x24|(1<<6)|(1<<8));
- OUT_RING(chan, 0x120001a4);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FORMAT, 1);
- OUT_RING(chan, 0x332213a1);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FILTER, 1);
- OUT_RING(chan, 0x11001010);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_COLORKEY, 1);
- OUT_RING(chan, 0x0);
-// BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_OFFSET, 1);
-// OUT_RING(SCREEN_OFFSET);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FOGCOLOR, 1);
- OUT_RING(chan, 0xff000000);
-
-
-
- FIRE_RING (chan);
- return TRUE;
-}
-
-struct pipe_context *
-nv04_create(struct pipe_screen *pscreen, unsigned pctx_id)
-{
- struct nv04_screen *screen = nv04_screen(pscreen);
- struct pipe_winsys *ws = pscreen->winsys;
- struct nv04_context *nv04;
- struct nouveau_winsys *nvws = screen->nvws;
-
- nv04 = CALLOC(1, sizeof(struct nv04_context));
- if (!nv04)
- return NULL;
- nv04->screen = screen;
- nv04->pctx_id = pctx_id;
-
- nv04->nvws = nvws;
-
- nv04->pipe.winsys = ws;
- nv04->pipe.screen = pscreen;
- nv04->pipe.destroy = nv04_destroy;
- nv04->pipe.draw_arrays = nv04_draw_arrays;
- nv04->pipe.draw_elements = nv04_draw_elements;
- nv04->pipe.clear = nv04_clear;
- nv04->pipe.flush = nv04_flush;
-
- nv04->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nv04->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
- nv04_init_surface_functions(nv04);
- nv04_init_state_functions(nv04);
-
- nv04->draw = draw_create();
- assert(nv04->draw);
- draw_wide_point_threshold(nv04->draw, 0.0);
- draw_wide_line_threshold(nv04->draw, 0.0);
- draw_enable_line_stipple(nv04->draw, FALSE);
- draw_enable_point_sprites(nv04->draw, FALSE);
- draw_set_rasterize_stage(nv04->draw, nv04_draw_vbuf_stage(nv04));
-
- nv04_init_hwctx(nv04);
-
- return &nv04->pipe;
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_context.h b/src/gallium/drivers/nv04/nv04_context.h
deleted file mode 100644
index fe3b527423..0000000000
--- a/src/gallium/drivers/nv04/nv04_context.h
+++ /dev/null
@@ -1,148 +0,0 @@
-#ifndef __NV04_CONTEXT_H__
-#define __NV04_CONTEXT_H__
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "pipe/p_compiler.h"
-
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "draw/draw_vertex.h"
-
-#include "nouveau/nouveau_winsys.h"
-#include "nouveau/nouveau_gldefs.h"
-#include "nouveau/nouveau_context.h"
-
-#include "nv04_state.h"
-
-#define NOUVEAU_ERR(fmt, args...) \
- fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
-#define NOUVEAU_MSG(fmt, args...) \
- fprintf(stderr, "nouveau: "fmt, ##args);
-
-#include "nv04_screen.h"
-
-#define NV04_NEW_VERTPROG (1 << 1)
-#define NV04_NEW_FRAGPROG (1 << 2)
-#define NV04_NEW_BLEND (1 << 3)
-#define NV04_NEW_RAST (1 << 4)
-#define NV04_NEW_CONTROL (1 << 5)
-#define NV04_NEW_VIEWPORT (1 << 6)
-#define NV04_NEW_SAMPLER (1 << 7)
-#define NV04_NEW_FRAMEBUFFER (1 << 8)
-#define NV04_NEW_VTXARRAYS (1 << 9)
-
-struct nv04_context {
- struct pipe_context pipe;
-
- struct nouveau_winsys *nvws;
- struct nv04_screen *screen;
- unsigned pctx_id;
-
- struct draw_context *draw;
-
- int chipset;
- struct nouveau_notifier *sync;
-
- uint32_t dirty;
-
- struct nv04_blend_state *blend;
- struct nv04_sampler_state *sampler[PIPE_MAX_SAMPLERS];
- struct nv04_fragtex_state fragtex;
- struct nv04_rasterizer_state *rast;
- struct nv04_depth_stencil_alpha_state *dsa;
-
- struct nv04_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
- unsigned dirty_samplers;
- unsigned fp_samplers;
- unsigned vp_samplers;
-
- uint32_t rt_enable;
- struct pipe_framebuffer_state *framebuffer;
- struct pipe_surface *rt;
- struct pipe_surface *zeta;
-
- struct {
- struct pipe_buffer *buffer;
- uint32_t format;
- } tex[16];
-
- unsigned vb_enable;
- struct {
- struct pipe_buffer *buffer;
- unsigned delta;
- } vb[16];
-
- float *constbuf[PIPE_SHADER_TYPES][32][4];
- unsigned constbuf_nr[PIPE_SHADER_TYPES];
-
- struct vertex_info vertex_info;
- struct {
-
- struct nouveau_resource *exec_heap;
- struct nouveau_resource *data_heap;
-
- struct nv04_vertex_program *active;
-
- struct nv04_vertex_program *current;
- struct pipe_buffer *constant_buf;
- } vertprog;
-
- struct {
- struct nv04_fragment_program *active;
-
- struct nv04_fragment_program *current;
- struct pipe_buffer *constant_buf;
- } fragprog;
-
- struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
- struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
-
- struct pipe_viewport_state viewport;
-};
-
-static INLINE struct nv04_context *
-nv04_context(struct pipe_context *pipe)
-{
- return (struct nv04_context *)pipe;
-}
-
-extern void nv04_init_state_functions(struct nv04_context *nv04);
-extern void nv04_init_surface_functions(struct nv04_context *nv04);
-extern void nv04_screen_init_miptree_functions(struct pipe_screen *screen);
-
-/* nv04_clear.c */
-extern void nv04_clear(struct pipe_context *pipe, struct pipe_surface *ps,
- unsigned clearValue);
-
-/* nv04_draw.c */
-extern struct draw_stage *nv04_draw_render_stage(struct nv04_context *nv04);
-
-/* nv04_fragprog.c */
-extern void nv04_fragprog_bind(struct nv04_context *,
- struct nv04_fragment_program *);
-extern void nv04_fragprog_destroy(struct nv04_context *,
- struct nv04_fragment_program *);
-
-/* nv04_fragtex.c */
-extern void nv04_fragtex_bind(struct nv04_context *);
-
-/* nv04_prim_vbuf.c */
-struct draw_stage *nv04_draw_vbuf_stage( struct nv04_context *nv04 );
-
-/* nv04_state.c and friends */
-extern void nv04_emit_hw_state(struct nv04_context *nv04);
-extern void nv04_state_tex_update(struct nv04_context *nv04);
-
-/* nv04_vbo.c */
-extern void nv04_draw_arrays(struct pipe_context *, unsigned mode,
- unsigned start, unsigned count);
-extern void nv04_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count);
-
-
-#endif
diff --git a/src/gallium/drivers/nv04/nv04_fragprog.c b/src/gallium/drivers/nv04/nv04_fragprog.c
deleted file mode 100644
index 8a2af41fe0..0000000000
--- a/src/gallium/drivers/nv04/nv04_fragprog.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-
-#include "pipe/p_shader_tokens.h"
-#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_util.h"
-
-#include "nv04_context.h"
-
-void
-nv04_fragprog_bind(struct nv04_context *nv04, struct nv04_fragment_program *fp)
-{
-}
-
-void
-nv04_fragprog_destroy(struct nv04_context *nv04,
- struct nv04_fragment_program *fp)
-{
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_fragtex.c b/src/gallium/drivers/nv04/nv04_fragtex.c
deleted file mode 100644
index c152b52119..0000000000
--- a/src/gallium/drivers/nv04/nv04_fragtex.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "nv04_context.h"
-#include "nouveau/nouveau_util.h"
-
-#define _(m,tf) \
-{ \
- PIPE_FORMAT_##m, \
- NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_##tf, \
-}
-
-struct nv04_texture_format {
- uint pipe;
- int format;
-};
-
-static struct nv04_texture_format
-nv04_texture_formats[] = {
- _(A8R8G8B8_UNORM, A8R8G8B8),
- _(X8R8G8B8_UNORM, X8R8G8B8),
- _(A1R5G5B5_UNORM, A1R5G5B5),
- _(A4R4G4B4_UNORM, A4R4G4B4),
- _(L8_UNORM, Y8 ),
- _(A8_UNORM, Y8 ),
-};
-
-static uint32_t
-nv04_fragtex_format(uint pipe_format)
-{
- struct nv04_texture_format *tf = nv04_texture_formats;
- int i;
-
- for (i=0; i< sizeof(nv04_texture_formats)/sizeof(nv04_texture_formats[0]); i++) {
- if (tf->pipe == pipe_format)
- return tf->format;
- tf++;
- }
-
- NOUVEAU_ERR("unknown texture format %s\n", pf_name(pipe_format));
- return 0;
-}
-
-
-static void
-nv04_fragtex_build(struct nv04_context *nv04, int unit)
-{
- struct nv04_miptree *nv04mt = nv04->tex_miptree[unit];
- struct pipe_texture *pt = &nv04mt->base;
-
- switch (pt->target) {
- case PIPE_TEXTURE_2D:
- break;
- default:
- NOUVEAU_ERR("Unknown target %d\n", pt->target);
- return;
- }
-
- nv04->fragtex.format = NV04_TEXTURED_TRIANGLE_FORMAT_ORIGIN_ZOH_CORNER
- | NV04_TEXTURED_TRIANGLE_FORMAT_ORIGIN_FOH_CORNER
- | nv04_fragtex_format(pt->format)
- | ( (pt->last_level + 1) << NV04_TEXTURED_TRIANGLE_FORMAT_MIPMAP_LEVELS_SHIFT )
- | ( log2i(pt->width0) << NV04_TEXTURED_TRIANGLE_FORMAT_BASE_SIZE_U_SHIFT )
- | ( log2i(pt->height0) << NV04_TEXTURED_TRIANGLE_FORMAT_BASE_SIZE_V_SHIFT )
- | NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP_TO_EDGE
- | NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_CLAMP_TO_EDGE
- ;
-}
-
-
-void
-nv04_fragtex_bind(struct nv04_context *nv04)
-{
- nv04_fragtex_build(nv04, 0);
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_miptree.c b/src/gallium/drivers/nv04/nv04_miptree.c
deleted file mode 100644
index e0a6948aeb..0000000000
--- a/src/gallium/drivers/nv04/nv04_miptree.c
+++ /dev/null
@@ -1,146 +0,0 @@
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "util/u_math.h"
-
-#include "nv04_context.h"
-#include "nv04_screen.h"
-
-static void
-nv04_miptree_layout(struct nv04_miptree *nv04mt)
-{
- struct pipe_texture *pt = &nv04mt->base;
- uint offset = 0;
- int nr_faces, l;
-
- nr_faces = 1;
-
- for (l = 0; l <= pt->last_level; l++) {
- nv04mt->level[l].pitch = pt->width0;
- nv04mt->level[l].pitch = (nv04mt->level[l].pitch + 63) & ~63;
- }
-
- for (l = 0; l <= pt->last_level; l++) {
- nv04mt->level[l].image_offset =
- CALLOC(nr_faces, sizeof(unsigned));
- /* XXX guess was obviously missing */
- nv04mt->level[l].image_offset[0] = offset;
- offset += nv04mt->level[l].pitch * u_minify(pt->height0, l);
- }
-
- nv04mt->total_size = offset;
-}
-
-static struct pipe_texture *
-nv04_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
-{
- struct nv04_miptree *mt;
-
- mt = MALLOC(sizeof(struct nv04_miptree));
- if (!mt)
- return NULL;
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
-
- //mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
-
- nv04_miptree_layout(mt);
-
- mt->buffer = pscreen->buffer_create(pscreen, 256, PIPE_BUFFER_USAGE_PIXEL |
- NOUVEAU_BUFFER_USAGE_TEXTURE,
- mt->total_size);
- if (!mt->buffer) {
- printf("failed %d byte alloc\n",mt->total_size);
- FREE(mt);
- return NULL;
- }
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
-}
-
-static struct pipe_texture *
-nv04_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
- const unsigned *stride, struct pipe_buffer *pb)
-{
- struct nv04_miptree *mt;
-
- /* Only supports 2D, non-mipmapped textures for the moment */
- if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
- pt->depth0 != 1)
- return NULL;
-
- mt = CALLOC_STRUCT(nv04_miptree);
- if (!mt)
- return NULL;
-
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
- mt->level[0].pitch = stride[0];
- mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
-
- pipe_buffer_reference(&mt->buffer, pb);
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
-}
-
-static void
-nv04_miptree_destroy(struct pipe_texture *pt)
-{
- struct nv04_miptree *mt = (struct nv04_miptree *)pt;
- int l;
-
- pipe_buffer_reference(&mt->buffer, NULL);
- for (l = 0; l <= pt->last_level; l++) {
- if (mt->level[l].image_offset)
- FREE(mt->level[l].image_offset);
- }
-
- FREE(mt);
-}
-
-static struct pipe_surface *
-nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
-{
- struct nv04_miptree *nv04mt = (struct nv04_miptree *)pt;
- struct nv04_surface *ns;
-
- ns = CALLOC_STRUCT(nv04_surface);
- if (!ns)
- return NULL;
- pipe_texture_reference(&ns->base.texture, pt);
- ns->base.format = pt->format;
- ns->base.width = u_minify(pt->width0, level);
- ns->base.height = u_minify(pt->height0, level);
- ns->base.usage = flags;
- pipe_reference_init(&ns->base.reference, 1);
- ns->base.face = face;
- ns->base.level = level;
- ns->base.zslice = zslice;
- ns->pitch = nv04mt->level[level].pitch;
-
- ns->base.offset = nv04mt->level[level].image_offset[0];
-
- return &ns->base;
-}
-
-static void
-nv04_miptree_surface_del(struct pipe_surface *ps)
-{
- pipe_texture_reference(&ps->texture, NULL);
- FREE(ps);
-}
-
-void
-nv04_screen_init_miptree_functions(struct pipe_screen *pscreen)
-{
- pscreen->texture_create = nv04_miptree_create;
- pscreen->texture_blanket = nv04_miptree_blanket;
- pscreen->texture_destroy = nv04_miptree_destroy;
- pscreen->get_tex_surface = nv04_miptree_surface_new;
- pscreen->tex_surface_destroy = nv04_miptree_surface_del;
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_prim_vbuf.c b/src/gallium/drivers/nv04/nv04_prim_vbuf.c
deleted file mode 100644
index 0b795ea243..0000000000
--- a/src/gallium/drivers/nv04/nv04_prim_vbuf.c
+++ /dev/null
@@ -1,339 +0,0 @@
-
-#include "util/u_debug.h"
-#include "pipe/p_inlines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_compiler.h"
-
-#include "draw/draw_vbuf.h"
-
-#include "nv04_context.h"
-#include "nv04_state.h"
-
-#define VERTEX_SIZE 40
-#define VERTEX_BUFFER_SIZE (4096*VERTEX_SIZE) // 4096 vertices of 40 bytes each
-
-/**
- * Primitive renderer for nv04.
- */
-struct nv04_vbuf_render {
- struct vbuf_render base;
-
- struct nv04_context *nv04;
-
- /** Vertex buffer */
- unsigned char* buffer;
-
- /** Vertex size in bytes */
- unsigned vertex_size;
-
- /** Current primitive */
- unsigned prim;
-};
-
-
-/**
- * Basically a cast wrapper.
- */
-static INLINE struct nv04_vbuf_render *
-nv04_vbuf_render( struct vbuf_render *render )
-{
- assert(render);
- return (struct nv04_vbuf_render *)render;
-}
-
-
-static const struct vertex_info *
-nv04_vbuf_render_get_vertex_info( struct vbuf_render *render )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
- struct nv04_context *nv04 = nv04_render->nv04;
- return &nv04->vertex_info;
-}
-
-
-static boolean
-nv04_vbuf_render_allocate_vertices( struct vbuf_render *render,
- ushort vertex_size,
- ushort nr_vertices )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
-
- nv04_render->buffer = (unsigned char*) MALLOC(VERTEX_BUFFER_SIZE);
- assert(!nv04_render->buffer);
-
- return nv04_render->buffer ? TRUE : FALSE;
-}
-
-static void *
-nv04_vbuf_render_map_vertices( struct vbuf_render *render )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
- return nv04_render->buffer;
-}
-
-static void
-nv04_vbuf_render_unmap_vertices( struct vbuf_render *render,
- ushort min_index,
- ushort max_index )
-{
-}
-
-static boolean
-nv04_vbuf_render_set_primitive( struct vbuf_render *render,
- unsigned prim )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
-
- if (prim <= PIPE_PRIM_LINE_STRIP)
- return FALSE;
-
- nv04_render->prim = prim;
- return TRUE;
-}
-
-static INLINE void nv04_2triangles(struct nv04_context* nv04, unsigned char* buffer, ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0xA), 49);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v0,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v1,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v2,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v3,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v4,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v5,8);
- OUT_RING(chan, 0xFEDCBA);
-}
-
-static INLINE void nv04_1triangle(struct nv04_context* nv04, unsigned char* buffer, ushort v0, ushort v1, ushort v2)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0xD), 25);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v0,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v1,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v2,8);
- OUT_RING(chan, 0xFED);
-}
-
-static INLINE void nv04_1quad(struct nv04_context* nv04, unsigned char* buffer, ushort v0, ushort v1, ushort v2, ushort v3)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0xC), 33);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v0,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v1,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v2,8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * v3,8);
- OUT_RING(chan, 0xFECEDC);
-}
-
-static void nv04_vbuf_render_triangles_elts(struct nv04_vbuf_render * render, const ushort * indices, uint nr_indices)
-{
- unsigned char* buffer = render->buffer;
- struct nv04_context* nv04 = render->nv04;
- int i;
-
- for( i=0; i< nr_indices-5; i+=6)
- nv04_2triangles(nv04,
- buffer,
- indices[i+0],
- indices[i+1],
- indices[i+2],
- indices[i+3],
- indices[i+4],
- indices[i+5]
- );
- if (i != nr_indices)
- {
- nv04_1triangle(nv04,
- buffer,
- indices[i+0],
- indices[i+1],
- indices[i+2]
- );
- i+=3;
- }
- if (i != nr_indices)
- NOUVEAU_ERR("Houston, we have lost some vertices\n");
-}
-
-static void nv04_vbuf_render_tri_strip_elts(struct nv04_vbuf_render* render, const ushort* indices, uint nr_indices)
-{
- const uint32_t striptbl[]={0x321210,0x543432,0x765654,0x987876,0xBA9A98,0xDCBCBA,0xFEDEDC};
- unsigned char* buffer = render->buffer;
- struct nv04_context *nv04 = render->nv04;
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
- int i,j;
-
- for(i = 0; i<nr_indices; i+=14)
- {
- int numvert = MIN2(16, nr_indices - i);
- int numtri = numvert - 2;
- if (numvert<3)
- break;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0x0), numvert*8);
- for(j = 0; j<numvert; j++)
- OUT_RINGp(chan, buffer + VERTEX_SIZE * indices [i+j], 8 );
-
- BEGIN_RING_NI(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_DRAWPRIMITIVE(0), (numtri+1)/2 );
- for(j = 0; j<numtri/2; j++ )
- OUT_RING(chan, striptbl[j]);
- if (numtri%2)
- OUT_RING(chan, striptbl[numtri/2]&0xFFF);
- }
-}
-
-static void nv04_vbuf_render_tri_fan_elts(struct nv04_vbuf_render* render, const ushort* indices, uint nr_indices)
-{
- const uint32_t fantbl[]={0x320210,0x540430,0x760650,0x980870,0xBA0A90,0xDC0CB0,0xFE0ED0};
- unsigned char* buffer = render->buffer;
- struct nv04_context *nv04 = render->nv04;
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
- int i,j;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0x0), 8);
- OUT_RINGp(chan, buffer + VERTEX_SIZE * indices[0], 8);
-
- for(i = 1; i<nr_indices; i+=14)
- {
- int numvert=MIN2(15, nr_indices - i);
- int numtri=numvert-2;
- if (numvert < 3)
- break;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0x1), numvert*8);
-
- for(j=0;j<numvert;j++)
- OUT_RINGp(chan, buffer + VERTEX_SIZE * indices[ i+j ], 8 );
-
- BEGIN_RING_NI(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_DRAWPRIMITIVE(0), (numtri+1)/2);
- for(j = 0; j<numtri/2; j++)
- OUT_RING(chan, fantbl[j]);
- if (numtri%2)
- OUT_RING(chan, fantbl[numtri/2]&0xFFF);
- }
-}
-
-static void nv04_vbuf_render_quads_elts(struct nv04_vbuf_render* render, const ushort* indices, uint nr_indices)
-{
- unsigned char* buffer = render->buffer;
- struct nv04_context* nv04 = render->nv04;
- int i;
-
- for(i = 0; i < nr_indices; i += 4)
- nv04_1quad(nv04,
- buffer,
- indices[i+0],
- indices[i+1],
- indices[i+2],
- indices[i+3]
- );
-}
-
-
-static void
-nv04_vbuf_render_draw( struct vbuf_render *render,
- const ushort *indices,
- uint nr_indices)
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
-
- // emit the indices
- switch( nv04_render->prim )
- {
- case PIPE_PRIM_TRIANGLES:
- nv04_vbuf_render_triangles_elts(nv04_render, indices, nr_indices);
- break;
- case PIPE_PRIM_QUAD_STRIP:
- case PIPE_PRIM_TRIANGLE_STRIP:
- nv04_vbuf_render_tri_strip_elts(nv04_render, indices, nr_indices);
- break;
- case PIPE_PRIM_TRIANGLE_FAN:
- case PIPE_PRIM_POLYGON:
- nv04_vbuf_render_tri_fan_elts(nv04_render, indices, nr_indices);
- break;
- case PIPE_PRIM_QUADS:
- nv04_vbuf_render_quads_elts(nv04_render, indices, nr_indices);
- break;
- default:
- NOUVEAU_ERR("You have to implement primitive %d, young padawan\n", nv04_render->prim);
- break;
- }
-}
-
-
-static void
-nv04_vbuf_render_release_vertices( struct vbuf_render *render )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
-
- free(nv04_render->buffer);
- nv04_render->buffer = NULL;
-}
-
-
-static void
-nv04_vbuf_render_destroy( struct vbuf_render *render )
-{
- struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
- FREE(nv04_render);
-}
-
-
-/**
- * Create a new primitive render.
- */
-static struct vbuf_render *
-nv04_vbuf_render_create( struct nv04_context *nv04 )
-{
- struct nv04_vbuf_render *nv04_render = CALLOC_STRUCT(nv04_vbuf_render);
-
- nv04_render->nv04 = nv04;
-
- nv04_render->base.max_vertex_buffer_bytes = VERTEX_BUFFER_SIZE;
- nv04_render->base.max_indices = 65536;
- nv04_render->base.get_vertex_info = nv04_vbuf_render_get_vertex_info;
- nv04_render->base.allocate_vertices = nv04_vbuf_render_allocate_vertices;
- nv04_render->base.map_vertices = nv04_vbuf_render_map_vertices;
- nv04_render->base.unmap_vertices = nv04_vbuf_render_unmap_vertices;
- nv04_render->base.set_primitive = nv04_vbuf_render_set_primitive;
- nv04_render->base.draw = nv04_vbuf_render_draw;
- nv04_render->base.release_vertices = nv04_vbuf_render_release_vertices;
- nv04_render->base.destroy = nv04_vbuf_render_destroy;
-
- return &nv04_render->base;
-}
-
-
-/**
- * Create a new primitive vbuf/render stage.
- */
-struct draw_stage *nv04_draw_vbuf_stage( struct nv04_context *nv04 )
-{
- struct vbuf_render *render;
- struct draw_stage *stage;
-
- render = nv04_vbuf_render_create(nv04);
- if(!render)
- return NULL;
-
- stage = draw_vbuf_stage( nv04->draw, render );
- if(!stage) {
- render->destroy(render);
- return NULL;
- }
-
- return stage;
-}
diff --git a/src/gallium/drivers/nv04/nv04_screen.c b/src/gallium/drivers/nv04/nv04_screen.c
deleted file mode 100644
index 97538964af..0000000000
--- a/src/gallium/drivers/nv04/nv04_screen.c
+++ /dev/null
@@ -1,222 +0,0 @@
-#include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
-
-#include "nv04_context.h"
-#include "nv04_screen.h"
-
-static int
-nv04_screen_get_param(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
- return 1;
- case PIPE_CAP_NPOT_TEXTURES:
- return 0;
- case PIPE_CAP_TWO_SIDED_STENCIL:
- return 0;
- case PIPE_CAP_GLSL:
- return 0;
- case PIPE_CAP_ANISOTROPIC_FILTER:
- return 0;
- case PIPE_CAP_POINT_SPRITE:
- return 0;
- case PIPE_CAP_MAX_RENDER_TARGETS:
- return 1;
- case PIPE_CAP_OCCLUSION_QUERY:
- return 0;
- case PIPE_CAP_TEXTURE_SHADOW_MAP:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
- return 10;
- case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
- return 0;
- case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
- return 0;
- case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
- return 0;
- case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
- return 1;
- case PIPE_CAP_TGSI_CONT_SUPPORTED:
- return 0;
- case PIPE_CAP_BLEND_EQUATION_SEPARATE:
- return 0;
- case NOUVEAU_CAP_HW_VTXBUF:
- case NOUVEAU_CAP_HW_IDXBUF:
- return 0;
- case PIPE_CAP_INDEP_BLEND_ENABLE:
- return 0;
- case PIPE_CAP_INDEP_BLEND_FUNC:
- return 0;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
- return 1;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
- return 0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0;
- }
-}
-
-static float
-nv04_screen_get_paramf(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_LINE_WIDTH:
- case PIPE_CAP_MAX_LINE_WIDTH_AA:
- return 0.0;
- case PIPE_CAP_MAX_POINT_WIDTH:
- case PIPE_CAP_MAX_POINT_WIDTH_AA:
- return 0.0;
- case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
- return 0.0;
- case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
- return 0.0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0.0;
- }
-}
-
-static boolean
-nv04_screen_is_format_supported(struct pipe_screen *screen,
- enum pipe_format format,
- enum pipe_texture_target target,
- unsigned tex_usage, unsigned geom_flags)
-{
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- return TRUE;
- default:
- break;
- }
- } else
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- return TRUE;
- default:
- break;
- }
- } else {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_A8_UNORM:
- return TRUE;
- default:
- break;
- }
- }
-
- return FALSE;
-}
-
-static void
-nv04_screen_destroy(struct pipe_screen *pscreen)
-{
- struct nv04_screen *screen = nv04_screen(pscreen);
-
- nouveau_notifier_free(&screen->sync);
- nouveau_grobj_free(&screen->fahrenheit);
- nv04_surface_2d_takedown(&screen->eng2d);
-
- nouveau_screen_fini(&screen->base);
-
- FREE(pscreen);
-}
-
-static struct pipe_buffer *
-nv04_surface_buffer(struct pipe_surface *surf)
-{
- struct nv04_miptree *mt = (struct nv04_miptree *)surf->texture;
-
- return mt->buffer;
-}
-
-struct pipe_screen *
-nv04_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
-{
- struct nv04_screen *screen = CALLOC_STRUCT(nv04_screen);
- struct nouveau_channel *chan;
- struct pipe_screen *pscreen;
- unsigned fahrenheit_class = 0, sub3d_class = 0;
- int ret;
-
- if (!screen)
- return NULL;
- pscreen = &screen->base.base;
-
- ret = nouveau_screen_init(&screen->base, dev);
- if (ret) {
- nv04_screen_destroy(pscreen);
- return NULL;
- }
- chan = screen->base.channel;
-
- pscreen->winsys = ws;
- pscreen->destroy = nv04_screen_destroy;
- pscreen->get_param = nv04_screen_get_param;
- pscreen->get_paramf = nv04_screen_get_paramf;
- pscreen->is_format_supported = nv04_screen_is_format_supported;
-
- nv04_screen_init_miptree_functions(pscreen);
- nv04_screen_init_transfer_functions(pscreen);
-
- if (dev->chipset >= 0x20) {
- fahrenheit_class = 0;
- sub3d_class = 0;
- } else if (dev->chipset >= 0x10) {
- fahrenheit_class = NV10_TEXTURED_TRIANGLE;
- sub3d_class = NV10_CONTEXT_SURFACES_3D;
- } else {
- fahrenheit_class=NV04_TEXTURED_TRIANGLE;
- sub3d_class = NV04_CONTEXT_SURFACES_3D;
- }
-
- if (!fahrenheit_class) {
- NOUVEAU_ERR("Unknown nv04 chipset: nv%02x\n", dev->chipset);
- return NULL;
- }
-
- /* 3D object */
- ret = nouveau_grobj_alloc(chan, 0xbeef0001, fahrenheit_class,
- &screen->fahrenheit);
- if (ret) {
- NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
- return NULL;
- }
- BIND_RING(chan, screen->fahrenheit, 7);
-
- /* 3D surface object */
- ret = nouveau_grobj_alloc(chan, 0xbeef0002, sub3d_class,
- &screen->context_surfaces_3d);
- if (ret) {
- NOUVEAU_ERR("Error creating 3D surface object: %d\n", ret);
- return NULL;
- }
- BIND_RING(chan, screen->context_surfaces_3d, 6);
-
- /* 2D engine setup */
- screen->eng2d = nv04_surface_2d_init(&screen->base);
- screen->eng2d->buf = nv04_surface_buffer;
-
- /* Notifier for sync purposes */
- ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync);
- if (ret) {
- NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
- nv04_screen_destroy(pscreen);
- return NULL;
- }
-
- return pscreen;
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_screen.h b/src/gallium/drivers/nv04/nv04_screen.h
deleted file mode 100644
index 11466b9442..0000000000
--- a/src/gallium/drivers/nv04/nv04_screen.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef __NV04_SCREEN_H__
-#define __NV04_SCREEN_H__
-
-#include "nouveau/nouveau_screen.h"
-#include "nv04_surface_2d.h"
-
-struct nv04_screen {
- struct nouveau_screen base;
-
- struct nouveau_winsys *nvws;
- unsigned chipset;
-
- /* HW graphics objects */
- struct nv04_surface_2d *eng2d;
- struct nouveau_grobj *fahrenheit;
- struct nouveau_grobj *context_surfaces_3d;
- struct nouveau_notifier *sync;
-
-};
-
-static INLINE struct nv04_screen *
-nv04_screen(struct pipe_screen *screen)
-{
- return (struct nv04_screen *)screen;
-}
-
-void
-nv04_screen_init_transfer_functions(struct pipe_screen *pscreen);
-
-#endif
diff --git a/src/gallium/drivers/nv04/nv04_state.c b/src/gallium/drivers/nv04/nv04_state.c
deleted file mode 100644
index 1fdb764b53..0000000000
--- a/src/gallium/drivers/nv04/nv04_state.c
+++ /dev/null
@@ -1,459 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_shader_tokens.h"
-#include "pipe/p_inlines.h"
-
-#include "tgsi/tgsi_parse.h"
-
-#include "nv04_context.h"
-#include "nv04_state.h"
-
-static void *
-nv04_blend_state_create(struct pipe_context *pipe,
- const struct pipe_blend_state *cso)
-{
- struct nv04_blend_state *cb;
-
- cb = MALLOC(sizeof(struct nv04_blend_state));
-
- cb->b_enable = cso->rt[0].blend_enable ? 1 : 0;
- cb->b_src = ((nvgl_blend_func(cso->rt[0].alpha_src_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_src_factor)));
- cb->b_dst = ((nvgl_blend_func(cso->rt[0].alpha_dst_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_dst_factor)));
-
-
- return (void *)cb;
-}
-
-static void
-nv04_blend_state_bind(struct pipe_context *pipe, void *blend)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- nv04->blend = (struct nv04_blend_state*)blend;
-
- nv04->dirty |= NV04_NEW_BLEND;
-}
-
-static void
-nv04_blend_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- free(hwcso);
-}
-
-
-static INLINE unsigned
-wrap_mode(unsigned wrap) {
- unsigned ret;
-
- switch (wrap) {
- case PIPE_TEX_WRAP_REPEAT:
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT;
- break;
- case PIPE_TEX_WRAP_MIRROR_REPEAT:
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_MIRRORED_REPEAT;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP_TO_EDGE;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP_TO_BORDER;
- break;
- case PIPE_TEX_WRAP_CLAMP:
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP;
- break;
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
- case PIPE_TEX_WRAP_MIRROR_CLAMP:
- default:
- NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
- ret = NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP;
- }
- return ret >> NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_SHIFT;
-}
-
-static void *
-nv04_sampler_state_create(struct pipe_context *pipe,
- const struct pipe_sampler_state *cso)
-{
-
- struct nv04_sampler_state *ss;
- uint32_t filter = 0;
-
- ss = MALLOC(sizeof(struct nv04_sampler_state));
-
- ss->format = ((wrap_mode(cso->wrap_s) << NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_SHIFT) |
- (wrap_mode(cso->wrap_t) << NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_SHIFT));
-
- if (cso->max_anisotropy > 1.0) {
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_ANISOTROPIC_MINIFY_ENABLE | NV04_TEXTURED_TRIANGLE_FILTER_ANISOTROPIC_MAGNIFY_ENABLE;
- }
-
- switch (cso->mag_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_LINEAR;
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST;
- break;
- }
-
- switch (cso->min_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_LINEAR;
- break;
- }
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST;
- break;
- }
- break;
- }
-
- ss->filter = filter;
-
- return (void *)ss;
-}
-
-static void
-nv04_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv04->sampler[unit] = sampler[unit];
- nv04->dirty_samplers |= (1 << unit);
- }
-}
-
-static void
-nv04_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- free(hwcso);
-}
-
-static void
-nv04_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
- struct pipe_texture **miptree)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv04->tex_miptree[unit] = (struct nv04_miptree *)miptree[unit];
- nv04->dirty_samplers |= (1 << unit);
- }
-}
-
-static void *
-nv04_rasterizer_state_create(struct pipe_context *pipe,
- const struct pipe_rasterizer_state *cso)
-{
- struct nv04_rasterizer_state *rs;
-
- /*XXX: ignored:
- * scissor
- * points/lines (no hw support, emulated with tris in gallium)
- */
- rs = MALLOC(sizeof(struct nv04_rasterizer_state));
-
- rs->blend = cso->flatshade ? NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_FLAT : NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_GOURAUD;
-
- return (void *)rs;
-}
-
-static void
-nv04_rasterizer_state_bind(struct pipe_context *pipe, void *rast)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- nv04->rast = (struct nv04_rasterizer_state*)rast;
-
- draw_set_rasterizer_state(nv04->draw, (nv04->rast ? nv04->rast->templ : NULL));
-
- nv04->dirty |= NV04_NEW_RAST | NV04_NEW_BLEND;
-}
-
-static void
-nv04_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- free(hwcso);
-}
-
-static INLINE uint32_t nv04_compare_func(uint32_t f)
-{
- switch ( f ) {
- case PIPE_FUNC_NEVER: return 1;
- case PIPE_FUNC_LESS: return 2;
- case PIPE_FUNC_EQUAL: return 3;
- case PIPE_FUNC_LEQUAL: return 4;
- case PIPE_FUNC_GREATER: return 5;
- case PIPE_FUNC_NOTEQUAL: return 6;
- case PIPE_FUNC_GEQUAL: return 7;
- case PIPE_FUNC_ALWAYS: return 8;
- }
- NOUVEAU_MSG("Unable to find the function\n");
- return 0;
-}
-
-static void *
-nv04_depth_stencil_alpha_state_create(struct pipe_context *pipe,
- const struct pipe_depth_stencil_alpha_state *cso)
-{
- struct nv04_depth_stencil_alpha_state *hw;
-
- hw = MALLOC(sizeof(struct nv04_depth_stencil_alpha_state));
-
- hw->control = float_to_ubyte(cso->alpha.ref_value);
- hw->control |= ( nv04_compare_func(cso->alpha.func) << NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_FUNC_SHIFT );
- hw->control |= cso->alpha.enabled ? NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_ENABLE : 0;
- hw->control |= NV04_TEXTURED_TRIANGLE_CONTROL_ORIGIN;
- hw->control |= cso->depth.enabled ? NV04_TEXTURED_TRIANGLE_CONTROL_Z_ENABLE : 0;
- hw->control |= ( nv04_compare_func(cso->depth.func)<< NV04_TEXTURED_TRIANGLE_CONTROL_Z_FUNC_SHIFT );
- hw->control |= 1 << NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_SHIFT; // no culling, handled by the draw module
- hw->control |= NV04_TEXTURED_TRIANGLE_CONTROL_DITHER_ENABLE;
- hw->control |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_PERSPECTIVE_ENABLE;
- hw->control |= cso->depth.writemask ? NV04_TEXTURED_TRIANGLE_CONTROL_Z_WRITE : 0;
- hw->control |= 1 << NV04_TEXTURED_TRIANGLE_CONTROL_Z_FORMAT_SHIFT; // integer zbuffer format
-
- return (void *)hw;
-}
-
-static void
-nv04_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- nv04->dsa = hwcso;
- nv04->dirty |= NV04_NEW_CONTROL;
-}
-
-static void
-nv04_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- free(hwcso);
-}
-
-static void *
-nv04_vp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *templ)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- return draw_create_vertex_shader(nv04->draw, templ);
-}
-
-static void
-nv04_vp_state_bind(struct pipe_context *pipe, void *shader)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- draw_bind_vertex_shader(nv04->draw, (struct draw_vertex_shader *) shader);
-
- nv04->dirty |= NV04_NEW_VERTPROG;
-}
-
-static void
-nv04_vp_state_delete(struct pipe_context *pipe, void *shader)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- draw_delete_vertex_shader(nv04->draw, (struct draw_vertex_shader *) shader);
-}
-
-static void *
-nv04_fp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *cso)
-{
- struct nv04_fragment_program *fp;
-
- fp = CALLOC(1, sizeof(struct nv04_fragment_program));
- fp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
-
- return (void *)fp;
-}
-
-static void
-nv04_fp_state_bind(struct pipe_context *pipe, void *hwcso)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_fragment_program *fp = hwcso;
-
- nv04->fragprog.current = fp;
- nv04->dirty |= NV04_NEW_FRAGPROG;
-}
-
-static void
-nv04_fp_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_fragment_program *fp = hwcso;
-
- nv04_fragprog_destroy(nv04, fp);
- free((void*)fp->pipe.tokens);
- free(fp);
-}
-
-static void
-nv04_set_blend_color(struct pipe_context *pipe,
- const struct pipe_blend_color *bcol)
-{
-}
-
-static void
-nv04_set_clip_state(struct pipe_context *pipe,
- const struct pipe_clip_state *clip)
-{
-}
-
-static void
-nv04_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
- struct pipe_buffer *buf )
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct pipe_screen *pscreen = pipe->screen;
-
- assert(shader < PIPE_SHADER_TYPES);
- assert(index == 0);
-
- if (buf) {
- void *mapped;
- if (buf && buf->size &&
- (mapped = pipe_buffer_map(pscreen, buf, PIPE_BUFFER_USAGE_CPU_READ)))
- {
- memcpy(nv04->constbuf[shader], mapped, buf->size);
- nv04->constbuf_nr[shader] =
- buf->size / (4 * sizeof(float));
- pipe_buffer_unmap(pscreen, buf);
- }
- }
-}
-
-static void
-nv04_set_framebuffer_state(struct pipe_context *pipe,
- const struct pipe_framebuffer_state *fb)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- nv04->framebuffer = (struct pipe_framebuffer_state*)fb;
-
- nv04->dirty |= NV04_NEW_FRAMEBUFFER;
-}
-static void
-nv04_set_polygon_stipple(struct pipe_context *pipe,
- const struct pipe_poly_stipple *stipple)
-{
- NOUVEAU_ERR("line stipple hahaha\n");
-}
-
-static void
-nv04_set_scissor_state(struct pipe_context *pipe,
- const struct pipe_scissor_state *s)
-{
-/* struct nv04_context *nv04 = nv04_context(pipe);
-
- // XXX
- BEGIN_RING(fahrenheit, NV04_TEXTURED_TRIANGLE_SCISSOR_HORIZ, 2);
- OUT_RING (((s->maxx - s->minx) << 16) | s->minx);
- OUT_RING (((s->maxy - s->miny) << 16) | s->miny);*/
-}
-
-static void
-nv04_set_viewport_state(struct pipe_context *pipe,
- const struct pipe_viewport_state *viewport)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- nv04->viewport = *viewport;
-
- draw_set_viewport_state(nv04->draw, &nv04->viewport);
-}
-
-static void
-nv04_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_buffer *buffers)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- memcpy(nv04->vtxbuf, buffers, count * sizeof(buffers[0]));
- nv04->dirty |= NV04_NEW_VTXARRAYS;
-
- draw_set_vertex_buffers(nv04->draw, count, buffers);
-}
-
-static void
-nv04_set_vertex_elements(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_element *elements)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
-
- memcpy(nv04->vtxelt, elements, sizeof(*elements) * count);
- nv04->dirty |= NV04_NEW_VTXARRAYS;
-
- draw_set_vertex_elements(nv04->draw, count, elements);
-}
-
-void
-nv04_init_state_functions(struct nv04_context *nv04)
-{
- nv04->pipe.create_blend_state = nv04_blend_state_create;
- nv04->pipe.bind_blend_state = nv04_blend_state_bind;
- nv04->pipe.delete_blend_state = nv04_blend_state_delete;
-
- nv04->pipe.create_sampler_state = nv04_sampler_state_create;
- nv04->pipe.bind_fragment_sampler_states = nv04_sampler_state_bind;
- nv04->pipe.delete_sampler_state = nv04_sampler_state_delete;
- nv04->pipe.set_fragment_sampler_textures = nv04_set_sampler_texture;
-
- nv04->pipe.create_rasterizer_state = nv04_rasterizer_state_create;
- nv04->pipe.bind_rasterizer_state = nv04_rasterizer_state_bind;
- nv04->pipe.delete_rasterizer_state = nv04_rasterizer_state_delete;
-
- nv04->pipe.create_depth_stencil_alpha_state = nv04_depth_stencil_alpha_state_create;
- nv04->pipe.bind_depth_stencil_alpha_state = nv04_depth_stencil_alpha_state_bind;
- nv04->pipe.delete_depth_stencil_alpha_state = nv04_depth_stencil_alpha_state_delete;
-
- nv04->pipe.create_vs_state = nv04_vp_state_create;
- nv04->pipe.bind_vs_state = nv04_vp_state_bind;
- nv04->pipe.delete_vs_state = nv04_vp_state_delete;
-
- nv04->pipe.create_fs_state = nv04_fp_state_create;
- nv04->pipe.bind_fs_state = nv04_fp_state_bind;
- nv04->pipe.delete_fs_state = nv04_fp_state_delete;
-
- nv04->pipe.set_blend_color = nv04_set_blend_color;
- nv04->pipe.set_clip_state = nv04_set_clip_state;
- nv04->pipe.set_constant_buffer = nv04_set_constant_buffer;
- nv04->pipe.set_framebuffer_state = nv04_set_framebuffer_state;
- nv04->pipe.set_polygon_stipple = nv04_set_polygon_stipple;
- nv04->pipe.set_scissor_state = nv04_set_scissor_state;
- nv04->pipe.set_viewport_state = nv04_set_viewport_state;
-
- nv04->pipe.set_vertex_buffers = nv04_set_vertex_buffers;
- nv04->pipe.set_vertex_elements = nv04_set_vertex_elements;
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_state.h b/src/gallium/drivers/nv04/nv04_state.h
deleted file mode 100644
index 81d1d2ebaa..0000000000
--- a/src/gallium/drivers/nv04/nv04_state.h
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef __NV04_STATE_H__
-#define __NV04_STATE_H__
-
-#include "pipe/p_state.h"
-#include "tgsi/tgsi_scan.h"
-
-struct nv04_blend_state {
- uint32_t b_enable;
- uint32_t b_src;
- uint32_t b_dst;
-};
-
-struct nv04_fragtex_state {
- uint32_t format;
-};
-
-struct nv04_sampler_state {
- uint32_t filter;
- uint32_t format;
-};
-
-struct nv04_depth_stencil_alpha_state {
- uint32_t control;
-};
-
-struct nv04_rasterizer_state {
- uint32_t blend;
-
- const struct pipe_rasterizer_state *templ;
-};
-
-struct nv04_miptree {
- struct pipe_texture base;
- struct nouveau_bo *bo;
-
- struct pipe_buffer *buffer;
- uint total_size;
-
- struct {
- uint pitch;
- uint *image_offset;
- } level[PIPE_MAX_TEXTURE_LEVELS];
-};
-
-struct nv04_fragment_program_data {
- unsigned offset;
- unsigned index;
-};
-
-struct nv04_fragment_program {
- struct pipe_shader_state pipe;
- struct tgsi_shader_info info;
-
- boolean translated;
- boolean on_hw;
- unsigned samplers;
-
- uint32_t *insn;
- int insn_len;
-
- struct nv04_fragment_program_data *consts;
- unsigned nr_consts;
-
- struct pipe_buffer *buffer;
-
- uint32_t fp_control;
- uint32_t fp_reg_control;
-};
-
-
-
-#endif
diff --git a/src/gallium/drivers/nv04/nv04_state_emit.c b/src/gallium/drivers/nv04/nv04_state_emit.c
deleted file mode 100644
index b8d6dc560f..0000000000
--- a/src/gallium/drivers/nv04/nv04_state_emit.c
+++ /dev/null
@@ -1,246 +0,0 @@
-#include "nv04_context.h"
-#include "nv04_state.h"
-
-static void nv04_vertex_layout(struct pipe_context* pipe)
-{
- struct nv04_context *nv04 = nv04_context(pipe);
- struct nv04_fragment_program *fp = nv04->fragprog.current;
- uint32_t src = 0;
- int i;
- struct vertex_info vinfo;
-
- memset(&vinfo, 0, sizeof(vinfo));
-
- for (i = 0; i < fp->info.num_inputs; i++) {
- int isn = fp->info.input_semantic_name[i];
- int isi = fp->info.input_semantic_index[i];
- switch (isn) {
- case TGSI_SEMANTIC_POSITION:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
- break;
- case TGSI_SEMANTIC_COLOR:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
- break;
- default:
- case TGSI_SEMANTIC_GENERIC:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
- break;
- case TGSI_SEMANTIC_FOG:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
- break;
- }
- }
-
- printf("%d vertex input\n",fp->info.num_inputs);
- draw_compute_vertex_size(&vinfo);
-}
-
-static uint32_t nv04_blend_func(uint32_t f)
-{
- switch ( f ) {
- case PIPE_BLENDFACTOR_ZERO: return 0x1;
- case PIPE_BLENDFACTOR_ONE: return 0x2;
- case PIPE_BLENDFACTOR_SRC_COLOR: return 0x3;
- case PIPE_BLENDFACTOR_INV_SRC_COLOR: return 0x4;
- case PIPE_BLENDFACTOR_SRC_ALPHA: return 0x5;
- case PIPE_BLENDFACTOR_INV_SRC_ALPHA: return 0x6;
- case PIPE_BLENDFACTOR_DST_ALPHA: return 0x7;
- case PIPE_BLENDFACTOR_INV_DST_ALPHA: return 0x8;
- case PIPE_BLENDFACTOR_DST_COLOR: return 0x9;
- case PIPE_BLENDFACTOR_INV_DST_COLOR: return 0xA;
- case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: return 0xB;
- }
- NOUVEAU_MSG("Unable to find the blend function 0x%x\n",f);
- return 0;
-}
-
-static void nv04_emit_control(struct nv04_context* nv04)
-{
- uint32_t control = nv04->dsa->control;
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_CONTROL, 1);
- OUT_RING(chan, control);
-}
-
-static void nv04_emit_blend(struct nv04_context* nv04)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
- uint32_t blend;
-
- blend=0x4; // texture MODULATE_ALPHA
- blend|=0x20; // alpha is MSB
- blend|=(2<<6); // flat shading
- blend|=(1<<8); // persp correct
- blend|=(0<<16); // no fog
- blend|=(nv04->blend->b_enable<<20);
- blend|=(nv04_blend_func(nv04->blend->b_src)<<24);
- blend|=(nv04_blend_func(nv04->blend->b_dst)<<28);
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_BLEND, 1);
- OUT_RING(chan, blend);
-}
-
-static void nv04_emit_sampler(struct nv04_context *nv04, int unit)
-{
- struct nv04_miptree *nv04mt = nv04->tex_miptree[unit];
- struct pipe_texture *pt = &nv04mt->base;
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
- struct nouveau_bo *bo = nouveau_bo(nv04mt->buffer);
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_OFFSET, 3);
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- OUT_RELOCd(chan, bo, (nv04->fragtex.format | nv04->sampler[unit]->format), NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
- OUT_RING(chan, nv04->sampler[unit]->filter);
-}
-
-static void nv04_state_emit_framebuffer(struct nv04_context* nv04)
-{
- struct pipe_framebuffer_state* fb = nv04->framebuffer;
- struct nv04_surface *rt, *zeta;
- uint32_t rt_format, w, h;
- int colour_format = 0, zeta_format = 0;
- struct nv04_miptree *nv04mt = 0;
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *context_surfaces_3d = screen->context_surfaces_3d;
- struct nouveau_bo *bo;
-
- w = fb->cbufs[0]->width;
- h = fb->cbufs[0]->height;
- colour_format = fb->cbufs[0]->format;
- rt = (struct nv04_surface *)fb->cbufs[0];
-
- if (fb->zsbuf) {
- if (colour_format) {
- assert(w == fb->zsbuf->width);
- assert(h == fb->zsbuf->height);
- } else {
- w = fb->zsbuf->width;
- h = fb->zsbuf->height;
- }
-
- zeta_format = fb->zsbuf->format;
- zeta = (struct nv04_surface *)fb->zsbuf;
- }
-
- switch (colour_format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case 0:
- rt_format = 0x108;
- break;
- case PIPE_FORMAT_R5G6B5_UNORM:
- rt_format = 0x103;
- break;
- default:
- assert(0);
- }
-
- BEGIN_RING(chan, context_surfaces_3d, NV04_CONTEXT_SURFACES_3D_FORMAT, 1);
- OUT_RING(chan, rt_format);
-
- nv04mt = (struct nv04_miptree *)rt->base.texture;
- bo = nouveau_bo(nv04mt->buffer);
- /* FIXME pitches have to be aligned ! */
- BEGIN_RING(chan, context_surfaces_3d, NV04_CONTEXT_SURFACES_3D_PITCH, 2);
- OUT_RING(chan, rt->pitch|(zeta->pitch<<16));
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- if (fb->zsbuf) {
- nv04mt = (struct nv04_miptree *)zeta->base.texture;
- BEGIN_RING(chan, context_surfaces_3d, NV04_CONTEXT_SURFACES_3D_OFFSET_ZETA, 1);
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- }
-}
-
-void
-nv04_emit_hw_state(struct nv04_context *nv04)
-{
- struct nv04_screen *screen = nv04->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *fahrenheit = screen->fahrenheit;
- struct nouveau_grobj *context_surfaces_3d = screen->context_surfaces_3d;
- int i;
-
- if (nv04->dirty & NV04_NEW_VERTPROG) {
- //nv04_vertprog_bind(nv04, nv04->vertprog.current);
- nv04->dirty &= ~NV04_NEW_VERTPROG;
- }
-
- if (nv04->dirty & NV04_NEW_FRAGPROG) {
- nv04_fragprog_bind(nv04, nv04->fragprog.current);
- nv04->dirty &= ~NV04_NEW_FRAGPROG;
- nv04->dirty_samplers |= (1<<10);
- nv04->dirty_samplers = 0;
- }
-
- if (nv04->dirty & NV04_NEW_CONTROL) {
- nv04->dirty &= ~NV04_NEW_CONTROL;
-
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_CONTROL, 1);
- OUT_RING(chan, nv04->dsa->control);
- }
-
- if (nv04->dirty & NV04_NEW_BLEND) {
- nv04->dirty &= ~NV04_NEW_BLEND;
-
- nv04_emit_blend(nv04);
- }
-
- if (nv04->dirty & NV04_NEW_VTXARRAYS) {
- nv04->dirty &= ~NV04_NEW_VTXARRAYS;
- nv04_vertex_layout(nv04);
- }
-
- if (nv04->dirty & NV04_NEW_SAMPLER) {
- nv04->dirty &= ~NV04_NEW_SAMPLER;
-
- nv04_emit_sampler(nv04, 0);
- }
-
- if (nv04->dirty & NV04_NEW_VIEWPORT) {
- nv04->dirty &= ~NV04_NEW_VIEWPORT;
-// nv04_state_emit_viewport(nv04);
- }
-
- if (nv04->dirty & NV04_NEW_FRAMEBUFFER) {
- nv04->dirty &= ~NV04_NEW_FRAMEBUFFER;
- nv04_state_emit_framebuffer(nv04);
- }
-
- /* Emit relocs for every referenced buffer.
- * This is to ensure the bufmgr has an accurate idea of how
- * the buffer is used. This isn't very efficient, but we don't
- * seem to take a significant performance hit. Will be improved
- * at some point. Vertex arrays are emitted by nv04_vbo.c
- */
-
- /* Render target */
- unsigned rt_pitch = ((struct nv04_surface *)nv04->rt)->pitch;
- unsigned zeta_pitch = ((struct nv04_surface *)nv04->zeta)->pitch;
-
- BEGIN_RING(chan, context_surfaces_3d, NV04_CONTEXT_SURFACES_3D_PITCH, 2);
- OUT_RING(chan, rt_pitch|(zeta_pitch<<16));
- OUT_RELOCl(chan, nouveau_bo(nv04->rt), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- if (nv04->zeta) {
- BEGIN_RING(chan, context_surfaces_3d, NV04_CONTEXT_SURFACES_3D_OFFSET_ZETA, 1);
- OUT_RELOCl(chan, nouveau_bo(nv04->zeta), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- }
-
- /* Texture images */
- for (i = 0; i < 1; i++) {
- if (!(nv04->fp_samplers & (1 << i)))
- continue;
- struct nv04_miptree *nv04mt = nv04->tex_miptree[i];
- struct nouveau_bo *bo = nouveau_bo(nv04mt->buffer);
- BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_OFFSET, 2);
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- OUT_RELOCd(chan, bo, (nv04->fragtex.format | nv04->sampler[i]->format), NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
- }
-}
-
diff --git a/src/gallium/drivers/nv04/nv04_transfer.c b/src/gallium/drivers/nv04/nv04_transfer.c
deleted file mode 100644
index 2dd2e146a8..0000000000
--- a/src/gallium/drivers/nv04/nv04_transfer.c
+++ /dev/null
@@ -1,178 +0,0 @@
-#include <pipe/p_state.h>
-#include <pipe/p_defines.h>
-#include <pipe/p_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
-#include <util/u_math.h>
-#include <nouveau/nouveau_winsys.h>
-#include "nv04_context.h"
-#include "nv04_screen.h"
-#include "nv04_state.h"
-
-struct nv04_transfer {
- struct pipe_transfer base;
- struct pipe_surface *surface;
- boolean direct;
-};
-
-static void
-nv04_compatible_transfer_tex(struct pipe_texture *pt, unsigned width, unsigned height,
- struct pipe_texture *template)
-{
- memset(template, 0, sizeof(struct pipe_texture));
- template->target = pt->target;
- template->format = pt->format;
- template->width0 = width;
- template->height0 = height;
- template->depth0 = 1;
- template->last_level = 0;
- template->nr_samples = pt->nr_samples;
-
- template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
- NOUVEAU_TEXTURE_USAGE_LINEAR;
-}
-
-static struct pipe_transfer *
-nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
-{
- struct nv04_miptree *mt = (struct nv04_miptree *)pt;
- struct nv04_transfer *tx;
- struct pipe_texture tx_tex_template, *tx_tex;
-
- tx = CALLOC_STRUCT(nv04_transfer);
- if (!tx)
- return NULL;
-
- pipe_texture_reference(&tx->base.texture, pt);
- tx->base.x = x;
- tx->base.y = y;
- tx->base.width = w;
- tx->base.height = h;
- tx->base.stride = mt->level[level].pitch;
- tx->base.usage = usage;
- tx->base.face = face;
- tx->base.level = level;
- tx->base.zslice = zslice;
-
- /* Direct access to texture */
- if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC ||
- debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/)) &&
- pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)
- {
- tx->direct = true;
- tx->surface = pscreen->get_tex_surface(pscreen, pt,
- 0, 0, 0,
- pipe_transfer_buffer_flags(&tx->base));
- return &tx->base;
- }
-
- tx->direct = false;
-
- nv04_compatible_transfer_tex(pt, w, h, &tx_tex_template);
-
- tx_tex = pscreen->texture_create(pscreen, &tx_tex_template);
- if (!tx_tex)
- {
- FREE(tx);
- return NULL;
- }
-
- tx->base.stride = ((struct nv04_miptree*)tx_tex)->level[0].pitch;
-
- tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
- face, level, zslice,
- pipe_transfer_buffer_flags(&tx->base));
-
- pipe_texture_reference(&tx_tex, NULL);
-
- if (!tx->surface)
- {
- pipe_surface_reference(&tx->surface, NULL);
- FREE(tx);
- return NULL;
- }
-
- if (usage & PIPE_TRANSFER_READ) {
- struct nv04_screen *nvscreen = nv04_screen(pscreen);
- struct pipe_surface *src;
-
- src = pscreen->get_tex_surface(pscreen, pt,
- face, level, zslice,
- PIPE_BUFFER_USAGE_GPU_READ);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- /* TODO: Check if SIFM can un-swizzle */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- tx->surface, 0, 0,
- src, x, y,
- w, h);
-
- pipe_surface_reference(&src, NULL);
- }
-
- return &tx->base;
-}
-
-static void
-nv04_transfer_del(struct pipe_transfer *ptx)
-{
- struct nv04_transfer *tx = (struct nv04_transfer *)ptx;
-
- if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
- struct pipe_screen *pscreen = ptx->texture->screen;
- struct nv04_screen *nvscreen = nv04_screen(pscreen);
- struct pipe_surface *dst;
-
- dst = pscreen->get_tex_surface(pscreen, ptx->texture,
- ptx->face, ptx->level, ptx->zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- dst, tx->base.x, tx->base.y,
- tx->surface, 0, 0,
- tx->base.width, tx->base.height);
-
- pipe_surface_reference(&dst, NULL);
- }
-
- pipe_surface_reference(&tx->surface, NULL);
- pipe_texture_reference(&ptx->texture, NULL);
- FREE(ptx);
-}
-
-static void *
-nv04_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv04_transfer *tx = (struct nv04_transfer *)ptx;
- struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
- struct nv04_miptree *mt = (struct nv04_miptree *)tx->surface->texture;
- void *map = pipe_buffer_map(pscreen, mt->buffer,
- pipe_transfer_buffer_flags(ptx));
-
- if(!tx->direct)
- return map + ns->base.offset;
- else
- return map + ns->base.offset + ptx->y * ns->pitch + ptx->x * util_format_get_blocksize(ptx->texture->format);
-}
-
-static void
-nv04_transfer_unmap(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv04_transfer *tx = (struct nv04_transfer *)ptx;
- struct nv04_miptree *mt = (struct nv04_miptree *)tx->surface->texture;
-
- pipe_buffer_unmap(pscreen, mt->buffer);
-}
-
-void
-nv04_screen_init_transfer_functions(struct pipe_screen *pscreen)
-{
- pscreen->get_tex_transfer = nv04_transfer_new;
- pscreen->tex_transfer_destroy = nv04_transfer_del;
- pscreen->transfer_map = nv04_transfer_map;
- pscreen->transfer_unmap = nv04_transfer_unmap;
-}
diff --git a/src/gallium/drivers/nv04/nv04_vbo.c b/src/gallium/drivers/nv04/nv04_vbo.c
deleted file mode 100644
index 2db61d8941..0000000000
--- a/src/gallium/drivers/nv04/nv04_vbo.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-#include "nv04_context.h"
-#include "nv04_state.h"
-
-#include "nouveau/nouveau_channel.h"
-#include "nouveau/nouveau_pushbuf.h"
-
-void nv04_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count)
-{
- struct pipe_screen *pscreen = pipe->screen;
- struct nv04_context *nv04 = nv04_context( pipe );
- struct draw_context *draw = nv04->draw;
- unsigned i;
-
- nv04_emit_hw_state(nv04);
-
- /*
- * Map vertex buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv04->vtxbuf[i].buffer) {
- void *buf
- = pipe_buffer_map(pscreen,
- nv04->vtxbuf[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_vertex_buffer(draw, i, buf);
- }
- }
- /* Map index buffer, if present */
- if (indexBuffer) {
- void *mapped_indexes
- = pipe_buffer_map(pscreen, indexBuffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
- }
- else {
- /* no index/element buffer */
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-
- draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
- nv04->constbuf[PIPE_SHADER_VERTEX],
- nv04->constbuf_nr[PIPE_SHADER_VERTEX]);
-
- /* draw! */
- draw_arrays(nv04->draw, prim, start, count);
-
- /*
- * unmap vertex/index buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv04->vtxbuf[i].buffer) {
- pipe_buffer_unmap(pscreen, nv04->vtxbuf[i].buffer);
- draw_set_mapped_vertex_buffer(draw, i, NULL);
- }
- }
- if (indexBuffer) {
- pipe_buffer_unmap(pscreen, indexBuffer);
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-}
-
-void nv04_draw_arrays( struct pipe_context *pipe,
- unsigned prim, unsigned start, unsigned count)
-{
- printf("coucou in draw arrays\n");
- nv04_draw_elements(pipe, NULL, 0, prim, start, count);
-}
-
-
-
diff --git a/src/gallium/drivers/nv10/Makefile b/src/gallium/drivers/nv10/Makefile
deleted file mode 100644
index 62677f5194..0000000000
--- a/src/gallium/drivers/nv10/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-TOP = ../../../..
-include $(TOP)/configs/current
-
-LIBNAME = nv10
-
-C_SOURCES = \
- nv10_clear.c \
- nv10_context.c \
- nv10_fragprog.c \
- nv10_fragtex.c \
- nv10_miptree.c \
- nv10_prim_vbuf.c \
- nv10_screen.c \
- nv10_state.c \
- nv10_state_emit.c \
- nv10_surface.c \
- nv10_transfer.c \
- nv10_vbo.c
-
-include ../../Makefile.template
diff --git a/src/gallium/drivers/nv10/nv10_clear.c b/src/gallium/drivers/nv10/nv10_clear.c
deleted file mode 100644
index a39a2b5f52..0000000000
--- a/src/gallium/drivers/nv10/nv10_clear.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "util/u_clear.h"
-
-#include "nv10_context.h"
-
-void
-nv10_clear(struct pipe_context *pipe, unsigned buffers,
- const float *rgba, double depth, unsigned stencil)
-{
- util_clear(pipe, nv10_context(pipe)->framebuffer, buffers, rgba, depth,
- stencil);
-}
diff --git a/src/gallium/drivers/nv10/nv10_context.c b/src/gallium/drivers/nv10/nv10_context.c
deleted file mode 100644
index 1ecb73d06e..0000000000
--- a/src/gallium/drivers/nv10/nv10_context.c
+++ /dev/null
@@ -1,298 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-
-#include "nv10_context.h"
-#include "nv10_screen.h"
-
-static void
-nv10_flush(struct pipe_context *pipe, unsigned flags,
- struct pipe_fence_handle **fence)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
-
- draw_flush(nv10->draw);
-
- FIRE_RING(chan);
- if (fence)
- *fence = NULL;
-}
-
-static void
-nv10_destroy(struct pipe_context *pipe)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- if (nv10->draw)
- draw_destroy(nv10->draw);
-
- FREE(nv10);
-}
-
-static void nv10_init_hwctx(struct nv10_context *nv10)
-{
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- int i;
- float projectionmatrix[16];
-
- BEGIN_RING(chan, celsius, NV10TCL_DMA_NOTIFY, 1);
- OUT_RING (chan, screen->sync->handle);
- BEGIN_RING(chan, celsius, NV10TCL_DMA_IN_MEMORY0, 2);
- OUT_RING (chan, chan->vram->handle);
- OUT_RING (chan, chan->gart->handle);
- BEGIN_RING(chan, celsius, NV10TCL_DMA_IN_MEMORY2, 2);
- OUT_RING (chan, chan->vram->handle);
- OUT_RING (chan, chan->vram->handle);
-
- BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
- OUT_RING (chan, 0);
-
- BEGIN_RING(chan, celsius, NV10TCL_RT_HORIZ, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
-
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 1);
- OUT_RING (chan, (0x7ff<<16)|0x800);
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_VERT(0), 1);
- OUT_RING (chan, (0x7ff<<16)|0x800);
-
- for (i=1;i<8;i++) {
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(i), 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_VERT(i), 1);
- OUT_RING (chan, 0);
- }
-
- BEGIN_RING(chan, celsius, 0x290, 1);
- OUT_RING (chan, (0x10<<16)|1);
- BEGIN_RING(chan, celsius, 0x3f4, 1);
- OUT_RING (chan, 0);
-
- BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
- OUT_RING (chan, 0);
-
- if (nv10->screen->celsius->grclass != NV10TCL) {
- /* For nv11, nv17 */
- BEGIN_RING(chan, celsius, 0x120, 3);
- OUT_RING (chan, 0);
- OUT_RING (chan, 1);
- OUT_RING (chan, 2);
-
- BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
- OUT_RING (chan, 0);
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
- OUT_RING (chan, 0);
-
- /* Set state */
- BEGIN_RING(chan, celsius, NV10TCL_FOG_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_FUNC, 2);
- OUT_RING (chan, 0x207);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(0), 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
-
- BEGIN_RING(chan, celsius, NV10TCL_RC_IN_ALPHA(0), 12);
- OUT_RING (chan, 0x30141010);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0x20040000);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0x00000c00);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0x00000c00);
- OUT_RING (chan, 0x18000000);
- OUT_RING (chan, 0x300e0300);
- OUT_RING (chan, 0x0c091c80);
-
- BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_DITHER_ENABLE, 2);
- OUT_RING (chan, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_WEIGHT_ENABLE, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_SRC, 4);
- OUT_RING (chan, 1);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0x8006);
- BEGIN_RING(chan, celsius, NV10TCL_STENCIL_MASK, 8);
- OUT_RING (chan, 0xff);
- OUT_RING (chan, 0x207);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0xff);
- OUT_RING (chan, 0x1e00);
- OUT_RING (chan, 0x1e00);
- OUT_RING (chan, 0x1e00);
- OUT_RING (chan, 0x1d01);
- BEGIN_RING(chan, celsius, NV10TCL_NORMALIZE_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_FOG_ENABLE, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_COLOR_CONTROL, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_ENABLED_LIGHTS, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_FUNC, 1);
- OUT_RING (chan, 0x201);
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_WRITE_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_TEST_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_FACTOR, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_POINT_SIZE, 1);
- OUT_RING (chan, 8);
- BEGIN_RING(chan, celsius, NV10TCL_POINT_PARAMETERS_ENABLE, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_LINE_WIDTH, 1);
- OUT_RING (chan, 8);
- BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
- OUT_RING (chan, 0x1b02);
- OUT_RING (chan, 0x1b02);
- BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE, 2);
- OUT_RING (chan, 0x405);
- OUT_RING (chan, 0x901);
- BEGIN_RING(chan, celsius, NV10TCL_POLYGON_SMOOTH_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE_ENABLE, 1);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_TX_GEN_S(0), 8);
- for (i=0;i<8;i++) {
- OUT_RING (chan, 0);
- }
- BEGIN_RING(chan, celsius, NV10TCL_FOG_EQUATION_CONSTANT, 3);
- OUT_RING (chan, 0x3fc00000); /* -1.50 */
- OUT_RING (chan, 0xbdb8aa0a); /* -0.09 */
- OUT_RING (chan, 0); /* 0.00 */
-
- BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
- OUT_RING (chan, 0);
-
- BEGIN_RING(chan, celsius, NV10TCL_FOG_MODE, 2);
- OUT_RING (chan, 0x802);
- OUT_RING (chan, 2);
- /* for some reason VIEW_MATRIX_ENABLE need to be 6 instead of 4 when
- * using texturing, except when using the texture matrix
- */
- BEGIN_RING(chan, celsius, NV10TCL_VIEW_MATRIX_ENABLE, 1);
- OUT_RING (chan, 6);
- BEGIN_RING(chan, celsius, NV10TCL_COLOR_MASK, 1);
- OUT_RING (chan, 0x01010101);
-
- /* Set vertex component */
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_COL_4F_R, 4);
- OUT_RINGf (chan, 1.0);
- OUT_RINGf (chan, 1.0);
- OUT_RINGf (chan, 1.0);
- OUT_RINGf (chan, 1.0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_COL2_3F_R, 3);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_NOR_3F_X, 3);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0);
- OUT_RINGf (chan, 1.0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_TX0_4F_S, 4);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 1.0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_TX1_4F_S, 4);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 1.0);
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_FOG_1F, 1);
- OUT_RINGf (chan, 0.0);
- BEGIN_RING(chan, celsius, NV10TCL_EDGEFLAG_ENABLE, 1);
- OUT_RING (chan, 1);
-
- memset(projectionmatrix, 0, sizeof(projectionmatrix));
- BEGIN_RING(chan, celsius, NV10TCL_PROJECTION_MATRIX(0), 16);
- projectionmatrix[0*4+0] = 1.0;
- projectionmatrix[1*4+1] = 1.0;
- projectionmatrix[2*4+2] = 1.0;
- projectionmatrix[3*4+3] = 1.0;
- for (i=0;i<16;i++) {
- OUT_RINGf (chan, projectionmatrix[i]);
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_RANGE_NEAR, 2);
- OUT_RING (chan, 0.0);
- OUT_RINGf (chan, 16777216.0);
-
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_TRANSLATE_X, 4);
- OUT_RINGf (chan, -2048.0);
- OUT_RINGf (chan, -2048.0);
- OUT_RINGf (chan, 16777215.0 * 0.5);
- OUT_RING (chan, 0);
-
- FIRE_RING (chan);
-}
-
-struct pipe_context *
-nv10_create(struct pipe_screen *pscreen, unsigned pctx_id)
-{
- struct nv10_screen *screen = nv10_screen(pscreen);
- struct pipe_winsys *ws = pscreen->winsys;
- struct nv10_context *nv10;
- struct nouveau_winsys *nvws = screen->nvws;
-
- nv10 = CALLOC(1, sizeof(struct nv10_context));
- if (!nv10)
- return NULL;
- nv10->screen = screen;
- nv10->pctx_id = pctx_id;
-
- nv10->nvws = nvws;
-
- nv10->pipe.winsys = ws;
- nv10->pipe.screen = pscreen;
- nv10->pipe.destroy = nv10_destroy;
- nv10->pipe.draw_arrays = nv10_draw_arrays;
- nv10->pipe.draw_elements = nv10_draw_elements;
- nv10->pipe.clear = nv10_clear;
- nv10->pipe.flush = nv10_flush;
-
- nv10->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nv10->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
- nv10_init_surface_functions(nv10);
- nv10_init_state_functions(nv10);
-
- nv10->draw = draw_create();
- assert(nv10->draw);
- draw_set_rasterize_stage(nv10->draw, nv10_draw_vbuf_stage(nv10));
-
- nv10_init_hwctx(nv10);
-
- return &nv10->pipe;
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_context.h b/src/gallium/drivers/nv10/nv10_context.h
deleted file mode 100644
index ab4b825487..0000000000
--- a/src/gallium/drivers/nv10/nv10_context.h
+++ /dev/null
@@ -1,151 +0,0 @@
-#ifndef __NV10_CONTEXT_H__
-#define __NV10_CONTEXT_H__
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "pipe/p_compiler.h"
-
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "draw/draw_vertex.h"
-
-#include "nouveau/nouveau_winsys.h"
-#include "nouveau/nouveau_gldefs.h"
-#include "nouveau/nouveau_context.h"
-
-#include "nv10_state.h"
-
-#define NOUVEAU_ERR(fmt, args...) \
- fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
-#define NOUVEAU_MSG(fmt, args...) \
- fprintf(stderr, "nouveau: "fmt, ##args);
-
-#define NV10_NEW_VERTPROG (1 << 0)
-#define NV10_NEW_FRAGPROG (1 << 1)
-#define NV10_NEW_VTXARRAYS (1 << 2)
-#define NV10_NEW_BLEND (1 << 3)
-#define NV10_NEW_BLENDCOL (1 << 4)
-#define NV10_NEW_RAST (1 << 5)
-#define NV10_NEW_DSA (1 << 6)
-#define NV10_NEW_VIEWPORT (1 << 7)
-#define NV10_NEW_SCISSOR (1 << 8)
-#define NV10_NEW_FRAMEBUFFER (1 << 9)
-
-#include "nv10_screen.h"
-
-struct nv10_context {
- struct pipe_context pipe;
-
- struct nouveau_winsys *nvws;
- struct nv10_screen *screen;
- unsigned pctx_id;
-
- struct draw_context *draw;
-
- uint32_t dirty;
-
- struct nv10_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
- struct nv10_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
- unsigned dirty_samplers;
- unsigned fp_samplers;
- unsigned vp_samplers;
-
- uint32_t rt_enable;
- struct pipe_buffer *rt[4];
- struct pipe_buffer *zeta;
- uint32_t lma_offset;
-
- struct nv10_blend_state *blend;
- struct pipe_blend_color *blend_color;
- struct nv10_rasterizer_state *rast;
- struct nv10_depth_stencil_alpha_state *dsa;
- struct pipe_viewport_state *viewport;
- struct pipe_scissor_state *scissor;
- struct pipe_framebuffer_state *framebuffer;
-
- //struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
- float *constbuf[PIPE_SHADER_TYPES][32][4];
- unsigned constbuf_nr[PIPE_SHADER_TYPES];
-
- struct vertex_info vertex_info;
-
- struct {
- struct pipe_buffer *buffer;
- uint32_t format;
- } tex[2];
-
- unsigned vb_enable;
- struct {
- struct pipe_buffer *buffer;
- unsigned delta;
- } vb[16];
-
-/* struct {
-
- struct nouveau_resource *exec_heap;
- struct nouveau_resource *data_heap;
-
- struct nv10_vertex_program *active;
-
- struct nv10_vertex_program *current;
- } vertprog;
-*/
- struct {
- struct nv10_fragment_program *active;
-
- struct nv10_fragment_program *current;
- struct pipe_buffer *constant_buf;
- } fragprog;
-
- struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
- struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
-};
-
-static INLINE struct nv10_context *
-nv10_context(struct pipe_context *pipe)
-{
- return (struct nv10_context *)pipe;
-}
-
-extern void nv10_init_state_functions(struct nv10_context *nv10);
-extern void nv10_init_surface_functions(struct nv10_context *nv10);
-
-extern void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen);
-
-/* nv10_clear.c */
-extern void nv10_clear(struct pipe_context *pipe, unsigned buffers,
- const float *rgba, double depth, unsigned stencil);
-
-
-/* nv10_draw.c */
-extern struct draw_stage *nv10_draw_render_stage(struct nv10_context *nv10);
-
-/* nv10_fragprog.c */
-extern void nv10_fragprog_bind(struct nv10_context *,
- struct nv10_fragment_program *);
-extern void nv10_fragprog_destroy(struct nv10_context *,
- struct nv10_fragment_program *);
-
-/* nv10_fragtex.c */
-extern void nv10_fragtex_bind(struct nv10_context *);
-
-/* nv10_prim_vbuf.c */
-struct draw_stage *nv10_draw_vbuf_stage( struct nv10_context *nv10 );
-extern void nv10_vtxbuf_bind(struct nv10_context* nv10);
-
-/* nv10_state.c and friends */
-extern void nv10_emit_hw_state(struct nv10_context *nv10);
-extern void nv10_state_tex_update(struct nv10_context *nv10);
-
-/* nv10_vbo.c */
-extern void nv10_draw_arrays(struct pipe_context *, unsigned mode,
- unsigned start, unsigned count);
-extern void nv10_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count);
-
-
-#endif
diff --git a/src/gallium/drivers/nv10/nv10_fragprog.c b/src/gallium/drivers/nv10/nv10_fragprog.c
deleted file mode 100644
index 698db5a16a..0000000000
--- a/src/gallium/drivers/nv10/nv10_fragprog.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-
-#include "pipe/p_shader_tokens.h"
-#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_util.h"
-
-#include "nv10_context.h"
-
-void
-nv10_fragprog_bind(struct nv10_context *nv10, struct nv10_fragment_program *fp)
-{
-}
-
-void
-nv10_fragprog_destroy(struct nv10_context *nv10,
- struct nv10_fragment_program *fp)
-{
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_fragtex.c b/src/gallium/drivers/nv10/nv10_fragtex.c
deleted file mode 100644
index c1f7ccb9ab..0000000000
--- a/src/gallium/drivers/nv10/nv10_fragtex.c
+++ /dev/null
@@ -1,130 +0,0 @@
-#include "nv10_context.h"
-#include "nouveau/nouveau_util.h"
-
-#define _(m,tf) \
-{ \
- TRUE, \
- PIPE_FORMAT_##m, \
- NV10TCL_TX_FORMAT_FORMAT_##tf, \
-}
-
-struct nv10_texture_format {
- boolean defined;
- uint pipe;
- int format;
-};
-
-static struct nv10_texture_format
-nv10_texture_formats[] = {
- _(A8R8G8B8_UNORM, A8R8G8B8),
- _(A1R5G5B5_UNORM, A1R5G5B5),
- _(A4R4G4B4_UNORM, A4R4G4B4),
- _(L8_UNORM , L8 ),
- _(A8_UNORM , A8 ),
- _(A8L8_UNORM , A8L8 ),
-// _(RGB_DXT1 , DXT1, ),
-// _(RGBA_DXT1 , DXT1, ),
-// _(RGBA_DXT3 , DXT3, ),
-// _(RGBA_DXT5 , DXT5, ),
- {},
-};
-
-static struct nv10_texture_format *
-nv10_fragtex_format(uint pipe_format)
-{
- struct nv10_texture_format *tf = nv10_texture_formats;
-
- while (tf->defined) {
- if (tf->pipe == pipe_format)
- return tf;
- tf++;
- }
-
- return NULL;
-}
-
-
-static void
-nv10_fragtex_build(struct nv10_context *nv10, int unit)
-{
-#if 0
- struct nv10_sampler_state *ps = nv10->tex_sampler[unit];
- struct nv10_miptree *nv10mt = nv10->tex_miptree[unit];
- struct pipe_texture *pt = &nv10mt->base;
- struct nv10_texture_format *tf;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- uint32_t txf, txs, txp;
-
- tf = nv10_fragtex_format(pt->format);
- if (!tf || !tf->defined) {
- NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format);
- return;
- }
-
- txf = tf->format << 8;
- txf |= (pt->last_level + 1) << 16;
- txf |= log2i(pt->width0) << 20;
- txf |= log2i(pt->height0) << 24;
- txf |= log2i(pt->depth0) << 28;
- txf |= 8;
-
- switch (pt->target) {
- case PIPE_TEXTURE_CUBE:
- txf |= NV10TCL_TX_FORMAT_CUBE_MAP;
- /* fall-through */
- case PIPE_TEXTURE_2D:
- txf |= (2<<4);
- break;
- case PIPE_TEXTURE_1D:
- txf |= (1<<4);
- break;
- default:
- NOUVEAU_ERR("Unknown target %d\n", pt->target);
- return;
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_TX_OFFSET(unit), 8);
- OUT_RELOCl(chan, nouveau_bo(nv10mt->buffer), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- OUT_RELOCd(chan, nouveau_bo(nv10mt->buffer),txf,NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
- OUT_RING (chan, ps->wrap);
- OUT_RING (chan, 0x40000000); /* enable */
- OUT_RING (chan, txs);
- OUT_RING (chan, ps->filt | 0x2000 /* magic */);
- OUT_RING (chan, (pt->width0 << 16) | pt->height0);
- OUT_RING (chan, ps->bcol);
-#endif
-}
-
-void
-nv10_fragtex_bind(struct nv10_context *nv10)
-{
-#if 0
- struct nv10_fragment_program *fp = nv10->fragprog.active;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- unsigned samplers, unit;
-
- samplers = nv10->fp_samplers & ~fp->samplers;
- while (samplers) {
- unit = ffs(samplers) - 1;
- samplers &= ~(1 << unit);
-
- BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(unit), 1);
- OUT_RING (chan, 0);
- }
-
- samplers = nv10->dirty_samplers & fp->samplers;
- while (samplers) {
- unit = ffs(samplers) - 1;
- samplers &= ~(1 << unit);
-
- nv10_fragtex_build(nv10, unit);
- }
-
- nv10->fp_samplers = fp->samplers;
-#endif
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_miptree.c b/src/gallium/drivers/nv10/nv10_miptree.c
deleted file mode 100644
index 908482ad85..0000000000
--- a/src/gallium/drivers/nv10/nv10_miptree.c
+++ /dev/null
@@ -1,165 +0,0 @@
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-
-#include "nv10_context.h"
-#include "nv10_screen.h"
-
-static void
-nv10_miptree_layout(struct nv10_miptree *nv10mt)
-{
- struct pipe_texture *pt = &nv10mt->base;
- boolean swizzled = FALSE;
- uint width = pt->width0;
- uint offset = 0;
- int nr_faces, l, f;
-
- if (pt->target == PIPE_TEXTURE_CUBE) {
- nr_faces = 6;
- } else {
- nr_faces = 1;
- }
-
- for (l = 0; l <= pt->last_level; l++) {
- if (swizzled)
- nv10mt->level[l].pitch = util_format_get_stride(pt->format, width);
- else
- nv10mt->level[l].pitch = util_format_get_stride(pt->format, pt->width0);
- nv10mt->level[l].pitch = (nv10mt->level[l].pitch + 63) & ~63;
-
- nv10mt->level[l].image_offset =
- CALLOC(nr_faces, sizeof(unsigned));
-
- width = u_minify(width, 1);
-
- }
-
- for (f = 0; f < nr_faces; f++) {
- for (l = 0; l <= pt->last_level; l++) {
- nv10mt->level[l].image_offset[f] = offset;
- offset += nv10mt->level[l].pitch * u_minify(pt->height0, l);
- }
- }
-
- nv10mt->total_size = offset;
-}
-
-static struct pipe_texture *
-nv10_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
- const unsigned *stride, struct pipe_buffer *pb)
-{
- struct nv10_miptree *mt;
-
- /* Only supports 2D, non-mipmapped textures for the moment */
- if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
- pt->depth0 != 1)
- return NULL;
-
- mt = CALLOC_STRUCT(nv10_miptree);
- if (!mt)
- return NULL;
-
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
- mt->level[0].pitch = stride[0];
- mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
-
- pipe_buffer_reference(&mt->buffer, pb);
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
-}
-
-static struct pipe_texture *
-nv10_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
-{
- struct nv10_miptree *mt;
-
- mt = MALLOC(sizeof(struct nv10_miptree));
- if (!mt)
- return NULL;
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = screen;
-
- nv10_miptree_layout(mt);
-
- mt->buffer = screen->buffer_create(screen, 256, PIPE_BUFFER_USAGE_PIXEL,
- mt->total_size);
- if (!mt->buffer) {
- FREE(mt);
- return NULL;
- }
- mt->bo = nouveau_bo(mt->buffer);
-
- return &mt->base;
-}
-
-static void
-nv10_miptree_destroy(struct pipe_texture *pt)
-{
- struct nv10_miptree *nv10mt = (struct nv10_miptree *)pt;
- int l;
-
- pipe_buffer_reference(&nv10mt->buffer, NULL);
- for (l = 0; l <= pt->last_level; l++) {
- if (nv10mt->level[l].image_offset)
- FREE(nv10mt->level[l].image_offset);
- }
- FREE(nv10mt);
-}
-
-static void
-nv10_miptree_update(struct pipe_context *pipe, struct pipe_texture *mt,
- uint face, uint levels)
-{
-}
-
-
-static struct pipe_surface *
-nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
-{
- struct nv10_miptree *nv10mt = (struct nv10_miptree *)pt;
- struct nv04_surface *ns;
-
- ns = CALLOC_STRUCT(nv04_surface);
- if (!ns)
- return NULL;
- pipe_texture_reference(&ns->base.texture, pt);
- ns->base.format = pt->format;
- ns->base.width = u_minify(pt->width0, level);
- ns->base.height = u_minify(pt->height0, level);
- ns->base.usage = flags;
- pipe_reference_init(&ns->base.reference, 1);
- ns->base.face = face;
- ns->base.level = level;
- ns->base.zslice = zslice;
- ns->pitch = nv10mt->level[level].pitch;
-
- if (pt->target == PIPE_TEXTURE_CUBE) {
- ns->base.offset = nv10mt->level[level].image_offset[face];
- } else {
- ns->base.offset = nv10mt->level[level].image_offset[0];
- }
-
- return &ns->base;
-}
-
-static void
-nv10_miptree_surface_destroy(struct pipe_surface *surface)
-{
-}
-
-void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen)
-{
- pscreen->texture_create = nv10_miptree_create;
- pscreen->texture_blanket = nv10_miptree_blanket;
- pscreen->texture_destroy = nv10_miptree_destroy;
- pscreen->get_tex_surface = nv10_miptree_surface_get;
- pscreen->tex_surface_destroy = nv10_miptree_surface_destroy;
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_prim_vbuf.c b/src/gallium/drivers/nv10/nv10_prim_vbuf.c
deleted file mode 100644
index c5dbe43dbc..0000000000
--- a/src/gallium/drivers/nv10/nv10_prim_vbuf.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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
- * without limitation the rights to use, copy, modify, merge, publish,
- * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * 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.
- *
- **************************************************************************/
-
-/**
- * \file
- * Build post-transformation, post-clipping vertex buffers and element
- * lists by hooking into the end of the primitive pipeline and
- * manipulating the vertex_id field in the vertex headers.
- *
- * XXX: work in progress
- *
- * \author José Fonseca <jrfonseca@tungstengraphics.com>
- * \author Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-#include "util/u_debug.h"
-#include "pipe/p_inlines.h"
-
-#include "nv10_context.h"
-#include "nv10_state.h"
-
-#include "draw/draw_vbuf.h"
-
-/**
- * Primitive renderer for nv10.
- */
-struct nv10_vbuf_render {
- struct vbuf_render base;
-
- struct nv10_context *nv10;
-
- /** Vertex buffer */
- struct pipe_buffer* buffer;
-
- /** Vertex size in bytes */
- unsigned vertex_size;
-
- /** Hardware primitive */
- unsigned hwprim;
-};
-
-
-void nv10_vtxbuf_bind( struct nv10_context* nv10 )
-{
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- int i;
- for(i = 0; i < 8; i++) {
- BEGIN_RING(chan, celsius, NV10TCL_VTXBUF_ADDRESS(i), 1);
- OUT_RING(chan, 0/*nv10->vtxbuf*/);
- BEGIN_RING(chan, celsius, NV10TCL_VTXFMT(i), 1);
- OUT_RING(chan, 0/*XXX*/);
- }
-}
-
-/**
- * Basically a cast wrapper.
- */
-static INLINE struct nv10_vbuf_render *
-nv10_vbuf_render( struct vbuf_render *render )
-{
- assert(render);
- return (struct nv10_vbuf_render *)render;
-}
-
-
-static const struct vertex_info *
-nv10_vbuf_render_get_vertex_info( struct vbuf_render *render )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- struct nv10_context *nv10 = nv10_render->nv10;
-
- nv10_emit_hw_state(nv10);
-
- return &nv10->vertex_info;
-}
-
-static boolean
-nv10_vbuf_render_allocate_vertices( struct vbuf_render *render,
- ushort vertex_size,
- ushort nr_vertices )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- struct nv10_context *nv10 = nv10_render->nv10;
- struct pipe_screen *screen = nv10->pipe.screen;
- size_t size = (size_t)vertex_size * (size_t)nr_vertices;
-
- assert(!nv10_render->buffer);
- nv10_render->buffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_VERTEX, size);
-
- nv10->dirty |= NV10_NEW_VTXARRAYS;
-
- if (nv10_render->buffer)
- return FALSE;
- return TRUE;
-}
-
-static void *
-nv10_vbuf_render_map_vertices( struct vbuf_render *render )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- struct nv10_context *nv10 = nv10_render->nv10;
- struct pipe_screen *pscreen = nv10->pipe.screen;
-
- return pipe_buffer_map(pscreen, nv10_render->buffer,
- PIPE_BUFFER_USAGE_CPU_WRITE);
-}
-
-static void
-nv10_vbuf_render_unmap_vertices( struct vbuf_render *render,
- ushort min_index,
- ushort max_index )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- struct nv10_context *nv10 = nv10_render->nv10;
- struct pipe_screen *pscreen = nv10->pipe.screen;
-
- assert(!nv10_render->buffer);
- pipe_buffer_unmap(pscreen, nv10_render->buffer);
-}
-
-static boolean
-nv10_vbuf_render_set_primitive( struct vbuf_render *render,
- unsigned prim )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- unsigned hwp = nvgl_primitive(prim);
- if (hwp == 0)
- return FALSE;
-
- nv10_render->hwprim = hwp;
- return TRUE;
-}
-
-
-static void
-nv10_vbuf_render_draw( struct vbuf_render *render,
- const ushort *indices,
- uint nr_indices)
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- struct nv10_context *nv10 = nv10_render->nv10;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- int push, i;
-
- nv10_emit_hw_state(nv10);
-
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_OFFSET_POS, 1);
- OUT_RELOCl(chan, nouveau_bo(nv10_render->buffer), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
-
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1);
- OUT_RING(chan, nv10_render->hwprim);
-
- if (nr_indices & 1) {
- BEGIN_RING(chan, celsius, NV10TCL_VB_ELEMENT_U32, 1);
- OUT_RING (chan, indices[0]);
- indices++; nr_indices--;
- }
-
- while (nr_indices) {
- // XXX too big/small ? check the size
- push = MIN2(nr_indices, 1200 * 2);
-
- BEGIN_RING_NI(chan, celsius, NV10TCL_VB_ELEMENT_U16, push >> 1);
- for (i = 0; i < push; i+=2)
- OUT_RING(chan, (indices[i+1] << 16) | indices[i]);
-
- nr_indices -= push;
- indices += push;
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1);
- OUT_RING (chan, 0);
-}
-
-
-static void
-nv10_vbuf_render_release_vertices( struct vbuf_render *render )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
-
- assert(nv10_render->buffer);
- pipe_buffer_reference(&nv10_render->buffer, NULL);
-}
-
-
-static void
-nv10_vbuf_render_destroy( struct vbuf_render *render )
-{
- struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render);
- FREE(nv10_render);
-}
-
-
-/**
- * Create a new primitive render.
- */
-static struct vbuf_render *
-nv10_vbuf_render_create( struct nv10_context *nv10 )
-{
- struct nv10_vbuf_render *nv10_render = CALLOC_STRUCT(nv10_vbuf_render);
-
- nv10_render->nv10 = nv10;
-
- nv10_render->base.max_vertex_buffer_bytes = 16*1024;
- nv10_render->base.max_indices = 1024;
- nv10_render->base.get_vertex_info = nv10_vbuf_render_get_vertex_info;
- nv10_render->base.allocate_vertices = nv10_vbuf_render_allocate_vertices;
- nv10_render->base.map_vertices = nv10_vbuf_render_map_vertices;
- nv10_render->base.unmap_vertices = nv10_vbuf_render_unmap_vertices;
- nv10_render->base.set_primitive = nv10_vbuf_render_set_primitive;
- nv10_render->base.draw = nv10_vbuf_render_draw;
- nv10_render->base.release_vertices = nv10_vbuf_render_release_vertices;
- nv10_render->base.destroy = nv10_vbuf_render_destroy;
-
- return &nv10_render->base;
-}
-
-
-/**
- * Create a new primitive vbuf/render stage.
- */
-struct draw_stage *nv10_draw_vbuf_stage( struct nv10_context *nv10 )
-{
- struct vbuf_render *render;
- struct draw_stage *stage;
-
- render = nv10_vbuf_render_create(nv10);
- if(!render)
- return NULL;
-
- stage = draw_vbuf_stage( nv10->draw, render );
- if(!stage) {
- render->destroy(render);
- return NULL;
- }
-
- return stage;
-}
diff --git a/src/gallium/drivers/nv10/nv10_screen.c b/src/gallium/drivers/nv10/nv10_screen.c
deleted file mode 100644
index 4e6bc12994..0000000000
--- a/src/gallium/drivers/nv10/nv10_screen.c
+++ /dev/null
@@ -1,208 +0,0 @@
-#include "pipe/p_screen.h"
-
-#include "nv10_context.h"
-#include "nv10_screen.h"
-
-static int
-nv10_screen_get_param(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
- return 2;
- case PIPE_CAP_NPOT_TEXTURES:
- return 0;
- case PIPE_CAP_TWO_SIDED_STENCIL:
- return 0;
- case PIPE_CAP_GLSL:
- return 0;
- case PIPE_CAP_ANISOTROPIC_FILTER:
- return 1;
- case PIPE_CAP_POINT_SPRITE:
- return 0;
- case PIPE_CAP_MAX_RENDER_TARGETS:
- return 1;
- case PIPE_CAP_OCCLUSION_QUERY:
- return 0;
- case PIPE_CAP_TEXTURE_SHADOW_MAP:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
- return 12;
- case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
- return 12;
- case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
- return 0;
- case PIPE_CAP_TGSI_CONT_SUPPORTED:
- return 0;
- case PIPE_CAP_BLEND_EQUATION_SEPARATE:
- return 0;
- case NOUVEAU_CAP_HW_VTXBUF:
- case NOUVEAU_CAP_HW_IDXBUF:
- return 0;
- case PIPE_CAP_INDEP_BLEND_ENABLE:
- return 0;
- case PIPE_CAP_INDEP_BLEND_FUNC:
- return 0;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
- return 1;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
- return 0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0;
- }
-}
-
-static float
-nv10_screen_get_paramf(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_LINE_WIDTH:
- case PIPE_CAP_MAX_LINE_WIDTH_AA:
- return 10.0;
- case PIPE_CAP_MAX_POINT_WIDTH:
- case PIPE_CAP_MAX_POINT_WIDTH_AA:
- return 64.0;
- case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
- return 2.0;
- case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
- return 4.0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0.0;
- }
-}
-
-static boolean
-nv10_screen_is_format_supported(struct pipe_screen *screen,
- enum pipe_format format,
- enum pipe_texture_target target,
- unsigned tex_usage, unsigned geom_flags)
-{
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- return TRUE;
- default:
- break;
- }
- } else
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
- switch (format) {
- case PIPE_FORMAT_Z24S8_UNORM:
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z16_UNORM:
- return TRUE;
- default:
- break;
- }
- } else {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- case PIPE_FORMAT_A4R4G4B4_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_A8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- return TRUE;
- default:
- break;
- }
- }
-
- return FALSE;
-}
-
-static void
-nv10_screen_destroy(struct pipe_screen *pscreen)
-{
- struct nv10_screen *screen = nv10_screen(pscreen);
-
- nouveau_notifier_free(&screen->sync);
- nouveau_grobj_free(&screen->celsius);
- nv04_surface_2d_takedown(&screen->eng2d);
-
- nouveau_screen_fini(&screen->base);
-
- FREE(pscreen);
-}
-
-static struct pipe_buffer *
-nv10_surface_buffer(struct pipe_surface *surf)
-{
- struct nv10_miptree *mt = (struct nv10_miptree *)surf->texture;
-
- return mt->buffer;
-}
-
-struct pipe_screen *
-nv10_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
-{
- struct nv10_screen *screen = CALLOC_STRUCT(nv10_screen);
- struct nouveau_channel *chan;
- struct pipe_screen *pscreen;
- unsigned celsius_class;
- int ret;
-
- if (!screen)
- return NULL;
- pscreen = &screen->base.base;
-
- ret = nouveau_screen_init(&screen->base, dev);
- if (ret) {
- nv10_screen_destroy(pscreen);
- return NULL;
- }
- chan = screen->base.channel;
-
- pscreen->winsys = ws;
- pscreen->destroy = nv10_screen_destroy;
- pscreen->get_param = nv10_screen_get_param;
- pscreen->get_paramf = nv10_screen_get_paramf;
- pscreen->is_format_supported = nv10_screen_is_format_supported;
-
- nv10_screen_init_miptree_functions(pscreen);
- nv10_screen_init_transfer_functions(pscreen);
-
- /* 3D object */
- if (dev->chipset >= 0x20)
- celsius_class = NV11TCL;
- else if (dev->chipset >= 0x17)
- celsius_class = NV17TCL;
- else if (dev->chipset >= 0x11)
- celsius_class = NV11TCL;
- else
- celsius_class = NV10TCL;
-
- if (!celsius_class) {
- NOUVEAU_ERR("Unknown nv1x chipset: nv%02x\n", dev->chipset);
- return NULL;
- }
-
- ret = nouveau_grobj_alloc(chan, 0xbeef0001, celsius_class,
- &screen->celsius);
- if (ret) {
- NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
- return FALSE;
- }
-
- /* 2D engine setup */
- screen->eng2d = nv04_surface_2d_init(&screen->base);
- screen->eng2d->buf = nv10_surface_buffer;
-
- /* Notifier for sync purposes */
- ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync);
- if (ret) {
- NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
- nv10_screen_destroy(pscreen);
- return NULL;
- }
-
- return pscreen;
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_screen.h b/src/gallium/drivers/nv10/nv10_screen.h
deleted file mode 100644
index 86b6d8def5..0000000000
--- a/src/gallium/drivers/nv10/nv10_screen.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __NV10_SCREEN_H__
-#define __NV10_SCREEN_H__
-
-#include "nouveau/nouveau_screen.h"
-#include "nv04/nv04_surface_2d.h"
-
-struct nv10_screen {
- struct nouveau_screen base;
-
- struct nouveau_winsys *nvws;
-
- /* HW graphics objects */
- struct nv04_surface_2d *eng2d;
- struct nouveau_grobj *celsius;
- struct nouveau_notifier *sync;
-};
-
-static INLINE struct nv10_screen *
-nv10_screen(struct pipe_screen *screen)
-{
- return (struct nv10_screen *)screen;
-}
-
-
-void
-nv10_screen_init_transfer_functions(struct pipe_screen *pscreen);
-
-#endif
diff --git a/src/gallium/drivers/nv10/nv10_state.c b/src/gallium/drivers/nv10/nv10_state.c
deleted file mode 100644
index 9aafc60411..0000000000
--- a/src/gallium/drivers/nv10/nv10_state.c
+++ /dev/null
@@ -1,590 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_shader_tokens.h"
-#include "pipe/p_inlines.h"
-
-#include "tgsi/tgsi_parse.h"
-
-#include "nv10_context.h"
-#include "nv10_state.h"
-
-static void *
-nv10_blend_state_create(struct pipe_context *pipe,
- const struct pipe_blend_state *cso)
-{
- struct nv10_blend_state *cb;
-
- cb = MALLOC(sizeof(struct nv10_blend_state));
-
- cb->b_enable = cso->rt[0].blend_enable ? 1 : 0;
- cb->b_srcfunc = ((nvgl_blend_func(cso->rt[0].alpha_src_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_src_factor)));
- cb->b_dstfunc = ((nvgl_blend_func(cso->rt[0].alpha_dst_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_dst_factor)));
-
- cb->c_mask = (((cso->rt[0].colormask & PIPE_MASK_A) ? (0x01<<24) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_R) ? (0x01<<16) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_G) ? (0x01<< 8) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_B) ? (0x01<< 0) : 0));
-
- cb->d_enable = cso->dither ? 1 : 0;
-
- return (void *)cb;
-}
-
-static void
-nv10_blend_state_bind(struct pipe_context *pipe, void *blend)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->blend = (struct nv10_blend_state*)blend;
-
- nv10->dirty |= NV10_NEW_BLEND;
-}
-
-static void
-nv10_blend_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-
-static INLINE unsigned
-wrap_mode(unsigned wrap) {
- unsigned ret;
-
- switch (wrap) {
- case PIPE_TEX_WRAP_REPEAT:
- ret = NV10TCL_TX_FORMAT_WRAP_S_REPEAT;
- break;
- case PIPE_TEX_WRAP_MIRROR_REPEAT:
- ret = NV10TCL_TX_FORMAT_WRAP_S_MIRRORED_REPEAT;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- ret = NV10TCL_TX_FORMAT_WRAP_S_CLAMP_TO_EDGE;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
- ret = NV10TCL_TX_FORMAT_WRAP_S_CLAMP_TO_BORDER;
- break;
- case PIPE_TEX_WRAP_CLAMP:
- ret = NV10TCL_TX_FORMAT_WRAP_S_CLAMP;
- break;
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
- case PIPE_TEX_WRAP_MIRROR_CLAMP:
- default:
- NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
- ret = NV10TCL_TX_FORMAT_WRAP_S_REPEAT;
- break;
- }
-
- return ret >> NV10TCL_TX_FORMAT_WRAP_S_SHIFT;
-}
-
-static void *
-nv10_sampler_state_create(struct pipe_context *pipe,
- const struct pipe_sampler_state *cso)
-{
- struct nv10_sampler_state *ps;
- uint32_t filter = 0;
-
- ps = MALLOC(sizeof(struct nv10_sampler_state));
-
- ps->wrap = ((wrap_mode(cso->wrap_s) << NV10TCL_TX_FORMAT_WRAP_S_SHIFT) |
- (wrap_mode(cso->wrap_t) << NV10TCL_TX_FORMAT_WRAP_T_SHIFT));
-
- ps->en = 0;
- if (cso->max_anisotropy > 1.0) {
- /* no idea, binary driver sets it, works without it.. meh.. */
- ps->wrap |= (1 << 5);
-
-/* if (cso->max_anisotropy >= 16.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_16X;
- } else
- if (cso->max_anisotropy >= 12.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_12X;
- } else
- if (cso->max_anisotropy >= 10.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_10X;
- } else
- if (cso->max_anisotropy >= 8.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_8X;
- } else
- if (cso->max_anisotropy >= 6.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_6X;
- } else
- if (cso->max_anisotropy >= 4.0) {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_4X;
- } else {
- ps->en |= NV10TCL_TX_ENABLE_ANISO_2X;
- }*/
- }
-
- switch (cso->mag_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- filter |= NV10TCL_TX_FILTER_MAGNIFY_LINEAR;
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- filter |= NV10TCL_TX_FILTER_MAGNIFY_NEAREST;
- break;
- }
-
- switch (cso->min_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |= NV10TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |= NV10TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV10TCL_TX_FILTER_MINIFY_LINEAR;
- break;
- }
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |= NV10TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |= NV10TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV10TCL_TX_FILTER_MINIFY_NEAREST;
- break;
- }
- break;
- }
-
- ps->filt = filter;
-
-/* if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
- switch (cso->compare_func) {
- case PIPE_FUNC_NEVER:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_NEVER;
- break;
- case PIPE_FUNC_GREATER:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_GREATER;
- break;
- case PIPE_FUNC_EQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_EQUAL;
- break;
- case PIPE_FUNC_GEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_GEQUAL;
- break;
- case PIPE_FUNC_LESS:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_LESS;
- break;
- case PIPE_FUNC_NOTEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_NOTEQUAL;
- break;
- case PIPE_FUNC_LEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_LEQUAL;
- break;
- case PIPE_FUNC_ALWAYS:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_ALWAYS;
- break;
- default:
- break;
- }
- }*/
-
- ps->bcol = ((float_to_ubyte(cso->border_color[3]) << 24) |
- (float_to_ubyte(cso->border_color[0]) << 16) |
- (float_to_ubyte(cso->border_color[1]) << 8) |
- (float_to_ubyte(cso->border_color[2]) << 0));
-
- return (void *)ps;
-}
-
-static void
-nv10_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv10->tex_sampler[unit] = sampler[unit];
- nv10->dirty_samplers |= (1 << unit);
- }
-}
-
-static void
-nv10_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void
-nv10_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
- struct pipe_texture **miptree)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv10->tex_miptree[unit] = (struct nv10_miptree *)miptree[unit];
- nv10->dirty_samplers |= (1 << unit);
- }
-}
-
-static void *
-nv10_rasterizer_state_create(struct pipe_context *pipe,
- const struct pipe_rasterizer_state *cso)
-{
- struct nv10_rasterizer_state *rs;
- int i;
-
- /*XXX: ignored:
- * light_twoside
- * offset_cw/ccw -nohw
- * scissor
- * point_smooth -nohw
- * multisample
- * offset_units / offset_scale
- */
- rs = MALLOC(sizeof(struct nv10_rasterizer_state));
-
- rs->templ = cso;
-
- rs->shade_model = cso->flatshade ? 0x1d00 : 0x1d01;
-
- rs->line_width = (unsigned char)(cso->line_width * 8.0) & 0xff;
- rs->line_smooth_en = cso->line_smooth ? 1 : 0;
-
- rs->point_size = *(uint32_t*)&cso->point_size;
-
- rs->poly_smooth_en = cso->poly_smooth ? 1 : 0;
-
- if (cso->front_winding == PIPE_WINDING_CCW) {
- rs->front_face = NV10TCL_FRONT_FACE_CCW;
- rs->poly_mode_front = nvgl_polygon_mode(cso->fill_ccw);
- rs->poly_mode_back = nvgl_polygon_mode(cso->fill_cw);
- } else {
- rs->front_face = NV10TCL_FRONT_FACE_CW;
- rs->poly_mode_front = nvgl_polygon_mode(cso->fill_cw);
- rs->poly_mode_back = nvgl_polygon_mode(cso->fill_ccw);
- }
-
- switch (cso->cull_mode) {
- case PIPE_WINDING_CCW:
- rs->cull_face_en = 1;
- if (cso->front_winding == PIPE_WINDING_CCW)
- rs->cull_face = NV10TCL_CULL_FACE_FRONT;
- else
- rs->cull_face = NV10TCL_CULL_FACE_BACK;
- break;
- case PIPE_WINDING_CW:
- rs->cull_face_en = 1;
- if (cso->front_winding == PIPE_WINDING_CW)
- rs->cull_face = NV10TCL_CULL_FACE_FRONT;
- else
- rs->cull_face = NV10TCL_CULL_FACE_BACK;
- break;
- case PIPE_WINDING_BOTH:
- rs->cull_face_en = 1;
- rs->cull_face = NV10TCL_CULL_FACE_FRONT_AND_BACK;
- break;
- case PIPE_WINDING_NONE:
- default:
- rs->cull_face_en = 0;
- rs->cull_face = 0;
- break;
- }
-
- if (cso->point_sprite) {
- rs->point_sprite = (1 << 0);
- for (i = 0; i < 8; i++) {
- if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
- rs->point_sprite |= (1 << (8 + i));
- }
- } else {
- rs->point_sprite = 0;
- }
-
- return (void *)rs;
-}
-
-static void
-nv10_rasterizer_state_bind(struct pipe_context *pipe, void *rast)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->rast = (struct nv10_rasterizer_state*)rast;
-
- draw_set_rasterizer_state(nv10->draw, (nv10->rast ? nv10->rast->templ : NULL));
-
- nv10->dirty |= NV10_NEW_RAST;
-}
-
-static void
-nv10_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void *
-nv10_depth_stencil_alpha_state_create(struct pipe_context *pipe,
- const struct pipe_depth_stencil_alpha_state *cso)
-{
- struct nv10_depth_stencil_alpha_state *hw;
-
- hw = MALLOC(sizeof(struct nv10_depth_stencil_alpha_state));
-
- hw->depth.func = nvgl_comparison_op(cso->depth.func);
- hw->depth.write_enable = cso->depth.writemask ? 1 : 0;
- hw->depth.test_enable = cso->depth.enabled ? 1 : 0;
-
- hw->stencil.enable = cso->stencil[0].enabled ? 1 : 0;
- hw->stencil.wmask = cso->stencil[0].writemask;
- hw->stencil.func = nvgl_comparison_op(cso->stencil[0].func);
- hw->stencil.ref = cso->stencil[0].ref_value;
- hw->stencil.vmask = cso->stencil[0].valuemask;
- hw->stencil.fail = nvgl_stencil_op(cso->stencil[0].fail_op);
- hw->stencil.zfail = nvgl_stencil_op(cso->stencil[0].zfail_op);
- hw->stencil.zpass = nvgl_stencil_op(cso->stencil[0].zpass_op);
-
- hw->alpha.enabled = cso->alpha.enabled ? 1 : 0;
- hw->alpha.func = nvgl_comparison_op(cso->alpha.func);
- hw->alpha.ref = float_to_ubyte(cso->alpha.ref_value);
-
- return (void *)hw;
-}
-
-static void
-nv10_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *dsa)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->dsa = (struct nv10_depth_stencil_alpha_state*)dsa;
-
- nv10->dirty |= NV10_NEW_DSA;
-}
-
-static void
-nv10_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void *
-nv10_vp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *templ)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- return draw_create_vertex_shader(nv10->draw, templ);
-}
-
-static void
-nv10_vp_state_bind(struct pipe_context *pipe, void *shader)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- draw_bind_vertex_shader(nv10->draw, (struct draw_vertex_shader *) shader);
-
- nv10->dirty |= NV10_NEW_VERTPROG;
-}
-
-static void
-nv10_vp_state_delete(struct pipe_context *pipe, void *shader)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- draw_delete_vertex_shader(nv10->draw, (struct draw_vertex_shader *) shader);
-}
-
-static void *
-nv10_fp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *cso)
-{
- struct nv10_fragment_program *fp;
-
- fp = CALLOC(1, sizeof(struct nv10_fragment_program));
- fp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
-
- tgsi_scan_shader(cso->tokens, &fp->info);
-
- return (void *)fp;
-}
-
-static void
-nv10_fp_state_bind(struct pipe_context *pipe, void *hwcso)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct nv10_fragment_program *fp = hwcso;
-
- nv10->fragprog.current = fp;
- nv10->dirty |= NV10_NEW_FRAGPROG;
-}
-
-static void
-nv10_fp_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct nv10_fragment_program *fp = hwcso;
-
- nv10_fragprog_destroy(nv10, fp);
- FREE((void*)fp->pipe.tokens);
- FREE(fp);
-}
-
-static void
-nv10_set_blend_color(struct pipe_context *pipe,
- const struct pipe_blend_color *bcol)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->blend_color = (struct pipe_blend_color*)bcol;
-
- nv10->dirty |= NV10_NEW_BLENDCOL;
-}
-
-static void
-nv10_set_clip_state(struct pipe_context *pipe,
- const struct pipe_clip_state *clip)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- draw_set_clip_state(nv10->draw, clip);
-}
-
-static void
-nv10_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
- struct pipe_buffer *buf )
-{
- struct nv10_context *nv10 = nv10_context(pipe);
- struct pipe_screen *pscreen = pipe->screen;
-
- assert(shader < PIPE_SHADER_TYPES);
- assert(index == 0);
-
- if (buf) {
- void *mapped;
- if (buf->size &&
- (mapped = pipe_buffer_map(pscreen, buf, PIPE_BUFFER_USAGE_CPU_READ)))
- {
- memcpy(nv10->constbuf[shader], mapped, buf->size);
- nv10->constbuf_nr[shader] =
- buf->size / (4 * sizeof(float));
- pipe_buffer_unmap(pscreen, buf);
- }
- }
-}
-
-static void
-nv10_set_framebuffer_state(struct pipe_context *pipe,
- const struct pipe_framebuffer_state *fb)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->framebuffer = (struct pipe_framebuffer_state*)fb;
-
- nv10->dirty |= NV10_NEW_FRAMEBUFFER;
-}
-
-static void
-nv10_set_polygon_stipple(struct pipe_context *pipe,
- const struct pipe_poly_stipple *stipple)
-{
- NOUVEAU_ERR("line stipple hahaha\n");
-}
-
-static void
-nv10_set_scissor_state(struct pipe_context *pipe,
- const struct pipe_scissor_state *s)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->scissor = (struct pipe_scissor_state*)s;
-
- nv10->dirty |= NV10_NEW_SCISSOR;
-}
-
-static void
-nv10_set_viewport_state(struct pipe_context *pipe,
- const struct pipe_viewport_state *vpt)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- nv10->viewport = (struct pipe_viewport_state*)vpt;
-
- draw_set_viewport_state(nv10->draw, nv10->viewport);
-
- nv10->dirty |= NV10_NEW_VIEWPORT;
-}
-
-static void
-nv10_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_buffer *vb)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- memcpy(nv10->vtxbuf, vb, sizeof(*vb) * count);
- nv10->dirty |= NV10_NEW_VTXARRAYS;
-
- draw_set_vertex_buffers(nv10->draw, count, vb);
-}
-
-static void
-nv10_set_vertex_elements(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_element *ve)
-{
- struct nv10_context *nv10 = nv10_context(pipe);
-
- memcpy(nv10->vtxelt, ve, sizeof(*ve) * count);
- nv10->dirty |= NV10_NEW_VTXARRAYS;
-
- draw_set_vertex_elements(nv10->draw, count, ve);
-}
-
-void
-nv10_init_state_functions(struct nv10_context *nv10)
-{
- nv10->pipe.create_blend_state = nv10_blend_state_create;
- nv10->pipe.bind_blend_state = nv10_blend_state_bind;
- nv10->pipe.delete_blend_state = nv10_blend_state_delete;
-
- nv10->pipe.create_sampler_state = nv10_sampler_state_create;
- nv10->pipe.bind_fragment_sampler_states = nv10_sampler_state_bind;
- nv10->pipe.delete_sampler_state = nv10_sampler_state_delete;
- nv10->pipe.set_fragment_sampler_textures = nv10_set_sampler_texture;
-
- nv10->pipe.create_rasterizer_state = nv10_rasterizer_state_create;
- nv10->pipe.bind_rasterizer_state = nv10_rasterizer_state_bind;
- nv10->pipe.delete_rasterizer_state = nv10_rasterizer_state_delete;
-
- nv10->pipe.create_depth_stencil_alpha_state =
- nv10_depth_stencil_alpha_state_create;
- nv10->pipe.bind_depth_stencil_alpha_state =
- nv10_depth_stencil_alpha_state_bind;
- nv10->pipe.delete_depth_stencil_alpha_state =
- nv10_depth_stencil_alpha_state_delete;
-
- nv10->pipe.create_vs_state = nv10_vp_state_create;
- nv10->pipe.bind_vs_state = nv10_vp_state_bind;
- nv10->pipe.delete_vs_state = nv10_vp_state_delete;
-
- nv10->pipe.create_fs_state = nv10_fp_state_create;
- nv10->pipe.bind_fs_state = nv10_fp_state_bind;
- nv10->pipe.delete_fs_state = nv10_fp_state_delete;
-
- nv10->pipe.set_blend_color = nv10_set_blend_color;
- nv10->pipe.set_clip_state = nv10_set_clip_state;
- nv10->pipe.set_constant_buffer = nv10_set_constant_buffer;
- nv10->pipe.set_framebuffer_state = nv10_set_framebuffer_state;
- nv10->pipe.set_polygon_stipple = nv10_set_polygon_stipple;
- nv10->pipe.set_scissor_state = nv10_set_scissor_state;
- nv10->pipe.set_viewport_state = nv10_set_viewport_state;
-
- nv10->pipe.set_vertex_buffers = nv10_set_vertex_buffers;
- nv10->pipe.set_vertex_elements = nv10_set_vertex_elements;
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_state.h b/src/gallium/drivers/nv10/nv10_state.h
deleted file mode 100644
index 2524ac02e2..0000000000
--- a/src/gallium/drivers/nv10/nv10_state.h
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifndef __NV10_STATE_H__
-#define __NV10_STATE_H__
-
-#include "pipe/p_state.h"
-#include "tgsi/tgsi_scan.h"
-
-struct nv10_blend_state {
- uint32_t b_enable;
- uint32_t b_srcfunc;
- uint32_t b_dstfunc;
-
- uint32_t c_mask;
-
- uint32_t d_enable;
-};
-
-struct nv10_sampler_state {
- uint32_t wrap;
- uint32_t en;
- uint32_t filt;
- uint32_t bcol;
-};
-
-struct nv10_rasterizer_state {
- uint32_t shade_model;
-
- uint32_t line_width;
- uint32_t line_smooth_en;
-
- uint32_t point_size;
-
- uint32_t poly_smooth_en;
-
- uint32_t poly_mode_front;
- uint32_t poly_mode_back;
-
- uint32_t front_face;
- uint32_t cull_face;
- uint32_t cull_face_en;
-
- uint32_t point_sprite;
-
- const struct pipe_rasterizer_state *templ;
-};
-
-struct nv10_vertex_program_exec {
- uint32_t data[4];
- boolean has_branch_offset;
- int const_index;
-};
-
-struct nv10_vertex_program_data {
- int index; /* immediates == -1 */
- float value[4];
-};
-
-struct nv10_vertex_program {
- const struct pipe_shader_state *pipe;
-
- boolean translated;
- struct nv10_vertex_program_exec *insns;
- unsigned nr_insns;
- struct nv10_vertex_program_data *consts;
- unsigned nr_consts;
-
- struct nouveau_resource *exec;
- unsigned exec_start;
- struct nouveau_resource *data;
- unsigned data_start;
- unsigned data_start_min;
-
- uint32_t ir;
- uint32_t or;
-};
-
-struct nv10_fragment_program_data {
- unsigned offset;
- unsigned index;
-};
-
-struct nv10_fragment_program {
- struct pipe_shader_state pipe;
- struct tgsi_shader_info info;
-
- boolean translated;
- boolean on_hw;
- unsigned samplers;
-
- uint32_t *insn;
- int insn_len;
-
- struct nv10_fragment_program_data *consts;
- unsigned nr_consts;
-
- struct pipe_buffer *buffer;
-
- uint32_t fp_control;
- uint32_t fp_reg_control;
-};
-
-
-struct nv10_depth_stencil_alpha_state {
- struct {
- uint32_t func;
- uint32_t write_enable;
- uint32_t test_enable;
- } depth;
-
- struct {
- uint32_t enable;
- uint32_t wmask;
- uint32_t func;
- uint32_t ref;
- uint32_t vmask;
- uint32_t fail;
- uint32_t zfail;
- uint32_t zpass;
- } stencil;
-
- struct {
- uint32_t enabled;
- uint32_t func;
- uint32_t ref;
- } alpha;
-};
-
-struct nv10_miptree {
- struct pipe_texture base;
- struct nouveau_bo *bo;
-
- struct pipe_buffer *buffer;
- uint total_size;
-
- struct {
- uint pitch;
- uint *image_offset;
- } level[PIPE_MAX_TEXTURE_LEVELS];
-};
-
-#endif
diff --git a/src/gallium/drivers/nv10/nv10_state_emit.c b/src/gallium/drivers/nv10/nv10_state_emit.c
deleted file mode 100644
index 30a596ca60..0000000000
--- a/src/gallium/drivers/nv10/nv10_state_emit.c
+++ /dev/null
@@ -1,333 +0,0 @@
-#include "nv10_context.h"
-#include "nv10_state.h"
-
-static void nv10_state_emit_blend(struct nv10_context* nv10)
-{
- struct nv10_blend_state *b = nv10->blend;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
-
- BEGIN_RING(chan, celsius, NV10TCL_DITHER_ENABLE, 1);
- OUT_RING (chan, b->d_enable);
-
- BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_ENABLE, 3);
- OUT_RING (chan, b->b_enable);
- OUT_RING (chan, b->b_srcfunc);
- OUT_RING (chan, b->b_dstfunc);
-
- BEGIN_RING(chan, celsius, NV10TCL_COLOR_MASK, 1);
- OUT_RING (chan, b->c_mask);
-}
-
-static void nv10_state_emit_blend_color(struct nv10_context* nv10)
-{
- struct pipe_blend_color *c = nv10->blend_color;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
-
- BEGIN_RING(chan, celsius, NV10TCL_BLEND_COLOR, 1);
- OUT_RING (chan,
- (float_to_ubyte(c->color[3]) << 24)|
- (float_to_ubyte(c->color[0]) << 16)|
- (float_to_ubyte(c->color[1]) << 8) |
- (float_to_ubyte(c->color[2]) << 0));
-}
-
-static void nv10_state_emit_rast(struct nv10_context* nv10)
-{
- struct nv10_rasterizer_state *r = nv10->rast;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
-
- BEGIN_RING(chan, celsius, NV10TCL_SHADE_MODEL, 2);
- OUT_RING (chan, r->shade_model);
- OUT_RING (chan, r->line_width);
-
-
- BEGIN_RING(chan, celsius, NV10TCL_POINT_SIZE, 1);
- OUT_RING (chan, r->point_size);
-
- BEGIN_RING(chan, celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
- OUT_RING (chan, r->poly_mode_front);
- OUT_RING (chan, r->poly_mode_back);
-
-
- BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE, 2);
- OUT_RING (chan, r->cull_face);
- OUT_RING (chan, r->front_face);
-
- BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 2);
- OUT_RING (chan, r->line_smooth_en);
- OUT_RING (chan, r->poly_smooth_en);
-
- BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE_ENABLE, 1);
- OUT_RING (chan, r->cull_face_en);
-}
-
-static void nv10_state_emit_dsa(struct nv10_context* nv10)
-{
- struct nv10_depth_stencil_alpha_state *d = nv10->dsa;
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
-
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_FUNC, 1);
- OUT_RING (chan, d->depth.func);
-
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_WRITE_ENABLE, 1);
- OUT_RING (chan, d->depth.write_enable);
-
- BEGIN_RING(chan, celsius, NV10TCL_DEPTH_TEST_ENABLE, 1);
- OUT_RING (chan, d->depth.test_enable);
-
-#if 0
- BEGIN_RING(chan, celsius, NV10TCL_STENCIL_ENABLE, 1);
- OUT_RING (chan, d->stencil.enable);
- BEGIN_RING(chan, celsius, NV10TCL_STENCIL_MASK, 7);
- OUT_RINGp (chan, (uint32_t *)&(d->stencil.wmask), 7);
-#endif
-
- BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_ENABLE, 1);
- OUT_RING (chan, d->alpha.enabled);
-
- BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_FUNC, 1);
- OUT_RING (chan, d->alpha.func);
-
- BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_REF, 1);
- OUT_RING (chan, d->alpha.ref);
-}
-
-static void nv10_state_emit_viewport(struct nv10_context* nv10)
-{
-}
-
-static void nv10_state_emit_scissor(struct nv10_context* nv10)
-{
- // XXX this is so not working
-/* struct pipe_scissor_state *s = nv10->scissor;
- BEGIN_RING(celsius, NV10TCL_SCISSOR_HORIZ, 2);
- OUT_RING (((s->maxx - s->minx) << 16) | s->minx);
- OUT_RING (((s->maxy - s->miny) << 16) | s->miny);*/
-}
-
-static void nv10_state_emit_framebuffer(struct nv10_context* nv10)
-{
- struct pipe_framebuffer_state* fb = nv10->framebuffer;
- struct nv04_surface *rt, *zeta = NULL;
- uint32_t rt_format, w, h;
- int colour_format = 0, zeta_format = 0;
- struct nv10_miptree *nv10mt = 0;
-
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
-
- w = fb->cbufs[0]->width;
- h = fb->cbufs[0]->height;
- colour_format = fb->cbufs[0]->format;
- rt = (struct nv04_surface *)fb->cbufs[0];
-
- if (fb->zsbuf) {
- if (colour_format) {
- assert(w == fb->zsbuf->width);
- assert(h == fb->zsbuf->height);
- } else {
- w = fb->zsbuf->width;
- h = fb->zsbuf->height;
- }
-
- zeta_format = fb->zsbuf->format;
- zeta = (struct nv04_surface *)fb->zsbuf;
- }
-
- rt_format = NV10TCL_RT_FORMAT_TYPE_LINEAR;
-
- switch (colour_format) {
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- rt_format |= NV10TCL_RT_FORMAT_COLOR_X8R8G8B8;
- break;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case 0:
- rt_format |= NV10TCL_RT_FORMAT_COLOR_A8R8G8B8;
- break;
- case PIPE_FORMAT_R5G6B5_UNORM:
- rt_format |= NV10TCL_RT_FORMAT_COLOR_R5G6B5;
- break;
- default:
- assert(0);
- }
-
- if (zeta) {
- BEGIN_RING(chan, celsius, NV10TCL_RT_PITCH, 1);
- OUT_RING (chan, rt->pitch | (zeta->pitch << 16));
- } else {
- BEGIN_RING(chan, celsius, NV10TCL_RT_PITCH, 1);
- OUT_RING (chan, rt->pitch | (rt->pitch << 16));
- }
-
- nv10mt = (struct nv10_miptree *)rt->base.texture;
- nv10->rt[0] = nv10mt->buffer;
-
- if (zeta_format)
- {
- nv10mt = (struct nv10_miptree *)zeta->base.texture;
- nv10->zeta = nv10mt->buffer;
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_RT_HORIZ, 3);
- OUT_RING (chan, (w << 16) | 0);
- OUT_RING (chan, (h << 16) | 0);
- OUT_RING (chan, rt_format);
- BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 2);
- OUT_RING (chan, ((w - 1) << 16) | 0 | 0x08000800);
- OUT_RING (chan, ((h - 1) << 16) | 0 | 0x08000800);
-}
-
-static void nv10_vertex_layout(struct nv10_context *nv10)
-{
- struct nv10_fragment_program *fp = nv10->fragprog.current;
- uint32_t src = 0;
- int i;
- struct vertex_info vinfo;
-
- memset(&vinfo, 0, sizeof(vinfo));
-
- for (i = 0; i < fp->info.num_inputs; i++) {
- switch (fp->info.input_semantic_name[i]) {
- case TGSI_SEMANTIC_POSITION:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
- break;
- case TGSI_SEMANTIC_COLOR:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
- break;
- default:
- case TGSI_SEMANTIC_GENERIC:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
- break;
- case TGSI_SEMANTIC_FOG:
- draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
- break;
- }
- }
- draw_compute_vertex_size(&vinfo);
-}
-
-void
-nv10_emit_hw_state(struct nv10_context *nv10)
-{
- struct nv10_screen *screen = nv10->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *celsius = screen->celsius;
- struct nouveau_bo *rt_bo;
- int i;
-
- if (nv10->dirty & NV10_NEW_VERTPROG) {
- //nv10_vertprog_bind(nv10, nv10->vertprog.current);
- nv10->dirty &= ~NV10_NEW_VERTPROG;
- }
-
- if (nv10->dirty & NV10_NEW_FRAGPROG) {
- nv10_fragprog_bind(nv10, nv10->fragprog.current);
- /*XXX: clear NV10_NEW_FRAGPROG if no new program uploaded */
- nv10->dirty_samplers |= (1<<10);
- nv10->dirty_samplers = 0;
- }
-
- if (nv10->dirty_samplers || (nv10->dirty & NV10_NEW_FRAGPROG)) {
- nv10_fragtex_bind(nv10);
- nv10->dirty &= ~NV10_NEW_FRAGPROG;
- }
-
- if (nv10->dirty & NV10_NEW_VTXARRAYS) {
- nv10->dirty &= ~NV10_NEW_VTXARRAYS;
- nv10_vertex_layout(nv10);
- nv10_vtxbuf_bind(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_BLEND) {
- nv10->dirty &= ~NV10_NEW_BLEND;
- nv10_state_emit_blend(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_BLENDCOL) {
- nv10->dirty &= ~NV10_NEW_BLENDCOL;
- nv10_state_emit_blend_color(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_RAST) {
- nv10->dirty &= ~NV10_NEW_RAST;
- nv10_state_emit_rast(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_DSA) {
- nv10->dirty &= ~NV10_NEW_DSA;
- nv10_state_emit_dsa(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_VIEWPORT) {
- nv10->dirty &= ~NV10_NEW_VIEWPORT;
- nv10_state_emit_viewport(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_SCISSOR) {
- nv10->dirty &= ~NV10_NEW_SCISSOR;
- nv10_state_emit_scissor(nv10);
- }
-
- if (nv10->dirty & NV10_NEW_FRAMEBUFFER) {
- nv10->dirty &= ~NV10_NEW_FRAMEBUFFER;
- nv10_state_emit_framebuffer(nv10);
- }
-
- /* Emit relocs for every referenced buffer.
- * This is to ensure the bufmgr has an accurate idea of how
- * the buffer is used. This isn't very efficient, but we don't
- * seem to take a significant performance hit. Will be improved
- * at some point. Vertex arrays are emitted by nv10_vbo.c
- */
-
- /* Render target */
- rt_bo = nouveau_bo(nv10->rt[0]);
-// XXX figre out who's who for NV10TCL_DMA_* and fill accordingly
-// BEGIN_RING(chan, celsius, NV10TCL_DMA_COLOR0, 1);
-// OUT_RELOCo(chan, rt_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, celsius, NV10TCL_COLOR_OFFSET, 1);
- OUT_RELOCl(chan, rt_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
-
- if (nv10->zeta) {
- struct nouveau_bo *zeta_bo = nouveau_bo(nv10->zeta);
-// XXX
-// BEGIN_RING(chan, celsius, NV10TCL_DMA_ZETA, 1);
-// OUT_RELOCo(chan, zeta_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, celsius, NV10TCL_ZETA_OFFSET, 1);
- OUT_RELOCl(chan, zeta_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- /* XXX for when we allocate LMA on nv17 */
-/* BEGIN_RING(chan, celsius, NV10TCL_LMA_DEPTH_BUFFER_OFFSET, 1);
- OUT_RELOCl(chan, nouveau_bo(nv10->zeta + lma_offset));*/
- }
-
- /* Vertex buffer */
- BEGIN_RING(chan, celsius, NV10TCL_DMA_VTXBUF0, 1);
- OUT_RELOCo(chan, rt_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, celsius, NV10TCL_COLOR_OFFSET, 1);
- OUT_RELOCl(chan, rt_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
-
- /* Texture images */
- for (i = 0; i < 2; i++) {
- if (!(nv10->fp_samplers & (1 << i)))
- continue;
- struct nouveau_bo *bo = nouveau_bo(nv10->tex[i].buffer);
- BEGIN_RING(chan, celsius, NV10TCL_TX_OFFSET(i), 1);
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM |
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- BEGIN_RING(chan, celsius, NV10TCL_TX_FORMAT(i), 1);
- OUT_RELOCd(chan, bo, nv10->tex[i].format,
- NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
- NOUVEAU_BO_OR, NV10TCL_TX_FORMAT_DMA0,
- NV10TCL_TX_FORMAT_DMA1);
- }
-}
-
diff --git a/src/gallium/drivers/nv10/nv10_transfer.c b/src/gallium/drivers/nv10/nv10_transfer.c
deleted file mode 100644
index eb04af9782..0000000000
--- a/src/gallium/drivers/nv10/nv10_transfer.c
+++ /dev/null
@@ -1,178 +0,0 @@
-#include <pipe/p_state.h>
-#include <pipe/p_defines.h>
-#include <pipe/p_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
-#include <util/u_math.h>
-#include <nouveau/nouveau_winsys.h>
-#include "nv10_context.h"
-#include "nv10_screen.h"
-#include "nv10_state.h"
-
-struct nv10_transfer {
- struct pipe_transfer base;
- struct pipe_surface *surface;
- boolean direct;
-};
-
-static void
-nv10_compatible_transfer_tex(struct pipe_texture *pt, unsigned width, unsigned height,
- struct pipe_texture *template)
-{
- memset(template, 0, sizeof(struct pipe_texture));
- template->target = pt->target;
- template->format = pt->format;
- template->width0 = width;
- template->height0 = height;
- template->depth0 = 1;
- template->last_level = 0;
- template->nr_samples = pt->nr_samples;
-
- template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
- NOUVEAU_TEXTURE_USAGE_LINEAR;
-}
-
-static struct pipe_transfer *
-nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
-{
- struct nv10_miptree *mt = (struct nv10_miptree *)pt;
- struct nv10_transfer *tx;
- struct pipe_texture tx_tex_template, *tx_tex;
-
- tx = CALLOC_STRUCT(nv10_transfer);
- if (!tx)
- return NULL;
-
- pipe_texture_reference(&tx->base.texture, pt);
- tx->base.x = x;
- tx->base.y = y;
- tx->base.width = w;
- tx->base.height = h;
- tx->base.stride = mt->level[level].pitch;
- tx->base.usage = usage;
- tx->base.face = face;
- tx->base.level = level;
- tx->base.zslice = zslice;
-
- /* Direct access to texture */
- if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC ||
- debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/)) &&
- pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)
- {
- tx->direct = true;
- tx->surface = pscreen->get_tex_surface(pscreen, pt,
- 0, 0, 0,
- pipe_transfer_buffer_flags(&tx->base));
- return &tx->base;
- }
-
- tx->direct = false;
-
- nv10_compatible_transfer_tex(pt, w, h, &tx_tex_template);
-
- tx_tex = pscreen->texture_create(pscreen, &tx_tex_template);
- if (!tx_tex)
- {
- FREE(tx);
- return NULL;
- }
-
- tx->base.stride = ((struct nv10_miptree*)tx_tex)->level[0].pitch;
-
- tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
- face, level, zslice,
- pipe_transfer_buffer_flags(&tx->base));
-
- pipe_texture_reference(&tx_tex, NULL);
-
- if (!tx->surface)
- {
- pipe_surface_reference(&tx->surface, NULL);
- FREE(tx);
- return NULL;
- }
-
- if (usage & PIPE_TRANSFER_READ) {
- struct nv10_screen *nvscreen = nv10_screen(pscreen);
- struct pipe_surface *src;
-
- src = pscreen->get_tex_surface(pscreen, pt,
- face, level, zslice,
- PIPE_BUFFER_USAGE_GPU_READ);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- /* TODO: Check if SIFM can un-swizzle */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- tx->surface, 0, 0,
- src, x, y,
- w, h);
-
- pipe_surface_reference(&src, NULL);
- }
-
- return &tx->base;
-}
-
-static void
-nv10_transfer_del(struct pipe_transfer *ptx)
-{
- struct nv10_transfer *tx = (struct nv10_transfer *)ptx;
-
- if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
- struct pipe_screen *pscreen = ptx->texture->screen;
- struct nv10_screen *nvscreen = nv10_screen(pscreen);
- struct pipe_surface *dst;
-
- dst = pscreen->get_tex_surface(pscreen, ptx->texture,
- ptx->face, ptx->level, ptx->zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- dst, tx->base.x, tx->base.y,
- tx->surface, 0, 0,
- tx->base.width, tx->base.height);
-
- pipe_surface_reference(&dst, NULL);
- }
-
- pipe_surface_reference(&tx->surface, NULL);
- pipe_texture_reference(&ptx->texture, NULL);
- FREE(ptx);
-}
-
-static void *
-nv10_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv10_transfer *tx = (struct nv10_transfer *)ptx;
- struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
- struct nv10_miptree *mt = (struct nv10_miptree *)tx->surface->texture;
- void *map = pipe_buffer_map(pscreen, mt->buffer,
- pipe_transfer_buffer_flags(ptx));
-
- if(!tx->direct)
- return map + ns->base.offset;
- else
- return map + ns->base.offset + ptx->y * ns->pitch + ptx->x * util_format_get_blocksize(ptx->texture->format);
-}
-
-static void
-nv10_transfer_unmap(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv10_transfer *tx = (struct nv10_transfer *)ptx;
- struct nv10_miptree *mt = (struct nv10_miptree *)tx->surface->texture;
-
- pipe_buffer_unmap(pscreen, mt->buffer);
-}
-
-void
-nv10_screen_init_transfer_functions(struct pipe_screen *pscreen)
-{
- pscreen->get_tex_transfer = nv10_transfer_new;
- pscreen->tex_transfer_destroy = nv10_transfer_del;
- pscreen->transfer_map = nv10_transfer_map;
- pscreen->transfer_unmap = nv10_transfer_unmap;
-}
diff --git a/src/gallium/drivers/nv10/nv10_vbo.c b/src/gallium/drivers/nv10/nv10_vbo.c
deleted file mode 100644
index da5c93f081..0000000000
--- a/src/gallium/drivers/nv10/nv10_vbo.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-#include "nv10_context.h"
-#include "nv10_state.h"
-
-#include "nouveau/nouveau_channel.h"
-#include "nouveau/nouveau_pushbuf.h"
-
-void nv10_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count)
-{
- struct nv10_context *nv10 = nv10_context( pipe );
- struct draw_context *draw = nv10->draw;
- struct pipe_screen *pscreen = pipe->screen;
- unsigned i;
-
- nv10_emit_hw_state(nv10);
-
- /*
- * Map vertex buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv10->vtxbuf[i].buffer) {
- void *buf =
- pipe_buffer_map(pscreen, nv10->vtxbuf[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_vertex_buffer(draw, i, buf);
- }
- }
- /* Map index buffer, if present */
- if (indexBuffer) {
- void *mapped_indexes
- = pipe_buffer_map(pscreen, indexBuffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
- }
- else {
- /* no index/element buffer */
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-
- draw_set_mapped_constant_buffer(draw,
- PIPE_SHADER_VERTEX,
- 0,
- nv10->constbuf[PIPE_SHADER_VERTEX],
- nv10->constbuf_nr[PIPE_SHADER_VERTEX]);
-
- /* draw! */
- draw_arrays(nv10->draw, prim, start, count);
-
- /*
- * unmap vertex/index buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv10->vtxbuf[i].buffer) {
- pipe_buffer_unmap(pscreen, nv10->vtxbuf[i].buffer);
- draw_set_mapped_vertex_buffer(draw, i, NULL);
- }
- }
- if (indexBuffer) {
- pipe_buffer_unmap(pscreen, indexBuffer);
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-}
-
-void nv10_draw_arrays( struct pipe_context *pipe,
- unsigned prim, unsigned start, unsigned count)
-{
- nv10_draw_elements(pipe, NULL, 0, prim, start, count);
-}
-
-
-
diff --git a/src/gallium/drivers/nv20/Makefile b/src/gallium/drivers/nv20/Makefile
deleted file mode 100644
index 1305f26c59..0000000000
--- a/src/gallium/drivers/nv20/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-TOP = ../../../..
-include $(TOP)/configs/current
-
-LIBNAME = nv20
-
-C_SOURCES = \
- nv20_clear.c \
- nv20_context.c \
- nv20_fragprog.c \
- nv20_fragtex.c \
- nv20_miptree.c \
- nv20_prim_vbuf.c \
- nv20_screen.c \
- nv20_state.c \
- nv20_state_emit.c \
- nv20_surface.c \
- nv20_transfer.c \
- nv20_vbo.c
-# nv20_vertprog.c
-
-include ../../Makefile.template
diff --git a/src/gallium/drivers/nv20/nv20_clear.c b/src/gallium/drivers/nv20/nv20_clear.c
deleted file mode 100644
index 2b4490fa5e..0000000000
--- a/src/gallium/drivers/nv20/nv20_clear.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "util/u_clear.h"
-
-#include "nv20_context.h"
-
-void
-nv20_clear(struct pipe_context *pipe, unsigned buffers,
- const float *rgba, double depth, unsigned stencil)
-{
- util_clear(pipe, nv20_context(pipe)->framebuffer, buffers, rgba, depth,
- stencil);
-}
diff --git a/src/gallium/drivers/nv20/nv20_context.h b/src/gallium/drivers/nv20/nv20_context.h
deleted file mode 100644
index c7dfadaa31..0000000000
--- a/src/gallium/drivers/nv20/nv20_context.h
+++ /dev/null
@@ -1,150 +0,0 @@
-#ifndef __NV20_CONTEXT_H__
-#define __NV20_CONTEXT_H__
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "pipe/p_compiler.h"
-
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "draw/draw_vertex.h"
-
-#include "nouveau/nouveau_winsys.h"
-#include "nouveau/nouveau_gldefs.h"
-#include "nouveau/nouveau_context.h"
-
-#include "nv20_state.h"
-
-#define NOUVEAU_ERR(fmt, args...) \
- fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
-#define NOUVEAU_MSG(fmt, args...) \
- fprintf(stderr, "nouveau: "fmt, ##args);
-
-#define NV20_NEW_VERTPROG (1 << 0)
-#define NV20_NEW_FRAGPROG (1 << 1)
-#define NV20_NEW_VTXARRAYS (1 << 2)
-#define NV20_NEW_BLEND (1 << 3)
-#define NV20_NEW_BLENDCOL (1 << 4)
-#define NV20_NEW_RAST (1 << 5)
-#define NV20_NEW_DSA (1 << 6)
-#define NV20_NEW_VIEWPORT (1 << 7)
-#define NV20_NEW_SCISSOR (1 << 8)
-#define NV20_NEW_FRAMEBUFFER (1 << 9)
-
-#include "nv20_screen.h"
-
-struct nv20_context {
- struct pipe_context pipe;
-
- struct nouveau_winsys *nvws;
- struct nv20_screen *screen;
- unsigned pctx_id;
-
- struct draw_context *draw;
-
- uint32_t dirty;
-
- struct nv20_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
- struct nv20_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
- unsigned dirty_samplers;
- unsigned fp_samplers;
- unsigned vp_samplers;
-
- uint32_t rt_enable;
- struct pipe_buffer *rt[4];
- struct pipe_buffer *zeta;
- uint32_t lma_offset;
-
- struct nv20_blend_state *blend;
- struct pipe_blend_color *blend_color;
- struct nv20_rasterizer_state *rast;
- struct nv20_depth_stencil_alpha_state *dsa;
- struct pipe_viewport_state *viewport;
- struct pipe_scissor_state *scissor;
- struct pipe_framebuffer_state *framebuffer;
-
- //struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
- float *constbuf[PIPE_SHADER_TYPES][32][4];
- unsigned constbuf_nr[PIPE_SHADER_TYPES];
-
- struct vertex_info vertex_info;
-
- struct {
- struct pipe_buffer *buffer;
- uint32_t format;
- } tex[2];
-
- unsigned vb_enable;
- struct {
- struct pipe_buffer *buffer;
- unsigned delta;
- } vb[16];
-
-/* struct {
-
- struct nouveau_resource *exec_heap;
- struct nouveau_resource *data_heap;
-
- struct nv20_vertex_program *active;
-
- struct nv20_vertex_program *current;
- } vertprog;
-*/
- struct {
- struct nv20_fragment_program *active;
-
- struct nv20_fragment_program *current;
- struct pipe_buffer *constant_buf;
- } fragprog;
-
- struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
- struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
-};
-
-static INLINE struct nv20_context *
-nv20_context(struct pipe_context *pipe)
-{
- return (struct nv20_context *)pipe;
-}
-
-extern void nv20_init_state_functions(struct nv20_context *nv20);
-extern void nv20_init_surface_functions(struct nv20_context *nv20);
-
-extern void nv20_screen_init_miptree_functions(struct pipe_screen *pscreen);
-
-/* nv20_clear.c */
-extern void nv20_clear(struct pipe_context *pipe, unsigned buffers,
- const float *rgba, double depth, unsigned stencil);
-
-/* nv20_draw.c */
-extern struct draw_stage *nv20_draw_render_stage(struct nv20_context *nv20);
-
-/* nv20_fragprog.c */
-extern void nv20_fragprog_bind(struct nv20_context *,
- struct nv20_fragment_program *);
-extern void nv20_fragprog_destroy(struct nv20_context *,
- struct nv20_fragment_program *);
-
-/* nv20_fragtex.c */
-extern void nv20_fragtex_bind(struct nv20_context *);
-
-/* nv20_prim_vbuf.c */
-struct draw_stage *nv20_draw_vbuf_stage( struct nv20_context *nv20 );
-extern void nv20_vtxbuf_bind(struct nv20_context* nv20);
-
-/* nv20_state.c and friends */
-extern void nv20_emit_hw_state(struct nv20_context *nv20);
-extern void nv20_state_tex_update(struct nv20_context *nv20);
-
-/* nv20_vbo.c */
-extern void nv20_draw_arrays(struct pipe_context *, unsigned mode,
- unsigned start, unsigned count);
-extern void nv20_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count);
-
-
-#endif
diff --git a/src/gallium/drivers/nv20/nv20_fragprog.c b/src/gallium/drivers/nv20/nv20_fragprog.c
deleted file mode 100644
index 4f496369dd..0000000000
--- a/src/gallium/drivers/nv20/nv20_fragprog.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-
-#include "pipe/p_shader_tokens.h"
-#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_util.h"
-
-#include "nv20_context.h"
-
-void
-nv20_fragprog_bind(struct nv20_context *nv20, struct nv20_fragment_program *fp)
-{
-}
-
-void
-nv20_fragprog_destroy(struct nv20_context *nv20,
- struct nv20_fragment_program *fp)
-{
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_fragtex.c b/src/gallium/drivers/nv20/nv20_fragtex.c
deleted file mode 100644
index dedbec73f3..0000000000
--- a/src/gallium/drivers/nv20/nv20_fragtex.c
+++ /dev/null
@@ -1,130 +0,0 @@
-#include "nv20_context.h"
-#include "nouveau/nouveau_util.h"
-
-#define _(m,tf) \
-{ \
- TRUE, \
- PIPE_FORMAT_##m, \
- NV20TCL_TX_FORMAT_FORMAT_##tf, \
-}
-
-struct nv20_texture_format {
- boolean defined;
- uint pipe;
- int format;
-};
-
-static struct nv20_texture_format
-nv20_texture_formats[] = {
- _(A8R8G8B8_UNORM, A8R8G8B8),
- _(A1R5G5B5_UNORM, A1R5G5B5),
- _(A4R4G4B4_UNORM, A4R4G4B4),
- _(L8_UNORM , L8 ),
- _(A8_UNORM , A8 ),
- _(A8L8_UNORM , A8L8 ),
-/* _(RGB_DXT1 , DXT1, ), */
-/* _(RGBA_DXT1 , DXT1, ), */
-/* _(RGBA_DXT3 , DXT3, ), */
-/* _(RGBA_DXT5 , DXT5, ), */
- {},
-};
-
-static struct nv20_texture_format *
-nv20_fragtex_format(uint pipe_format)
-{
- struct nv20_texture_format *tf = nv20_texture_formats;
-
- while (tf->defined) {
- if (tf->pipe == pipe_format)
- return tf;
- tf++;
- }
-
- return NULL;
-}
-
-
-static void
-nv20_fragtex_build(struct nv20_context *nv20, int unit)
-{
-#if 0
- struct nv20_sampler_state *ps = nv20->tex_sampler[unit];
- struct nv20_miptree *nv20mt = nv20->tex_miptree[unit];
- struct pipe_texture *pt = &nv20mt->base;
- struct nv20_texture_format *tf;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- uint32_t txf, txs, txp;
-
- tf = nv20_fragtex_format(pt->format);
- if (!tf || !tf->defined) {
- NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format);
- return;
- }
-
- txf = tf->format << 8;
- txf |= (pt->last_level + 1) << 16;
- txf |= log2i(pt->width0) << 20;
- txf |= log2i(pt->height0) << 24;
- txf |= log2i(pt->depth0) << 28;
- txf |= 8;
-
- switch (pt->target) {
- case PIPE_TEXTURE_CUBE:
- txf |= NV10TCL_TX_FORMAT_CUBE_MAP;
- /* fall-through */
- case PIPE_TEXTURE_2D:
- txf |= (2<<4);
- break;
- case PIPE_TEXTURE_1D:
- txf |= (1<<4);
- break;
- default:
- NOUVEAU_ERR("Unknown target %d\n", pt->target);
- return;
- }
-
- BEGIN_RING(chan, kelvin, NV10TCL_TX_OFFSET(unit), 8);
- OUT_RELOCl(chan, nouveau_bo(nv20mt->buffer), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- OUT_RELOCd(chan, nouveau_bo(nv20mt->buffer),txf,NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
- OUT_RING (chan, ps->wrap);
- OUT_RING (chan, 0x40000000); /* enable */
- OUT_RING (chan, txs);
- OUT_RING (chan, ps->filt | 0x2000 /* magic */);
- OUT_RING (chan, (pt->width0 << 16) | pt->height0);
- OUT_RING (chan, ps->bcol);
-#endif
-}
-
-void
-nv20_fragtex_bind(struct nv20_context *nv20)
-{
-#if 0
- struct nv20_fragment_program *fp = nv20->fragprog.active;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- unsigned samplers, unit;
-
- samplers = nv20->fp_samplers & ~fp->samplers;
- while (samplers) {
- unit = ffs(samplers) - 1;
- samplers &= ~(1 << unit);
-
- BEGIN_RING(chan, kelvin, NV10TCL_TX_ENABLE(unit), 1);
- OUT_RING (chan, 0);
- }
-
- samplers = nv20->dirty_samplers & fp->samplers;
- while (samplers) {
- unit = ffs(samplers) - 1;
- samplers &= ~(1 << unit);
-
- nv20_fragtex_build(nv20, unit);
- }
-
- nv20->fp_samplers = fp->samplers;
-#endif
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_miptree.c b/src/gallium/drivers/nv20/nv20_miptree.c
deleted file mode 100644
index 8f7538e7f5..0000000000
--- a/src/gallium/drivers/nv20/nv20_miptree.c
+++ /dev/null
@@ -1,226 +0,0 @@
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-
-#include "nv20_context.h"
-#include "nv20_screen.h"
-#include "../nv04/nv04_surface_2d.h"
-
-static void
-nv20_miptree_layout(struct nv20_miptree *nv20mt)
-{
- struct pipe_texture *pt = &nv20mt->base;
- uint width = pt->width0;
- uint offset = 0;
- int nr_faces, l, f;
- uint wide_pitch = pt->tex_usage & (PIPE_TEXTURE_USAGE_SAMPLER |
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL |
- PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_PRIMARY);
-
- if (pt->target == PIPE_TEXTURE_CUBE) {
- nr_faces = 6;
- } else {
- nr_faces = 1;
- }
-
- for (l = 0; l <= pt->last_level; l++) {
- if (wide_pitch && (pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR))
- nv20mt->level[l].pitch = align(util_format_get_stride(pt->format, pt->width0), 64);
- else
- nv20mt->level[l].pitch = util_format_get_stride(pt->format, width);
-
- nv20mt->level[l].image_offset =
- CALLOC(nr_faces, sizeof(unsigned));
-
- width = u_minify(width, 1);
- }
-
- for (f = 0; f < nr_faces; f++) {
- for (l = 0; l < pt->last_level; l++) {
- nv20mt->level[l].image_offset[f] = offset;
-
- if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR) &&
- u_minify(pt->width0, l + 1) > 1 && u_minify(pt->height0, l + 1) > 1)
- offset += align(nv20mt->level[l].pitch * u_minify(pt->height0, l), 64);
- else
- offset += nv20mt->level[l].pitch * u_minify(pt->height0, l);
- }
-
- nv20mt->level[l].image_offset[f] = offset;
- offset += nv20mt->level[l].pitch * u_minify(pt->height0, l);
- }
-
- nv20mt->total_size = offset;
-}
-
-static struct pipe_texture *
-nv20_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
- const unsigned *stride, struct pipe_buffer *pb)
-{
- struct nv20_miptree *mt;
-
- /* Only supports 2D, non-mipmapped textures for the moment */
- if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
- pt->depth0 != 1)
- return NULL;
-
- mt = CALLOC_STRUCT(nv20_miptree);
- if (!mt)
- return NULL;
-
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
- mt->level[0].pitch = stride[0];
- mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
-
- pipe_buffer_reference(&mt->buffer, pb);
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
-}
-
-static struct pipe_texture *
-nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
-{
- struct nv20_miptree *mt;
- unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL |
- NOUVEAU_BUFFER_USAGE_TEXTURE;
-
- mt = MALLOC(sizeof(struct nv20_miptree));
- if (!mt)
- return NULL;
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = screen;
-
- /* Swizzled textures must be POT */
- if (pt->width0 & (pt->width0 - 1) ||
- pt->height0 & (pt->height0 - 1))
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
- else
- if (pt->tex_usage & (PIPE_TEXTURE_USAGE_PRIMARY |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL))
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
- else
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
- else {
- switch (pt->format) {
- /* TODO: Figure out which formats can be swizzled */
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- case PIPE_FORMAT_R16_SNORM:
- {
- if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE))
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
- break;
- }
- default:
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
- }
- }
-
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
- buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-
- /* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear.
- * If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy.
- * This also happens for small mipmaps of large textures. */
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET && util_format_get_stride(pt->format, pt->width0) < 64)
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
-
- nv20_miptree_layout(mt);
-
- mt->buffer = screen->buffer_create(screen, 256, buf_usage, mt->total_size);
- if (!mt->buffer) {
- FREE(mt);
- return NULL;
- }
- mt->bo = nouveau_bo(mt->buffer);
-
- return &mt->base;
-}
-
-static void
-nv20_miptree_destroy(struct pipe_texture *pt)
-{
- struct nv20_miptree *nv20mt = (struct nv20_miptree *)pt;
- int l;
-
- pipe_buffer_reference(&nv20mt->buffer, NULL);
- for (l = 0; l <= pt->last_level; l++) {
- if (nv20mt->level[l].image_offset)
- FREE(nv20mt->level[l].image_offset);
- }
-}
-
-static struct pipe_surface *
-nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
-{
- struct nv20_miptree *nv20mt = (struct nv20_miptree *)pt;
- struct nv04_surface *ns;
-
- ns = CALLOC_STRUCT(nv04_surface);
- if (!ns)
- return NULL;
- pipe_texture_reference(&ns->base.texture, pt);
- ns->base.format = pt->format;
- ns->base.width = u_minify(pt->width0, level);
- ns->base.height = u_minify(pt->height0, level);
- ns->base.usage = flags;
- pipe_reference_init(&ns->base.reference, 1);
- ns->base.face = face;
- ns->base.level = level;
- ns->base.zslice = zslice;
- ns->pitch = nv20mt->level[level].pitch;
-
- if (pt->target == PIPE_TEXTURE_CUBE) {
- ns->base.offset = nv20mt->level[level].image_offset[face];
- } else
- if (pt->target == PIPE_TEXTURE_3D) {
- ns->base.offset = nv20mt->level[level].image_offset[zslice];
- } else {
- ns->base.offset = nv20mt->level[level].image_offset[0];
- }
-
- /* create a linear temporary that we can render into if necessary.
- * Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so
- * ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/
- if((ns->pitch & 63) && (ns->base.usage & (PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER)) == PIPE_BUFFER_USAGE_GPU_WRITE)
- return &nv04_surface_wrap_for_render(screen, ((struct nv20_screen*)screen)->eng2d, ns)->base;
-
- return &ns->base;
-}
-
-static void
-nv20_miptree_surface_destroy(struct pipe_surface *ps)
-{
- struct nv04_surface* ns = (struct nv04_surface*)ps;
- if(ns->backing)
- {
- struct nv20_screen* screen = (struct nv20_screen*)ps->texture->screen;
- if(ns->backing->base.usage & PIPE_BUFFER_USAGE_GPU_WRITE)
- screen->eng2d->copy(screen->eng2d, &ns->backing->base, 0, 0, ps, 0, 0, ns->base.width, ns->base.height);
- nv20_miptree_surface_destroy(&ns->backing->base);
- }
-
- pipe_texture_reference(&ps->texture, NULL);
- FREE(ps);
-}
-
-void nv20_screen_init_miptree_functions(struct pipe_screen *pscreen)
-{
- pscreen->texture_create = nv20_miptree_create;
- pscreen->texture_blanket = nv20_miptree_blanket;
- pscreen->texture_destroy = nv20_miptree_destroy;
- pscreen->get_tex_surface = nv20_miptree_surface_get;
- pscreen->tex_surface_destroy = nv20_miptree_surface_destroy;
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_prim_vbuf.c b/src/gallium/drivers/nv20/nv20_prim_vbuf.c
deleted file mode 100644
index 2e145672da..0000000000
--- a/src/gallium/drivers/nv20/nv20_prim_vbuf.c
+++ /dev/null
@@ -1,440 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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
- * without limitation the rights to use, copy, modify, merge, publish,
- * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * 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.
- *
- **************************************************************************/
-
-/**
- * \file
- * Build post-transformation, post-clipping vertex buffers and element
- * lists by hooking into the end of the primitive pipeline and
- * manipulating the vertex_id field in the vertex headers.
- *
- * XXX: work in progress
- *
- * \author José Fonseca <jrfonseca@tungstengraphics.com>
- * \author Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-#include "util/u_debug.h"
-#include "pipe/p_inlines.h"
-#include "pipe/internal/p_winsys_screen.h"
-
-#include "nv20_context.h"
-#include "nv20_state.h"
-
-#include "draw/draw_vbuf.h"
-
-/**
- * Primitive renderer for nv20.
- */
-struct nv20_vbuf_render {
- struct vbuf_render base;
-
- struct nv20_context *nv20;
-
- /** Vertex buffer in VRAM */
- struct pipe_buffer *pbuffer;
-
- /** Vertex buffer in normal memory */
- void *mbuffer;
-
- /** Vertex size in bytes */
- /*unsigned vertex_size;*/
-
- /** Hardware primitive */
- unsigned hwprim;
-};
-
-/**
- * Basically a cast wrapper.
- */
-static INLINE struct nv20_vbuf_render *
-nv20_vbuf_render(struct vbuf_render *render)
-{
- assert(render);
- return (struct nv20_vbuf_render *)render;
-}
-
-void nv20_vtxbuf_bind( struct nv20_context* nv20 )
-{
-#if 0
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- int i;
- for(i = 0; i < NV20TCL_VTXBUF_ADDRESS__SIZE; i++) {
- BEGIN_RING(chan, kelvin, NV20TCL_VTXBUF_ADDRESS(i), 1);
- OUT_RING(chan, 0/*nv20->vtxbuf*/);
- BEGIN_RING(chan, kelvin, NV20TCL_VTXFMT(i) ,1);
- OUT_RING(chan, 0/*XXX*/);
- }
-#endif
-}
-
-static const struct vertex_info *
-nv20_vbuf_render_get_vertex_info( struct vbuf_render *render )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- struct nv20_context *nv20 = nv20_render->nv20;
-
- nv20_emit_hw_state(nv20);
-
- return &nv20->vertex_info;
-}
-
-static void *
-nv20__allocate_mbuffer(struct nv20_vbuf_render *nv20_render, size_t size)
-{
- nv20_render->mbuffer = MALLOC(size);
- return nv20_render->mbuffer;
-}
-
-static void
-nv20__allocate_pbuffer(struct nv20_vbuf_render *nv20_render, size_t size)
-{
- struct pipe_screen *screen = nv20_render->nv20->pipe.screen;
- nv20_render->pbuffer = screen->buffer_create(screen, 64,
- PIPE_BUFFER_USAGE_VERTEX, size);
-}
-
-static boolean
-nv20_vbuf_render_allocate_vertices( struct vbuf_render *render,
- ushort vertex_size,
- ushort nr_vertices )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- size_t size = (size_t)vertex_size * (size_t)nr_vertices;
- void *buf;
-
- assert(!nv20_render->pbuffer);
- assert(!nv20_render->mbuffer);
-
- /*
- * For small amount of vertices, don't bother with pipe vertex
- * buffer, the data will be passed directly via the fifo.
- */
- /* XXX: Pipe vertex buffers don't work. */
- if (0 && size > 16 * 1024) {
- nv20__allocate_pbuffer(nv20_render, size);
- /* umm yeah so this is ugly */
- buf = nv20_render->pbuffer;
- } else {
- buf = nv20__allocate_mbuffer(nv20_render, size);
- }
-
- if (buf)
- nv20_render->nv20->dirty |= NV20_NEW_VTXARRAYS;
-
- return buf ? TRUE : FALSE;
-}
-
-static void *
-nv20_vbuf_render_map_vertices( struct vbuf_render *render )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- struct pipe_screen *pscreen = nv20_render->nv20->pipe.screen;
-
- if (nv20_render->pbuffer) {
- return pipe_buffer_map(pscreen, nv20_render->pbuffer,
- PIPE_BUFFER_USAGE_CPU_WRITE);
- } else if (nv20_render->mbuffer) {
- return nv20_render->mbuffer;
- } else
- assert(0);
-
- /* warnings be gone */
- return NULL;
-}
-
-static void
-nv20_vbuf_render_unmap_vertices( struct vbuf_render *render,
- ushort min_index,
- ushort max_index )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- struct pipe_screen *pscreen = nv20_render->nv20->pipe.screen;
-
- if (nv20_render->pbuffer)
- pipe_buffer_unmap(pscreen, nv20_render->pbuffer);
-}
-
-static boolean
-nv20_vbuf_render_set_primitive( struct vbuf_render *render,
- unsigned prim )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- unsigned hwp = nvgl_primitive(prim);
- if (hwp == 0)
- return FALSE;
-
- nv20_render->hwprim = hwp;
- return TRUE;
-}
-
-static uint32_t
-nv20__vtxhwformat(unsigned stride, unsigned fields, unsigned type)
-{
- return (stride << NV20TCL_VTXFMT_STRIDE_SHIFT) |
- (fields << NV20TCL_VTXFMT_SIZE_SHIFT) |
- (type << NV20TCL_VTXFMT_TYPE_SHIFT);
-}
-
-static unsigned
-nv20__emit_format(struct nv20_context *nv20, enum attrib_emit type, int hwattr)
-{
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- uint32_t hwfmt = 0;
- unsigned fields;
-
- switch (type) {
- case EMIT_OMIT:
- hwfmt = nv20__vtxhwformat(0, 0, 2);
- fields = 0;
- break;
- case EMIT_1F:
- hwfmt = nv20__vtxhwformat(4, 1, 2);
- fields = 1;
- break;
- case EMIT_2F:
- hwfmt = nv20__vtxhwformat(8, 2, 2);
- fields = 2;
- break;
- case EMIT_3F:
- hwfmt = nv20__vtxhwformat(12, 3, 2);
- fields = 3;
- break;
- case EMIT_4F:
- hwfmt = nv20__vtxhwformat(16, 4, 2);
- fields = 4;
- break;
- default:
- NOUVEAU_ERR("unhandled attrib_emit %d\n", type);
- return 0;
- }
-
- BEGIN_RING(chan, kelvin, NV20TCL_VTXFMT(hwattr), 1);
- OUT_RING(chan, hwfmt);
- return fields;
-}
-
-static unsigned
-nv20__emit_vertex_array_format(struct nv20_context *nv20)
-{
- struct vertex_info *vinfo = &nv20->vertex_info;
- int hwattr = NV20TCL_VTXFMT__SIZE;
- int attr = 0;
- unsigned nr_fields = 0;
-
- while (hwattr-- > 0) {
- if (vinfo->hwfmt[0] & (1 << hwattr)) {
- nr_fields += nv20__emit_format(nv20,
- vinfo->attrib[attr].emit, hwattr);
- attr++;
- } else
- nv20__emit_format(nv20, EMIT_OMIT, hwattr);
- }
-
- return nr_fields;
-}
-
-static void
-nv20__draw_mbuffer(struct nv20_vbuf_render *nv20_render,
- const ushort *indices,
- uint nr_indices)
-{
- struct nv20_context *nv20 = nv20_render->nv20;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- struct vertex_info *vinfo = &nv20->vertex_info;
- unsigned nr_fields;
- int max_push;
- ubyte *data = nv20_render->mbuffer;
- int vsz = 4 * vinfo->size;
-
- nr_fields = nv20__emit_vertex_array_format(nv20);
-
- BEGIN_RING(chan, kelvin, NV20TCL_VERTEX_BEGIN_END, 1);
- OUT_RING(chan, nv20_render->hwprim);
-
- max_push = 1200 / nr_fields;
- while (nr_indices) {
- int i;
- int push = MIN2(nr_indices, max_push);
-
- BEGIN_RING_NI(chan, kelvin, NV20TCL_VERTEX_DATA, push * nr_fields);
- for (i = 0; i < push; i++) {
- /* XXX: fixme to handle other than floats? */
- int f = nr_fields;
- float *attrv = (float*)&data[indices[i] * vsz];
- while (f-- > 0)
- OUT_RINGf(chan, *attrv++);
- }
-
- nr_indices -= push;
- indices += push;
- }
-
- BEGIN_RING(chan, kelvin, NV20TCL_VERTEX_BEGIN_END, 1);
- OUT_RING(chan, NV20TCL_VERTEX_BEGIN_END_STOP);
-}
-
-static void
-nv20__draw_pbuffer(struct nv20_vbuf_render *nv20_render,
- const ushort *indices,
- uint nr_indices)
-{
- struct nv20_context *nv20 = nv20_render->nv20;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- int push, i;
-
- NOUVEAU_ERR("nv20__draw_pbuffer: this path is broken.\n");
-
- BEGIN_RING(chan, kelvin, NV10TCL_VERTEX_ARRAY_OFFSET_POS, 1);
- OUT_RELOCl(chan, nouveau_bo(nv20_render->pbuffer), 0,
- NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
-
- BEGIN_RING(chan, kelvin, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1);
- OUT_RING(chan, nv20_render->hwprim);
-
- if (nr_indices & 1) {
- BEGIN_RING(chan, kelvin, NV10TCL_VB_ELEMENT_U32, 1);
- OUT_RING (chan, indices[0]);
- indices++; nr_indices--;
- }
-
- while (nr_indices) {
- // XXX too big/small ? check the size
- push = MIN2(nr_indices, 1200 * 2);
-
- BEGIN_RING_NI(chan, kelvin, NV10TCL_VB_ELEMENT_U16, push >> 1);
- for (i = 0; i < push; i+=2)
- OUT_RING(chan, (indices[i+1] << 16) | indices[i]);
-
- nr_indices -= push;
- indices += push;
- }
-
- BEGIN_RING(chan, kelvin, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1);
- OUT_RING (chan, 0);
-}
-
-static void
-nv20_vbuf_render_draw( struct vbuf_render *render,
- const ushort *indices,
- uint nr_indices)
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
-
- nv20_emit_hw_state(nv20_render->nv20);
-
- if (nv20_render->pbuffer)
- nv20__draw_pbuffer(nv20_render, indices, nr_indices);
- else if (nv20_render->mbuffer)
- nv20__draw_mbuffer(nv20_render, indices, nr_indices);
- else
- assert(0);
-}
-
-
-static void
-nv20_vbuf_render_release_vertices( struct vbuf_render *render )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
- struct nv20_context *nv20 = nv20_render->nv20;
-
- if (nv20_render->pbuffer) {
- pipe_buffer_reference(&nv20_render->pbuffer, NULL);
- } else if (nv20_render->mbuffer) {
- FREE(nv20_render->mbuffer);
- nv20_render->mbuffer = NULL;
- } else
- assert(0);
-}
-
-
-static void
-nv20_vbuf_render_destroy( struct vbuf_render *render )
-{
- struct nv20_vbuf_render *nv20_render = nv20_vbuf_render(render);
-
- assert(!nv20_render->pbuffer);
- assert(!nv20_render->mbuffer);
-
- FREE(nv20_render);
-}
-
-
-/**
- * Create a new primitive render.
- */
-static struct vbuf_render *
-nv20_vbuf_render_create( struct nv20_context *nv20 )
-{
- struct nv20_vbuf_render *nv20_render = CALLOC_STRUCT(nv20_vbuf_render);
-
- nv20_render->nv20 = nv20;
-
- nv20_render->base.max_vertex_buffer_bytes = 16*1024;
- nv20_render->base.max_indices = 1024;
- nv20_render->base.get_vertex_info = nv20_vbuf_render_get_vertex_info;
- nv20_render->base.allocate_vertices =
- nv20_vbuf_render_allocate_vertices;
- nv20_render->base.map_vertices = nv20_vbuf_render_map_vertices;
- nv20_render->base.unmap_vertices = nv20_vbuf_render_unmap_vertices;
- nv20_render->base.set_primitive = nv20_vbuf_render_set_primitive;
- nv20_render->base.draw = nv20_vbuf_render_draw;
- nv20_render->base.release_vertices = nv20_vbuf_render_release_vertices;
- nv20_render->base.destroy = nv20_vbuf_render_destroy;
-
- return &nv20_render->base;
-}
-
-
-/**
- * Create a new primitive vbuf/render stage.
- */
-struct draw_stage *nv20_draw_vbuf_stage( struct nv20_context *nv20 )
-{
- struct vbuf_render *render;
- struct draw_stage *stage;
-
- render = nv20_vbuf_render_create(nv20);
- if(!render)
- return NULL;
-
- stage = draw_vbuf_stage( nv20->draw, render );
- if(!stage) {
- render->destroy(render);
- return NULL;
- }
-
- return stage;
-}
diff --git a/src/gallium/drivers/nv20/nv20_screen.c b/src/gallium/drivers/nv20/nv20_screen.c
deleted file mode 100644
index df9401bcce..0000000000
--- a/src/gallium/drivers/nv20/nv20_screen.c
+++ /dev/null
@@ -1,204 +0,0 @@
-#include "pipe/p_screen.h"
-
-#include "nv20_context.h"
-#include "nv20_screen.h"
-
-static int
-nv20_screen_get_param(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
- return 2;
- case PIPE_CAP_NPOT_TEXTURES:
- return 0;
- case PIPE_CAP_TWO_SIDED_STENCIL:
- return 0;
- case PIPE_CAP_GLSL:
- return 0;
- case PIPE_CAP_ANISOTROPIC_FILTER:
- return 1;
- case PIPE_CAP_POINT_SPRITE:
- return 0;
- case PIPE_CAP_MAX_RENDER_TARGETS:
- return 1;
- case PIPE_CAP_OCCLUSION_QUERY:
- return 0;
- case PIPE_CAP_TEXTURE_SHADOW_MAP:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
- return 12;
- case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
- return 0;
- case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
- return 12;
- case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
- return 0;
- case PIPE_CAP_TGSI_CONT_SUPPORTED:
- return 0;
- case PIPE_CAP_BLEND_EQUATION_SEPARATE:
- return 0;
- case NOUVEAU_CAP_HW_VTXBUF:
- case NOUVEAU_CAP_HW_IDXBUF:
- return 0;
- case PIPE_CAP_INDEP_BLEND_ENABLE:
- return 0;
- case PIPE_CAP_INDEP_BLEND_FUNC:
- return 0;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
- return 1;
- case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
- case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
- return 0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0;
- }
-}
-
-static float
-nv20_screen_get_paramf(struct pipe_screen *screen, int param)
-{
- switch (param) {
- case PIPE_CAP_MAX_LINE_WIDTH:
- case PIPE_CAP_MAX_LINE_WIDTH_AA:
- return 10.0;
- case PIPE_CAP_MAX_POINT_WIDTH:
- case PIPE_CAP_MAX_POINT_WIDTH_AA:
- return 64.0;
- case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
- return 2.0;
- case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
- return 4.0;
- default:
- NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
- return 0.0;
- }
-}
-
-static boolean
-nv20_screen_is_format_supported(struct pipe_screen *screen,
- enum pipe_format format,
- enum pipe_texture_target target,
- unsigned tex_usage, unsigned geom_flags)
-{
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- return TRUE;
- default:
- break;
- }
- } else
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
- switch (format) {
- case PIPE_FORMAT_Z24S8_UNORM:
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z16_UNORM:
- return TRUE;
- default:
- break;
- }
- } else {
- switch (format) {
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- case PIPE_FORMAT_A4R4G4B4_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_A8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- return TRUE;
- default:
- break;
- }
- }
-
- return FALSE;
-}
-
-static void
-nv20_screen_destroy(struct pipe_screen *pscreen)
-{
- struct nv20_screen *screen = nv20_screen(pscreen);
-
- nouveau_notifier_free(&screen->sync);
- nouveau_grobj_free(&screen->kelvin);
- nv04_surface_2d_takedown(&screen->eng2d);
-
- nouveau_screen_fini(&screen->base);
-
- FREE(pscreen);
-}
-
-static struct pipe_buffer *
-nv20_surface_buffer(struct pipe_surface *surf)
-{
- struct nv20_miptree *mt = (struct nv20_miptree *)surf->texture;
-
- return mt->buffer;
-}
-
-struct pipe_screen *
-nv20_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
-{
- struct nv20_screen *screen = CALLOC_STRUCT(nv20_screen);
- struct nouveau_channel *chan;
- struct pipe_screen *pscreen;
- unsigned kelvin_class = 0;
- int ret;
-
- if (!screen)
- return NULL;
- pscreen = &screen->base.base;
-
- ret = nouveau_screen_init(&screen->base, dev);
- if (ret) {
- nv20_screen_destroy(pscreen);
- return NULL;
- }
- chan = screen->base.channel;
-
- pscreen->winsys = ws;
- pscreen->destroy = nv20_screen_destroy;
- pscreen->get_param = nv20_screen_get_param;
- pscreen->get_paramf = nv20_screen_get_paramf;
- pscreen->is_format_supported = nv20_screen_is_format_supported;
-
- nv20_screen_init_miptree_functions(pscreen);
- nv20_screen_init_transfer_functions(pscreen);
-
- /* 3D object */
- if (dev->chipset >= 0x25)
- kelvin_class = NV25TCL;
- else if (dev->chipset >= 0x20)
- kelvin_class = NV20TCL;
-
- if (!kelvin_class || dev->chipset >= 0x30) {
- NOUVEAU_ERR("Unknown nv2x chipset: nv%02x\n", dev->chipset);
- return NULL;
- }
-
- ret = nouveau_grobj_alloc(chan, 0xbeef0097, kelvin_class,
- &screen->kelvin);
- if (ret) {
- NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
- return FALSE;
- }
-
- /* 2D engine setup */
- screen->eng2d = nv04_surface_2d_init(&screen->base);
- screen->eng2d->buf = nv20_surface_buffer;
-
- /* Notifier for sync purposes */
- ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync);
- if (ret) {
- NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
- nv20_screen_destroy(pscreen);
- return NULL;
- }
-
- return pscreen;
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_screen.h b/src/gallium/drivers/nv20/nv20_screen.h
deleted file mode 100644
index fc7bb05033..0000000000
--- a/src/gallium/drivers/nv20/nv20_screen.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __NV20_SCREEN_H__
-#define __NV20_SCREEN_H__
-
-#include "nouveau/nouveau_screen.h"
-#include "nv04/nv04_surface_2d.h"
-
-struct nv20_screen {
- struct nouveau_screen base;
-
- struct nouveau_winsys *nvws;
-
- /* HW graphics objects */
- struct nv04_surface_2d *eng2d;
- struct nouveau_grobj *kelvin;
- struct nouveau_notifier *sync;
-};
-
-static INLINE struct nv20_screen *
-nv20_screen(struct pipe_screen *screen)
-{
- return (struct nv20_screen *)screen;
-}
-
-
-void
-nv20_screen_init_transfer_functions(struct pipe_screen *pscreen);
-
-#endif
diff --git a/src/gallium/drivers/nv20/nv20_state.c b/src/gallium/drivers/nv20/nv20_state.c
deleted file mode 100644
index 83335c790a..0000000000
--- a/src/gallium/drivers/nv20/nv20_state.c
+++ /dev/null
@@ -1,583 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_shader_tokens.h"
-#include "pipe/p_inlines.h"
-
-#include "tgsi/tgsi_parse.h"
-
-#include "nv20_context.h"
-#include "nv20_state.h"
-
-static void *
-nv20_blend_state_create(struct pipe_context *pipe,
- const struct pipe_blend_state *cso)
-{
- struct nv20_blend_state *cb;
-
- cb = MALLOC(sizeof(struct nv20_blend_state));
-
- cb->b_enable = cso->rt[0].blend_enable ? 1 : 0;
- cb->b_srcfunc = ((nvgl_blend_func(cso->rt[0].alpha_src_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_src_factor)));
- cb->b_dstfunc = ((nvgl_blend_func(cso->rt[0].alpha_dst_factor)<<16) |
- (nvgl_blend_func(cso->rt[0].rgb_dst_factor)));
-
- cb->c_mask = (((cso->rt[0].colormask & PIPE_MASK_A) ? (0x01<<24) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_R) ? (0x01<<16) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_G) ? (0x01<< 8) : 0) |
- ((cso->rt[0].colormask & PIPE_MASK_B) ? (0x01<< 0) : 0));
-
- cb->d_enable = cso->dither ? 1 : 0;
-
- return (void *)cb;
-}
-
-static void
-nv20_blend_state_bind(struct pipe_context *pipe, void *blend)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->blend = (struct nv20_blend_state*)blend;
-
- nv20->dirty |= NV20_NEW_BLEND;
-}
-
-static void
-nv20_blend_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-
-static INLINE unsigned
-wrap_mode(unsigned wrap) {
- unsigned ret;
-
- switch (wrap) {
- case PIPE_TEX_WRAP_REPEAT:
- ret = NV20TCL_TX_WRAP_S_REPEAT;
- break;
- case PIPE_TEX_WRAP_MIRROR_REPEAT:
- ret = NV20TCL_TX_WRAP_S_MIRRORED_REPEAT;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- ret = NV20TCL_TX_WRAP_S_CLAMP_TO_EDGE;
- break;
- case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
- ret = NV20TCL_TX_WRAP_S_CLAMP_TO_BORDER;
- break;
- case PIPE_TEX_WRAP_CLAMP:
- ret = NV20TCL_TX_WRAP_S_CLAMP;
- break;
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
- case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
- case PIPE_TEX_WRAP_MIRROR_CLAMP:
- default:
- NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
- ret = NV20TCL_TX_WRAP_S_REPEAT;
- break;
- }
-
- return (ret >> NV20TCL_TX_WRAP_S_SHIFT);
-}
-
-static void *
-nv20_sampler_state_create(struct pipe_context *pipe,
- const struct pipe_sampler_state *cso)
-{
- struct nv20_sampler_state *ps;
- uint32_t filter = 0;
-
- ps = MALLOC(sizeof(struct nv20_sampler_state));
-
- ps->wrap = ((wrap_mode(cso->wrap_s) << NV20TCL_TX_WRAP_S_SHIFT) |
- (wrap_mode(cso->wrap_t) << NV20TCL_TX_WRAP_T_SHIFT));
-
- ps->en = 0;
- if (cso->max_anisotropy > 1.0) {
- /* no idea, binary driver sets it, works without it.. meh.. */
- ps->wrap |= (1 << 5);
-
-/* if (cso->max_anisotropy >= 8.0) {
- ps->en |= NV20TCL_TX_ENABLE_ANISO_8X;
- } else
- if (cso->max_anisotropy >= 4.0) {
- ps->en |= NV20TCL_TX_ENABLE_ANISO_4X;
- } else {
- ps->en |= NV20TCL_TX_ENABLE_ANISO_2X;
- }*/
- }
-
- switch (cso->mag_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- filter |= NV20TCL_TX_FILTER_MAGNIFY_LINEAR;
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- filter |= NV20TCL_TX_FILTER_MAGNIFY_NEAREST;
- break;
- }
-
- switch (cso->min_img_filter) {
- case PIPE_TEX_FILTER_LINEAR:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |=
- NV20TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |= NV20TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV20TCL_TX_FILTER_MINIFY_LINEAR;
- break;
- }
- break;
- case PIPE_TEX_FILTER_NEAREST:
- default:
- switch (cso->min_mip_filter) {
- case PIPE_TEX_MIPFILTER_NEAREST:
- filter |=
- NV20TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST;
- break;
- case PIPE_TEX_MIPFILTER_LINEAR:
- filter |=
- NV20TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR;
- break;
- case PIPE_TEX_MIPFILTER_NONE:
- default:
- filter |= NV20TCL_TX_FILTER_MINIFY_NEAREST;
- break;
- }
- break;
- }
-
- ps->filt = filter;
-
-/* if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
- switch (cso->compare_func) {
- case PIPE_FUNC_NEVER:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_NEVER;
- break;
- case PIPE_FUNC_GREATER:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_GREATER;
- break;
- case PIPE_FUNC_EQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_EQUAL;
- break;
- case PIPE_FUNC_GEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_GEQUAL;
- break;
- case PIPE_FUNC_LESS:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_LESS;
- break;
- case PIPE_FUNC_NOTEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_NOTEQUAL;
- break;
- case PIPE_FUNC_LEQUAL:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_LEQUAL;
- break;
- case PIPE_FUNC_ALWAYS:
- ps->wrap |= NV10TCL_TX_WRAP_RCOMP_ALWAYS;
- break;
- default:
- break;
- }
- }*/
-
- ps->bcol = ((float_to_ubyte(cso->border_color[3]) << 24) |
- (float_to_ubyte(cso->border_color[0]) << 16) |
- (float_to_ubyte(cso->border_color[1]) << 8) |
- (float_to_ubyte(cso->border_color[2]) << 0));
-
- return (void *)ps;
-}
-
-static void
-nv20_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv20->tex_sampler[unit] = sampler[unit];
- nv20->dirty_samplers |= (1 << unit);
- }
-}
-
-static void
-nv20_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void
-nv20_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
- struct pipe_texture **miptree)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- unsigned unit;
-
- for (unit = 0; unit < nr; unit++) {
- nv20->tex_miptree[unit] = (struct nv20_miptree *)miptree[unit];
- nv20->dirty_samplers |= (1 << unit);
- }
-}
-
-static void *
-nv20_rasterizer_state_create(struct pipe_context *pipe,
- const struct pipe_rasterizer_state *cso)
-{
- struct nv20_rasterizer_state *rs;
- int i;
-
- /*XXX: ignored:
- * light_twoside
- * offset_cw/ccw -nohw
- * scissor
- * point_smooth -nohw
- * multisample
- * offset_units / offset_scale
- */
- rs = MALLOC(sizeof(struct nv20_rasterizer_state));
-
- rs->templ = cso;
-
- rs->shade_model = cso->flatshade ? NV20TCL_SHADE_MODEL_FLAT :
- NV20TCL_SHADE_MODEL_SMOOTH;
-
- rs->line_width = (unsigned char)(cso->line_width * 8.0) & 0xff;
- rs->line_smooth_en = cso->line_smooth ? 1 : 0;
-
- /* XXX: nv20 and nv25 different! */
- rs->point_size = *(uint32_t*)&cso->point_size;
-
- rs->poly_smooth_en = cso->poly_smooth ? 1 : 0;
-
- if (cso->front_winding == PIPE_WINDING_CCW) {
- rs->front_face = NV20TCL_FRONT_FACE_CCW;
- rs->poly_mode_front = nvgl_polygon_mode(cso->fill_ccw);
- rs->poly_mode_back = nvgl_polygon_mode(cso->fill_cw);
- } else {
- rs->front_face = NV20TCL_FRONT_FACE_CW;
- rs->poly_mode_front = nvgl_polygon_mode(cso->fill_cw);
- rs->poly_mode_back = nvgl_polygon_mode(cso->fill_ccw);
- }
-
- switch (cso->cull_mode) {
- case PIPE_WINDING_CCW:
- rs->cull_face_en = 1;
- if (cso->front_winding == PIPE_WINDING_CCW)
- rs->cull_face = NV20TCL_CULL_FACE_FRONT;
- else
- rs->cull_face = NV20TCL_CULL_FACE_BACK;
- break;
- case PIPE_WINDING_CW:
- rs->cull_face_en = 1;
- if (cso->front_winding == PIPE_WINDING_CW)
- rs->cull_face = NV20TCL_CULL_FACE_FRONT;
- else
- rs->cull_face = NV20TCL_CULL_FACE_BACK;
- break;
- case PIPE_WINDING_BOTH:
- rs->cull_face_en = 1;
- rs->cull_face = NV20TCL_CULL_FACE_FRONT_AND_BACK;
- break;
- case PIPE_WINDING_NONE:
- default:
- rs->cull_face_en = 0;
- rs->cull_face = 0;
- break;
- }
-
- if (cso->point_sprite) {
- rs->point_sprite = (1 << 0);
- for (i = 0; i < 8; i++) {
- if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
- rs->point_sprite |= (1 << (8 + i));
- }
- } else {
- rs->point_sprite = 0;
- }
-
- return (void *)rs;
-}
-
-static void
-nv20_rasterizer_state_bind(struct pipe_context *pipe, void *rast)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->rast = (struct nv20_rasterizer_state*)rast;
-
- draw_set_rasterizer_state(nv20->draw, (nv20->rast ? nv20->rast->templ : NULL));
-
- nv20->dirty |= NV20_NEW_RAST;
-}
-
-static void
-nv20_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void *
-nv20_depth_stencil_alpha_state_create(struct pipe_context *pipe,
- const struct pipe_depth_stencil_alpha_state *cso)
-{
- struct nv20_depth_stencil_alpha_state *hw;
-
- hw = MALLOC(sizeof(struct nv20_depth_stencil_alpha_state));
-
- hw->depth.func = nvgl_comparison_op(cso->depth.func);
- hw->depth.write_enable = cso->depth.writemask ? 1 : 0;
- hw->depth.test_enable = cso->depth.enabled ? 1 : 0;
-
- hw->stencil.enable = cso->stencil[0].enabled ? 1 : 0;
- hw->stencil.wmask = cso->stencil[0].writemask;
- hw->stencil.func = nvgl_comparison_op(cso->stencil[0].func);
- hw->stencil.ref = cso->stencil[0].ref_value;
- hw->stencil.vmask = cso->stencil[0].valuemask;
- hw->stencil.fail = nvgl_stencil_op(cso->stencil[0].fail_op);
- hw->stencil.zfail = nvgl_stencil_op(cso->stencil[0].zfail_op);
- hw->stencil.zpass = nvgl_stencil_op(cso->stencil[0].zpass_op);
-
- hw->alpha.enabled = cso->alpha.enabled ? 1 : 0;
- hw->alpha.func = nvgl_comparison_op(cso->alpha.func);
- hw->alpha.ref = float_to_ubyte(cso->alpha.ref_value);
-
- return (void *)hw;
-}
-
-static void
-nv20_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *dsa)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->dsa = (struct nv20_depth_stencil_alpha_state*)dsa;
-
- nv20->dirty |= NV20_NEW_DSA;
-}
-
-static void
-nv20_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- FREE(hwcso);
-}
-
-static void *
-nv20_vp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *templ)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- return draw_create_vertex_shader(nv20->draw, templ);
-}
-
-static void
-nv20_vp_state_bind(struct pipe_context *pipe, void *shader)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- draw_bind_vertex_shader(nv20->draw, (struct draw_vertex_shader *) shader);
-
- nv20->dirty |= NV20_NEW_VERTPROG;
-}
-
-static void
-nv20_vp_state_delete(struct pipe_context *pipe, void *shader)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- draw_delete_vertex_shader(nv20->draw, (struct draw_vertex_shader *) shader);
-}
-
-static void *
-nv20_fp_state_create(struct pipe_context *pipe,
- const struct pipe_shader_state *cso)
-{
- struct nv20_fragment_program *fp;
-
- fp = CALLOC(1, sizeof(struct nv20_fragment_program));
- fp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
-
- tgsi_scan_shader(cso->tokens, &fp->info);
-
- return (void *)fp;
-}
-
-static void
-nv20_fp_state_bind(struct pipe_context *pipe, void *hwcso)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct nv20_fragment_program *fp = hwcso;
-
- nv20->fragprog.current = fp;
- nv20->dirty |= NV20_NEW_FRAGPROG;
-}
-
-static void
-nv20_fp_state_delete(struct pipe_context *pipe, void *hwcso)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct nv20_fragment_program *fp = hwcso;
-
- nv20_fragprog_destroy(nv20, fp);
- FREE((void*)fp->pipe.tokens);
- FREE(fp);
-}
-
-static void
-nv20_set_blend_color(struct pipe_context *pipe,
- const struct pipe_blend_color *bcol)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->blend_color = (struct pipe_blend_color*)bcol;
-
- nv20->dirty |= NV20_NEW_BLENDCOL;
-}
-
-static void
-nv20_set_clip_state(struct pipe_context *pipe,
- const struct pipe_clip_state *clip)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- draw_set_clip_state(nv20->draw, clip);
-}
-
-static void
-nv20_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
- struct pipe_buffer *buf )
-{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct pipe_screen *pscreen = pipe->screen;
-
- assert(shader < PIPE_SHADER_TYPES);
- assert(index == 0);
-
- if (buf) {
- void *mapped;
- if (buf->size &&
- (mapped = pipe_buffer_map(pscreen, buf, PIPE_BUFFER_USAGE_CPU_READ)))
- {
- memcpy(nv20->constbuf[shader], mapped, buf->size);
- nv20->constbuf_nr[shader] =
- buf->size / (4 * sizeof(float));
- pipe_buffer_unmap(pscreen, buf);
- }
- }
-}
-
-static void
-nv20_set_framebuffer_state(struct pipe_context *pipe,
- const struct pipe_framebuffer_state *fb)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->framebuffer = (struct pipe_framebuffer_state*)fb;
-
- nv20->dirty |= NV20_NEW_FRAMEBUFFER;
-}
-
-static void
-nv20_set_polygon_stipple(struct pipe_context *pipe,
- const struct pipe_poly_stipple *stipple)
-{
- NOUVEAU_ERR("line stipple hahaha\n");
-}
-
-static void
-nv20_set_scissor_state(struct pipe_context *pipe,
- const struct pipe_scissor_state *s)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->scissor = (struct pipe_scissor_state*)s;
-
- nv20->dirty |= NV20_NEW_SCISSOR;
-}
-
-static void
-nv20_set_viewport_state(struct pipe_context *pipe,
- const struct pipe_viewport_state *vpt)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- nv20->viewport = (struct pipe_viewport_state*)vpt;
-
- draw_set_viewport_state(nv20->draw, nv20->viewport);
-
- nv20->dirty |= NV20_NEW_VIEWPORT;
-}
-
-static void
-nv20_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_buffer *vb)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- memcpy(nv20->vtxbuf, vb, sizeof(*vb) * count);
- nv20->dirty |= NV20_NEW_VTXARRAYS;
-
- draw_set_vertex_buffers(nv20->draw, count, vb);
-}
-
-static void
-nv20_set_vertex_elements(struct pipe_context *pipe, unsigned count,
- const struct pipe_vertex_element *ve)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- memcpy(nv20->vtxelt, ve, sizeof(*ve) * count);
- nv20->dirty |= NV20_NEW_VTXARRAYS;
-
- draw_set_vertex_elements(nv20->draw, count, ve);
-}
-
-void
-nv20_init_state_functions(struct nv20_context *nv20)
-{
- nv20->pipe.create_blend_state = nv20_blend_state_create;
- nv20->pipe.bind_blend_state = nv20_blend_state_bind;
- nv20->pipe.delete_blend_state = nv20_blend_state_delete;
-
- nv20->pipe.create_sampler_state = nv20_sampler_state_create;
- nv20->pipe.bind_fragment_sampler_states = nv20_sampler_state_bind;
- nv20->pipe.delete_sampler_state = nv20_sampler_state_delete;
- nv20->pipe.set_fragment_sampler_textures = nv20_set_sampler_texture;
-
- nv20->pipe.create_rasterizer_state = nv20_rasterizer_state_create;
- nv20->pipe.bind_rasterizer_state = nv20_rasterizer_state_bind;
- nv20->pipe.delete_rasterizer_state = nv20_rasterizer_state_delete;
-
- nv20->pipe.create_depth_stencil_alpha_state =
- nv20_depth_stencil_alpha_state_create;
- nv20->pipe.bind_depth_stencil_alpha_state =
- nv20_depth_stencil_alpha_state_bind;
- nv20->pipe.delete_depth_stencil_alpha_state =
- nv20_depth_stencil_alpha_state_delete;
-
- nv20->pipe.create_vs_state = nv20_vp_state_create;
- nv20->pipe.bind_vs_state = nv20_vp_state_bind;
- nv20->pipe.delete_vs_state = nv20_vp_state_delete;
-
- nv20->pipe.create_fs_state = nv20_fp_state_create;
- nv20->pipe.bind_fs_state = nv20_fp_state_bind;
- nv20->pipe.delete_fs_state = nv20_fp_state_delete;
-
- nv20->pipe.set_blend_color = nv20_set_blend_color;
- nv20->pipe.set_clip_state = nv20_set_clip_state;
- nv20->pipe.set_constant_buffer = nv20_set_constant_buffer;
- nv20->pipe.set_framebuffer_state = nv20_set_framebuffer_state;
- nv20->pipe.set_polygon_stipple = nv20_set_polygon_stipple;
- nv20->pipe.set_scissor_state = nv20_set_scissor_state;
- nv20->pipe.set_viewport_state = nv20_set_viewport_state;
-
- nv20->pipe.set_vertex_buffers = nv20_set_vertex_buffers;
- nv20->pipe.set_vertex_elements = nv20_set_vertex_elements;
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_state.h b/src/gallium/drivers/nv20/nv20_state.h
deleted file mode 100644
index dde4106568..0000000000
--- a/src/gallium/drivers/nv20/nv20_state.h
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifndef __NV20_STATE_H__
-#define __NV20_STATE_H__
-
-#include "pipe/p_state.h"
-#include "tgsi/tgsi_scan.h"
-
-struct nv20_blend_state {
- uint32_t b_enable;
- uint32_t b_srcfunc;
- uint32_t b_dstfunc;
-
- uint32_t c_mask;
-
- uint32_t d_enable;
-};
-
-struct nv20_sampler_state {
- uint32_t wrap;
- uint32_t en;
- uint32_t filt;
- uint32_t bcol;
-};
-
-struct nv20_rasterizer_state {
- uint32_t shade_model;
-
- uint32_t line_width;
- uint32_t line_smooth_en;
-
- uint32_t point_size;
-
- uint32_t poly_smooth_en;
-
- uint32_t poly_mode_front;
- uint32_t poly_mode_back;
-
- uint32_t front_face;
- uint32_t cull_face;
- uint32_t cull_face_en;
-
- uint32_t point_sprite;
-
- const struct pipe_rasterizer_state *templ;
-};
-
-struct nv20_vertex_program_exec {
- uint32_t data[4];
- boolean has_branch_offset;
- int const_index;
-};
-
-struct nv20_vertex_program_data {
- int index; /* immediates == -1 */
- float value[4];
-};
-
-struct nv20_vertex_program {
- const struct pipe_shader_state *pipe;
-
- boolean translated;
- struct nv20_vertex_program_exec *insns;
- unsigned nr_insns;
- struct nv20_vertex_program_data *consts;
- unsigned nr_consts;
-
- struct nouveau_resource *exec;
- unsigned exec_start;
- struct nouveau_resource *data;
- unsigned data_start;
- unsigned data_start_min;
-
- uint32_t ir;
- uint32_t or;
-};
-
-struct nv20_fragment_program_data {
- unsigned offset;
- unsigned index;
-};
-
-struct nv20_fragment_program {
- struct pipe_shader_state pipe;
- struct tgsi_shader_info info;
-
- boolean translated;
- boolean on_hw;
- unsigned samplers;
-
- uint32_t *insn;
- int insn_len;
-
- struct nv20_fragment_program_data *consts;
- unsigned nr_consts;
-
- struct pipe_buffer *buffer;
-
- uint32_t fp_control;
- uint32_t fp_reg_control;
-};
-
-
-struct nv20_depth_stencil_alpha_state {
- struct {
- uint32_t func;
- uint32_t write_enable;
- uint32_t test_enable;
- } depth;
-
- struct {
- uint32_t enable;
- uint32_t wmask;
- uint32_t func;
- uint32_t ref;
- uint32_t vmask;
- uint32_t fail;
- uint32_t zfail;
- uint32_t zpass;
- } stencil;
-
- struct {
- uint32_t enabled;
- uint32_t func;
- uint32_t ref;
- } alpha;
-};
-
-struct nv20_miptree {
- struct pipe_texture base;
- struct nouveau_bo *bo;
-
- struct pipe_buffer *buffer;
- uint total_size;
-
- struct {
- uint pitch;
- uint *image_offset;
- } level[PIPE_MAX_TEXTURE_LEVELS];
-};
-
-#endif
diff --git a/src/gallium/drivers/nv20/nv20_state_emit.c b/src/gallium/drivers/nv20/nv20_state_emit.c
deleted file mode 100644
index 6bbd1fdae9..0000000000
--- a/src/gallium/drivers/nv20/nv20_state_emit.c
+++ /dev/null
@@ -1,426 +0,0 @@
-#include "nv20_context.h"
-#include "nv20_state.h"
-#include "draw/draw_context.h"
-
-static void nv20_state_emit_blend(struct nv20_context* nv20)
-{
- struct nv20_blend_state *b = nv20->blend;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- BEGIN_RING(chan, kelvin, NV20TCL_DITHER_ENABLE, 1);
- OUT_RING (chan, b->d_enable);
-
- BEGIN_RING(chan, kelvin, NV20TCL_BLEND_FUNC_ENABLE, 1);
- OUT_RING (chan, b->b_enable);
-
- BEGIN_RING(chan, kelvin, NV20TCL_BLEND_FUNC_SRC, 2);
- OUT_RING (chan, b->b_srcfunc);
- OUT_RING (chan, b->b_dstfunc);
-
- BEGIN_RING(chan, kelvin, NV20TCL_COLOR_MASK, 1);
- OUT_RING (chan, b->c_mask);
-}
-
-static void nv20_state_emit_blend_color(struct nv20_context* nv20)
-{
- struct pipe_blend_color *c = nv20->blend_color;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- BEGIN_RING(chan, kelvin, NV20TCL_BLEND_COLOR, 1);
- OUT_RING (chan,
- (float_to_ubyte(c->color[3]) << 24)|
- (float_to_ubyte(c->color[0]) << 16)|
- (float_to_ubyte(c->color[1]) << 8) |
- (float_to_ubyte(c->color[2]) << 0));
-}
-
-static void nv20_state_emit_rast(struct nv20_context* nv20)
-{
- struct nv20_rasterizer_state *r = nv20->rast;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- BEGIN_RING(chan, kelvin, NV20TCL_SHADE_MODEL, 2);
- OUT_RING (chan, r->shade_model);
- OUT_RING (chan, r->line_width);
-
-
- BEGIN_RING(chan, kelvin, NV20TCL_POINT_SIZE, 1);
- OUT_RING (chan, r->point_size);
-
- BEGIN_RING(chan, kelvin, NV20TCL_POLYGON_MODE_FRONT, 2);
- OUT_RING (chan, r->poly_mode_front);
- OUT_RING (chan, r->poly_mode_back);
-
-
- BEGIN_RING(chan, kelvin, NV20TCL_CULL_FACE, 2);
- OUT_RING (chan, r->cull_face);
- OUT_RING (chan, r->front_face);
-
- BEGIN_RING(chan, kelvin, NV20TCL_LINE_SMOOTH_ENABLE, 2);
- OUT_RING (chan, r->line_smooth_en);
- OUT_RING (chan, r->poly_smooth_en);
-
- BEGIN_RING(chan, kelvin, NV20TCL_CULL_FACE_ENABLE, 1);
- OUT_RING (chan, r->cull_face_en);
-}
-
-static void nv20_state_emit_dsa(struct nv20_context* nv20)
-{
- struct nv20_depth_stencil_alpha_state *d = nv20->dsa;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_FUNC, 1);
- OUT_RING (chan, d->depth.func);
-
- BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_WRITE_ENABLE, 1);
- OUT_RING (chan, d->depth.write_enable);
-
- BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_TEST_ENABLE, 1);
- OUT_RING (chan, d->depth.test_enable);
-
- BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_UNK17D8, 1);
- OUT_RING (chan, 1);
-
-#if 0
- BEGIN_RING(chan, kelvin, NV20TCL_STENCIL_ENABLE, 1);
- OUT_RING (chan, d->stencil.enable);
- BEGIN_RING(chan, kelvin, NV20TCL_STENCIL_MASK, 7);
- OUT_RINGp (chan, (uint32_t *)&(d->stencil.wmask), 7);
-#endif
-
- BEGIN_RING(chan, kelvin, NV20TCL_ALPHA_FUNC_ENABLE, 1);
- OUT_RING (chan, d->alpha.enabled);
-
- BEGIN_RING(chan, kelvin, NV20TCL_ALPHA_FUNC_FUNC, 1);
- OUT_RING (chan, d->alpha.func);
-
- BEGIN_RING(chan, kelvin, NV20TCL_ALPHA_FUNC_REF, 1);
- OUT_RING (chan, d->alpha.ref);
-}
-
-static void nv20_state_emit_viewport(struct nv20_context* nv20)
-{
-}
-
-static void nv20_state_emit_scissor(struct nv20_context* nv20)
-{
- /* NV20TCL_SCISSOR_* is probably a software method */
-/* struct pipe_scissor_state *s = nv20->scissor;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- BEGIN_RING(chan, kelvin, NV20TCL_SCISSOR_HORIZ, 2);
- OUT_RING (chan, ((s->maxx - s->minx) << 16) | s->minx);
- OUT_RING (chan, ((s->maxy - s->miny) << 16) | s->miny);*/
-}
-
-static void nv20_state_emit_framebuffer(struct nv20_context* nv20)
-{
- struct pipe_framebuffer_state* fb = nv20->framebuffer;
- struct nv04_surface *rt, *zeta = NULL;
- uint32_t rt_format, w, h;
- int colour_format = 0, zeta_format = 0;
- struct nv20_miptree *nv20mt = 0;
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
-
- w = fb->cbufs[0]->width;
- h = fb->cbufs[0]->height;
- colour_format = fb->cbufs[0]->format;
- rt = (struct nv04_surface *)fb->cbufs[0];
-
- if (fb->zsbuf) {
- if (colour_format) {
- assert(w == fb->zsbuf->width);
- assert(h == fb->zsbuf->height);
- } else {
- w = fb->zsbuf->width;
- h = fb->zsbuf->height;
- }
-
- zeta_format = fb->zsbuf->format;
- zeta = (struct nv04_surface *)fb->zsbuf;
- }
-
- rt_format = NV20TCL_RT_FORMAT_TYPE_LINEAR | 0x20;
-
- switch (colour_format) {
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- rt_format |= NV20TCL_RT_FORMAT_COLOR_X8R8G8B8;
- break;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case 0:
- rt_format |= NV20TCL_RT_FORMAT_COLOR_A8R8G8B8;
- break;
- case PIPE_FORMAT_R5G6B5_UNORM:
- rt_format |= NV20TCL_RT_FORMAT_COLOR_R5G6B5;
- break;
- default:
- assert(0);
- }
-
- if (zeta) {
- BEGIN_RING(chan, kelvin, NV20TCL_RT_PITCH, 1);
- OUT_RING (chan, rt->pitch | (zeta->pitch << 16));
- } else {
- BEGIN_RING(chan, kelvin, NV20TCL_RT_PITCH, 1);
- OUT_RING (chan, rt->pitch | (rt->pitch << 16));
- }
-
- nv20mt = (struct nv20_miptree *)rt->base.texture;
- nv20->rt[0] = nv20mt->buffer;
-
- if (zeta_format)
- {
- nv20mt = (struct nv20_miptree *)zeta->base.texture;
- nv20->zeta = nv20mt->buffer;
- }
-
- BEGIN_RING(chan, kelvin, NV20TCL_RT_HORIZ, 3);
- OUT_RING (chan, (w << 16) | 0);
- OUT_RING (chan, (h << 16) | 0); /*NV20TCL_RT_VERT */
- OUT_RING (chan, rt_format); /* NV20TCL_RT_FORMAT */
- BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_HORIZ(0), 2);
- OUT_RING (chan, ((w - 1) << 16) | 0);
- OUT_RING (chan, ((h - 1) << 16) | 0);
-}
-
-static void nv20_vertex_layout(struct nv20_context *nv20)
-{
- struct nv20_fragment_program *fp = nv20->fragprog.current;
- struct draw_context *dc = nv20->draw;
- int src;
- int i;
- struct vertex_info *vinfo = &nv20->vertex_info;
- const enum interp_mode colorInterp = INTERP_LINEAR;
- boolean colors[2] = { FALSE };
- boolean generics[12] = { FALSE };
- boolean fog = FALSE;
-
- memset(vinfo, 0, sizeof(*vinfo));
-
- /*
- * Assumed NV20 hardware vertex attribute order:
- * 0 position, 1 ?, 2 ?, 3 col0,
- * 4 col1?, 5 ?, 6 ?, 7 ?,
- * 8 ?, 9 tex0, 10 tex1, 11 tex2,
- * 12 tex3, 13 ?, 14 ?, 15 ?
- * unaccounted: wgh, nor, fog
- * There are total 16 attrs.
- * vinfo->hwfmt[0] has a used-bit corresponding to each of these.
- * relation to TGSI_SEMANTIC_*:
- * - POSITION: position (always used)
- * - COLOR: col1, col0
- * - GENERIC: tex3, tex2, tex1, tex0, normal, weight
- * - FOG: fog
- */
-
- for (i = 0; i < fp->info.num_inputs; i++) {
- int isn = fp->info.input_semantic_name[i];
- int isi = fp->info.input_semantic_index[i];
- switch (isn) {
- case TGSI_SEMANTIC_POSITION:
- break;
- case TGSI_SEMANTIC_COLOR:
- assert(isi < 2);
- colors[isi] = TRUE;
- break;
- case TGSI_SEMANTIC_GENERIC:
- assert(isi < 12);
- generics[isi] = TRUE;
- break;
- case TGSI_SEMANTIC_FOG:
- fog = TRUE;
- break;
- default:
- assert(0 && "unknown input_semantic_name");
- }
- }
-
- /* always do position */ {
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_POSITION, 0);
- draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, src);
- vinfo->hwfmt[0] |= (1 << 0);
- }
-
- /* two unnamed generics */
- for (i = 4; i < 6; i++) {
- if (!generics[i])
- continue;
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_GENERIC, i);
- draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
- vinfo->hwfmt[0] |= (1 << (i - 3));
- }
-
- if (colors[0]) {
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_COLOR, 0);
- draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
- vinfo->hwfmt[0] |= (1 << 3);
- }
-
- if (colors[1]) {
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_COLOR, 1);
- draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
- vinfo->hwfmt[0] |= (1 << 4);
- }
-
- /* four unnamed generics */
- for (i = 6; i < 10; i++) {
- if (!generics[i])
- continue;
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_GENERIC, i);
- draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
- vinfo->hwfmt[0] |= (1 << (i - 1));
- }
-
- /* tex0, tex1, tex2, tex3 */
- for (i = 0; i < 4; i++) {
- if (!generics[i])
- continue;
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_GENERIC, i);
- draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
- vinfo->hwfmt[0] |= (1 << (i + 9));
- }
-
- /* two unnamed generics */
- for (i = 10; i < 12; i++) {
- if (!generics[i])
- continue;
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_GENERIC, i);
- draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
- vinfo->hwfmt[0] |= (1 << (i + 3));
- }
-
- if (fog) {
- src = draw_find_shader_output(dc, TGSI_SEMANTIC_FOG, 0);
- draw_emit_vertex_attr(vinfo, EMIT_1F, INTERP_PERSPECTIVE, src);
- vinfo->hwfmt[0] |= (1 << 15);
- }
-
- draw_compute_vertex_size(vinfo);
-}
-
-void
-nv20_emit_hw_state(struct nv20_context *nv20)
-{
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
- struct nouveau_bo *rt_bo;
- int i;
-
- if (nv20->dirty & NV20_NEW_VERTPROG) {
- //nv20_vertprog_bind(nv20, nv20->vertprog.current);
- nv20->dirty &= ~NV20_NEW_VERTPROG;
- }
-
- if (nv20->dirty & NV20_NEW_FRAGPROG) {
- nv20_fragprog_bind(nv20, nv20->fragprog.current);
- /*XXX: clear NV20_NEW_FRAGPROG if no new program uploaded */
- nv20->dirty_samplers |= (1<<10);
- nv20->dirty_samplers = 0;
- }
-
- if (nv20->dirty_samplers || (nv20->dirty & NV20_NEW_FRAGPROG)) {
- nv20_fragtex_bind(nv20);
- nv20->dirty &= ~NV20_NEW_FRAGPROG;
- }
-
- if (nv20->dirty & NV20_NEW_VTXARRAYS) {
- nv20->dirty &= ~NV20_NEW_VTXARRAYS;
- nv20_vertex_layout(nv20);
- nv20_vtxbuf_bind(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_BLEND) {
- nv20->dirty &= ~NV20_NEW_BLEND;
- nv20_state_emit_blend(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_BLENDCOL) {
- nv20->dirty &= ~NV20_NEW_BLENDCOL;
- nv20_state_emit_blend_color(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_RAST) {
- nv20->dirty &= ~NV20_NEW_RAST;
- nv20_state_emit_rast(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_DSA) {
- nv20->dirty &= ~NV20_NEW_DSA;
- nv20_state_emit_dsa(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_VIEWPORT) {
- nv20->dirty &= ~NV20_NEW_VIEWPORT;
- nv20_state_emit_viewport(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_SCISSOR) {
- nv20->dirty &= ~NV20_NEW_SCISSOR;
- nv20_state_emit_scissor(nv20);
- }
-
- if (nv20->dirty & NV20_NEW_FRAMEBUFFER) {
- nv20->dirty &= ~NV20_NEW_FRAMEBUFFER;
- nv20_state_emit_framebuffer(nv20);
- }
-
- /* Emit relocs for every referenced buffer.
- * This is to ensure the bufmgr has an accurate idea of how
- * the buffer is used. This isn't very efficient, but we don't
- * seem to take a significant performance hit. Will be improved
- * at some point. Vertex arrays are emitted by nv20_vbo.c
- */
-
- /* Render target */
- rt_bo = nouveau_bo(nv20->rt[0]);
- BEGIN_RING(chan, kelvin, NV20TCL_DMA_COLOR, 1);
- OUT_RELOCo(chan, rt_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, kelvin, NV20TCL_COLOR_OFFSET, 1);
- OUT_RELOCl(chan, rt_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
-
- if (nv20->zeta) {
- struct nouveau_bo *zeta_bo = nouveau_bo(nv20->zeta);
- BEGIN_RING(chan, kelvin, NV20TCL_DMA_ZETA, 1);
- OUT_RELOCo(chan, zeta_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, kelvin, NV20TCL_ZETA_OFFSET, 1);
- OUT_RELOCl(chan, zeta_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- /* XXX for when we allocate LMA on nv17 */
-/* BEGIN_RING(chan, kelvin, NV10TCL_LMA_DEPTH_BUFFER_OFFSET, 1);
- OUT_RELOCl(chan, nouveau_bo(nv20->zeta + lma_offset));*/
- }
-
- /* Vertex buffer */
- BEGIN_RING(chan, kelvin, NV20TCL_DMA_VTXBUF0, 1);
- OUT_RELOCo(chan, rt_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- BEGIN_RING(chan, kelvin, NV20TCL_COLOR_OFFSET, 1);
- OUT_RELOCl(chan, rt_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
-
- /* Texture images */
- for (i = 0; i < 2; i++) {
- if (!(nv20->fp_samplers & (1 << i)))
- continue;
- struct nouveau_bo *bo = nouveau_bo(nv20->tex[i].buffer);
- BEGIN_RING(chan, kelvin, NV20TCL_TX_OFFSET(i), 1);
- OUT_RELOCl(chan, bo, 0, NOUVEAU_BO_VRAM |
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- BEGIN_RING(chan, kelvin, NV20TCL_TX_FORMAT(i), 1);
- OUT_RELOCd(chan, bo, nv20->tex[i].format,
- NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
- NOUVEAU_BO_OR, NV20TCL_TX_FORMAT_DMA0,
- NV20TCL_TX_FORMAT_DMA1);
- }
-}
-
diff --git a/src/gallium/drivers/nv20/nv20_transfer.c b/src/gallium/drivers/nv20/nv20_transfer.c
deleted file mode 100644
index 699773e8e6..0000000000
--- a/src/gallium/drivers/nv20/nv20_transfer.c
+++ /dev/null
@@ -1,178 +0,0 @@
-#include <pipe/p_state.h>
-#include <pipe/p_defines.h>
-#include <pipe/p_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
-#include <util/u_math.h>
-#include <nouveau/nouveau_winsys.h>
-#include "nv20_context.h"
-#include "nv20_screen.h"
-#include "nv20_state.h"
-
-struct nv20_transfer {
- struct pipe_transfer base;
- struct pipe_surface *surface;
- boolean direct;
-};
-
-static void
-nv20_compatible_transfer_tex(struct pipe_texture *pt, unsigned width, unsigned height,
- struct pipe_texture *template)
-{
- memset(template, 0, sizeof(struct pipe_texture));
- template->target = pt->target;
- template->format = pt->format;
- template->width0 = width;
- template->height0 = height;
- template->depth0 = 1;
- template->last_level = 0;
- template->nr_samples = pt->nr_samples;
-
- template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
- NOUVEAU_TEXTURE_USAGE_LINEAR;
-}
-
-static struct pipe_transfer *
-nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
-{
- struct nv20_miptree *mt = (struct nv20_miptree *)pt;
- struct nv20_transfer *tx;
- struct pipe_texture tx_tex_template, *tx_tex;
-
- tx = CALLOC_STRUCT(nv20_transfer);
- if (!tx)
- return NULL;
-
- pipe_texture_reference(&tx->base.texture, pt);
- tx->base.x = x;
- tx->base.y = y;
- tx->base.width = w;
- tx->base.height = h;
- tx->base.stride = mt->level[level].pitch;
- tx->base.usage = usage;
- tx->base.face = face;
- tx->base.level = level;
- tx->base.zslice = zslice;
-
- /* Direct access to texture */
- if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC ||
- debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/)) &&
- pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)
- {
- tx->direct = true;
- tx->surface = pscreen->get_tex_surface(pscreen, pt,
- 0, 0, 0,
- pipe_transfer_buffer_flags(&tx->base));
- return &tx->base;
- }
-
- tx->direct = false;
-
- nv20_compatible_transfer_tex(pt, w, h, &tx_tex_template);
-
- tx_tex = pscreen->texture_create(pscreen, &tx_tex_template);
- if (!tx_tex)
- {
- FREE(tx);
- return NULL;
- }
-
- tx->base.stride = ((struct nv20_miptree*)tx_tex)->level[0].pitch;
-
- tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
- face, level, zslice,
- pipe_transfer_buffer_flags(&tx->base));
-
- pipe_texture_reference(&tx_tex, NULL);
-
- if (!tx->surface)
- {
- pipe_surface_reference(&tx->surface, NULL);
- FREE(tx);
- return NULL;
- }
-
- if (usage & PIPE_TRANSFER_READ) {
- struct nv20_screen *nvscreen = nv20_screen(pscreen);
- struct pipe_surface *src;
-
- src = pscreen->get_tex_surface(pscreen, pt,
- face, level, zslice,
- PIPE_BUFFER_USAGE_GPU_READ);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- /* TODO: Check if SIFM can un-swizzle */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- tx->surface, 0, 0,
- src, x, y,
- w, h);
-
- pipe_surface_reference(&src, NULL);
- }
-
- return &tx->base;
-}
-
-static void
-nv20_transfer_del(struct pipe_transfer *ptx)
-{
- struct nv20_transfer *tx = (struct nv20_transfer *)ptx;
-
- if (!tx->direct && (ptx->usage = PIPE_TRANSFER_WRITE)) {
- struct pipe_screen *pscreen = ptx->texture->screen;
- struct nv20_screen *nvscreen = nv20_screen(pscreen);
- struct pipe_surface *dst;
-
- dst = pscreen->get_tex_surface(pscreen, ptx->texture,
- ptx->face, ptx->level, ptx->zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER);
-
- /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
- nvscreen->eng2d->copy(nvscreen->eng2d,
- dst, tx->base.x, tx->base.y,
- tx->surface, 0, 0,
- tx->base.width, tx->base.height);
-
- pipe_surface_reference(&dst, NULL);
- }
-
- pipe_surface_reference(&tx->surface, NULL);
- pipe_texture_reference(&ptx->texture, NULL);
- FREE(ptx);
-}
-
-static void *
-nv20_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv20_transfer *tx = (struct nv20_transfer *)ptx;
- struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
- struct nv20_miptree *mt = (struct nv20_miptree *)tx->surface->texture;
- void *map = pipe_buffer_map(pscreen, mt->buffer,
- pipe_transfer_buffer_flags(ptx));
-
- if(!tx->direct)
- return map + ns->base.offset;
- else
- return map + ns->base.offset + ptx->y * ns->pitch + ptx->x * util_format_get_blocksize(ptx->texture->format);
-}
-
-static void
-nv20_transfer_unmap(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
-{
- struct nv20_transfer *tx = (struct nv20_transfer *)ptx;
- struct nv20_miptree *mt = (struct nv20_miptree *)tx->surface->texture;
-
- pipe_buffer_unmap(pscreen, mt->buffer);
-}
-
-void
-nv20_screen_init_transfer_functions(struct pipe_screen *pscreen)
-{
- pscreen->get_tex_transfer = nv20_transfer_new;
- pscreen->tex_transfer_destroy = nv20_transfer_del;
- pscreen->transfer_map = nv20_transfer_map;
- pscreen->transfer_unmap = nv20_transfer_unmap;
-}
diff --git a/src/gallium/drivers/nv20/nv20_vbo.c b/src/gallium/drivers/nv20/nv20_vbo.c
deleted file mode 100644
index 6dc9538901..0000000000
--- a/src/gallium/drivers/nv20/nv20_vbo.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "draw/draw_context.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-#include "nv20_context.h"
-#include "nv20_state.h"
-
-#include "nouveau/nouveau_channel.h"
-#include "nouveau/nouveau_pushbuf.h"
-
-void nv20_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
- unsigned indexSize,
- unsigned prim, unsigned start, unsigned count)
-{
- struct pipe_screen *pscreen = pipe->screen;
- struct nv20_context *nv20 = nv20_context( pipe );
- struct draw_context *draw = nv20->draw;
- unsigned i;
-
- nv20_emit_hw_state(nv20);
-
- /*
- * Map vertex buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv20->vtxbuf[i].buffer) {
- void *buf
- = pipe_buffer_map(pscreen,
- nv20->vtxbuf[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_vertex_buffer(draw, i, buf);
- }
- }
- /* Map index buffer, if present */
- if (indexBuffer) {
- void *mapped_indexes
- = pipe_buffer_map(pscreen, indexBuffer,
- PIPE_BUFFER_USAGE_CPU_READ);
- draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
- }
- else {
- /* no index/element buffer */
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-
- draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
- nv20->constbuf[PIPE_SHADER_VERTEX],
- nv20->constbuf_nr[PIPE_SHADER_VERTEX]);
-
- /* draw! */
- draw_arrays(nv20->draw, prim, start, count);
-
- /*
- * unmap vertex/index buffers
- */
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (nv20->vtxbuf[i].buffer) {
- pipe_buffer_unmap(pscreen, nv20->vtxbuf[i].buffer);
- draw_set_mapped_vertex_buffer(draw, i, NULL);
- }
- }
- if (indexBuffer) {
- pipe_buffer_unmap(pscreen, indexBuffer);
- draw_set_mapped_element_buffer(draw, 0, NULL);
- }
-
- draw_flush(nv20->draw);
-}
-
-void nv20_draw_arrays( struct pipe_context *pipe,
- unsigned prim, unsigned start, unsigned count)
-{
- nv20_draw_elements(pipe, NULL, 0, prim, start, count);
-}
-
-
-
diff --git a/src/gallium/drivers/nv20/nv20_vertprog.c b/src/gallium/drivers/nv20/nv20_vertprog.c
deleted file mode 100644
index 7886c2af7e..0000000000
--- a/src/gallium/drivers/nv20/nv20_vertprog.c
+++ /dev/null
@@ -1,841 +0,0 @@
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-#include "pipe/p_shader_tokens.h"
-#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_dump.h"
-
-#include "nv20_context.h"
-#include "nv20_state.h"
-
-/* TODO (at least...):
- * 1. Indexed consts + ARL
- * 2. Arb. swz/negation
- * 3. NV_vp11, NV_vp2, NV_vp3 features
- * - extra arith opcodes
- * - branching
- * - texture sampling
- * - indexed attribs
- * - indexed results
- * 4. bugs
- */
-
-#define SWZ_X 0
-#define SWZ_Y 1
-#define SWZ_Z 2
-#define SWZ_W 3
-#define MASK_X 8
-#define MASK_Y 4
-#define MASK_Z 2
-#define MASK_W 1
-#define MASK_ALL (MASK_X|MASK_Y|MASK_Z|MASK_W)
-#define DEF_SCALE 0
-#define DEF_CTEST 0
-#include "nv20_shader.h"
-
-#define swz(s,x,y,z,w) nv20_sr_swz((s), SWZ_##x, SWZ_##y, SWZ_##z, SWZ_##w)
-#define neg(s) nv20_sr_neg((s))
-#define abs(s) nv20_sr_abs((s))
-
-struct nv20_vpc {
- struct nv20_vertex_program *vp;
-
- struct nv20_vertex_program_exec *vpi;
-
- unsigned output_map[PIPE_MAX_SHADER_OUTPUTS];
-
- int high_temp;
- int temp_temp_count;
-
- struct nv20_sreg *imm;
- unsigned nr_imm;
-};
-
-static struct nv20_sreg
-temp(struct nv20_vpc *vpc)
-{
- int idx;
-
- idx = vpc->temp_temp_count++;
- idx += vpc->high_temp + 1;
- return nv20_sr(NV30SR_TEMP, idx);
-}
-
-static struct nv20_sreg
-constant(struct nv20_vpc *vpc, int pipe, float x, float y, float z, float w)
-{
- struct nv20_vertex_program *vp = vpc->vp;
- struct nv20_vertex_program_data *vpd;
- int idx;
-
- if (pipe >= 0) {
- for (idx = 0; idx < vp->nr_consts; idx++) {
- if (vp->consts[idx].index == pipe)
- return nv20_sr(NV30SR_CONST, idx);
- }
- }
-
- idx = vp->nr_consts++;
- vp->consts = realloc(vp->consts, sizeof(*vpd) * vp->nr_consts);
- vpd = &vp->consts[idx];
-
- vpd->index = pipe;
- vpd->value[0] = x;
- vpd->value[1] = y;
- vpd->value[2] = z;
- vpd->value[3] = w;
- return nv20_sr(NV30SR_CONST, idx);
-}
-
-#define arith(cc,s,o,d,m,s0,s1,s2) \
- nv20_vp_arith((cc), (s), NV30_VP_INST_##o, (d), (m), (s0), (s1), (s2))
-
-static void
-emit_src(struct nv20_vpc *vpc, uint32_t *hw, int pos, struct nv20_sreg src)
-{
- struct nv20_vertex_program *vp = vpc->vp;
- uint32_t sr = 0;
-
- switch (src.type) {
- case NV30SR_TEMP:
- sr |= (NV30_VP_SRC_REG_TYPE_TEMP << NV30_VP_SRC_REG_TYPE_SHIFT);
- sr |= (src.index << NV30_VP_SRC_TEMP_SRC_SHIFT);
- break;
- case NV30SR_INPUT:
- sr |= (NV30_VP_SRC_REG_TYPE_INPUT <<
- NV30_VP_SRC_REG_TYPE_SHIFT);
- vp->ir |= (1 << src.index);
- hw[1] |= (src.index << NV30_VP_INST_INPUT_SRC_SHIFT);
- break;
- case NV30SR_CONST:
- sr |= (NV30_VP_SRC_REG_TYPE_CONST <<
- NV30_VP_SRC_REG_TYPE_SHIFT);
- assert(vpc->vpi->const_index == -1 ||
- vpc->vpi->const_index == src.index);
- vpc->vpi->const_index = src.index;
- break;
- case NV30SR_NONE:
- sr |= (NV30_VP_SRC_REG_TYPE_INPUT <<
- NV30_VP_SRC_REG_TYPE_SHIFT);
- break;
- default:
- assert(0);
- }
-
- if (src.negate)
- sr |= NV30_VP_SRC_NEGATE;
-
- if (src.abs)
- hw[0] |= (1 << (21 + pos));
-
- sr |= ((src.swz[0] << NV30_VP_SRC_SWZ_X_SHIFT) |
- (src.swz[1] << NV30_VP_SRC_SWZ_Y_SHIFT) |
- (src.swz[2] << NV30_VP_SRC_SWZ_Z_SHIFT) |
- (src.swz[3] << NV30_VP_SRC_SWZ_W_SHIFT));
-
-/*
- * |VVV|
- * d�.�b
- * \u/
- *
- */
-
- switch (pos) {
- case 0:
- hw[1] |= ((sr & NV30_VP_SRC0_HIGH_MASK) >>
- NV30_VP_SRC0_HIGH_SHIFT) << NV30_VP_INST_SRC0H_SHIFT;
- hw[2] |= (sr & NV30_VP_SRC0_LOW_MASK) <<
- NV30_VP_INST_SRC0L_SHIFT;
- break;
- case 1:
- hw[2] |= sr << NV30_VP_INST_SRC1_SHIFT;
- break;
- case 2:
- hw[2] |= ((sr & NV30_VP_SRC2_HIGH_MASK) >>
- NV30_VP_SRC2_HIGH_SHIFT) << NV30_VP_INST_SRC2H_SHIFT;
- hw[3] |= (sr & NV30_VP_SRC2_LOW_MASK) <<
- NV30_VP_INST_SRC2L_SHIFT;
- break;
- default:
- assert(0);
- }
-}
-
-static void
-emit_dst(struct nv20_vpc *vpc, uint32_t *hw, int slot, struct nv20_sreg dst)
-{
- struct nv20_vertex_program *vp = vpc->vp;
-
- switch (dst.type) {
- case NV30SR_TEMP:
- hw[0] |= (dst.index << NV30_VP_INST_DEST_TEMP_ID_SHIFT);
- break;
- case NV30SR_OUTPUT:
- switch (dst.index) {
- case NV30_VP_INST_DEST_COL0 : vp->or |= (1 << 0); break;
- case NV30_VP_INST_DEST_COL1 : vp->or |= (1 << 1); break;
- case NV30_VP_INST_DEST_BFC0 : vp->or |= (1 << 2); break;
- case NV30_VP_INST_DEST_BFC1 : vp->or |= (1 << 3); break;
- case NV30_VP_INST_DEST_FOGC : vp->or |= (1 << 4); break;
- case NV30_VP_INST_DEST_PSZ : vp->or |= (1 << 5); break;
- case NV30_VP_INST_DEST_TC(0): vp->or |= (1 << 14); break;
- case NV30_VP_INST_DEST_TC(1): vp->or |= (1 << 15); break;
- case NV30_VP_INST_DEST_TC(2): vp->or |= (1 << 16); break;
- case NV30_VP_INST_DEST_TC(3): vp->or |= (1 << 17); break;
- case NV30_VP_INST_DEST_TC(4): vp->or |= (1 << 18); break;
- case NV30_VP_INST_DEST_TC(5): vp->or |= (1 << 19); break;
- case NV30_VP_INST_DEST_TC(6): vp->or |= (1 << 20); break;
- case NV30_VP_INST_DEST_TC(7): vp->or |= (1 << 21); break;
- default:
- break;
- }
-
- hw[3] |= (dst.index << NV30_VP_INST_DEST_SHIFT);
- hw[0] |= NV30_VP_INST_VEC_DEST_TEMP_MASK | (1<<20);
-
- /*XXX: no way this is entirely correct, someone needs to
- * figure out what exactly it is.
- */
- hw[3] |= 0x800;
- break;
- default:
- assert(0);
- }
-}
-
-static void
-nv20_vp_arith(struct nv20_vpc *vpc, int slot, int op,
- struct nv20_sreg dst, int mask,
- struct nv20_sreg s0, struct nv20_sreg s1,
- struct nv20_sreg s2)
-{
- struct nv20_vertex_program *vp = vpc->vp;
- uint32_t *hw;
-
- vp->insns = realloc(vp->insns, ++vp->nr_insns * sizeof(*vpc->vpi));
- vpc->vpi = &vp->insns[vp->nr_insns - 1];
- memset(vpc->vpi, 0, sizeof(*vpc->vpi));
- vpc->vpi->const_index = -1;
-
- hw = vpc->vpi->data;
-
- hw[0] |= (NV30_VP_INST_COND_TR << NV30_VP_INST_COND_SHIFT);
- hw[0] |= ((0 << NV30_VP_INST_COND_SWZ_X_SHIFT) |
- (1 << NV30_VP_INST_COND_SWZ_Y_SHIFT) |
- (2 << NV30_VP_INST_COND_SWZ_Z_SHIFT) |
- (3 << NV30_VP_INST_COND_SWZ_W_SHIFT));
-
- hw[1] |= (op << NV30_VP_INST_VEC_OPCODE_SHIFT);
-// hw[3] |= NV30_VP_INST_SCA_DEST_TEMP_MASK;
-// hw[3] |= (mask << NV30_VP_INST_VEC_WRITEMASK_SHIFT);
-
- if (dst.type == NV30SR_OUTPUT) {
- if (slot)
- hw[3] |= (mask << NV30_VP_INST_SDEST_WRITEMASK_SHIFT);
- else
- hw[3] |= (mask << NV30_VP_INST_VDEST_WRITEMASK_SHIFT);
- } else {
- if (slot)
- hw[3] |= (mask << NV30_VP_INST_STEMP_WRITEMASK_SHIFT);
- else
- hw[3] |= (mask << NV30_VP_INST_VTEMP_WRITEMASK_SHIFT);
- }
-
- emit_dst(vpc, hw, slot, dst);
- emit_src(vpc, hw, 0, s0);
- emit_src(vpc, hw, 1, s1);
- emit_src(vpc, hw, 2, s2);
-}
-
-static INLINE struct nv20_sreg
-tgsi_src(struct nv20_vpc *vpc, const struct tgsi_full_src_register *fsrc) {
- struct nv20_sreg src;
-
- switch (fsrc->Register.File) {
- case TGSI_FILE_INPUT:
- src = nv20_sr(NV30SR_INPUT, fsrc->Register.Index);
- break;
- case TGSI_FILE_CONSTANT:
- src = constant(vpc, fsrc->Register.Index, 0, 0, 0, 0);
- break;
- case TGSI_FILE_IMMEDIATE:
- src = vpc->imm[fsrc->Register.Index];
- break;
- case TGSI_FILE_TEMPORARY:
- if (vpc->high_temp < fsrc->Register.Index)
- vpc->high_temp = fsrc->Register.Index;
- src = nv20_sr(NV30SR_TEMP, fsrc->Register.Index);
- break;
- default:
- NOUVEAU_ERR("bad src file\n");
- break;
- }
-
- src.abs = fsrc->Register.Absolute;
- src.negate = fsrc->Register.Negate;
- src.swz[0] = fsrc->Register.SwizzleX;
- src.swz[1] = fsrc->Register.SwizzleY;
- src.swz[2] = fsrc->Register.SwizzleZ;
- src.swz[3] = fsrc->Register.SwizzleW;
- return src;
-}
-
-static INLINE struct nv20_sreg
-tgsi_dst(struct nv20_vpc *vpc, const struct tgsi_full_dst_register *fdst) {
- struct nv20_sreg dst;
-
- switch (fdst->Register.File) {
- case TGSI_FILE_OUTPUT:
- dst = nv20_sr(NV30SR_OUTPUT,
- vpc->output_map[fdst->Register.Index]);
-
- break;
- case TGSI_FILE_TEMPORARY:
- dst = nv20_sr(NV30SR_TEMP, fdst->Register.Index);
- if (vpc->high_temp < dst.index)
- vpc->high_temp = dst.index;
- break;
- default:
- NOUVEAU_ERR("bad dst file\n");
- break;
- }
-
- return dst;
-}
-
-static INLINE int
-tgsi_mask(uint tgsi)
-{
- int mask = 0;
-
- if (tgsi & TGSI_WRITEMASK_X) mask |= MASK_X;
- if (tgsi & TGSI_WRITEMASK_Y) mask |= MASK_Y;
- if (tgsi & TGSI_WRITEMASK_Z) mask |= MASK_Z;
- if (tgsi & TGSI_WRITEMASK_W) mask |= MASK_W;
- return mask;
-}
-
-static boolean
-nv20_vertprog_parse_instruction(struct nv20_vpc *vpc,
- const struct tgsi_full_instruction *finst)
-{
- struct nv20_sreg src[3], dst, tmp;
- struct nv20_sreg none = nv20_sr(NV30SR_NONE, 0);
- int mask;
- int ai = -1, ci = -1;
- int i;
-
- if (finst->Instruction.Opcode == TGSI_OPCODE_END)
- return TRUE;
-
- vpc->temp_temp_count = 0;
- for (i = 0; i < finst->Instruction.NumSrcRegs; i++) {
- const struct tgsi_full_src_register *fsrc;
-
- fsrc = &finst->Src[i];
- if (fsrc->Register.File == TGSI_FILE_TEMPORARY) {
- src[i] = tgsi_src(vpc, fsrc);
- }
- }
-
- for (i = 0; i < finst->Instruction.NumSrcRegs; i++) {
- const struct tgsi_full_src_register *fsrc;
-
- fsrc = &finst->Src[i];
- switch (fsrc->Register.File) {
- case TGSI_FILE_INPUT:
- if (ai == -1 || ai == fsrc->Register.Index) {
- ai = fsrc->Register.Index;
- src[i] = tgsi_src(vpc, fsrc);
- } else {
- src[i] = temp(vpc);
- arith(vpc, 0, OP_MOV, src[i], MASK_ALL,
- tgsi_src(vpc, fsrc), none, none);
- }
- break;
- /*XXX: index comparison is broken now that consts come from
- * two different register files.
- */
- case TGSI_FILE_CONSTANT:
- case TGSI_FILE_IMMEDIATE:
- if (ci == -1 || ci == fsrc->Register.Index) {
- ci = fsrc->Register.Index;
- src[i] = tgsi_src(vpc, fsrc);
- } else {
- src[i] = temp(vpc);
- arith(vpc, 0, OP_MOV, src[i], MASK_ALL,
- tgsi_src(vpc, fsrc), none, none);
- }
- break;
- case TGSI_FILE_TEMPORARY:
- /* handled above */
- break;
- default:
- NOUVEAU_ERR("bad src file\n");
- return FALSE;
- }
- }
-
- dst = tgsi_dst(vpc, &finst->Dst[0]);
- mask = tgsi_mask(finst->Dst[0].Register.WriteMask);
-
- switch (finst->Instruction.Opcode) {
- case TGSI_OPCODE_ABS:
- arith(vpc, 0, OP_MOV, dst, mask, abs(src[0]), none, none);
- break;
- case TGSI_OPCODE_ADD:
- arith(vpc, 0, OP_ADD, dst, mask, src[0], none, src[1]);
- break;
- case TGSI_OPCODE_ARL:
- arith(vpc, 0, OP_ARL, dst, mask, src[0], none, none);
- break;
- case TGSI_OPCODE_DP3:
- arith(vpc, 0, OP_DP3, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_DP4:
- arith(vpc, 0, OP_DP4, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_DPH:
- arith(vpc, 0, OP_DPH, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_DST:
- arith(vpc, 0, OP_DST, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_EX2:
- arith(vpc, 1, OP_EX2, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_EXP:
- arith(vpc, 1, OP_EXP, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_FLR:
- arith(vpc, 0, OP_FLR, dst, mask, src[0], none, none);
- break;
- case TGSI_OPCODE_FRC:
- arith(vpc, 0, OP_FRC, dst, mask, src[0], none, none);
- break;
- case TGSI_OPCODE_LG2:
- arith(vpc, 1, OP_LG2, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_LIT:
- arith(vpc, 1, OP_LIT, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_LOG:
- arith(vpc, 1, OP_LOG, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_MAD:
- arith(vpc, 0, OP_MAD, dst, mask, src[0], src[1], src[2]);
- break;
- case TGSI_OPCODE_MAX:
- arith(vpc, 0, OP_MAX, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_MIN:
- arith(vpc, 0, OP_MIN, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_MOV:
- arith(vpc, 0, OP_MOV, dst, mask, src[0], none, none);
- break;
- case TGSI_OPCODE_MUL:
- arith(vpc, 0, OP_MUL, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_POW:
- tmp = temp(vpc);
- arith(vpc, 1, OP_LG2, tmp, MASK_X, none, none,
- swz(src[0], X, X, X, X));
- arith(vpc, 0, OP_MUL, tmp, MASK_X, swz(tmp, X, X, X, X),
- swz(src[1], X, X, X, X), none);
- arith(vpc, 1, OP_EX2, dst, mask, none, none,
- swz(tmp, X, X, X, X));
- break;
- case TGSI_OPCODE_RCP:
- arith(vpc, 1, OP_RCP, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_RET:
- break;
- case TGSI_OPCODE_RSQ:
- arith(vpc, 1, OP_RSQ, dst, mask, none, none, src[0]);
- break;
- case TGSI_OPCODE_SGE:
- arith(vpc, 0, OP_SGE, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_SGT:
- arith(vpc, 0, OP_SGT, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_SLT:
- arith(vpc, 0, OP_SLT, dst, mask, src[0], src[1], none);
- break;
- case TGSI_OPCODE_SUB:
- arith(vpc, 0, OP_ADD, dst, mask, src[0], none, neg(src[1]));
- break;
- case TGSI_OPCODE_XPD:
- tmp = temp(vpc);
- arith(vpc, 0, OP_MUL, tmp, mask,
- swz(src[0], Z, X, Y, Y), swz(src[1], Y, Z, X, X), none);
- arith(vpc, 0, OP_MAD, dst, (mask & ~MASK_W),
- swz(src[0], Y, Z, X, X), swz(src[1], Z, X, Y, Y),
- neg(tmp));
- break;
- default:
- NOUVEAU_ERR("invalid opcode %d\n", finst->Instruction.Opcode);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static boolean
-nv20_vertprog_parse_decl_output(struct nv20_vpc *vpc,
- const struct tgsi_full_declaration *fdec)
-{
- int hw;
-
- switch (fdec->Semantic.Name) {
- case TGSI_SEMANTIC_POSITION:
- hw = NV30_VP_INST_DEST_POS;
- break;
- case TGSI_SEMANTIC_COLOR:
- if (fdec->Semantic.Index == 0) {
- hw = NV30_VP_INST_DEST_COL0;
- } else
- if (fdec->Semantic.Index == 1) {
- hw = NV30_VP_INST_DEST_COL1;
- } else {
- NOUVEAU_ERR("bad colour semantic index\n");
- return FALSE;
- }
- break;
- case TGSI_SEMANTIC_BCOLOR:
- if (fdec->Semantic.Index == 0) {
- hw = NV30_VP_INST_DEST_BFC0;
- } else
- if (fdec->Semantic.Index == 1) {
- hw = NV30_VP_INST_DEST_BFC1;
- } else {
- NOUVEAU_ERR("bad bcolour semantic index\n");
- return FALSE;
- }
- break;
- case TGSI_SEMANTIC_FOG:
- hw = NV30_VP_INST_DEST_FOGC;
- break;
- case TGSI_SEMANTIC_PSIZE:
- hw = NV30_VP_INST_DEST_PSZ;
- break;
- case TGSI_SEMANTIC_GENERIC:
- if (fdec->Semantic.Index <= 7) {
- hw = NV30_VP_INST_DEST_TC(fdec->Semantic.Index);
- } else {
- NOUVEAU_ERR("bad generic semantic index\n");
- return FALSE;
- }
- break;
- case TGSI_SEMANTIC_EDGEFLAG:
- NOUVEAU_ERR("cannot handle edgeflag output\n");
- return FALSE;
- default:
- NOUVEAU_ERR("bad output semantic\n");
- return FALSE;
- }
-
- vpc->output_map[fdec->Range.First] = hw;
- return TRUE;
-}
-
-static boolean
-nv20_vertprog_prepare(struct nv20_vpc *vpc)
-{
- struct tgsi_parse_context p;
- int nr_imm = 0;
-
- tgsi_parse_init(&p, vpc->vp->pipe.tokens);
- while (!tgsi_parse_end_of_tokens(&p)) {
- const union tgsi_full_token *tok = &p.FullToken;
-
- tgsi_parse_token(&p);
- switch(tok->Token.Type) {
- case TGSI_TOKEN_TYPE_IMMEDIATE:
- nr_imm++;
- break;
- default:
- break;
- }
- }
- tgsi_parse_free(&p);
-
- if (nr_imm) {
- vpc->imm = CALLOC(nr_imm, sizeof(struct nv20_sreg));
- assert(vpc->imm);
- }
-
- return TRUE;
-}
-
-static void
-nv20_vertprog_translate(struct nv20_context *nv20,
- struct nv20_vertex_program *vp)
-{
- struct tgsi_parse_context parse;
- struct nv20_vpc *vpc = NULL;
-
- tgsi_dump(vp->pipe.tokens,0);
-
- vpc = CALLOC(1, sizeof(struct nv20_vpc));
- if (!vpc)
- return;
- vpc->vp = vp;
- vpc->high_temp = -1;
-
- if (!nv20_vertprog_prepare(vpc)) {
- FREE(vpc);
- return;
- }
-
- tgsi_parse_init(&parse, vp->pipe.tokens);
-
- while (!tgsi_parse_end_of_tokens(&parse)) {
- tgsi_parse_token(&parse);
-
- switch (parse.FullToken.Token.Type) {
- case TGSI_TOKEN_TYPE_DECLARATION:
- {
- const struct tgsi_full_declaration *fdec;
- fdec = &parse.FullToken.FullDeclaration;
- switch (fdec->Declaration.File) {
- case TGSI_FILE_OUTPUT:
- if (!nv20_vertprog_parse_decl_output(vpc, fdec))
- goto out_err;
- break;
- default:
- break;
- }
- }
- break;
- case TGSI_TOKEN_TYPE_IMMEDIATE:
- {
- const struct tgsi_full_immediate *imm;
-
- imm = &parse.FullToken.FullImmediate;
- assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32);
- assert(imm->Immediate.NrTokens == 4 + 1);
- vpc->imm[vpc->nr_imm++] =
- constant(vpc, -1,
- imm->u[0].Float,
- imm->u[1].Float,
- imm->u[2].Float,
- imm->u[3].Float);
- }
- break;
- case TGSI_TOKEN_TYPE_INSTRUCTION:
- {
- const struct tgsi_full_instruction *finst;
- finst = &parse.FullToken.FullInstruction;
- if (!nv20_vertprog_parse_instruction(vpc, finst))
- goto out_err;
- }
- break;
- default:
- break;
- }
- }
-
- vp->insns[vp->nr_insns - 1].data[3] |= NV30_VP_INST_LAST;
- vp->translated = TRUE;
-out_err:
- tgsi_parse_free(&parse);
- FREE(vpc);
-}
-
-static boolean
-nv20_vertprog_validate(struct nv20_context *nv20)
-{
- struct pipe_screen *pscreen = nv20->pipe.screen;
- struct nouveau_winsys *nvws = nv20->nvws;
- struct nouveau_grobj *rankine = nv20->screen->rankine;
- struct nv20_vertex_program *vp;
- struct pipe_buffer *constbuf;
- boolean upload_code = FALSE, upload_data = FALSE;
- int i;
-
- vp = nv20->vertprog;
- constbuf = nv20->constbuf[PIPE_SHADER_VERTEX];
-
- /* Translate TGSI shader into hw bytecode */
- if (!vp->translated) {
- nv20_vertprog_translate(nv20, vp);
- if (!vp->translated)
- return FALSE;
- }
-
- /* Allocate hw vtxprog exec slots */
- if (!vp->exec) {
- struct nouveau_resource *heap = nv20->screen->vp_exec_heap;
- struct nouveau_stateobj *so;
- uint vplen = vp->nr_insns;
-
- if (nvws->res_alloc(heap, vplen, vp, &vp->exec)) {
- while (heap->next && heap->size < vplen) {
- struct nv20_vertex_program *evict;
-
- evict = heap->next->priv;
- nvws->res_free(&evict->exec);
- }
-
- if (nvws->res_alloc(heap, vplen, vp, &vp->exec))
- assert(0);
- }
-
- so = so_new(2, 0);
- so_method(so, rankine, NV34TCL_VP_START_FROM_ID, 1);
- so_data (so, vp->exec->start);
- so_ref(so, &vp->so);
-
- upload_code = TRUE;
- }
-
- /* Allocate hw vtxprog const slots */
- if (vp->nr_consts && !vp->data) {
- struct nouveau_resource *heap = nv20->screen->vp_data_heap;
-
- if (nvws->res_alloc(heap, vp->nr_consts, vp, &vp->data)) {
- while (heap->next && heap->size < vp->nr_consts) {
- struct nv20_vertex_program *evict;
-
- evict = heap->next->priv;
- nvws->res_free(&evict->data);
- }
-
- if (nvws->res_alloc(heap, vp->nr_consts, vp, &vp->data))
- assert(0);
- }
-
- /*XXX: handle this some day */
- assert(vp->data->start >= vp->data_start_min);
-
- upload_data = TRUE;
- if (vp->data_start != vp->data->start)
- upload_code = TRUE;
- }
-
- /* If exec or data segments moved we need to patch the program to
- * fixup offsets and register IDs.
- */
- if (vp->exec_start != vp->exec->start) {
- for (i = 0; i < vp->nr_insns; i++) {
- struct nv20_vertex_program_exec *vpi = &vp->insns[i];
-
- if (vpi->has_branch_offset) {
- assert(0);
- }
- }
-
- vp->exec_start = vp->exec->start;
- }
-
- if (vp->nr_consts && vp->data_start != vp->data->start) {
- for (i = 0; i < vp->nr_insns; i++) {
- struct nv20_vertex_program_exec *vpi = &vp->insns[i];
-
- if (vpi->const_index >= 0) {
- vpi->data[1] &= ~NV30_VP_INST_CONST_SRC_MASK;
- vpi->data[1] |=
- (vpi->const_index + vp->data->start) <<
- NV30_VP_INST_CONST_SRC_SHIFT;
-
- }
- }
-
- vp->data_start = vp->data->start;
- }
-
- /* Update + Upload constant values */
- if (vp->nr_consts) {
- float *map = NULL;
-
- if (constbuf) {
- map = pipe_buffer_map(pscreen, constbuf,
- PIPE_BUFFER_USAGE_CPU_READ);
- }
-
- for (i = 0; i < vp->nr_consts; i++) {
- struct nv20_vertex_program_data *vpd = &vp->consts[i];
-
- if (vpd->index >= 0) {
- if (!upload_data &&
- !memcmp(vpd->value, &map[vpd->index * 4],
- 4 * sizeof(float)))
- continue;
- memcpy(vpd->value, &map[vpd->index * 4],
- 4 * sizeof(float));
- }
-
- BEGIN_RING(rankine, NV34TCL_VP_UPLOAD_CONST_ID, 5);
- OUT_RING (i + vp->data->start);
- OUT_RINGp ((uint32_t *)vpd->value, 4);
- }
-
- if (constbuf)
- pipe_buffer_unmap(pscreen, constbuf);
- }
-
- /* Upload vtxprog */
- if (upload_code) {
-#if 0
- for (i = 0; i < vp->nr_insns; i++) {
- NOUVEAU_MSG("VP inst %d: 0x%08x 0x%08x 0x%08x 0x%08x\n",
- i, vp->insns[i].data[0], vp->insns[i].data[1],
- vp->insns[i].data[2], vp->insns[i].data[3]);
- }
-#endif
- BEGIN_RING(rankine, NV34TCL_VP_UPLOAD_FROM_ID, 1);
- OUT_RING (vp->exec->start);
- for (i = 0; i < vp->nr_insns; i++) {
- BEGIN_RING(rankine, NV34TCL_VP_UPLOAD_INST(0), 4);
- OUT_RINGp (vp->insns[i].data, 4);
- }
- }
-
- if (vp->so != nv20->state.hw[NV30_STATE_VERTPROG]) {
- so_ref(vp->so, &nv20->state.hw[NV30_STATE_VERTPROG]);
- return TRUE;
- }
-
- return FALSE;
-}
-
-void
-nv20_vertprog_destroy(struct nv20_context *nv20, struct nv20_vertex_program *vp)
-{
- struct nouveau_winsys *nvws = nv20->screen->nvws;
-
- vp->translated = FALSE;
-
- if (vp->nr_insns) {
- FREE(vp->insns);
- vp->insns = NULL;
- vp->nr_insns = 0;
- }
-
- if (vp->nr_consts) {
- FREE(vp->consts);
- vp->consts = NULL;
- vp->nr_consts = 0;
- }
-
- nvws->res_free(&vp->exec);
- vp->exec_start = 0;
- nvws->res_free(&vp->data);
- vp->data_start = 0;
- vp->data_start_min = 0;
-
- vp->ir = vp->or = 0;
- so_ref(NULL, &vp->so);
-}
-
-struct nv20_state_entry nv20_state_vertprog = {
- .validate = nv20_vertprog_validate,
- .dirty = {
- .pipe = NV30_NEW_VERTPROG /*| NV30_NEW_UCP*/,
- .hw = NV30_STATE_VERTPROG,
- }
-};
diff --git a/src/gallium/drivers/nv30/nv30_context.c b/src/gallium/drivers/nv30/nv30_context.c
index 54572e9ab3..8a40cea2e5 100644
--- a/src/gallium/drivers/nv30/nv30_context.c
+++ b/src/gallium/drivers/nv30/nv30_context.c
@@ -1,6 +1,6 @@
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "nv30_context.h"
#include "nv30_screen.h"
diff --git a/src/gallium/drivers/nv30/nv30_context.h b/src/gallium/drivers/nv30/nv30_context.h
index e59449287b..7d05338327 100644
--- a/src/gallium/drivers/nv30/nv30_context.h
+++ b/src/gallium/drivers/nv30/nv30_context.h
@@ -1,6 +1,8 @@
#ifndef __NV30_CONTEXT_H__
#define __NV30_CONTEXT_H__
+#include <stdio.h>
+
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
@@ -8,6 +10,7 @@
#include "util/u_memory.h"
#include "util/u_math.h"
+#include "util/u_inlines.h"
#include "draw/draw_vertex.h"
diff --git a/src/gallium/drivers/nv30/nv30_fragprog.c b/src/gallium/drivers/nv30/nv30_fragprog.c
index 2d565cb631..2c432c6dfa 100644
--- a/src/gallium/drivers/nv30/nv30_fragprog.c
+++ b/src/gallium/drivers/nv30/nv30_fragprog.c
@@ -1,7 +1,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_dump.h"
diff --git a/src/gallium/drivers/nv30/nv30_miptree.c b/src/gallium/drivers/nv30/nv30_miptree.c
index 8fbba38e78..c29c36e20a 100644
--- a/src/gallium/drivers/nv30/nv30_miptree.c
+++ b/src/gallium/drivers/nv30/nv30_miptree.c
@@ -1,11 +1,11 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "nv30_context.h"
-#include "../nv04/nv04_surface_2d.h"
+#include "../nouveau/nv04_surface_2d.h"
static void
nv30_miptree_layout(struct nv30_miptree *nv30mt)
diff --git a/src/gallium/drivers/nv30/nv30_screen.c b/src/gallium/drivers/nv30/nv30_screen.c
index ee83ec5676..62ee2e7697 100644
--- a/src/gallium/drivers/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nv30/nv30_screen.c
@@ -173,9 +173,9 @@ nv30_screen_destroy(struct pipe_screen *pscreen)
so_ref(NULL, &screen->state[i]);
}
- nouveau_resource_free(&screen->vp_exec_heap);
- nouveau_resource_free(&screen->vp_data_heap);
- nouveau_resource_free(&screen->query_heap);
+ nouveau_resource_destroy(&screen->vp_exec_heap);
+ nouveau_resource_destroy(&screen->vp_data_heap);
+ nouveau_resource_destroy(&screen->query_heap);
nouveau_notifier_free(&screen->query);
nouveau_notifier_free(&screen->sync);
nouveau_grobj_free(&screen->rankine);
diff --git a/src/gallium/drivers/nv30/nv30_screen.h b/src/gallium/drivers/nv30/nv30_screen.h
index 5fbd998b53..744a72de91 100644
--- a/src/gallium/drivers/nv30/nv30_screen.h
+++ b/src/gallium/drivers/nv30/nv30_screen.h
@@ -3,7 +3,7 @@
#include "nouveau/nouveau_screen.h"
-#include "nv04/nv04_surface_2d.h"
+#include "nouveau/nv04_surface_2d.h"
struct nv30_screen {
struct nouveau_screen base;
diff --git a/src/gallium/drivers/nv30/nv30_state.c b/src/gallium/drivers/nv30/nv30_state.c
index 1f4c964270..25532e3a54 100644
--- a/src/gallium/drivers/nv30/nv30_state.c
+++ b/src/gallium/drivers/nv30/nv30_state.c
@@ -1,6 +1,6 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv30/nv30_surface.c b/src/gallium/drivers/nv30/nv30_surface.c
index 5e237e13eb..b48c5ab51a 100644
--- a/src/gallium/drivers/nv30/nv30_surface.c
+++ b/src/gallium/drivers/nv30/nv30_surface.c
@@ -28,8 +28,8 @@
#include "nv30_context.h"
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "util/u_tile.h"
static void
diff --git a/src/gallium/drivers/nv30/nv30_transfer.c b/src/gallium/drivers/nv30/nv30_transfer.c
index 65598991c6..554bcbbdd0 100644
--- a/src/gallium/drivers/nv30/nv30_transfer.c
+++ b/src/gallium/drivers/nv30/nv30_transfer.c
@@ -1,6 +1,6 @@
#include <pipe/p_state.h>
#include <pipe/p_defines.h>
-#include <pipe/p_inlines.h>
+#include <util/u_inlines.h>
#include <util/u_format.h>
#include <util/u_memory.h>
#include <util/u_math.h>
diff --git a/src/gallium/drivers/nv30/nv30_vbo.c b/src/gallium/drivers/nv30/nv30_vbo.c
index 1c5db03ea2..d50055fdd3 100644
--- a/src/gallium/drivers/nv30/nv30_vbo.c
+++ b/src/gallium/drivers/nv30/nv30_vbo.c
@@ -1,6 +1,6 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "nv30_context.h"
#include "nv30_state.h"
diff --git a/src/gallium/drivers/nv30/nv30_vertprog.c b/src/gallium/drivers/nv30/nv30_vertprog.c
index e77a5be3f2..809be3712d 100644
--- a/src/gallium/drivers/nv30/nv30_vertprog.c
+++ b/src/gallium/drivers/nv30/nv30_vertprog.c
@@ -1,7 +1,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv40/nv40_context.c b/src/gallium/drivers/nv40/nv40_context.c
index f79ae4db84..ffe25ffebd 100644
--- a/src/gallium/drivers/nv40/nv40_context.c
+++ b/src/gallium/drivers/nv40/nv40_context.c
@@ -1,6 +1,6 @@
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "nv40_context.h"
#include "nv40_screen.h"
diff --git a/src/gallium/drivers/nv40/nv40_context.h b/src/gallium/drivers/nv40/nv40_context.h
index e219bb537a..3998cf2dd3 100644
--- a/src/gallium/drivers/nv40/nv40_context.h
+++ b/src/gallium/drivers/nv40/nv40_context.h
@@ -1,6 +1,8 @@
#ifndef __NV40_CONTEXT_H__
#define __NV40_CONTEXT_H__
+#include <stdio.h>
+
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
@@ -8,6 +10,7 @@
#include "util/u_memory.h"
#include "util/u_math.h"
+#include "util/u_inlines.h"
#include "draw/draw_vertex.h"
diff --git a/src/gallium/drivers/nv40/nv40_draw.c b/src/gallium/drivers/nv40/nv40_draw.c
index a2fd5f6c02..60ab49fad1 100644
--- a/src/gallium/drivers/nv40/nv40_draw.c
+++ b/src/gallium/drivers/nv40/nv40_draw.c
@@ -1,5 +1,5 @@
#include "pipe/p_shader_tokens.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_pack_color.h"
diff --git a/src/gallium/drivers/nv40/nv40_fragprog.c b/src/gallium/drivers/nv40/nv40_fragprog.c
index 1237066c39..dc24f9b08a 100644
--- a/src/gallium/drivers/nv40/nv40_fragprog.c
+++ b/src/gallium/drivers/nv40/nv40_fragprog.c
@@ -1,7 +1,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv40/nv40_miptree.c b/src/gallium/drivers/nv40/nv40_miptree.c
index 89bd155ff4..ad1a9a5195 100644
--- a/src/gallium/drivers/nv40/nv40_miptree.c
+++ b/src/gallium/drivers/nv40/nv40_miptree.c
@@ -1,11 +1,11 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "nv40_context.h"
-#include "../nv04/nv04_surface_2d.h"
+#include "../nouveau/nv04_surface_2d.h"
diff --git a/src/gallium/drivers/nv40/nv40_screen.c b/src/gallium/drivers/nv40/nv40_screen.c
index b1a7343b40..56fb80975c 100644
--- a/src/gallium/drivers/nv40/nv40_screen.c
+++ b/src/gallium/drivers/nv40/nv40_screen.c
@@ -157,9 +157,9 @@ nv40_screen_destroy(struct pipe_screen *pscreen)
so_ref(NULL, &screen->state[i]);
}
- nouveau_resource_free(&screen->vp_exec_heap);
- nouveau_resource_free(&screen->vp_data_heap);
- nouveau_resource_free(&screen->query_heap);
+ nouveau_resource_destroy(&screen->vp_exec_heap);
+ nouveau_resource_destroy(&screen->vp_data_heap);
+ nouveau_resource_destroy(&screen->query_heap);
nouveau_notifier_free(&screen->query);
nouveau_notifier_free(&screen->sync);
nouveau_grobj_free(&screen->curie);
diff --git a/src/gallium/drivers/nv40/nv40_screen.h b/src/gallium/drivers/nv40/nv40_screen.h
index 57b4c8fc46..98fde8755b 100644
--- a/src/gallium/drivers/nv40/nv40_screen.h
+++ b/src/gallium/drivers/nv40/nv40_screen.h
@@ -2,7 +2,7 @@
#define __NV40_SCREEN_H__
#include "nouveau/nouveau_screen.h"
-#include "nv04/nv04_surface_2d.h"
+#include "nouveau/nv04_surface_2d.h"
struct nv40_screen {
struct nouveau_screen base;
diff --git a/src/gallium/drivers/nv40/nv40_state.c b/src/gallium/drivers/nv40/nv40_state.c
index 7a63fba18c..b09c450dc2 100644
--- a/src/gallium/drivers/nv40/nv40_state.c
+++ b/src/gallium/drivers/nv40/nv40_state.c
@@ -1,6 +1,6 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "draw/draw_context.h"
diff --git a/src/gallium/drivers/nv40/nv40_surface.c b/src/gallium/drivers/nv40/nv40_surface.c
index a596547974..02ecfd7bbb 100644
--- a/src/gallium/drivers/nv40/nv40_surface.c
+++ b/src/gallium/drivers/nv40/nv40_surface.c
@@ -27,7 +27,7 @@
**************************************************************************/
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_tile.h"
diff --git a/src/gallium/drivers/nv40/nv40_transfer.c b/src/gallium/drivers/nv40/nv40_transfer.c
index 791ee6823d..ee266c6cfb 100644
--- a/src/gallium/drivers/nv40/nv40_transfer.c
+++ b/src/gallium/drivers/nv40/nv40_transfer.c
@@ -1,6 +1,6 @@
#include <pipe/p_state.h>
#include <pipe/p_defines.h>
-#include <pipe/p_inlines.h>
+#include <util/u_inlines.h>
#include <util/u_format.h>
#include <util/u_memory.h>
#include <util/u_math.h>
diff --git a/src/gallium/drivers/nv40/nv40_vbo.c b/src/gallium/drivers/nv40/nv40_vbo.c
index a777898f68..d1c76c03cd 100644
--- a/src/gallium/drivers/nv40/nv40_vbo.c
+++ b/src/gallium/drivers/nv40/nv40_vbo.c
@@ -1,6 +1,6 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "nv40_context.h"
#include "nv40_state.h"
diff --git a/src/gallium/drivers/nv40/nv40_vertprog.c b/src/gallium/drivers/nv40/nv40_vertprog.c
index 8d80fcad38..b289eef0fc 100644
--- a/src/gallium/drivers/nv40/nv40_vertprog.c
+++ b/src/gallium/drivers/nv40/nv40_vertprog.c
@@ -1,7 +1,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c
index 5c705ccc8f..ac1abc1d5c 100644
--- a/src/gallium/drivers/nv50/nv50_context.c
+++ b/src/gallium/drivers/nv50/nv50_context.c
@@ -22,7 +22,7 @@
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "nv50_context.h"
#include "nv50_screen.h"
diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h
index bebcd95054..44d8f61342 100644
--- a/src/gallium/drivers/nv50/nv50_context.h
+++ b/src/gallium/drivers/nv50/nv50_context.h
@@ -1,6 +1,7 @@
#ifndef __NV50_CONTEXT_H__
#define __NV50_CONTEXT_H__
+#include <stdio.h>
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
@@ -8,6 +9,7 @@
#include "util/u_memory.h"
#include "util/u_math.h"
+#include "util/u_inlines.h"
#include "draw/draw_vertex.h"
diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c
index dc8364ced7..7297c74a83 100644
--- a/src/gallium/drivers/nv50/nv50_miptree.c
+++ b/src/gallium/drivers/nv50/nv50_miptree.c
@@ -22,7 +22,7 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "nv50_context.h"
diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c
index e74a526c62..3653e606ef 100644
--- a/src/gallium/drivers/nv50/nv50_program.c
+++ b/src/gallium/drivers/nv50/nv50_program.c
@@ -23,7 +23,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv50/nv50_query.c b/src/gallium/drivers/nv50/nv50_query.c
index 9eba4c9611..57b16a355d 100644
--- a/src/gallium/drivers/nv50/nv50_query.c
+++ b/src/gallium/drivers/nv50/nv50_query.c
@@ -21,7 +21,7 @@
*/
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "nv50_context.h"
diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c
index c4465a228c..48c7b19584 100644
--- a/src/gallium/drivers/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nv50/nv50_screen.c
@@ -195,6 +195,9 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
nouveau_grobj_free(&screen->tesla);
nouveau_grobj_free(&screen->eng2d);
nouveau_grobj_free(&screen->m2mf);
+ nouveau_resource_destroy(&screen->immd_heap[0]);
+ nouveau_resource_destroy(&screen->parm_heap[0]);
+ nouveau_resource_destroy(&screen->parm_heap[1]);
nouveau_screen_fini(&screen->base);
FREE(screen);
}
diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c
index da8dc933b0..7eb326adf5 100644
--- a/src/gallium/drivers/nv50/nv50_state.c
+++ b/src/gallium/drivers/nv50/nv50_state.c
@@ -22,7 +22,7 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c
index 6378132979..ac0c1d0270 100644
--- a/src/gallium/drivers/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nv50/nv50_surface.c
@@ -25,8 +25,8 @@
#include "nouveau/nouveau_pushbuf.h"
#include "nv50_context.h"
#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "util/u_tile.h"
diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c
index a2f1db2914..d08b4d7354 100644
--- a/src/gallium/drivers/nv50/nv50_transfer.c
+++ b/src/gallium/drivers/nv50/nv50_transfer.c
@@ -1,6 +1,6 @@
#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"
diff --git a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c
index bfb1b34d27..ca2f8061f3 100644
--- a/src/gallium/drivers/nv50/nv50_vbo.c
+++ b/src/gallium/drivers/nv50/nv50_vbo.c
@@ -22,7 +22,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 3f461640a0..ea9b4abfde 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -28,7 +28,7 @@
#include "util/u_blitter.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "r300_screen.h"
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index 60ea9c171d..39bcdc8fe6 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -77,17 +77,21 @@ void r300_shader_read_fs_inputs(struct tgsi_shader_info* info,
static void find_output_registers(struct r300_fragment_program_compiler * compiler,
struct r300_fragment_shader * fs)
{
- unsigned i;
+ unsigned i, colorbuf_count = 0;
/* Mark the outputs as not present initially */
- compiler->OutputColor = fs->info.num_outputs;
+ compiler->OutputColor[0] = fs->info.num_outputs;
+ compiler->OutputColor[1] = fs->info.num_outputs;
+ compiler->OutputColor[2] = fs->info.num_outputs;
+ compiler->OutputColor[3] = fs->info.num_outputs;
compiler->OutputDepth = fs->info.num_outputs;
/* Now see where they really are. */
for(i = 0; i < fs->info.num_outputs; ++i) {
switch(fs->info.output_semantic_name[i]) {
case TGSI_SEMANTIC_COLOR:
- compiler->OutputColor = i;
+ compiler->OutputColor[colorbuf_count] = i;
+ colorbuf_count++;
break;
case TGSI_SEMANTIC_POSITION:
compiler->OutputDepth = i;
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 95b7cb5fa4..cd4971ae13 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -26,7 +26,7 @@
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
@@ -142,7 +142,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
/* Stride to the same attrib in the next vertex in the vertex buffer,
* in dwords. */
- unsigned stride[PIPE_MAX_ATTRIBS];
+ unsigned stride[PIPE_MAX_ATTRIBS] = {0};
/* Mapped vertex buffers. */
uint32_t* map[PIPE_MAX_ATTRIBS] = {0};
diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index fa8ed581da..18eecf7c13 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -20,7 +20,7 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_simple_screen.h"
@@ -375,8 +375,11 @@ struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys)
struct r300_screen* r300screen = CALLOC_STRUCT(r300_screen);
struct r300_capabilities* caps = CALLOC_STRUCT(r300_capabilities);
- if (!r300screen || !caps)
+ if (!r300screen || !caps) {
+ FREE(r300screen);
+ FREE(caps);
return NULL;
+ }
caps->pci_id = radeon_winsys->pci_id;
caps->num_frag_pipes = radeon_winsys->gb_pipes;
diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h
index 453fb1accc..b37be26133 100644
--- a/src/gallium/drivers/r300/r300_texture.h
+++ b/src/gallium/drivers/r300/r300_texture.h
@@ -37,24 +37,31 @@ unsigned r300_texture_get_stride(struct r300_screen* screen,
unsigned r300_texture_get_offset(struct r300_texture* tex, unsigned level,
unsigned zslice, unsigned face);
-/* Note the signature of R300_EASY_TX_FORMAT(A, R, G, B, FORMAT)... */
+/* Translate a pipe_format into a useful texture format for sampling.
+ *
+ * R300_EASY_TX_FORMAT swizzles the texture.
+ * Note the signature of R300_EASY_TX_FORMAT:
+ * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT);
+ *
+ * The FORMAT specifies how the texture sampler will treat the texture, and
+ * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
static INLINE uint32_t r300_translate_texformat(enum pipe_format format)
{
switch (format) {
/* X8 */
case PIPE_FORMAT_A8_UNORM:
+ return R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X8);
case PIPE_FORMAT_I8_UNORM:
return R300_EASY_TX_FORMAT(X, X, X, X, X8);
case PIPE_FORMAT_L8_UNORM:
return R300_EASY_TX_FORMAT(X, X, X, ONE, X8);
/* X16 */
case PIPE_FORMAT_R16_UNORM:
+ case PIPE_FORMAT_Z16_UNORM:
return R300_EASY_TX_FORMAT(X, X, X, X, X16);
case PIPE_FORMAT_R16_SNORM:
return R300_EASY_TX_FORMAT(X, X, X, X, X16) |
R300_TX_FORMAT_SIGNED;
- case PIPE_FORMAT_Z16_UNORM:
- return R300_EASY_TX_FORMAT(X, X, X, X, X16);
/* Y8X8 */
case PIPE_FORMAT_A8L8_UNORM:
return R300_EASY_TX_FORMAT(X, X, X, Y, Y8X8);
diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c
index a792c2cf98..941ec17016 100644
--- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c
+++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c
@@ -201,6 +201,8 @@ static void transform_srcreg(
struct rc_src_register * dst,
struct tgsi_full_src_register * src)
{
+ unsigned i, j;
+
dst->File = translate_register_file(src->Register.File);
dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index);
dst->RelAddr = src->Register.Indirect;
@@ -210,6 +212,21 @@ static void transform_srcreg(
dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 3) << 9;
dst->Abs = src->Register.Absolute;
dst->Negate = src->Register.Negate ? RC_MASK_XYZW : 0;
+
+ if (src->Register.File == TGSI_FILE_IMMEDIATE) {
+ for (i = 0; i < ttr->imms_to_swizzle_count; i++) {
+ if (ttr->imms_to_swizzle[i].index == src->Register.Index) {
+ dst->File = RC_FILE_TEMPORARY;
+ dst->Index = 0;
+ dst->Swizzle = 0;
+ for (j = 0; j < 4; j++) {
+ dst->Swizzle |= GET_SWZ(ttr->imms_to_swizzle[i].swizzle,
+ tgsi_util_get_full_src_register_swizzle(src, j)) << (j * 3);
+ }
+ break;
+ }
+ }
+ }
}
static void transform_texture(struct rc_instruction * dst, struct tgsi_instruction_texture src,
@@ -277,21 +294,45 @@ static void transform_instruction(struct tgsi_to_rc * ttr, struct tgsi_full_inst
&ttr->compiler->Program.ShadowSamplers);
}
-static void handle_immediate(struct tgsi_to_rc * ttr, struct tgsi_full_immediate * imm)
+static void handle_immediate(struct tgsi_to_rc * ttr,
+ struct tgsi_full_immediate * imm,
+ unsigned index)
{
struct rc_constant constant;
- int i;
+ unsigned swizzle = 0;
+ boolean can_swizzle = TRUE;
+ unsigned i;
- constant.Type = RC_CONSTANT_IMMEDIATE;
- constant.Size = 4;
- for(i = 0; i < 4; ++i)
- constant.u.Immediate[i] = imm->u[i].Float;
- rc_constants_add(&ttr->compiler->Program.Constants, &constant);
+ for (i = 0; i < 4; i++) {
+ if (imm->u[i].Float == 0.0f) {
+ swizzle |= RC_SWIZZLE_ZERO << (i * 3);
+ } else if (imm->u[i].Float == 0.5f) {
+ swizzle |= RC_SWIZZLE_HALF << (i * 3);
+ } else if (imm->u[i].Float == 1.0f) {
+ swizzle |= RC_SWIZZLE_ONE << (i * 3);
+ } else {
+ can_swizzle = FALSE;
+ break;
+ }
+ }
+
+ if (can_swizzle) {
+ ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].index = index;
+ ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].swizzle = swizzle;
+ ttr->imms_to_swizzle_count++;
+ } else {
+ constant.Type = RC_CONSTANT_IMMEDIATE;
+ constant.Size = 4;
+ for(i = 0; i < 4; ++i)
+ constant.u.Immediate[i] = imm->u[i].Float;
+ rc_constants_add(&ttr->compiler->Program.Constants, &constant);
+ }
}
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens)
{
struct tgsi_parse_context parser;
+ unsigned imm_index = 0;
int i;
/* Allocate constants placeholders.
@@ -308,6 +349,9 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens)
ttr->immediate_offset = ttr->compiler->Program.Constants.Count;
+ ttr->imms_to_swizzle = malloc(ttr->info->immediate_count * sizeof(struct swizzled_imms));
+ ttr->imms_to_swizzle_count = 0;
+
tgsi_parse_init(&parser, tokens);
while (!tgsi_parse_end_of_tokens(&parser)) {
@@ -317,7 +361,8 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens)
case TGSI_TOKEN_TYPE_DECLARATION:
break;
case TGSI_TOKEN_TYPE_IMMEDIATE:
- handle_immediate(ttr, &parser.FullToken.FullImmediate);
+ handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index);
+ imm_index++;
break;
case TGSI_TOKEN_TYPE_INSTRUCTION:
transform_instruction(ttr, &parser.FullToken.FullInstruction);
@@ -327,6 +372,8 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens)
tgsi_parse_free(&parser);
+ free(ttr->imms_to_swizzle);
+
rc_calculate_inputs_outputs(ttr->compiler);
}
diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.h b/src/gallium/drivers/r300/r300_tgsi_to_rc.h
index 93e90ec6d2..39b473c7bf 100644
--- a/src/gallium/drivers/r300/r300_tgsi_to_rc.h
+++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.h
@@ -29,11 +29,18 @@ struct tgsi_full_declaration;
struct tgsi_shader_info;
struct tgsi_token;
+struct swizzled_imms {
+ unsigned index;
+ unsigned swizzle;
+};
+
struct tgsi_to_rc {
struct radeon_compiler * compiler;
const struct tgsi_shader_info * info;
int immediate_offset;
+ struct swizzled_imms * imms_to_swizzle;
+ unsigned imms_to_swizzle_count;
};
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens);
diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h
index bdb8b54bab..d4842e94ae 100644
--- a/src/gallium/drivers/r300/r300_winsys.h
+++ b/src/gallium/drivers/r300/r300_winsys.h
@@ -33,7 +33,7 @@ extern "C" {
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "radeon_winsys.h"
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index 53133d2888..b1cfe59bc1 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -35,6 +35,7 @@
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "sp_clear.h"
#include "sp_context.h"
#include "sp_flush.h"
diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c
index 2b82427d54..b2acc36bf7 100644
--- a/src/gallium/drivers/softpipe/sp_draw_arrays.c
+++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c
@@ -33,8 +33,8 @@
#include "pipe/p_defines.h"
#include "pipe/p_context.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "util/u_prim.h"
#include "sp_context.h"
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 714a1cf534..ee6969e60f 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -28,7 +28,7 @@
#include "util/u_memory.h"
#include "util/u_simple_screen.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c
index f6856a5f69..d2eda7324c 100644
--- a/src/gallium/drivers/softpipe/sp_state_derived.c
+++ b/src/gallium/drivers/softpipe/sp_state_derived.c
@@ -30,7 +30,6 @@
#include "pipe/p_shader_tokens.h"
#include "draw/draw_context.h"
#include "draw/draw_vertex.h"
-#include "draw/draw_private.h"
#include "sp_context.h"
#include "sp_screen.h"
#include "sp_state.h"
@@ -67,7 +66,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
/* compute vertex layout now */
const struct sp_fragment_shader *spfs = softpipe->fs;
struct vertex_info *vinfo_vbuf = &softpipe->vertex_info_vbuf;
- const uint num = draw_current_shader_outputs(softpipe->draw);
+ const uint num = draw_num_shader_outputs(softpipe->draw);
uint i;
/* Tell draw_vbuf to simply emit the whole post-xform vertex
diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c
index de3edde976..c88e213751 100644
--- a/src/gallium/drivers/softpipe/sp_state_fs.c
+++ b/src/gallium/drivers/softpipe/sp_state_fs.c
@@ -31,6 +31,7 @@
#include "pipe/p_defines.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "draw/draw_context.h"
#include "draw/draw_vs.h"
#include "tgsi/tgsi_dump.h"
diff --git a/src/gallium/drivers/softpipe/sp_state_surface.c b/src/gallium/drivers/softpipe/sp_state_surface.c
index 3946678219..2db6faeca4 100644
--- a/src/gallium/drivers/softpipe/sp_state_surface.c
+++ b/src/gallium/drivers/softpipe/sp_state_surface.c
@@ -35,6 +35,7 @@
#include "draw/draw_context.h"
#include "util/u_format.h"
+#include "util/u_inlines.h"
/**
diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
index 50242d5bd6..a0b95c8884 100644
--- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
@@ -32,7 +32,7 @@
* Brian Paul
*/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_tile.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
index a5fff91507..371c4e2025 100644
--- a/src/gallium/drivers/softpipe/sp_texture.c
+++ b/src/gallium/drivers/softpipe/sp_texture.c
@@ -31,7 +31,7 @@
*/
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c
index 112a6fe0cf..1b50bd7ffe 100644
--- a/src/gallium/drivers/softpipe/sp_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tile_cache.c
@@ -32,7 +32,7 @@
* Brian Paul
*/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_tile.h"
diff --git a/src/gallium/drivers/softpipe/sp_video_context.c b/src/gallium/drivers/softpipe/sp_video_context.c
index d0723ebe9e..7a8b132ddc 100644
--- a/src/gallium/drivers/softpipe/sp_video_context.c
+++ b/src/gallium/drivers/softpipe/sp_video_context.c
@@ -26,7 +26,7 @@
**************************************************************************/
#include "sp_video_context.h"
-#include <pipe/p_inlines.h>
+#include <util/u_inlines.h>
#include <util/u_memory.h>
#include "softpipe/sp_winsys.h"
#include "softpipe/sp_texture.h"
diff --git a/src/gallium/drivers/softpipe/sp_winsys.c b/src/gallium/drivers/softpipe/sp_winsys.c
index 38bcd64c6a..f6598927d3 100644
--- a/src/gallium/drivers/softpipe/sp_winsys.c
+++ b/src/gallium/drivers/softpipe/sp_winsys.c
@@ -36,12 +36,13 @@
*/
-#include "pipe/internal/p_winsys_screen.h"/* port to just p_screen */
+#include "util/u_simple_screen.h"/* port to just p_screen */
#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "softpipe/sp_winsys.h"
diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index af99c9de37..c4181c3f5b 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -26,7 +26,7 @@
#include "svga_cmd.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "util/u_memory.h"
#include "util/u_bitmask.h"
@@ -215,7 +215,6 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen )
svga->state.hw_draw.num_views = 0;
svga->dirty = ~0;
- svga->state.white_fs_id = SVGA3D_INVALID_ID;
LIST_INITHEAD(&svga->dirty_buffers);
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 66259fd010..ba86256eb2 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -327,10 +327,6 @@ struct svga_context
unsigned texture_timestamp;
- /* Internally generated shaders:
- */
- unsigned white_fs_id;
-
/*
*/
struct svga_sw_state sw;
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index ca73cf9d5a..f4d2d8992c 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -24,7 +24,7 @@
**********************************************************/
#include "pipe/p_compiler.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_memory.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_draw_arrays.c b/src/gallium/drivers/svga/svga_draw_arrays.c
index 6b6ebc9b58..6192aa96b1 100644
--- a/src/gallium/drivers/svga/svga_draw_arrays.c
+++ b/src/gallium/drivers/svga/svga_draw_arrays.c
@@ -25,7 +25,7 @@
#include "svga_cmd.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "indices/u_indices.h"
#include "svga_hw_reg.h"
diff --git a/src/gallium/drivers/svga/svga_draw_elements.c b/src/gallium/drivers/svga/svga_draw_elements.c
index 022b444eb9..e8097d82f1 100644
--- a/src/gallium/drivers/svga/svga_draw_elements.c
+++ b/src/gallium/drivers/svga/svga_draw_elements.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "indices/u_indices.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_blend.c b/src/gallium/drivers/svga/svga_pipe_blend.c
index 9df5485f46..9dd6fb068c 100644
--- a/src/gallium/drivers/svga/svga_pipe_blend.c
+++ b/src/gallium/drivers/svga/svga_pipe_blend.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_constants.c b/src/gallium/drivers/svga/svga_pipe_constants.c
index 9022f7c439..73a0cd6b3a 100644
--- a/src/gallium/drivers/svga/svga_pipe_constants.c
+++ b/src/gallium/drivers/svga/svga_pipe_constants.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_depthstencil.c b/src/gallium/drivers/svga/svga_pipe_depthstencil.c
index 34e60cb341..12bbd233a5 100644
--- a/src/gallium/drivers/svga/svga_pipe_depthstencil.c
+++ b/src/gallium/drivers/svga/svga_pipe_depthstencil.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c
index 4e0c499dc3..f1d23c0e74 100644
--- a/src/gallium/drivers/svga/svga_pipe_draw.c
+++ b/src/gallium/drivers/svga/svga_pipe_draw.c
@@ -25,7 +25,7 @@
#include "svga_cmd.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_prim.h"
#include "util/u_time.h"
#include "indices/u_indices.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_fs.c b/src/gallium/drivers/svga/svga_pipe_fs.c
index 32f07fb261..b71bc66552 100644
--- a/src/gallium/drivers/svga/svga_pipe_fs.c
+++ b/src/gallium/drivers/svga/svga_pipe_fs.c
@@ -23,12 +23,11 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_bitmask.h"
#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_text.h"
#include "svga_screen.h"
#include "svga_context.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_misc.c b/src/gallium/drivers/svga/svga_pipe_misc.c
index 8cf1f2e083..49b43bebc2 100644
--- a/src/gallium/drivers/svga/svga_pipe_misc.c
+++ b/src/gallium/drivers/svga/svga_pipe_misc.c
@@ -25,6 +25,8 @@
#include "svga_cmd.h"
+#include "util/u_inlines.h"
+
#include "svga_context.h"
#include "svga_screen_texture.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_rasterizer.c b/src/gallium/drivers/svga/svga_pipe_rasterizer.c
index 9ea11aad9a..2f0b54092b 100644
--- a/src/gallium/drivers/svga/svga_pipe_rasterizer.c
+++ b/src/gallium/drivers/svga/svga_pipe_rasterizer.c
@@ -24,7 +24,7 @@
**********************************************************/
#include "draw/draw_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c
index 161c66dd4f..b70081343d 100644
--- a/src/gallium/drivers/svga/svga_pipe_sampler.c
+++ b/src/gallium/drivers/svga/svga_pipe_sampler.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c
index 724166a335..ffc0f99565 100644
--- a/src/gallium/drivers/svga/svga_pipe_vertex.c
+++ b/src/gallium/drivers/svga/svga_pipe_vertex.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "tgsi/tgsi_parse.h"
diff --git a/src/gallium/drivers/svga/svga_pipe_vs.c b/src/gallium/drivers/svga/svga_pipe_vs.c
index c4ac5304ac..de8c919e12 100644
--- a/src/gallium/drivers/svga/svga_pipe_vs.c
+++ b/src/gallium/drivers/svga/svga_pipe_vs.c
@@ -24,7 +24,7 @@
**********************************************************/
#include "draw/draw_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_bitmask.h"
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index c9db9ac874..6933d51562 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -24,7 +24,7 @@
**********************************************************/
#include "util/u_memory.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_string.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h
index a009b60720..9dc229b0a8 100644
--- a/src/gallium/drivers/svga/svga_screen.h
+++ b/src/gallium/drivers/svga/svga_screen.h
@@ -28,7 +28,7 @@
#include "pipe/p_screen.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/drivers/svga/svga_screen_buffer.c b/src/gallium/drivers/svga/svga_screen_buffer.c
index 430a6970fd..c9e9bef540 100644
--- a/src/gallium/drivers/svga/svga_screen_buffer.c
+++ b/src/gallium/drivers/svga/svga_screen_buffer.c
@@ -27,8 +27,8 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "pipe/p_thread.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_screen_cache.h b/src/gallium/drivers/svga/svga_screen_cache.h
index f5aa740d40..62156e3f52 100644
--- a/src/gallium/drivers/svga/svga_screen_cache.h
+++ b/src/gallium/drivers/svga/svga_screen_cache.h
@@ -31,7 +31,7 @@
#include "svga_reg.h"
#include "svga3d_reg.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_double_list.h"
diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c
index 0d69007fd8..ad7bb65278 100644
--- a/src/gallium/drivers/svga/svga_screen_texture.c
+++ b/src/gallium/drivers/svga/svga_screen_texture.c
@@ -27,8 +27,8 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "pipe/p_thread.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_screen_texture.h b/src/gallium/drivers/svga/svga_screen_texture.h
index 89ae24219f..43853d48f8 100644
--- a/src/gallium/drivers/svga/svga_screen_texture.h
+++ b/src/gallium/drivers/svga/svga_screen_texture.h
@@ -29,6 +29,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
+#include "util/u_inlines.h"
#include "svga_screen_cache.h"
struct pipe_context;
diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c
index 6b0e511cec..bb92f818ea 100644
--- a/src/gallium/drivers/svga/svga_state_constants.c
+++ b/src/gallium/drivers/svga/svga_state_constants.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "svga_context.h"
diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c
index eda1aefd67..b4cafb8f21 100644
--- a/src/gallium/drivers/svga/svga_state_framebuffer.c
+++ b/src/gallium/drivers/svga/svga_state_framebuffer.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c
index ec2886348b..2973444d0a 100644
--- a/src/gallium/drivers/svga/svga_state_fs.c
+++ b/src/gallium/drivers/svga/svga_state_fs.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_bitmask.h"
@@ -108,70 +108,6 @@ fail:
return ret;
}
-/* The blend workaround for simulating logicop xor behaviour requires
- * that the incoming fragment color be white. This change achieves
- * that by hooking up a hard-wired fragment shader that just emits
- * color 1,1,1,1
- *
- * This is a slightly incomplete solution as it assumes that the
- * actual bound shader has no other effects beyond generating a
- * fragment color. In particular shaders containing TEXKIL and/or
- * depth-write will not have the correct behaviour, nor will those
- * expecting to use alphatest.
- *
- * These are avoidable issues, but they are not much worse than the
- * unavoidable ones associated with this technique, so it's not clear
- * how much effort should be expended trying to resolve them - the
- * ultimate result will still not be correct in most cases.
- *
- * Shader below was generated with:
- * SVGA_DEBUG=tgsi ./mesa/progs/fp/fp-tri white.txt
- */
-static int emit_white_fs( struct svga_context *svga )
-{
- int ret = PIPE_ERROR;
-
- /* ps_3_0
- * def c0, 1.000000, 0.000000, 0.000000, 1.000000
- * mov oC0, c0.x
- * end
- */
- static const unsigned white_tokens[] = {
- 0xffff0300,
- 0x05000051,
- 0xa00f0000,
- 0x3f800000,
- 0x00000000,
- 0x00000000,
- 0x3f800000,
- 0x02000001,
- 0x800f0800,
- 0xa0000000,
- 0x0000ffff,
- };
-
- assert(SVGA3D_INVALID_ID == UTIL_BITMASK_INVALID_INDEX);
- svga->state.white_fs_id = util_bitmask_add(svga->fs_bm);
- if(svga->state.white_fs_id == SVGA3D_INVALID_ID)
- goto no_fs_id;
-
- ret = SVGA3D_DefineShader(svga->swc,
- svga->state.white_fs_id,
- SVGA3D_SHADERTYPE_PS,
- white_tokens,
- sizeof(white_tokens));
- if (ret)
- goto no_definition;
-
- return 0;
-
-no_definition:
- util_bitmask_clear(svga->fs_bm, svga->state.white_fs_id);
- svga->state.white_fs_id = SVGA3D_INVALID_ID;
-no_fs_id:
- return ret;
-}
-
/* SVGA_NEW_TEXTURE_BINDING
* SVGA_NEW_RAST
@@ -199,6 +135,23 @@ static int make_fs_key( const struct svga_context *svga,
PIPE_WINDING_CW);
}
+ /* The blend workaround for simulating logicop xor behaviour
+ * requires that the incoming fragment color be white. This change
+ * achieves that by creating a varient of the current fragment
+ * shader that overrides all output colors with 1,1,1,1
+ *
+ * This will work for most shaders, including those containing
+ * TEXKIL and/or depth-write. However, it will break on the
+ * combination of xor-logicop plus alphatest.
+ *
+ * Ultimately, we could implement alphatest in the shader using
+ * texkil prior to overriding the outgoing fragment color.
+ *
+ * SVGA_NEW_BLEND
+ */
+ if (svga->curr.blend->need_white_fragments) {
+ key->white_fragments = 1;
+ }
/* XXX: want to limit this to the textures that the shader actually
* refers to.
@@ -238,40 +191,29 @@ static int emit_hw_fs( struct svga_context *svga,
unsigned id = SVGA3D_INVALID_ID;
int ret = 0;
+ struct svga_fragment_shader *fs = svga->curr.fs;
+ struct svga_fs_compile_key key;
+
/* SVGA_NEW_BLEND
+ * SVGA_NEW_TEXTURE_BINDING
+ * SVGA_NEW_RAST
+ * SVGA_NEW_NEED_SWTNL
+ * SVGA_NEW_SAMPLER
*/
- if (svga->curr.blend->need_white_fragments) {
- if (svga->state.white_fs_id == SVGA3D_INVALID_ID) {
- ret = emit_white_fs( svga );
- if (ret)
- return ret;
- }
- id = svga->state.white_fs_id;
- }
- else {
- struct svga_fragment_shader *fs = svga->curr.fs;
- struct svga_fs_compile_key key;
-
- /* SVGA_NEW_TEXTURE_BINDING
- * SVGA_NEW_RAST
- * SVGA_NEW_NEED_SWTNL
- * SVGA_NEW_SAMPLER
- */
- ret = make_fs_key( svga, &key );
+ ret = make_fs_key( svga, &key );
+ if (ret)
+ return ret;
+
+ result = search_fs_key( fs, &key );
+ if (!result) {
+ ret = compile_fs( svga, fs, &key, &result );
if (ret)
return ret;
-
- result = search_fs_key( fs, &key );
- if (!result) {
- ret = compile_fs( svga, fs, &key, &result );
- if (ret)
- return ret;
- }
-
- assert (result);
- id = result->id;
}
+ assert (result);
+ id = result->id;
+
assert(id != SVGA3D_INVALID_ID);
if (result != svga->state.hw_draw.fs) {
diff --git a/src/gallium/drivers/svga/svga_state_need_swtnl.c b/src/gallium/drivers/svga/svga_state_need_swtnl.c
index 3c35a8579f..dd13a89d24 100644
--- a/src/gallium/drivers/svga/svga_state_need_swtnl.c
+++ b/src/gallium/drivers/svga/svga_state_need_swtnl.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
diff --git a/src/gallium/drivers/svga/svga_state_rss.c b/src/gallium/drivers/svga/svga_state_rss.c
index 2f9adaeb56..ff656a7e05 100644
--- a/src/gallium/drivers/svga/svga_state_rss.c
+++ b/src/gallium/drivers/svga/svga_state_rss.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c
index b3c9687b1a..17b4785978 100644
--- a/src/gallium/drivers/svga/svga_state_tss.c
+++ b/src/gallium/drivers/svga/svga_state_tss.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_state_vdecl.c b/src/gallium/drivers/svga/svga_state_vdecl.c
index c534308f50..d1066ce13b 100644
--- a/src/gallium/drivers/svga/svga_state_vdecl.c
+++ b/src/gallium/drivers/svga/svga_state_vdecl.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_upload_mgr.h"
diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c
index e7e6c08432..d7999fe53d 100644
--- a/src/gallium/drivers/svga/svga_state_vs.c
+++ b/src/gallium/drivers/svga/svga_state_vs.c
@@ -23,7 +23,7 @@
*
**********************************************************/
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_defines.h"
#include "util/u_format.h"
#include "util/u_math.h"
diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c
index aafb3e26b0..e9d7942fb5 100644
--- a/src/gallium/drivers/svga/svga_swtnl_backend.c
+++ b/src/gallium/drivers/svga/svga_swtnl_backend.c
@@ -28,7 +28,7 @@
#include "draw/draw_vertex.h"
#include "util/u_debug.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/drivers/svga/svga_swtnl_draw.c b/src/gallium/drivers/svga/svga_swtnl_draw.c
index 5e6e30c7df..da15be155c 100644
--- a/src/gallium/drivers/svga/svga_swtnl_draw.c
+++ b/src/gallium/drivers/svga/svga_swtnl_draw.c
@@ -25,7 +25,7 @@
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
#include "svga_context.h"
diff --git a/src/gallium/drivers/svga/svga_swtnl_state.c b/src/gallium/drivers/svga/svga_swtnl_state.c
index fe03e207ff..35f36a828f 100644
--- a/src/gallium/drivers/svga/svga_swtnl_state.c
+++ b/src/gallium/drivers/svga/svga_swtnl_state.c
@@ -25,7 +25,7 @@
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
#include "svga_context.h"
diff --git a/src/gallium/drivers/svga/svga_tgsi.h b/src/gallium/drivers/svga/svga_tgsi.h
index 737a2213af..063c9cf422 100644
--- a/src/gallium/drivers/svga/svga_tgsi.h
+++ b/src/gallium/drivers/svga/svga_tgsi.h
@@ -49,6 +49,7 @@ struct svga_fs_compile_key
{
unsigned light_twoside:1;
unsigned front_cw:1;
+ unsigned white_fragments:1;
unsigned num_textures:8;
unsigned num_unnormalized_coords:8;
struct {
diff --git a/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c
index 43fc0d3235..73102a72a8 100644
--- a/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c
+++ b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c
@@ -194,8 +194,19 @@ static boolean ps30_output( struct svga_shader_emitter *emit,
switch (semantic.Name) {
case TGSI_SEMANTIC_COLOR:
- emit->output_map[idx] = dst_register( SVGA3DREG_COLOROUT,
- semantic.Index );
+ if (emit->unit == PIPE_SHADER_FRAGMENT &&
+ emit->key.fkey.white_fragments) {
+
+ emit->output_map[idx] = dst_register( SVGA3DREG_TEMP,
+ emit->nr_hw_temp++ );
+ emit->temp_col[idx] = emit->output_map[idx];
+ emit->true_col[idx] = dst_register( SVGA3DREG_COLOROUT,
+ semantic.Index );
+ }
+ else {
+ emit->output_map[idx] = dst_register( SVGA3DREG_COLOROUT,
+ semantic.Index );
+ }
break;
case TGSI_SEMANTIC_POSITION:
emit->output_map[idx] = dst_register( SVGA3DREG_TEMP,
diff --git a/src/gallium/drivers/svga/svga_tgsi_emit.h b/src/gallium/drivers/svga/svga_tgsi_emit.h
index 2557824293..e8f75485d5 100644
--- a/src/gallium/drivers/svga/svga_tgsi_emit.h
+++ b/src/gallium/drivers/svga/svga_tgsi_emit.h
@@ -79,6 +79,8 @@ struct svga_shader_emitter
int ps30_input_count;
+ int dynamic_branching_level;
+
boolean in_main_func;
boolean created_zero_immediate;
@@ -199,6 +201,23 @@ static INLINE boolean emit_op3( struct svga_shader_emitter *emit,
}
+static INLINE boolean emit_op4( struct svga_shader_emitter *emit,
+ SVGA3dShaderInstToken inst,
+ SVGA3dShaderDestToken dest,
+ struct src_register src0,
+ struct src_register src1,
+ struct src_register src2,
+ struct src_register src3)
+{
+ return (emit_instruction( emit, inst ) &&
+ emit_dst( emit, dest ) &&
+ emit_src( emit, src0 ) &&
+ emit_src( emit, src1 ) &&
+ emit_src( emit, src2 ) &&
+ emit_src( emit, src3 ));
+}
+
+
#define TRANSLATE_SWIZZLE(x,y,z,w) ((x) | ((y) << 2) | ((z) << 4) | ((w) << 6))
#define SWIZZLE_XYZW \
TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_W)
diff --git a/src/gallium/drivers/svga/svga_tgsi_insn.c b/src/gallium/drivers/svga/svga_tgsi_insn.c
index dc5eb8fc60..be821e9821 100644
--- a/src/gallium/drivers/svga/svga_tgsi_insn.c
+++ b/src/gallium/drivers/svga/svga_tgsi_insn.c
@@ -46,8 +46,6 @@ translate_opcode(
case TGSI_OPCODE_ABS: return SVGA3DOP_ABS;
case TGSI_OPCODE_ADD: return SVGA3DOP_ADD;
case TGSI_OPCODE_BREAKC: return SVGA3DOP_BREAKC;
- case TGSI_OPCODE_DDX: return SVGA3DOP_DSX;
- case TGSI_OPCODE_DDY: return SVGA3DOP_DSY;
case TGSI_OPCODE_DP2A: return SVGA3DOP_DP2ADD;
case TGSI_OPCODE_DP3: return SVGA3DOP_DP3;
case TGSI_OPCODE_DP4: return SVGA3DOP_DP4;
@@ -415,6 +413,88 @@ static boolean submit_op3( struct svga_shader_emitter *emit,
}
+
+
+/* SVGA shaders may not refer to >1 constant register in a single
+ * instruction. This function checks for that usage and inserts a
+ * move to temporary if detected.
+ */
+static boolean submit_op4( struct svga_shader_emitter *emit,
+ SVGA3dShaderInstToken inst,
+ SVGA3dShaderDestToken dest,
+ struct src_register src0,
+ struct src_register src1,
+ struct src_register src2,
+ struct src_register src3)
+{
+ SVGA3dShaderDestToken temp0;
+ SVGA3dShaderDestToken temp3;
+ boolean need_temp0 = FALSE;
+ boolean need_temp3 = FALSE;
+ SVGA3dShaderRegType type0, type1, type2, type3;
+
+ temp0.value = 0;
+ temp3.value = 0;
+ type0 = SVGA3dShaderGetRegType( src0.base.value );
+ type1 = SVGA3dShaderGetRegType( src1.base.value );
+ type2 = SVGA3dShaderGetRegType( src2.base.value );
+ type3 = SVGA3dShaderGetRegType( src2.base.value );
+
+ /* Make life a little easier - this is only used by the TXD
+ * instruction which is guaranteed not to have a constant/input reg
+ * in one slot at least:
+ */
+ assert(type1 == SVGA3DREG_SAMPLER);
+
+ if (type0 == SVGA3DREG_CONST &&
+ ((type3 == SVGA3DREG_CONST && src0.base.num != src3.base.num) ||
+ (type2 == SVGA3DREG_CONST && src0.base.num != src2.base.num)))
+ need_temp0 = TRUE;
+
+ if (type3 == SVGA3DREG_CONST &&
+ (type2 == SVGA3DREG_CONST && src3.base.num != src2.base.num))
+ need_temp3 = TRUE;
+
+ if (type0 == SVGA3DREG_INPUT &&
+ ((type3 == SVGA3DREG_INPUT && src0.base.num != src3.base.num) ||
+ (type2 == SVGA3DREG_INPUT && src0.base.num != src2.base.num)))
+ need_temp0 = TRUE;
+
+ if (type3 == SVGA3DREG_INPUT &&
+ (type2 == SVGA3DREG_INPUT && src3.base.num != src2.base.num))
+ need_temp3 = TRUE;
+
+ if (need_temp0)
+ {
+ temp0 = get_temp( emit );
+
+ if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp0, src0 ))
+ return FALSE;
+
+ src0 = src( temp0 );
+ }
+
+ if (need_temp3)
+ {
+ temp3 = get_temp( emit );
+
+ if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp3, src3 ))
+ return FALSE;
+
+ src3 = src( temp3 );
+ }
+
+ if (!emit_op4( emit, inst, dest, src0, src1, src2, src3 ))
+ return FALSE;
+
+ if (need_temp3)
+ release_temp( emit, temp3 );
+ if (need_temp0)
+ release_temp( emit, temp0 );
+ return TRUE;
+}
+
+
static boolean emit_def_const( struct svga_shader_emitter *emit,
SVGA3dShaderConstType type,
unsigned idx,
@@ -660,6 +740,8 @@ static boolean emit_if(struct svga_shader_emitter *emit,
if_token.control = SVGA3DOPCOMPC_NE;
zero = scalar(zero, TGSI_SWIZZLE_X);
+ emit->dynamic_branching_level++;
+
return (emit_instruction( emit, if_token ) &&
emit_src( emit, src ) &&
emit_src( emit, zero ) );
@@ -668,6 +750,8 @@ static boolean emit_if(struct svga_shader_emitter *emit,
static boolean emit_endif(struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn)
{
+ emit->dynamic_branching_level--;
+
return (emit_instruction( emit,
inst_token( SVGA3DOP_ENDIF )));
}
@@ -1011,10 +1095,10 @@ static boolean emit_kilp(struct svga_shader_emitter *emit,
{
SVGA3dShaderInstToken inst;
SVGA3dShaderDestToken temp;
- struct src_register one = get_zero_immediate( emit );
+ struct src_register one = scalar( get_zero_immediate( emit ),
+ TGSI_SWIZZLE_W );
inst = inst_token( SVGA3DOP_TEXKILL );
- one = scalar( one, TGSI_SWIZZLE_W );
/* texkill doesn't allow negation on the operand so lets move
* negation of {1} to a temp register */
@@ -1169,41 +1253,79 @@ static boolean emit_tex2(struct svga_shader_emitter *emit,
SVGA3dShaderDestToken dst )
{
SVGA3dShaderInstToken inst;
- struct src_register src0;
- struct src_register src1;
-
+ struct src_register texcoord;
+ struct src_register sampler;
+ SVGA3dShaderDestToken tmp;
+
inst.value = 0;
- inst.op = SVGA3DOP_TEX;
switch (insn->Instruction.Opcode) {
case TGSI_OPCODE_TEX:
+ inst.op = SVGA3DOP_TEX;
break;
case TGSI_OPCODE_TXP:
+ inst.op = SVGA3DOP_TEX;
inst.control = SVGA3DOPCONT_PROJECT;
break;
case TGSI_OPCODE_TXB:
+ inst.op = SVGA3DOP_TEX;
inst.control = SVGA3DOPCONT_BIAS;
break;
+ case TGSI_OPCODE_TXL:
+ inst.op = SVGA3DOP_TEXLDL;
+ break;
default:
assert(0);
return FALSE;
}
- src0 = translate_src_register( emit, &insn->Src[0] );
- src1 = translate_src_register( emit, &insn->Src[1] );
+ texcoord = translate_src_register( emit, &insn->Src[0] );
+ sampler = translate_src_register( emit, &insn->Src[1] );
- if (emit->key.fkey.tex[src1.base.num].unnormalized) {
- struct src_register wh = get_tex_dimensions( emit, src1.base.num );
- SVGA3dShaderDestToken tmp = get_temp( emit );
+ if (emit->key.fkey.tex[sampler.base.num].unnormalized ||
+ emit->dynamic_branching_level > 0)
+ tmp = get_temp( emit );
+
+ /* Can't do mipmapping inside dynamic branch constructs. Force LOD
+ * zero in that case.
+ */
+ if (emit->dynamic_branching_level > 0 &&
+ inst.op == SVGA3DOP_TEX &&
+ SVGA3dShaderGetRegType(texcoord.base.value) == SVGA3DREG_TEMP) {
+ struct src_register zero = get_zero_immediate( emit );
+
+ /* MOV tmp, texcoord */
+ if (!submit_op1( emit,
+ inst_token( SVGA3DOP_MOV ),
+ tmp,
+ texcoord ))
+ return FALSE;
+
+ /* MOV tmp.w, zero */
+ if (!submit_op1( emit,
+ inst_token( SVGA3DOP_MOV ),
+ writemask( tmp, TGSI_WRITEMASK_W ),
+ scalar( zero, TGSI_SWIZZLE_X )))
+ return FALSE;
+
+ texcoord = src( tmp );
+ inst.op = SVGA3DOP_TEXLDL;
+ }
+
+ /* Explicit normalization of texcoords:
+ */
+ if (emit->key.fkey.tex[sampler.base.num].unnormalized) {
+ struct src_register wh = get_tex_dimensions( emit, sampler.base.num );
/* MUL tmp, SRC0, WH */
if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
- tmp, src0, wh ))
+ tmp, texcoord, wh ))
return FALSE;
- src0 = src( tmp );
+
+ texcoord = src( tmp );
}
- return submit_op2( emit, inst, dst, src0, src1 );
+ return submit_op2( emit, inst, dst, texcoord, sampler );
}
@@ -1211,31 +1333,33 @@ static boolean emit_tex2(struct svga_shader_emitter *emit,
/* Translate texture instructions to SVGA3D representation.
*/
-static boolean emit_tex3(struct svga_shader_emitter *emit,
+static boolean emit_tex4(struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn,
SVGA3dShaderDestToken dst )
{
SVGA3dShaderInstToken inst;
- struct src_register src0;
- struct src_register src1;
- struct src_register src2;
+ struct src_register texcoord;
+ struct src_register ddx;
+ struct src_register ddy;
+ struct src_register sampler;
+
+ texcoord = translate_src_register( emit, &insn->Src[0] );
+ ddx = translate_src_register( emit, &insn->Src[1] );
+ ddy = translate_src_register( emit, &insn->Src[2] );
+ sampler = translate_src_register( emit, &insn->Src[3] );
inst.value = 0;
switch (insn->Instruction.Opcode) {
case TGSI_OPCODE_TXD:
- inst.op = SVGA3DOP_TEXLDD;
- break;
- case TGSI_OPCODE_TXL:
- inst.op = SVGA3DOP_TEXLDL;
+ inst.op = SVGA3DOP_TEXLDD; /* 4 args! */
break;
+ default:
+ assert(0);
+ return FALSE;
}
- src0 = translate_src_register( emit, &insn->Src[0] );
- src1 = translate_src_register( emit, &insn->Src[1] );
- src2 = translate_src_register( emit, &insn->Src[2] );
-
- return submit_op3( emit, inst, dst, src0, src1, src2 );
+ return submit_op4( emit, inst, dst, texcoord, sampler, ddx, ddy );
}
@@ -1271,12 +1395,12 @@ static boolean emit_tex(struct svga_shader_emitter *emit,
case TGSI_OPCODE_TEX:
case TGSI_OPCODE_TXB:
case TGSI_OPCODE_TXP:
+ case TGSI_OPCODE_TXL:
if (!emit_tex2( emit, insn, tex_result ))
return FALSE;
break;
- case TGSI_OPCODE_TXL:
case TGSI_OPCODE_TXD:
- if (!emit_tex3( emit, insn, tex_result ))
+ if (!emit_tex4( emit, insn, tex_result ))
return FALSE;
break;
default:
@@ -1330,6 +1454,8 @@ static boolean emit_bgnloop2( struct svga_shader_emitter *emit,
struct src_register loop_reg = src_register( SVGA3DREG_LOOP, 0 );
struct src_register const_int = get_loop_const( emit );
+ emit->dynamic_branching_level++;
+
return (emit_instruction( emit, inst ) &&
emit_src( emit, loop_reg ) &&
emit_src( emit, const_int ) );
@@ -1339,6 +1465,9 @@ static boolean emit_endloop2( struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn )
{
SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_ENDLOOP );
+
+ emit->dynamic_branching_level--;
+
return emit_instruction( emit, inst );
}
@@ -1398,6 +1527,46 @@ static boolean emit_simple_instruction(struct svga_shader_emitter *emit,
}
}
+
+static boolean emit_deriv(struct svga_shader_emitter *emit,
+ const struct tgsi_full_instruction *insn )
+{
+ if (emit->dynamic_branching_level > 0 &&
+ insn->Src[0].Register.File == TGSI_FILE_TEMPORARY)
+ {
+ struct src_register zero = get_zero_immediate( emit );
+ SVGA3dShaderDestToken dst =
+ translate_dst_register( emit, insn, 0 );
+
+ /* Deriv opcodes not valid inside dynamic branching, workaround
+ * by zeroing out the destination.
+ */
+ if (!submit_op1(emit,
+ inst_token( SVGA3DOP_MOV ),
+ dst,
+ scalar(zero, TGSI_SWIZZLE_X)))
+ return FALSE;
+
+ return TRUE;
+ }
+ else {
+ unsigned opcode;
+
+ switch (insn->Instruction.Opcode) {
+ case TGSI_OPCODE_DDX:
+ opcode = SVGA3DOP_DSX;
+ break;
+ case TGSI_OPCODE_DDY:
+ opcode = SVGA3DOP_DSY;
+ break;
+ default:
+ return FALSE;
+ }
+
+ return emit_simple_instruction( emit, opcode, insn );
+ }
+}
+
static boolean emit_arl(struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn)
{
@@ -2002,6 +2171,10 @@ static boolean svga_emit_instruction( struct svga_shader_emitter *emit,
case TGSI_OPCODE_TXD:
return emit_tex( emit, insn );
+ case TGSI_OPCODE_DDX:
+ case TGSI_OPCODE_DDY:
+ return emit_deriv( emit, insn );
+
case TGSI_OPCODE_BGNSUB:
return emit_bgnsub( emit, position, insn );
@@ -2254,11 +2427,28 @@ static boolean emit_ps_postamble( struct svga_shader_emitter *emit )
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
if (SVGA3dShaderGetRegType(emit->true_col[i].value) != 0) {
- if (!submit_op1( emit,
- inst_token(SVGA3DOP_MOV),
- emit->true_col[i],
- src(emit->temp_col[i]) ))
- return FALSE;
+ /* Potentially override output colors with white for XOR
+ * logicop workaround.
+ */
+ if (emit->unit == PIPE_SHADER_FRAGMENT &&
+ emit->key.fkey.white_fragments) {
+
+ struct src_register one = scalar( get_zero_immediate( emit ),
+ TGSI_SWIZZLE_W );
+
+ if (!submit_op1( emit,
+ inst_token(SVGA3DOP_MOV),
+ emit->true_col[i],
+ one ))
+ return FALSE;
+ }
+ else {
+ if (!submit_op1( emit,
+ inst_token(SVGA3DOP_MOV),
+ emit->true_col[i],
+ src(emit->temp_col[i]) ))
+ return FALSE;
+ }
}
}
@@ -2467,6 +2657,9 @@ needs_to_create_zero( struct svga_shader_emitter *emit )
if (emit->key.fkey.light_twoside)
return TRUE;
+ if (emit->key.fkey.white_fragments)
+ return TRUE;
+
if (emit->emit_frontface)
return TRUE;
@@ -2476,6 +2669,10 @@ needs_to_create_zero( struct svga_shader_emitter *emit )
}
if (emit->info.opcode_count[TGSI_OPCODE_IF] >= 1 ||
+ emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1 ||
+ emit->info.opcode_count[TGSI_OPCODE_BGNFOR] >= 1 ||
+ emit->info.opcode_count[TGSI_OPCODE_DDX] >= 1 ||
+ emit->info.opcode_count[TGSI_OPCODE_DDY] >= 1 ||
emit->info.opcode_count[TGSI_OPCODE_SGE] >= 1 ||
emit->info.opcode_count[TGSI_OPCODE_SGT] >= 1 ||
emit->info.opcode_count[TGSI_OPCODE_SLE] >= 1 ||
@@ -2702,6 +2899,8 @@ boolean svga_shader_emit_instructions( struct svga_shader_emitter *emit,
goto done;
}
+ assert(emit->dynamic_branching_level == 0);
+
/* Need to terminate the whole shader:
*/
ret = emit_instruction( emit, inst_token( SVGA3DOP_END ) );
diff --git a/src/gallium/drivers/trace/tr_buffer.c b/src/gallium/drivers/trace/tr_buffer.c
index 4f0eff6a5a..fa2ac068eb 100644
--- a/src/gallium/drivers/trace/tr_buffer.c
+++ b/src/gallium/drivers/trace/tr_buffer.c
@@ -26,6 +26,7 @@
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c
index 0f45e211a3..8de451c22c 100644
--- a/src/gallium/drivers/trace/tr_dump.c
+++ b/src/gallium/drivers/trace/tr_dump.c
@@ -45,11 +45,11 @@
#endif
#include "pipe/p_compiler.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
+#include "os/os_stream.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "util/u_string.h"
-#include "util/u_stream.h"
#include "tr_dump.h"
#include "tr_screen.h"
@@ -57,7 +57,7 @@
#include "tr_buffer.h"
-static struct util_stream *stream = NULL;
+static struct os_stream *stream = NULL;
static unsigned refcount = 0;
static pipe_mutex call_mutex;
static long unsigned call_no = 0;
@@ -69,7 +69,7 @@ static INLINE void
trace_dump_write(const char *buf, size_t size)
{
if(stream)
- util_stream_write(stream, buf, size);
+ os_stream_write(stream, buf, size);
}
@@ -220,7 +220,7 @@ trace_dump_trace_close(void)
{
if(stream) {
trace_dump_writes("</trace>\n");
- util_stream_close(stream);
+ os_stream_close(stream);
stream = NULL;
refcount = 0;
call_no = 0;
@@ -250,7 +250,7 @@ boolean trace_dump_trace_begin()
if(!stream) {
- stream = util_stream_create(filename, 0);
+ stream = os_stream_create(filename, 0);
if(!stream)
return FALSE;
@@ -367,7 +367,7 @@ void trace_dump_call_end_locked(void)
trace_dump_indent(1);
trace_dump_tag_end("call");
trace_dump_newline();
- util_stream_flush(stream);
+ os_stream_flush(stream);
}
void trace_dump_call_begin(const char *klass, const char *method)
diff --git a/src/gallium/drivers/trace/tr_dump_state.c b/src/gallium/drivers/trace/tr_dump_state.c
index dbca5de0a5..c7364e2bd1 100644
--- a/src/gallium/drivers/trace/tr_dump_state.c
+++ b/src/gallium/drivers/trace/tr_dump_state.c
@@ -49,7 +49,7 @@ static void trace_dump_reference(const struct pipe_reference *reference)
return;
trace_dump_struct_begin("pipe_reference");
- trace_dump_member(int, &reference->count, count);
+ trace_dump_member(int, reference, count);
trace_dump_struct_end();
}
diff --git a/src/gallium/drivers/trace/tr_rbug.c b/src/gallium/drivers/trace/tr_rbug.c
index 0546aad9b5..691b83c63f 100644
--- a/src/gallium/drivers/trace/tr_rbug.c
+++ b/src/gallium/drivers/trace/tr_rbug.c
@@ -26,11 +26,13 @@
**************************************************************************/
+#include "os/os_thread.h"
#include "util/u_format.h"
#include "util/u_string.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
#include "util/u_network.h"
+#include "util/u_time.h"
#include "tgsi/tgsi_parse.h"
@@ -43,15 +45,6 @@
#include <errno.h>
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-# define sleep Sleep
-#elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_APPLE)
-void usleep(int);
-# define sleep usleep
-#else
-# warning "No socket implementation"
-#endif
-
#define U642VOID(x) ((void *)(unsigned long)(x))
#define VOID2U64(x) ((uint64_t)(unsigned long)(x))
@@ -805,7 +798,7 @@ PIPE_THREAD_ROUTINE(trace_rbug_thread, void_tr_rbug)
debug_printf("trace_rbug - remote debugging listening on port %u\n", --port);
while(tr_rbug->running) {
- sleep(1);
+ util_time_sleep(1);
c = u_socket_accept(s);
if (c < 0)
diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c
index 117503aaff..6cdb4c04a8 100644
--- a/src/gallium/drivers/trace/tr_screen.c
+++ b/src/gallium/drivers/trace/tr_screen.c
@@ -35,7 +35,7 @@
#include "tr_texture.h"
#include "tr_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_format.h"
diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h
index dba8cd7c65..fe5a0fa190 100644
--- a/src/gallium/drivers/trace/tr_screen.h
+++ b/src/gallium/drivers/trace/tr_screen.h
@@ -30,7 +30,7 @@
#include "pipe/p_screen.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#ifdef __cplusplus
diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c
index 1f25fe38d4..5321d68ec0 100644
--- a/src/gallium/drivers/trace/tr_texture.c
+++ b/src/gallium/drivers/trace/tr_texture.c
@@ -25,6 +25,7 @@
*
**************************************************************************/
+#include "util/u_inlines.h"
#include "util/u_hash_table.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
diff --git a/src/gallium/include/pipe/internal/p_winsys_screen.h b/src/gallium/include/pipe/internal/p_winsys_screen.h
deleted file mode 100644
index a1542dada7..0000000000
--- a/src/gallium/include/pipe/internal/p_winsys_screen.h
+++ /dev/null
@@ -1,190 +0,0 @@
- /**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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
- * without limitation the rights to use, copy, modify, merge, publish,
- * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * 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.
- *
- **************************************************************************/
-
-/**
- * \file
- * This is the interface that Gallium3D requires any window system
- * hosting it to implement. This is the only include file in Gallium3D
- * which is public.
- */
-
-#ifndef P_WINSYS_H
-#define P_WINSYS_H
-
-
-#include "pipe/p_format.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/** Opaque type */
-struct pipe_fence_handle;
-
-struct pipe_surface;
-
-
-/**
- * Gallium3D drivers are (meant to be!) independent of both GL and the
- * window system. The window system provides a buffer manager and a
- * set of additional hooks for things like command buffer submission,
- * etc.
- *
- * There clearly has to be some agreement between the window system
- * driver and the hardware driver about the format of command buffers,
- * etc.
- */
-struct pipe_winsys
-{
- void (*destroy)( struct pipe_winsys *ws );
-
- /** Returns name of this winsys interface */
- const char *(*get_name)( struct pipe_winsys *ws );
-
- /**
- * Do any special operations to ensure buffer size is correct
- */
- void (*update_buffer)( struct pipe_winsys *ws,
- void *context_private );
- /**
- * Do any special operations to ensure frontbuffer contents are
- * displayed, eg copy fake frontbuffer.
- */
- void (*flush_frontbuffer)( struct pipe_winsys *ws,
- struct pipe_surface *surf,
- void *context_private );
-
-
- /**
- * Buffer management. Buffer attributes are mostly fixed over its lifetime.
- *
- * Remember that gallium gets to choose the interface it needs, and the
- * window systems must then implement that interface (rather than the
- * other way around...).
- *
- * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
- * usage argument is only an optimization hint, not a guarantee, therefore
- * proper behavior must be observed in all circumstances.
- *
- * alignment indicates the client's alignment requirements, eg for
- * SSE instructions.
- */
- struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,
- unsigned alignment,
- unsigned usage,
- unsigned size );
-
- /**
- * Create a buffer that wraps user-space data.
- *
- * Effectively this schedules a delayed call to buffer_create
- * followed by an upload of the data at *some point in the future*,
- * or perhaps never. Basically the allocate/upload is delayed
- * until the buffer is actually passed to hardware.
- *
- * The intention is to provide a quick way to turn regular data
- * into a buffer, and secondly to avoid a copy operation if that
- * data subsequently turns out to be only accessed by the CPU.
- *
- * Common example is OpenGL vertex buffers that are subsequently
- * processed either by software TNL in the driver or by passing to
- * hardware.
- *
- * XXX: What happens if the delayed call to buffer_create() fails?
- *
- * Note that ptr may be accessed at any time upto the time when the
- * buffer is destroyed, so the data must not be freed before then.
- */
- struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,
- void *ptr,
- unsigned bytes);
-
- /**
- * Allocate storage for a display target surface.
- *
- * Often surfaces which are meant to be blitted to the front screen (i.e.,
- * display targets) must be allocated with special characteristics, memory
- * pools, or obtained directly from the windowing system.
- *
- * This callback is invoked by the pipe_screenwhen creating a texture marked
- * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
- * buffer storage.
- */
- struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
- unsigned width, unsigned height,
- enum pipe_format format,
- unsigned usage,
- unsigned tex_usage,
- unsigned *stride);
-
-
- /**
- * Map the entire data store of a buffer object into the client's address.
- * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
- */
- void *(*buffer_map)( struct pipe_winsys *ws,
- struct pipe_buffer *buf,
- unsigned usage );
-
- void (*buffer_unmap)( struct pipe_winsys *ws,
- struct pipe_buffer *buf );
-
- void (*buffer_destroy)( struct pipe_buffer *buf );
-
-
- /** Set ptr = fence, with reference counting */
- void (*fence_reference)( struct pipe_winsys *ws,
- struct pipe_fence_handle **ptr,
- struct pipe_fence_handle *fence );
-
- /**
- * Checks whether the fence has been signalled.
- * \param flags driver-specific meaning
- * \return zero on success.
- */
- int (*fence_signalled)( struct pipe_winsys *ws,
- struct pipe_fence_handle *fence,
- unsigned flag );
-
- /**
- * Wait for the fence to finish.
- * \param flags driver-specific meaning
- * \return zero on success.
- */
- int (*fence_finish)( struct pipe_winsys *ws,
- struct pipe_fence_handle *fence,
- unsigned flag );
-
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* P_WINSYS_H */
diff --git a/src/gallium/include/pipe/p_atomic.h b/src/gallium/include/pipe/p_atomic.h
deleted file mode 100644
index 0c3fbae428..0000000000
--- a/src/gallium/include/pipe/p_atomic.h
+++ /dev/null
@@ -1,353 +0,0 @@
-/**
- * Many similar implementations exist. See for example libwsbm
- * or the linux kernel include/atomic.h
- *
- * No copyright claimed on this file.
- *
- */
-
-#ifndef P_ATOMIC_H
-#define P_ATOMIC_H
-
-#include "p_compiler.h"
-#include "p_defines.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Favor OS-provided implementations.
- *
- * Where no OS-provided implementation is available, fall back to
- * locally coded assembly, compiler intrinsic or ultimately a
- * mutex-based implementation.
- */
-#if (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \
- defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT))
-#define PIPE_ATOMIC_OS_UNLOCKED
-#elif (defined(PIPE_CC_MSVC) && defined(PIPE_SUBSYSTEM_WINDOWS_USER))
-#define PIPE_ATOMIC_OS_MS_INTERLOCK
-#elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86))
-#define PIPE_ATOMIC_ASM_MSVC_X86
-#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86))
-#define PIPE_ATOMIC_ASM_GCC_X86
-#elif defined(PIPE_CC_GCC)
-#define PIPE_ATOMIC_GCC_INTRINSIC
-#else
-#define PIPE_ATOMIC_MUTEX
-#endif
-
-
-
-#if defined(PIPE_ATOMIC_ASM_GCC_X86)
-
-#define PIPE_ATOMIC "GCC x86 assembly"
-
-struct pipe_atomic {
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-
-
-static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
-{
- unsigned char c;
-
- __asm__ __volatile__("lock; decl %0; sete %1":"+m"(v->count), "=qm"(c)
- ::"memory");
-
- return c != 0;
-}
-
-static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
-{
- __asm__ __volatile__("lock; incl %0":"+m"(v->count));
-}
-
-static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
-{
- __asm__ __volatile__("lock; decl %0":"+m"(v->count));
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
-{
- return __sync_val_compare_and_swap(&v->count, old, _new);
-}
-#endif
-
-
-
-/* Implementation using GCC-provided synchronization intrinsics
- */
-#if defined(PIPE_ATOMIC_GCC_INTRINSIC)
-
-#define PIPE_ATOMIC "GCC Sync Intrinsics"
-
-struct pipe_atomic {
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-
-
-static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
-{
- return (__sync_sub_and_fetch(&v->count, 1) == 0);
-}
-
-static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
-{
- (void) __sync_add_and_fetch(&v->count, 1);
-}
-
-static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
-{
- (void) __sync_sub_and_fetch(&v->count, 1);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
-{
- return __sync_val_compare_and_swap(&v->count, old, _new);
-}
-#endif
-
-
-
-/* Unlocked version for single threaded environments, such as some
- * windows kernel modules.
- */
-#if defined(PIPE_ATOMIC_OS_UNLOCKED)
-
-#define PIPE_ATOMIC "Unlocked"
-
-struct pipe_atomic
-{
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-#define p_atomic_dec_zero(_v) ((boolean) --(_v)->count)
-#define p_atomic_inc(_v) ((void) (_v)->count++)
-#define p_atomic_dec(_v) ((void) (_v)->count--)
-#define p_atomic_cmpxchg(_v, old, _new) ((_v)->count == old ? (_v)->count = (_new) : (_v)->count)
-
-#endif
-
-
-/* Locally coded assembly for MSVC on x86:
- */
-#if defined(PIPE_ATOMIC_ASM_MSVC_X86)
-
-#define PIPE_ATOMIC "MSVC x86 assembly"
-
-struct pipe_atomic
-{
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-
-static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
-{
- int32_t *pcount = &v->count;
- unsigned char c;
-
- __asm {
- mov eax, [pcount]
- lock dec dword ptr [eax]
- sete byte ptr [c]
- }
-
- return c != 0;
-}
-
-static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
-{
- int32_t *pcount = &v->count;
-
- __asm {
- mov eax, [pcount]
- lock inc dword ptr [eax]
- }
-}
-
-static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
-{
- int32_t *pcount = &v->count;
-
- __asm {
- mov eax, [pcount]
- lock dec dword ptr [eax]
- }
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
-{
- int32_t *pcount = &v->count;
- int32_t orig;
-
- __asm {
- mov ecx, [pcount]
- mov eax, [old]
- mov edx, [_new]
- lock cmpxchg [ecx], edx
- mov [orig], eax
- }
-
- return orig;
-}
-#endif
-
-
-#if defined(PIPE_ATOMIC_OS_MS_INTERLOCK)
-
-#define PIPE_ATOMIC "MS userspace interlocks"
-
-#include <windows.h>
-
-struct pipe_atomic
-{
- volatile long count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-
-static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
-{
- return InterlockedDecrement(&v->count) == 0;
-}
-
-static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
-{
- InterlockedIncrement(&v->count);
-}
-
-static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
-{
- InterlockedDecrement(&v->count);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
-{
- return InterlockedCompareExchange(&v->count, _new, old);
-}
-
-#endif
-
-
-
-#if defined(PIPE_ATOMIC_MUTEX)
-
-#define PIPE_ATOMIC "mutex-based fallback"
-
-#include "pipe/p_thread.h"
-
-/**
- * This implementation should really not be used.
- * Add an assembly port instead. It may abort and
- * doesn't destroy used mutexes.
- */
-
-struct pipe_atomic {
- pipe_mutex mutex;
- int32_t count;
-};
-
-static INLINE void
-p_atomic_set(struct pipe_atomic *v, int32_t i)
-{
- pipe_mutex_init(v->mutex);
- pipe_mutex_lock(v->mutex);
- v->count = i;
- pipe_mutex_unlock(v->mutex);
-}
-
-static INLINE int32_t
-p_atomic_read(struct pipe_atomic *v)
-{
- int32_t ret;
-
- pipe_mutex_lock(v->mutex);
- ret = v->count;
- pipe_mutex_unlock(v->mutex);
- return ret;
-}
-
-static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
-{
- pipe_mutex_lock(v->mutex);
- ++v->count;
- pipe_mutex_unlock(v->mutex);
-}
-
-static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
-{
- pipe_mutex_lock(v->mutex);
- --v->count;
- pipe_mutex_unlock(v->mutex);
-}
-
-static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
-{
- boolean ret;
-
- pipe_mutex_lock(v->mutex);
- ret = (--v->count == 0);
- pipe_mutex_unlock(v->mutex);
- return ret;
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
-{
- int32_t ret;
-
- pipe_mutex_lock(v->mutex);
- ret = v->count;
- if (ret == old)
- v->count = _new;
- pipe_mutex_unlock(v->mutex);
-
- return ret;
-}
-
-#endif
-
-
-#ifndef PIPE_ATOMIC
-#error "No pipe_atomic implementation selected"
-#endif
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* P_ATOMIC_H */
diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h
index 6a9018aa3a..c7d3507494 100644
--- a/src/gallium/include/pipe/p_compiler.h
+++ b/src/gallium/include/pipe/p_compiler.h
@@ -38,6 +38,8 @@
#include "xf86_ansic.h"
#include "xf86_libc.h"
#endif
+#include <stddef.h>
+#include <stdarg.h>
#if defined(_WIN32) && !defined(__WIN32__)
@@ -125,6 +127,9 @@ typedef unsigned char boolean;
# define __FUNCTION__ "<unknown>"
# endif
# endif
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# define __FUNCTION__ "<unknown>"
+# endif
#endif
@@ -140,6 +145,14 @@ typedef unsigned char boolean;
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define PIPE_DEPRECATED __attribute__((__deprecated__))
+#else
+#define PIPE_DEPRECATED
+#endif
+
+
+
/* Macros for data alignment. */
#if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
diff --git a/src/gallium/include/pipe/p_config.h b/src/gallium/include/pipe/p_config.h
index 064605a4a0..c5928dde47 100644
--- a/src/gallium/include/pipe/p_config.h
+++ b/src/gallium/include/pipe/p_config.h
@@ -115,8 +115,10 @@
#endif
+#if !defined(PIPE_OS_EMBEDDED)
+
/*
- * Operating system family.
+ * Auto-detect the operating system family.
*
* See subsystem below for a more fine-grained distinction.
*/
@@ -164,7 +166,7 @@
#endif
/*
- * Subsystem.
+ * Try to auto-detect the subsystem.
*
* NOTE: There is no way to auto-detect most of these.
*/
@@ -191,5 +193,7 @@
#endif
#endif /* PIPE_OS_WINDOWS */
+#endif /* !PIPE_OS_EMBEDDED */
+
#endif /* P_CONFIG_H_ */
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index 6bfff1cc59..2894e13e7d 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -31,10 +31,6 @@
#include "p_compiler.h"
-/* FIXME: remove these header dependencies */
-#include "util/u_debug.h"
-#include "util/u_string.h"
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index 03cd74efed..9ae096ee3c 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -43,7 +43,6 @@
#include "p_compiler.h"
#include "p_defines.h"
#include "p_format.h"
-#include "p_refcnt.h"
#include "p_screen.h"
@@ -66,6 +65,12 @@ extern "C" {
#define PIPE_MAX_TEXTURE_LEVELS 16
+struct pipe_reference
+{
+ int32_t count; /* atomic */
+};
+
+
/**
* The driver will certainly subclass this to include actual memory
* management information.
@@ -383,38 +388,6 @@ struct pipe_vertex_element
};
-/* Reference counting helper functions */
-static INLINE void
-pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf)
-{
- struct pipe_buffer *old_buf = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &buf->reference))
- old_buf->screen->buffer_destroy(old_buf);
- *ptr = buf;
-}
-
-static INLINE void
-pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
-{
- struct pipe_surface *old_surf = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &surf->reference))
- old_surf->texture->screen->tex_surface_destroy(old_surf);
- *ptr = surf;
-}
-
-static INLINE void
-pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex)
-{
- struct pipe_texture *old_tex = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &tex->reference))
- old_tex->screen->texture_destroy(old_tex);
- *ptr = tex;
-}
-
-
#ifdef __cplusplus
}
#endif
diff --git a/src/gallium/include/pipe/p_video_state.h b/src/gallium/include/pipe/p_video_state.h
index b85f01c2b0..77e22d0a56 100644
--- a/src/gallium/include/pipe/p_video_state.h
+++ b/src/gallium/include/pipe/p_video_state.h
@@ -30,12 +30,12 @@
/* u_reduce_video_profile() needs these */
#include <pipe/p_compiler.h>
-#include <util/u_debug.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" {
diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c
index 1f456cb829..f7ed6605bf 100644
--- a/src/gallium/state_trackers/dri/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/dri_drawable.c
@@ -46,6 +46,7 @@
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_rect.h"
+#include "util/u_inlines.h"
static struct pipe_surface *
dri_surface_from_handle(struct drm_api *api,
diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c
index a412b81256..2052867309 100644
--- a/src/gallium/state_trackers/dri/dri_screen.c
+++ b/src/gallium/state_trackers/dri/dri_screen.c
@@ -42,6 +42,8 @@
#include "state_tracker/drm_api.h"
#include "state_tracker/dri1_api.h"
+#include "util/u_debug.h"
+
PUBLIC const char __driConfigOptions[] =
DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
@@ -194,7 +196,7 @@ dri_fill_in_modes(struct dri_screen *screen,
return NULL;
}
- return (const const __DRIconfig **)configs;
+ return (const __DRIconfig **)configs;
}
/**
diff --git a/src/gallium/state_trackers/egl/Makefile b/src/gallium/state_trackers/egl/Makefile
index b696f2fae9..2863320a48 100644
--- a/src/gallium/state_trackers/egl/Makefile
+++ b/src/gallium/state_trackers/egl/Makefile
@@ -15,13 +15,11 @@ common_OBJECTS = $(common_SOURCES:.c=.o)
x11_INCLUDES = \
-I$(TOP)/src/gallium/drivers \
-I$(TOP)/src/glx/x11 \
- -I$(TOP)/src/egl/drivers/xdri \
-I$(TOP)/src/mesa \
$(shell pkg-config --cflags-only-I libdrm)
x11_SOURCES = $(wildcard x11/*.c) \
- $(TOP)/src/glx/x11/dri2.c \
- $(TOP)/src/egl/drivers/xdri/glxinit.c
+ $(TOP)/src/glx/x11/dri2.c
x11_OBJECTS = $(x11_SOURCES:.c=.o)
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 6c8f3b9f79..70216177bd 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -23,10 +23,12 @@
*/
#include <assert.h>
+#include <stdio.h>
#include <string.h>
#include "pipe/p_screen.h"
#include "util/u_memory.h"
#include "util/u_rect.h"
+#include "util/u_inlines.h"
#include "egldriver.h"
#include "eglcurrent.h"
#include "eglconfigutil.h"
@@ -468,7 +470,7 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
if (!gconf)
continue;
- _eglInitConfig(&gconf->base, id);
+ _eglInitConfig(&gconf->base, dpy, id);
api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
if (!api_mask) {
@@ -631,7 +633,7 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
return NULL;
}
- if (!_eglInitContext(drv, &gctx->base, conf, attribs)) {
+ if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) {
free(gctx);
return NULL;
}
@@ -713,7 +715,7 @@ egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
return NULL;
}
- if (!_eglInitSurface(drv, &gsurf->base, EGL_WINDOW_BIT, conf, attribs)) {
+ if (!_eglInitSurface(&gsurf->base, dpy, EGL_WINDOW_BIT, conf, attribs)) {
free(gsurf);
return NULL;
}
@@ -753,7 +755,7 @@ egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
return NULL;
}
- if (!_eglInitSurface(drv, &gsurf->base, EGL_PIXMAP_BIT, conf, attribs)) {
+ if (!_eglInitSurface(&gsurf->base, dpy, EGL_PIXMAP_BIT, conf, attribs)) {
free(gsurf);
return NULL;
}
@@ -790,7 +792,7 @@ egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
return NULL;
}
- if (!_eglInitSurface(drv, &gsurf->base, EGL_PBUFFER_BIT, conf, attribs)) {
+ if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) {
free(gsurf);
return NULL;
}
@@ -1087,8 +1089,8 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLSurface *surf, EGLint buffer)
{
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
- _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API);
- struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+ _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API);
+ struct egl_g3d_context *gctx;
enum pipe_format target_format;
int target;
@@ -1118,6 +1120,11 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
}
+ if (!es1)
+ return EGL_TRUE;
+ if (!gsurf->render_surface)
+ return EGL_FALSE;
+
/* flush properly if the surface is bound */
if (gsurf->base.CurrentContext) {
gctx = egl_g3d_context(gsurf->base.CurrentContext);
@@ -1125,14 +1132,11 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
}
- if (gctx) {
- if (!gsurf->render_surface)
- return EGL_FALSE;
+ gctx = egl_g3d_context(es1);
+ gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
+ target, gsurf->base.MipmapLevel, target_format);
- gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
- target, gsurf->base.MipmapLevel, target_format);
- gsurf->base.BoundToTexture = EGL_TRUE;
- }
+ gsurf->base.BoundToTexture = EGL_TRUE;
return EGL_TRUE;
}
@@ -1180,7 +1184,7 @@ egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
return NULL;
}
- if (!_eglInitSurface(drv, &gsurf->base,
+ if (!_eglInitSurface(&gsurf->base, dpy,
EGL_SCREEN_BIT_MESA, conf, attribs)) {
free(gsurf);
return NULL;
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h
index 3dae8c4052..5d2d9c481a 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.h
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.h
@@ -87,41 +87,8 @@ struct egl_g3d_screen {
const struct native_mode **native_modes;
};
-static INLINE struct egl_g3d_driver *
-egl_g3d_driver(_EGLDriver *drv)
-{
- return (struct egl_g3d_driver *) drv;
-}
-
-static INLINE struct egl_g3d_display *
-egl_g3d_display(_EGLDisplay *dpy)
-{
- /* note that it is not direct casting */
- return (struct egl_g3d_display *) dpy->DriverData;
-}
-
-static INLINE struct egl_g3d_context *
-egl_g3d_context(_EGLContext *ctx)
-{
- return (struct egl_g3d_context *) ctx;
-}
-
-static INLINE struct egl_g3d_surface *
-egl_g3d_surface(_EGLSurface *surf)
-{
- return (struct egl_g3d_surface *) surf;
-}
-
-static INLINE struct egl_g3d_config *
-egl_g3d_config(_EGLConfig *conf)
-{
- return (struct egl_g3d_config *) conf;
-}
-
-static INLINE struct egl_g3d_screen *
-egl_g3d_screen(_EGLScreen *scr)
-{
- return (struct egl_g3d_screen *) scr;
-}
+/* standard typecasts */
+_EGL_DRIVER_STANDARD_TYPECASTS(egl_g3d)
+_EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj)
#endif /* _EGL_G3D_H_ */
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c
index d5baf2c2f0..445c28c383 100644
--- a/src/gallium/state_trackers/egl/kms/native_kms.c
+++ b/src/gallium/state_trackers/egl/kms/native_kms.c
@@ -22,12 +22,14 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <stdio.h>
#include <string.h>
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "egllog.h"
#include "native_kms.h"
diff --git a/src/egl/drivers/xdri/glxinit.c b/src/gallium/state_trackers/egl/x11/glxinit.c
index ba6132788a..ba6132788a 100644
--- a/src/egl/drivers/xdri/glxinit.c
+++ b/src/gallium/state_trackers/egl/x11/glxinit.c
diff --git a/src/egl/drivers/xdri/glxinit.h b/src/gallium/state_trackers/egl/x11/glxinit.h
index 1cc7c460fe..1cc7c460fe 100644
--- a/src/egl/drivers/xdri/glxinit.h
+++ b/src/gallium/state_trackers/egl/x11/glxinit.h
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index 07f82d878c..b2eba7219f 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -25,6 +25,7 @@
#include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_format.h"
+#include "util/u_inlines.h"
#include "pipe/p_compiler.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c
index dd3c9f8b6a..8eb542bd82 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.c
+++ b/src/gallium/state_trackers/egl/x11/native_x11.c
@@ -22,6 +22,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <stdio.h>
#include <string.h>
#include "util/u_debug.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
index dfa8df2223..7946415ce7 100644
--- a/src/gallium/state_trackers/egl/x11/native_ximage.c
+++ b/src/gallium/state_trackers/egl/x11/native_ximage.c
@@ -33,7 +33,8 @@
#include "util/u_math.h"
#include "util/u_format.h"
#include "pipe/p_compiler.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "softpipe/sp_winsys.h"
#include "egllog.h"
diff --git a/src/gallium/state_trackers/egl/x11/sw_winsys.c b/src/gallium/state_trackers/egl/x11/sw_winsys.c
index 6ee3ede38c..33328aadf2 100644
--- a/src/gallium/state_trackers/egl/x11/sw_winsys.c
+++ b/src/gallium/state_trackers/egl/x11/sw_winsys.c
@@ -35,9 +35,9 @@
*/
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_state.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"
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c
index 76ce45ee57..d72bfc99d3 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.c
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.c
@@ -43,7 +43,7 @@ struct x11_screen {
int number;
/*
- * This is used to fetch GLX visuals/fbconfigs. It uses code from egl_xdri.
+ * This is used to fetch GLX visuals/fbconfigs. It steals code from GLX.
* It might be better to rewrite the part in Xlib or XCB.
*/
__GLXdisplayPrivate *glx_dpy;
diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h
index d24971ca1c..63a329cbe0 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.h
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.h
@@ -60,7 +60,7 @@ and create a window, you must do the following to use the X/Mesa interface:
#include "main/mtypes.h"
#include "state_tracker/st_context.h"
#include "state_tracker/st_public.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
# include <X11/Xlib.h>
diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i
index 6879722845..99e177b0be 100644
--- a/src/gallium/state_trackers/python/gallium.i
+++ b/src/gallium/state_trackers/python/gallium.i
@@ -40,9 +40,9 @@
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "cso_cache/cso_context.h"
+#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
#include "util/u_tile.h"
#include "util/u_math.h"
diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c
index e41125f6f9..467e20207a 100644
--- a/src/gallium/state_trackers/python/st_device.c
+++ b/src/gallium/state_trackers/python/st_device.c
@@ -29,7 +29,7 @@
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "cso_cache/cso_context.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/python/st_llvmpipe_winsys.c b/src/gallium/state_trackers/python/st_llvmpipe_winsys.c
index 0096b18c99..c5ee1679f0 100644
--- a/src/gallium/state_trackers/python/st_llvmpipe_winsys.c
+++ b/src/gallium/state_trackers/python/st_llvmpipe_winsys.c
@@ -36,7 +36,7 @@
#include "pipe/p_format.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "llvmpipe/lp_winsys.h"
diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c
index 9637741421..32a6551a87 100644
--- a/src/gallium/state_trackers/python/st_sample.c
+++ b/src/gallium/state_trackers/python/st_sample.c
@@ -29,7 +29,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_tile.h"
#include "util/u_math.h"
diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c
index cf4a11bb14..20c72c1ff5 100644
--- a/src/gallium/state_trackers/vega/api_filters.c
+++ b/src/gallium/state_trackers/vega/api_filters.c
@@ -34,7 +34,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "pipe/p_shader_tokens.h"
diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c
index c437553bc2..015241498e 100644
--- a/src/gallium/state_trackers/vega/api_images.c
+++ b/src/gallium/state_trackers/vega/api_images.c
@@ -35,7 +35,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_blit.h"
#include "util/u_tile.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c
index e6070c7353..9c123a4cf9 100644
--- a/src/gallium/state_trackers/vega/api_masks.c
+++ b/src/gallium/state_trackers/vega/api_masks.c
@@ -31,7 +31,7 @@
#include "vg_context.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_pack_color.h"
#include "util/u_draw_quad.h"
diff --git a/src/gallium/state_trackers/vega/api_path.c b/src/gallium/state_trackers/vega/api_path.c
index 15ac1900f4..58ebb3b60e 100644
--- a/src/gallium/state_trackers/vega/api_path.c
+++ b/src/gallium/state_trackers/vega/api_path.c
@@ -32,7 +32,7 @@
#include "paint.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
VGPath vgCreatePath(VGint pathFormat,
diff --git a/src/gallium/state_trackers/vega/asm_fill.h b/src/gallium/state_trackers/vega/asm_fill.h
index 2f394ad6c5..27773467fa 100644
--- a/src/gallium/state_trackers/vega/asm_fill.h
+++ b/src/gallium/state_trackers/vega/asm_fill.h
@@ -27,166 +27,375 @@
#ifndef ASM_FILL_H
#define ASM_FILL_H
-static const char solid_fill_asm[] =
- "MOV %s, CONST[0]\n";
-
-
-static const char linear_grad_asm[] =
- "MOV TEMP[0].xy, IN[0]\n"
- "MOV TEMP[0].z, CONST[1].yyyy\n"
- "DP3 TEMP[1], CONST[2], TEMP[0]\n"
- "DP3 TEMP[2], CONST[3], TEMP[0]\n"
- "DP3 TEMP[3], CONST[4], TEMP[0]\n"
- "RCP TEMP[3], TEMP[3]\n"
- "MUL TEMP[1], TEMP[1], TEMP[3]\n"
- "MUL TEMP[2], TEMP[2], TEMP[3]\n"
- "MOV TEMP[4].x, TEMP[1]\n"
- "MOV TEMP[4].y, TEMP[2]\n"
- "MUL TEMP[0], CONST[0].yyyy, TEMP[4].yyyy\n"
- "MAD TEMP[1], CONST[0].xxxx, TEMP[4].xxxx, TEMP[0]\n"
- "MUL TEMP[2], TEMP[1], CONST[0].zzzz\n"
- "TEX %s, TEMP[2], SAMP[0], 1D\n";
-
-static const char radial_grad_asm[] =
- "MOV TEMP[0].xy, IN[0]\n"
- "MOV TEMP[0].z, CONST[1].yyyy\n"
- "DP3 TEMP[1], CONST[2], TEMP[0]\n"
- "DP3 TEMP[2], CONST[3], TEMP[0]\n"
- "DP3 TEMP[3], CONST[4], TEMP[0]\n"
- "RCP TEMP[3], TEMP[3]\n"
- "MUL TEMP[1], TEMP[1], TEMP[3]\n"
- "MUL TEMP[2], TEMP[2], TEMP[3]\n"
- "MOV TEMP[5].x, TEMP[1]\n"
- "MOV TEMP[5].y, TEMP[2]\n"
- "MUL TEMP[0], CONST[0].yyyy, TEMP[5].yyyy\n"
- "MAD TEMP[1], CONST[0].xxxx, TEMP[5].xxxx, TEMP[0]\n"
- "ADD TEMP[1], TEMP[1], TEMP[1]\n"
- "MUL TEMP[3], TEMP[5].yyyy, TEMP[5].yyyy\n"
- "MAD TEMP[4], TEMP[5].xxxx, TEMP[5].xxxx, TEMP[3]\n"
- "MOV TEMP[4], -TEMP[4]\n"
- "MUL TEMP[2], CONST[0].zzzz, TEMP[4]\n"
- "MUL TEMP[0], CONST[1].wwww, TEMP[2]\n"
- "MUL TEMP[3], TEMP[1], TEMP[1]\n"
- "SUB TEMP[2], TEMP[3], TEMP[0]\n"
- "RSQ TEMP[2], |TEMP[2]|\n"
- "RCP TEMP[2], TEMP[2]\n"
- "SUB TEMP[1], TEMP[2], TEMP[1]\n"
- "ADD TEMP[0], CONST[0].zzzz, CONST[0].zzzz\n"
- "RCP TEMP[0], TEMP[0]\n"
- "MUL TEMP[2], TEMP[1], TEMP[0]\n"
- "TEX %s, TEMP[2], SAMP[0], 1D\n";
-
-static const char pattern_asm[] =
- "MOV TEMP[0].xy, IN[0]\n"
- "MOV TEMP[0].z, CONST[1].yyyy\n"
- "DP3 TEMP[1], CONST[2], TEMP[0]\n"
- "DP3 TEMP[2], CONST[3], TEMP[0]\n"
- "DP3 TEMP[3], CONST[4], TEMP[0]\n"
- "RCP TEMP[3], TEMP[3]\n"
- "MUL TEMP[1], TEMP[1], TEMP[3]\n"
- "MUL TEMP[2], TEMP[2], TEMP[3]\n"
- "MOV TEMP[4].x, TEMP[1]\n"
- "MOV TEMP[4].y, TEMP[2]\n"
- "RCP TEMP[0], CONST[1].zwzw\n"
- "MOV TEMP[1], TEMP[4]\n"
- "MUL TEMP[1].x, TEMP[1], TEMP[0]\n"
- "MUL TEMP[1].y, TEMP[1], TEMP[0]\n"
- "TEX %s, TEMP[1], SAMP[0], 2D\n";
-
-
-static const char mask_asm[] =
- "TEX TEMP[1], IN[0], SAMP[1], 2D\n"
- "MUL TEMP[0].w, TEMP[0].wwww, TEMP[1].wwww\n"
- "MOV %s, TEMP[0]\n";
-
-
-static const char image_normal_asm[] =
- "TEX %s, IN[1], SAMP[3], 2D\n";
-
-static const char image_multiply_asm[] =
- "TEX TEMP[1], IN[1], SAMP[3], 2D\n"
- "MUL %s, TEMP[0], TEMP[1]\n";
-
-static const char image_stencil_asm[] =
- "TEX TEMP[1], IN[1], SAMP[3], 2D\n"
- "MUL %s, TEMP[0], TEMP[1]\n";
-
-
-#define EXTENDED_BLEND_OVER \
- "SUB TEMP[3], CONST[1].yyyy, TEMP[1].wwww\n" \
- "SUB TEMP[4], CONST[1].yyyy, TEMP[0].wwww\n" \
- "MUL TEMP[3], TEMP[0], TEMP[3]\n" \
- "MUL TEMP[4], TEMP[1], TEMP[4]\n" \
- "ADD TEMP[3], TEMP[3], TEMP[4]\n"
-
-static const char blend_multiply_asm[] =
- "TEX TEMP[1], IN[0], SAMP[2], 2D\n"
- EXTENDED_BLEND_OVER
- "MUL TEMP[4], TEMP[0], TEMP[1]\n"
- "ADD TEMP[1], TEMP[4], TEMP[3]\n"/*result.rgb*/
- "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n"
- "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n"
- "SUB TEMP[1].w, TEMP[3], TEMP[2]\n"
- "MOV %s, TEMP[1]\n";
-#if 1
-static const char blend_screen_asm[] =
- "TEX TEMP[1], IN[0], SAMP[2], 2D\n"
- "ADD TEMP[3], TEMP[0], TEMP[1]\n"
- "MUL TEMP[2], TEMP[0], TEMP[1]\n"
- "SUB %s, TEMP[3], TEMP[2]\n";
-#else
-static const char blend_screen_asm[] =
- "TEX TEMP[1], IN[0], SAMP[2], 2D\n"
- "MOV %s, TEMP[1]\n";
-#endif
-
-static const char blend_darken_asm[] =
- "TEX TEMP[1], IN[0], SAMP[2], 2D\n"
- EXTENDED_BLEND_OVER
- "MUL TEMP[4], TEMP[0], TEMP[1].wwww\n"
- "MUL TEMP[5], TEMP[1], TEMP[0].wwww\n"
- "MIN TEMP[4], TEMP[4], TEMP[5]\n"
- "ADD TEMP[1], TEMP[3], TEMP[4]\n"
- "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n"
- "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n"
- "SUB TEMP[1].w, TEMP[3], TEMP[2]\n"
- "MOV %s, TEMP[1]\n";
-
-static const char blend_lighten_asm[] =
- "TEX TEMP[1], IN[0], SAMP[2], 2D\n"
- EXTENDED_BLEND_OVER
- "MUL TEMP[4], TEMP[0], TEMP[1].wwww\n"
- "MUL TEMP[5], TEMP[1], TEMP[0].wwww\n"
- "MAX TEMP[4], TEMP[4], TEMP[5]\n"
- "ADD TEMP[1], TEMP[3], TEMP[4]\n"
- "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n"
- "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n"
- "SUB TEMP[1].w, TEMP[3], TEMP[2]\n"
- "MOV %s, TEMP[1]\n";
-
-
-static const char premultiply_asm[] =
- "MUL TEMP[0].xyz, TEMP[0], TEMP[0].wwww\n";
-
-static const char unpremultiply_asm[] =
- "TEX TEMP[0], IN[0], SAMP[1], 2D\n";
-
-
-static const char color_bw_asm[] =
- "ADD TEMP[1], CONST[1].yyyy, CONST[1].yyyy\n"
- "RCP TEMP[2], TEMP[1]\n"
- "ADD TEMP[1], CONST[1].yyyy, TEMP[2]\n"
- "ADD TEMP[2].x, TEMP[0].xxxx, TEMP[0].yyyy\n"
- "ADD TEMP[2].x, TEMP[0].zzzz, TEMP[0].xxxx\n"
- "SGE TEMP[0].xyz, TEMP[2].xxxx, TEMP[1]\n"
- "SGE TEMP[0].w, TEMP[0].wwww, TEMP[2].yyyy\n"
- "MOV %s, TEMP[0]\n";
+#include "tgsi/tgsi_ureg.h"
+
+typedef void (* ureg_func)( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant);
+
+static INLINE void
+solid_fill( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_MOV(ureg, *out, constant[0]);
+}
+
+static INLINE void
+linear_grad( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+
+ ureg_MOV(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_XY),
+ in[0]);
+ ureg_MOV(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_Z),
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y));
+ ureg_DP3(ureg, temp[1], constant[2], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[2], constant[3], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[3], constant[4], ureg_src(temp[0]));
+ ureg_RCP(ureg, temp[3], ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[1], ureg_src(temp[1]), ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[2]), ureg_src(temp[3]));
+ ureg_MOV(ureg, ureg_writemask(temp[4], TGSI_WRITEMASK_X), ureg_src(temp[1]));
+ ureg_MOV(ureg, ureg_writemask(temp[4], TGSI_WRITEMASK_Y), ureg_src(temp[2]));
+ ureg_MUL(ureg, temp[0],
+ ureg_scalar(constant[0], TGSI_SWIZZLE_Y),
+ ureg_scalar(ureg_src(temp[4]), TGSI_SWIZZLE_Y));
+ ureg_MAD(ureg, temp[1],
+ ureg_scalar(constant[0], TGSI_SWIZZLE_X),
+ ureg_scalar(ureg_src(temp[4]), TGSI_SWIZZLE_X),
+ ureg_src(temp[0]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[1]),
+ ureg_scalar(constant[0], TGSI_SWIZZLE_Z));
+ ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[2]), sampler[0]);
+}
+
+static INLINE void
+radial_grad( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+
+ ureg_MOV(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_XY), in[0]);
+ ureg_MOV(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_Z),
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y));
+ ureg_DP3(ureg, temp[1], constant[2], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[2], constant[3], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[3], constant[4], ureg_src(temp[0]));
+ ureg_RCP(ureg, temp[3], ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[1], ureg_src(temp[1]), ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[2]), ureg_src(temp[3]));
+ ureg_MOV(ureg, ureg_writemask(temp[5], TGSI_WRITEMASK_X), ureg_src(temp[1]));
+ ureg_MOV(ureg, ureg_writemask(temp[5], TGSI_WRITEMASK_Y), ureg_src(temp[2]));
+ ureg_MUL(ureg, temp[0], ureg_scalar(constant[0], TGSI_SWIZZLE_Y),
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_Y));
+ ureg_MAD(ureg, temp[1],
+ ureg_scalar(constant[0], TGSI_SWIZZLE_X),
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_X), ureg_src(temp[0]));
+ ureg_ADD(ureg, temp[1], ureg_src(temp[1]), ureg_src(temp[1]));
+ ureg_MUL(ureg, temp[3],
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_Y),
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_Y));
+ ureg_MAD(ureg, temp[4],
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_X),
+ ureg_scalar(ureg_src(temp[5]), TGSI_SWIZZLE_X),
+ ureg_src(temp[3]));
+ ureg_MOV(ureg, temp[4], ureg_negate(ureg_src(temp[4])));
+ ureg_MUL(ureg, temp[2],
+ ureg_scalar(constant[0], TGSI_SWIZZLE_Z),
+ ureg_src(temp[4]));
+ ureg_MUL(ureg, temp[0],
+ ureg_scalar(constant[1], TGSI_SWIZZLE_W),
+ ureg_src(temp[2]));
+ ureg_MUL(ureg, temp[3], ureg_src(temp[1]), ureg_src(temp[1]));
+
+ ureg_SUB(ureg, temp[2], ureg_src(temp[3]), ureg_src(temp[0]));
+ ureg_RSQ(ureg, temp[2], ureg_abs(ureg_src(temp[2])));
+ ureg_RCP(ureg, temp[2], ureg_src(temp[2]));
+ ureg_SUB(ureg, temp[1], ureg_src(temp[2]), ureg_src(temp[1]));
+ ureg_ADD(ureg, temp[0],
+ ureg_scalar(constant[0], TGSI_SWIZZLE_Z),
+ ureg_scalar(constant[0], TGSI_SWIZZLE_Z));
+ ureg_RCP(ureg, temp[0], ureg_src(temp[0]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[1]), ureg_src(temp[0]));
+ ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[2]), sampler[0]);
+
+}
+
+
+static INLINE void
+pattern( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_MOV(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_XY),
+ in[0]);
+ ureg_MOV(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_Z),
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y));
+ ureg_DP3(ureg, temp[1], constant[2], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[2], constant[3], ureg_src(temp[0]));
+ ureg_DP3(ureg, temp[3], constant[4], ureg_src(temp[0]));
+ ureg_RCP(ureg, temp[3], ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[1], ureg_src(temp[1]), ureg_src(temp[3]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[2]), ureg_src(temp[3]));
+ ureg_MOV(ureg, ureg_writemask(temp[4], TGSI_WRITEMASK_X), ureg_src(temp[1]));
+ ureg_MOV(ureg, ureg_writemask(temp[4], TGSI_WRITEMASK_Y), ureg_src(temp[2]));
+ ureg_RCP(ureg, temp[0],
+ ureg_swizzle(constant[1],
+ TGSI_SWIZZLE_Z,
+ TGSI_SWIZZLE_W,
+ TGSI_SWIZZLE_Z,
+ TGSI_SWIZZLE_W));
+ ureg_MOV(ureg, temp[1], ureg_src(temp[4]));
+ ureg_MUL(ureg,
+ ureg_writemask(temp[1], TGSI_WRITEMASK_X),
+ ureg_src(temp[1]),
+ ureg_src(temp[0]));
+ ureg_MUL(ureg,
+ ureg_writemask(temp[1], TGSI_WRITEMASK_Y),
+ ureg_src(temp[1]),
+ ureg_src(temp[0]));
+ ureg_TEX(ureg, *out, TGSI_TEXTURE_2D, ureg_src(temp[1]), sampler[0]);
+}
+
+static INLINE void
+mask( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[1]);
+ ureg_MUL(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_W),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_MOV(ureg, *out, ureg_src(temp[0]));
+}
+
+static INLINE void
+image_normal( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, *out, TGSI_TEXTURE_2D, in[1], sampler[3]);
+}
+
+
+static INLINE void
+image_multiply( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[1], sampler[3]);
+ ureg_MUL(ureg, *out, ureg_src(temp[0]), ureg_src(temp[1]));
+}
+
+
+static INLINE void
+image_stencil( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[1], sampler[3]);
+ ureg_MUL(ureg, *out, ureg_src(temp[0]), ureg_src(temp[1]));
+}
+
+#define EXTENDED_BLENDER_OVER_FUNC \
+ ureg_SUB(ureg, temp[3], \
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y), \
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W)); \
+ ureg_SUB(ureg, temp[3], \
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y), \
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W)); \
+ ureg_MUL(ureg, temp[3], ureg_src(temp[0]), ureg_src(temp[3])); \
+ ureg_MUL(ureg, temp[4], ureg_src(temp[1]), ureg_src(temp[4])); \
+ ureg_ADD(ureg, temp[3], ureg_src(temp[3]), ureg_src(temp[4]));
+
+
+static INLINE void
+blend_multiply( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[2]);
+ EXTENDED_BLENDER_OVER_FUNC
+ ureg_MUL(ureg, temp[4], ureg_src(temp[0]), ureg_src(temp[1]));
+ ureg_ADD(ureg, temp[1], ureg_src(temp[4]), ureg_src(temp[3]));
+
+ ureg_MUL(ureg, temp[2], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_ADD(ureg, temp[3], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_SUB(ureg, ureg_writemask(temp[1], TGSI_WRITEMASK_W),
+ ureg_src(temp[3]), ureg_src(temp[2]));
+
+ ureg_MOV(ureg, *out, ureg_src(temp[1]));
+}
+
+static INLINE void
+blend_screen( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[2]);
+ ureg_ADD(ureg, temp[3], ureg_src(temp[0]), ureg_src(temp[1]));
+ ureg_MUL(ureg, temp[2], ureg_src(temp[0]), ureg_src(temp[1]));
+ ureg_SUB(ureg, *out, ureg_src(temp[3]), ureg_src(temp[2]));
+}
+
+static INLINE void
+blend_darken( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[2]);
+ EXTENDED_BLENDER_OVER_FUNC
+ ureg_MUL(ureg, temp[4], ureg_src(temp[0]),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_MUL(ureg, temp[5], ureg_src(temp[1]),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W));
+ ureg_MIN(ureg, temp[4], ureg_src(temp[4]), ureg_src(temp[5]));
+ ureg_ADD(ureg, temp[1], ureg_src(temp[3]), ureg_src(temp[4]));
+
+ ureg_MUL(ureg, temp[2], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_ADD(ureg, temp[3], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_SUB(ureg, ureg_writemask(temp[1], TGSI_WRITEMASK_W),
+ ureg_src(temp[3]), ureg_src(temp[2]));
+
+ ureg_MOV(ureg, *out, ureg_src(temp[1]));
+}
+
+static INLINE void
+blend_lighten( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[2]);
+ EXTENDED_BLENDER_OVER_FUNC
+ ureg_MUL(ureg, temp[4], ureg_src(temp[0]),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_MUL(ureg, temp[5], ureg_src(temp[1]),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W));
+ ureg_MAX(ureg, temp[4], ureg_src(temp[4]), ureg_src(temp[5]));
+ ureg_ADD(ureg, temp[1], ureg_src(temp[3]), ureg_src(temp[4]));
+
+ ureg_MUL(ureg, temp[2], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_ADD(ureg, temp[3], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W));
+ ureg_SUB(ureg, ureg_writemask(temp[1], TGSI_WRITEMASK_W),
+ ureg_src(temp[3]), ureg_src(temp[2]));
+
+ ureg_MOV(ureg, *out, ureg_src(temp[1]));
+}
+
+static INLINE void
+premultiply( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_MUL(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_XYZ),
+ ureg_src(temp[0]),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W));
+}
+
+static INLINE void
+unpremultiply( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_TEX(ureg, temp[0], TGSI_TEXTURE_2D, in[0], sampler[1]);
+}
+
+
+static INLINE void
+color_bw( struct ureg_program *ureg,
+ struct ureg_dst *out,
+ struct ureg_src *in,
+ struct ureg_src *sampler,
+ struct ureg_dst *temp,
+ struct ureg_src *constant)
+{
+ ureg_ADD(ureg, temp[1],
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y),
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y));
+ ureg_RCP(ureg, temp[2], ureg_src(temp[1]));
+ ureg_ADD(ureg, temp[1],
+ ureg_scalar(constant[1], TGSI_SWIZZLE_Y),
+ ureg_src(temp[2]));
+ ureg_ADD(ureg, ureg_writemask(temp[2], TGSI_WRITEMASK_X),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_X),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_Y));
+ ureg_ADD(ureg, ureg_writemask(temp[2], TGSI_WRITEMASK_X),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_Z),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_X));
+ ureg_SGE(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_XYZ),
+ ureg_scalar(ureg_src(temp[2]), TGSI_SWIZZLE_X),
+ ureg_src(temp[1]));
+ ureg_SGE(ureg,
+ ureg_writemask(temp[0], TGSI_WRITEMASK_W),
+ ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W),
+ ureg_scalar(ureg_src(temp[2]), TGSI_SWIZZLE_Y));
+ ureg_MOV(ureg, *out, ureg_src(temp[0]));
+}
struct shader_asm_info {
VGint id;
- VGint num_tokens;
- const char * txt;
+ ureg_func func;
VGboolean needs_position;
@@ -203,44 +412,44 @@ struct shader_asm_info {
static const struct shader_asm_info shaders_asm[] = {
/* fills */
- {VEGA_SOLID_FILL_SHADER, 40, solid_fill_asm,
+ {VEGA_SOLID_FILL_SHADER, solid_fill,
VG_FALSE, 0, 1, 0, 0, 0, 0},
- {VEGA_LINEAR_GRADIENT_SHADER, 200, linear_grad_asm,
+ {VEGA_LINEAR_GRADIENT_SHADER, linear_grad,
VG_TRUE, 0, 5, 0, 1, 0, 5},
- {VEGA_RADIAL_GRADIENT_SHADER, 200, radial_grad_asm,
+ {VEGA_RADIAL_GRADIENT_SHADER, radial_grad,
VG_TRUE, 0, 5, 0, 1, 0, 6},
- {VEGA_PATTERN_SHADER, 100, pattern_asm,
+ {VEGA_PATTERN_SHADER, pattern,
VG_TRUE, 1, 4, 0, 1, 0, 5},
/* image draw modes */
- {VEGA_IMAGE_NORMAL_SHADER, 200, image_normal_asm,
+ {VEGA_IMAGE_NORMAL_SHADER, image_normal,
VG_TRUE, 0, 0, 3, 1, 0, 0},
- {VEGA_IMAGE_MULTIPLY_SHADER, 200, image_multiply_asm,
+ {VEGA_IMAGE_MULTIPLY_SHADER, image_multiply,
VG_TRUE, 0, 0, 3, 1, 0, 2},
- {VEGA_IMAGE_STENCIL_SHADER, 200, image_stencil_asm,
+ {VEGA_IMAGE_STENCIL_SHADER, image_stencil,
VG_TRUE, 0, 0, 3, 1, 0, 2},
- {VEGA_MASK_SHADER, 100, mask_asm,
+ {VEGA_MASK_SHADER, mask,
VG_TRUE, 0, 0, 1, 1, 0, 2},
/* extra blend modes */
- {VEGA_BLEND_MULTIPLY_SHADER, 200, blend_multiply_asm,
+ {VEGA_BLEND_MULTIPLY_SHADER, blend_multiply,
VG_TRUE, 1, 1, 2, 1, 0, 5},
- {VEGA_BLEND_SCREEN_SHADER, 200, blend_screen_asm,
+ {VEGA_BLEND_SCREEN_SHADER, blend_screen,
VG_TRUE, 0, 0, 2, 1, 0, 4},
- {VEGA_BLEND_DARKEN_SHADER, 200, blend_darken_asm,
+ {VEGA_BLEND_DARKEN_SHADER, blend_darken,
VG_TRUE, 1, 1, 2, 1, 0, 6},
- {VEGA_BLEND_LIGHTEN_SHADER, 200, blend_lighten_asm,
+ {VEGA_BLEND_LIGHTEN_SHADER, blend_lighten,
VG_TRUE, 1, 1, 2, 1, 0, 6},
/* premultiply */
- {VEGA_PREMULTIPLY_SHADER, 100, premultiply_asm,
+ {VEGA_PREMULTIPLY_SHADER, premultiply,
VG_FALSE, 0, 0, 0, 0, 0, 1},
- {VEGA_UNPREMULTIPLY_SHADER, 100, unpremultiply_asm,
+ {VEGA_UNPREMULTIPLY_SHADER, unpremultiply,
VG_FALSE, 0, 0, 0, 0, 0, 1},
/* color transform to black and white */
- {VEGA_BW_SHADER, 150, color_bw_asm,
+ {VEGA_BW_SHADER, color_bw,
VG_FALSE, 1, 1, 0, 0, 0, 3},
};
#endif
diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c
index 1112ad9839..2e10965be4 100644
--- a/src/gallium/state_trackers/vega/image.c
+++ b/src/gallium/state_trackers/vega/image.c
@@ -37,7 +37,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_blit.h"
#include "util/u_format.h"
#include "util/u_tile.h"
diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c
index ba8ecef1d2..467b95b751 100644
--- a/src/gallium/state_trackers/vega/mask.c
+++ b/src/gallium/state_trackers/vega/mask.c
@@ -35,7 +35,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c
index d8f6299b2d..3405d635f0 100644
--- a/src/gallium/state_trackers/vega/paint.c
+++ b/src/gallium/state_trackers/vega/paint.c
@@ -32,7 +32,7 @@
#include "st_inlines.h"
#include "pipe/p_compiler.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/vega/polygon.c b/src/gallium/state_trackers/vega/polygon.c
index f5352ee84e..f56ea0c8b4 100644
--- a/src/gallium/state_trackers/vega/polygon.c
+++ b/src/gallium/state_trackers/vega/polygon.c
@@ -37,7 +37,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "util/u_draw_quad.h"
diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c
index 47e18dc1e2..05620efa9c 100644
--- a/src/gallium/state_trackers/vega/renderer.c
+++ b/src/gallium/state_trackers/vega/renderer.c
@@ -30,7 +30,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "pipe/p_shader_tokens.h"
diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c
index 8e59d53dc7..0e71a507bf 100644
--- a/src/gallium/state_trackers/vega/shader.c
+++ b/src/gallium/state_trackers/vega/shader.c
@@ -35,7 +35,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#define MAX_CONSTANTS 20
diff --git a/src/gallium/state_trackers/vega/shaders_cache.c b/src/gallium/state_trackers/vega/shaders_cache.c
index f620075d0b..f43fe6ee4c 100644
--- a/src/gallium/state_trackers/vega/shaders_cache.c
+++ b/src/gallium/state_trackers/vega/shaders_cache.c
@@ -30,7 +30,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "pipe/p_shader_tokens.h"
@@ -123,17 +123,23 @@ static INLINE VGint range_max(VGint max, VGint current)
return MAX2(max, current);
}
-static void
-create_preamble(char *txt,
- const struct shader_asm_info *shaders[SHADER_STAGES],
- int num_shaders)
+static void *
+combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_shaders,
+ struct pipe_context *pipe,
+ struct pipe_shader_state *shader)
{
VGboolean declare_input = VG_FALSE;
VGint start_const = -1, end_const = 0;
VGint start_temp = -1, end_temp = 0;
VGint start_sampler = -1, end_sampler = 0;
- VGint i;
+ VGint i, current_shader = 0;
VGint num_consts, num_temps, num_samplers;
+ struct ureg_program *ureg;
+ struct ureg_src in[2];
+ struct ureg_src *sampler = NULL;
+ struct ureg_src *constant = NULL;
+ struct ureg_dst out, *temp = NULL;
+ void *p = NULL;
for (i = 0; i < num_shaders; ++i) {
if (shaders[i]->num_consts)
@@ -158,99 +164,94 @@ create_preamble(char *txt,
if (start_temp < 0)
start_temp = 0;
if (start_sampler < 0)
- start_sampler = 0;
+ start_sampler = 0;
num_consts = end_const - start_const;
num_temps = end_temp - start_temp;
num_samplers = end_sampler - start_sampler;
- /* end exclusive */
- --end_const;
- --end_temp;
- --end_sampler;
- sprintf(txt, "FRAG\n");
+ ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
+ if (!ureg)
+ return NULL;
if (declare_input) {
- sprintf(txt + strlen(txt), "DCL IN[0], POSITION, LINEAR\n");
- sprintf(txt + strlen(txt), "DCL IN[1], GENERIC[0], PERSPECTIVE\n");
+ in[0] = ureg_DECL_fs_input(ureg,
+ TGSI_SEMANTIC_POSITION,
+ 0,
+ TGSI_INTERPOLATE_LINEAR);
+ in[1] = ureg_DECL_fs_input(ureg,
+ TGSI_SEMANTIC_GENERIC,
+ 0,
+ TGSI_INTERPOLATE_PERSPECTIVE);
}
/* we always have a color output */
- sprintf(txt + strlen(txt), "DCL OUT[0], COLOR, CONSTANT\n");
-
- if (num_consts > 1)
- sprintf(txt + strlen(txt), "DCL CONST[%d..%d], CONSTANT\n", start_const, end_const);
- else if (num_consts == 1)
- sprintf(txt + strlen(txt), "DCL CONST[%d], CONSTANT\n", start_const);
-
- if (num_temps > 1)
- sprintf(txt + strlen(txt), "DCL TEMP[%d..%d], CONSTANT\n", start_temp, end_temp);
- else if (num_temps > 1)
- sprintf(txt + strlen(txt), "DCL TEMP[%d], CONSTANT\n", start_temp);
-
- if (num_samplers > 1)
- sprintf(txt + strlen(txt), "DCL SAMP[%d..%d], CONSTANT\n", start_sampler, end_sampler);
- else if (num_samplers == 1)
- sprintf(txt + strlen(txt), "DCL SAMP[%d], CONSTANT\n", start_sampler);
-}
+ out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0);
-static void *
-combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_shaders,
- struct pipe_context *pipe,
- struct pipe_shader_state *shader)
-{
- char *combined_txt;
- int combined_len = MAX_PREAMBLE;
- int combined_tokens = 0;
- int i = 0;
- int current_shader = 0;
- int current_len;
+ if (num_consts >= 1) {
+ constant = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_const);
+ for (i = start_const; i < end_const; i++) {
+ constant[i] = ureg_DECL_constant(ureg, i);
+ }
- for (i = 0; i < num_shaders; ++i) {
- combined_len += strlen(shaders[i]->txt);
- combined_tokens += shaders[i]->num_tokens;
}
- /* add for the %s->TEMP[0] substitutions */
- combined_len += num_shaders * 7 /*TEMP[0]*/ + 4 /*"END\n"*/;
- combined_txt = (char*)malloc(combined_len);
- combined_txt[0] = '\0';
+ if (num_temps >= 1) {
+ temp = (struct ureg_dst *) malloc(sizeof(struct ureg_dst) * end_temp);
+ for (i = start_temp; i < end_temp; i++) {
+ temp[i] = ureg_DECL_temporary(ureg);
+ }
+ }
- create_preamble(combined_txt, shaders, num_shaders);
+ if (num_samplers >= 1) {
+ sampler = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_sampler);
+ for (i = start_sampler; i < end_sampler; i++) {
+ sampler[i] = ureg_DECL_sampler(ureg, i);
+ }
+ }
while (current_shader < num_shaders) {
- const char temp[] = "TEMP[0]";
- const char out[] = "OUT[0]";
- const char *subst = temp;
-
- current_len = strlen(combined_txt);
-
- /* if the last shader then output */
- if (current_shader + 1 == num_shaders)
- subst = out;
-
- snprintf(combined_txt + current_len,
- combined_len - current_len,
- shaders[current_shader]->txt,
- subst);
- ++current_shader;
+ if ((current_shader + 1) == num_shaders) {
+ shaders[current_shader]->func(ureg,
+ &out,
+ in,
+ sampler,
+ temp,
+ constant);
+ } else {
+ shaders[current_shader]->func(ureg,
+ &temp[0],
+ in,
+ sampler,
+ temp,
+ constant);
+ }
+ current_shader++;
}
+ ureg_END(ureg);
- current_len = strlen(combined_txt);
- snprintf(combined_txt + current_len,
- combined_len - current_len,
- "END\n");
+ shader->tokens = ureg_finalize(ureg);
+ if(!shader->tokens)
+ return NULL;
- debug_printf("Combined shader is : \n%s\n",
- combined_txt);
+ p = pipe->create_fs_state(pipe, shader);
+ ureg_destroy(ureg);
- shader->tokens = tokens_from_assembly(
- combined_txt, combined_tokens);
+ if (num_temps >= 1) {
+ for (i = start_temp; i < end_temp; i++) {
+ ureg_release_temporary(ureg, temp[i]);
+ }
+ }
- free(combined_txt);
+ if (temp)
+ free(temp);
+ if (constant)
+ free(constant);
+ if (sampler)
+ free(sampler);
- return pipe->create_fs_state(pipe, shader);
+ return p;
}
static void *
diff --git a/src/gallium/state_trackers/vega/st_inlines.h b/src/gallium/state_trackers/vega/st_inlines.h
index 610755e063..419151c3ae 100644
--- a/src/gallium/state_trackers/vega/st_inlines.h
+++ b/src/gallium/state_trackers/vega/st_inlines.h
@@ -38,7 +38,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
static INLINE struct pipe_transfer *
diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c
index 64207d97ba..426bf9bc62 100644
--- a/src/gallium/state_trackers/vega/vg_context.c
+++ b/src/gallium/state_trackers/vega/vg_context.c
@@ -34,7 +34,7 @@
#include "st_inlines.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "cso_cache/cso_context.h"
diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c
index 617c174eb6..a94dfb160c 100644
--- a/src/gallium/state_trackers/vega/vg_tracker.c
+++ b/src/gallium/state_trackers/vega/vg_tracker.c
@@ -29,7 +29,7 @@
#include "mask.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_screen.h"
#include "util/u_format.h"
#include "util/u_memory.h"
diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h
index 0bf3b0da82..a83841f6b7 100644
--- a/src/gallium/state_trackers/wgl/stw_device.h
+++ b/src/gallium/state_trackers/wgl/stw_device.h
@@ -30,7 +30,7 @@
#include "pipe/p_compiler.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
#include "util/u_handle_table.h"
#include "stw_icd.h"
#include "stw_pixelformat.h"
diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.h b/src/gallium/state_trackers/wgl/stw_framebuffer.h
index b80d168a7c..08cc4973bc 100644
--- a/src/gallium/state_trackers/wgl/stw_framebuffer.h
+++ b/src/gallium/state_trackers/wgl/stw_framebuffer.h
@@ -32,7 +32,7 @@
#include "main/mtypes.h"
-#include "pipe/p_thread.h"
+#include "os/os_thread.h"
struct pipe_surface;
struct stw_pixelformat_info;
diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c
index 2395d54975..221ce772af 100644
--- a/src/gallium/state_trackers/xorg/xorg_crtc.c
+++ b/src/gallium/state_trackers/xorg/xorg_crtc.c
@@ -49,7 +49,7 @@
#include <X11/extensions/dpms.h>
#endif
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_rect.h"
#ifdef HAVE_LIBKMS
diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c
index 59588f0ff7..7457fe1c6d 100644
--- a/src/gallium/state_trackers/xorg/xorg_dri2.c
+++ b/src/gallium/state_trackers/xorg/xorg_dri2.c
@@ -38,7 +38,7 @@
#include "dri2.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c
index a3c3993ab8..83b0d31e38 100644
--- a/src/gallium/state_trackers/xorg/xorg_renderer.c
+++ b/src/gallium/state_trackers/xorg/xorg_renderer.c
@@ -9,7 +9,7 @@
#include "util/u_memory.h"
#include "util/u_rect.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include <math.h>
diff --git a/src/gallium/state_trackers/xorg/xorg_tracker.h b/src/gallium/state_trackers/xorg/xorg_tracker.h
index a88b1d520d..58bb60a721 100644
--- a/src/gallium/state_trackers/xorg/xorg_tracker.h
+++ b/src/gallium/state_trackers/xorg/xorg_tracker.h
@@ -47,6 +47,8 @@
#endif
#include "pipe/p_screen.h"
+#include "util/u_inlines.h"
+#include "util/u_debug.h"
#include "state_tracker/drm_api.h"
#define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c
index a4a72b372d..07be1df87f 100644
--- a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c
+++ b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c
@@ -1,6 +1,7 @@
#include "i965_drm_winsys.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "i915_drm.h"
#include "intel_bufmgr.h"
diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c
index 8c8176e44a..118afc3395 100644
--- a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c
+++ b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include "state_tracker/drm_api.h"
diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c b/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c
index e8b58742ab..102faedfea 100644
--- a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c
+++ b/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c
@@ -1,7 +1,8 @@
#include "intel_drm_winsys.h"
#include "util/u_memory.h"
-#include "pipe/p_refcnt.h"
+#include "util/u_atomic.h"
+#include "util/u_inlines.h"
/**
* Because gem does not have fence's we have to create our own fences.
diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile
index 0937f68c34..7e95f79d03 100644
--- a/src/gallium/winsys/drm/nouveau/dri/Makefile
+++ b/src/gallium/winsys/drm/nouveau/dri/Makefile
@@ -6,9 +6,6 @@ LIBNAME = nouveau_dri.so
PIPE_DRIVERS = \
$(TOP)/src/gallium/state_trackers/dri/libdridrm.a \
$(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \
- $(TOP)/src/gallium/drivers/nv04/libnv04.a \
- $(TOP)/src/gallium/drivers/nv10/libnv10.a \
- $(TOP)/src/gallium/drivers/nv20/libnv20.a \
$(TOP)/src/gallium/drivers/nv30/libnv30.a \
$(TOP)/src/gallium/drivers/nv40/libnv40.a \
$(TOP)/src/gallium/drivers/nv50/libnv50.a \
diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
index 75cd1e2902..3f41e5d0ce 100644
--- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
+++ b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
@@ -81,15 +81,6 @@ nouveau_drm_create_screen(struct drm_api *api, int fd,
return NULL;
switch (dev->chipset & 0xf0) {
- case 0x00:
- init = nv04_screen_create;
- break;
- case 0x10:
- init = nv10_screen_create;
- break;
- case 0x20:
- init = nv20_screen_create;
- break;
case 0x30:
init = nv30_screen_create;
break;
@@ -160,15 +151,6 @@ nouveau_drm_create_context(struct drm_api *api, struct pipe_screen *pscreen)
int i;
switch (chipset & 0xf0) {
- case 0x00:
- init = nv04_create;
- break;
- case 0x10:
- init = nv10_create;
- break;
- case 0x20:
- init = nv20_create;
- break;
case 0x30:
init = nv30_create;
break;
diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h
index e61e0e0957..a32f2907b3 100644
--- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h
+++ b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h
@@ -4,7 +4,7 @@
#include "state_tracker/drm_api.h"
#include "state_tracker/dri1_api.h"
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "nouveau_dri.h"
diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile
index 8e812acc86..2c35260332 100644
--- a/src/gallium/winsys/drm/nouveau/egl/Makefile
+++ b/src/gallium/winsys/drm/nouveau/egl/Makefile
@@ -7,9 +7,6 @@ EGL_DRIVER_LIBS = -ldrm_nouveau
EGL_DRIVER_PIPES = \
$(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \
- $(TOP)/src/gallium/drivers/nv04/libnv04.a \
- $(TOP)/src/gallium/drivers/nv10/libnv10.a \
- $(TOP)/src/gallium/drivers/nv20/libnv20.a \
$(TOP)/src/gallium/drivers/nv30/libnv30.a \
$(TOP)/src/gallium/drivers/nv40/libnv40.a \
$(TOP)/src/gallium/drivers/nv50/libnv50.a \
diff --git a/src/gallium/winsys/drm/nouveau/xorg/Makefile b/src/gallium/winsys/drm/nouveau/xorg/Makefile
index f0d3b337e8..179b50230b 100644
--- a/src/gallium/winsys/drm/nouveau/xorg/Makefile
+++ b/src/gallium/winsys/drm/nouveau/xorg/Makefile
@@ -18,9 +18,6 @@ INCLUDES = \
LIBS = \
$(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \
$(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \
- $(TOP)/src/gallium/drivers/nv04/libnv04.a \
- $(TOP)/src/gallium/drivers/nv10/libnv10.a \
- $(TOP)/src/gallium/drivers/nv20/libnv20.a \
$(TOP)/src/gallium/drivers/nv30/libnv30.a \
$(TOP)/src/gallium/drivers/nv40/libnv40.a \
$(TOP)/src/gallium/drivers/nv50/libnv50.a \
diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h
index de71cb2f42..f1c8fc2a3b 100644
--- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h
+++ b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h
@@ -32,9 +32,9 @@
#include <stdio.h>
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipebuffer/pb_buffer.h"
diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h
index 864082b99b..4901080ca7 100644
--- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h
+++ b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h
@@ -30,7 +30,7 @@
#ifndef RADEON_WINSYS_H
#define RADEON_WINSYS_H
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
struct radeon_winsys_priv;
diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c b/src/gallium/winsys/drm/vmware/core/vmw_buffer.c
index b812fb59d3..eca174a6c5 100644
--- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c
+++ b/src/gallium/winsys/drm/vmware/core/vmw_buffer.c
@@ -41,7 +41,7 @@
#include "svga_cmd.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "pipebuffer/pb_buffer.h"
#include "pipebuffer/pb_bufmgr.h"
diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h b/src/gallium/winsys/drm/vmware/core/vmw_buffer.h
index 634bdcabd2..41fb4476da 100644
--- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h
+++ b/src/gallium/winsys/drm/vmware/core/vmw_buffer.h
@@ -27,7 +27,7 @@
#ifndef VMW_BUFFER_H_
#define VMW_BUFFER_H_
-
+#include <assert.h>
#include "pipe/p_compiler.h"
struct SVGAGuestPtr;
diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c
index d9abde3079..2939c10918 100644
--- a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c
+++ b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c
@@ -25,8 +25,9 @@
#include "pipe/p_compiler.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
+#include "util/u_format.h"
#include "vmw_screen.h"
#include "trace/tr_drm.h"
diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c
index d7d008859b..2b4e80f003 100644
--- a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c
+++ b/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c
@@ -36,7 +36,7 @@
#include "svga_cmd.h"
#include "svga3d_caps.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "pipebuffer/pb_buffer.h"
diff --git a/src/gallium/winsys/drm/vmware/core/vmw_surface.h b/src/gallium/winsys/drm/vmware/core/vmw_surface.h
index 340cc1532e..3d61595c28 100644
--- a/src/gallium/winsys/drm/vmware/core/vmw_surface.h
+++ b/src/gallium/winsys/drm/vmware/core/vmw_surface.h
@@ -36,8 +36,8 @@
#include "pipe/p_compiler.h"
-#include "pipe/p_atomic.h"
-#include "pipe/p_refcnt.h"
+#include "util/u_atomic.h"
+#include "util/u_inlines.h"
#define VMW_MAX_PRESENTS 3
@@ -45,7 +45,7 @@
struct vmw_svga_winsys_surface
{
- struct pipe_atomic validated;
+ int32_t validated; /* atomic */
struct pipe_reference refcnt;
struct vmw_winsys_screen *screen;
diff --git a/src/gallium/winsys/g3dvl/nouveau/Makefile b/src/gallium/winsys/g3dvl/nouveau/Makefile
index 3965bd949f..f07a7926d6 100644
--- a/src/gallium/winsys/g3dvl/nouveau/Makefile
+++ b/src/gallium/winsys/g3dvl/nouveau/Makefile
@@ -20,14 +20,11 @@ LDFLAGS += -L${DRMDIR}/lib \
-L${DRIDIR}/lib \
-L${GALLIUMDIR}/winsys/drm/nouveau/common \
-L${GALLIUMDIR}/auxiliary \
- -L${GALLIUMDIR}/drivers/nv04 \
- -L${GALLIUMDIR}/drivers/nv10 \
- -L${GALLIUMDIR}/drivers/nv20 \
-L${GALLIUMDIR}/drivers/nv30 \
-L${GALLIUMDIR}/drivers/nv40 \
-L${GALLIUMDIR}/drivers/nv50
-LIBS += -lnouveaudrm -ldriclient -ldrm_nouveau -ldrm -lnv04 -lnv10 -lnv20 -lnv30 -lnv40 -lnv50 -lgallium -lm
+LIBS += -lnouveaudrm -ldriclient -ldrm_nouveau -ldrm -lnv30 -lnv40 -lnv50 -lgallium -lm
#############################################
diff --git a/src/gallium/winsys/g3dvl/xlib/xsp_winsys.c b/src/gallium/winsys/g3dvl/xlib/xsp_winsys.c
index f15bcd37b5..048af62ed3 100644
--- a/src/gallium/winsys/g3dvl/xlib/xsp_winsys.c
+++ b/src/gallium/winsys/g3dvl/xlib/xsp_winsys.c
@@ -27,9 +27,9 @@
#include <vl_winsys.h>
#include <X11/Xutil.h>
-#include <pipe/internal/p_winsys_screen.h>
+#include <util/u_simple_screen.h>
#include <pipe/p_state.h>
-#include <pipe/p_inlines.h>
+#include <util/u_inlines.h>
#include <util/u_format.h>
#include <util/u_memory.h>
#include <util/u_math.h>
diff --git a/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c b/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c
index 7d076be3a3..33c83210eb 100644
--- a/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c
+++ b/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c
@@ -38,7 +38,7 @@
#include "pipe/p_format.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"
diff --git a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c
index 2ad794c3f0..36bf867f19 100644
--- a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c
+++ b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c
@@ -38,10 +38,10 @@
#include <windows.h>
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_format.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"
diff --git a/src/gallium/winsys/xlib/xlib_brw_context.c b/src/gallium/winsys/xlib/xlib_brw_context.c
index fc9addd09e..22bf41a46f 100644
--- a/src/gallium/winsys/xlib/xlib_brw_context.c
+++ b/src/gallium/winsys/xlib/xlib_brw_context.c
@@ -36,8 +36,8 @@
/* #include "glxheader.h" */
/* #include "xmesaP.h" */
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_simple_screen.h"
+#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "i965simple/brw_winsys.h"
diff --git a/src/gallium/winsys/xlib/xlib_cell.c b/src/gallium/winsys/xlib/xlib_cell.c
index 47ae0519a4..9520bac69d 100644
--- a/src/gallium/winsys/xlib/xlib_cell.c
+++ b/src/gallium/winsys/xlib/xlib_cell.c
@@ -41,10 +41,10 @@
#undef ASSERT
#undef Elements
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_format.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"
diff --git a/src/gallium/winsys/xlib/xlib_llvmpipe.c b/src/gallium/winsys/xlib/xlib_llvmpipe.c
index 2a434b5fd2..503addb55c 100644
--- a/src/gallium/winsys/xlib/xlib_llvmpipe.c
+++ b/src/gallium/winsys/xlib/xlib_llvmpipe.c
@@ -40,10 +40,10 @@
#undef ASSERT
#undef Elements
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_format.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"
diff --git a/src/gallium/winsys/xlib/xlib_softpipe.c b/src/gallium/winsys/xlib/xlib_softpipe.c
index bf78aca686..8ce1ea7936 100644
--- a/src/gallium/winsys/xlib/xlib_softpipe.c
+++ b/src/gallium/winsys/xlib/xlib_softpipe.c
@@ -38,10 +38,10 @@
#undef ASSERT
#undef Elements
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
#include "pipe/p_format.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"
diff --git a/src/glut/glx/SConscript b/src/glut/glx/SConscript
index 5234e6d58a..9363b5ca5c 100644
--- a/src/glut/glx/SConscript
+++ b/src/glut/glx/SConscript
@@ -105,5 +105,7 @@ env.InstallSharedLibrary(glut, version=(3, 7, 1))
if env['platform'] == 'windows':
glut = env.FindIxes(glut, 'LIBPREFIX', 'LIBSUFFIX')
+else:
+ glut = env.FindIxes(glut, 'SHLIBPREFIX', 'SHLIBSUFFIX')
Export('glut')
diff --git a/src/glut/glx/glut_fullscrn.c b/src/glut/glx/glut_fullscrn.c
index aab3b48763..78a7a6148b 100644
--- a/src/glut/glx/glut_fullscrn.c
+++ b/src/glut/glx/glut_fullscrn.c
@@ -14,7 +14,6 @@
#if !defined(_WIN32)
#include <X11/Xlib.h>
-#include <X11/Xatom.h>
#endif
/* SGI optimization introduced in IRIX 6.3 to avoid X server
diff --git a/src/glut/glx/glut_gamemode.c b/src/glut/glx/glut_gamemode.c
index 3ffeafee57..4a92099f3f 100644
--- a/src/glut/glx/glut_gamemode.c
+++ b/src/glut/glx/glut_gamemode.c
@@ -18,7 +18,6 @@
#ifndef _WIN32
#include <X11/Xlib.h>
-#include <X11/Xatom.h>
/* SGI optimization introduced in IRIX 6.3 to avoid X server
round trips for interning common X atoms. */
diff --git a/src/glut/glx/glut_init.c b/src/glut/glx/glut_init.c
index 78843e93bc..842aefc93c 100644
--- a/src/glut/glx/glut_init.c
+++ b/src/glut/glx/glut_init.c
@@ -15,7 +15,6 @@
#if !defined(_WIN32)
#include <X11/Xlib.h>
-#include <X11/Xatom.h>
#endif
/* SGI optimization introduced in IRIX 6.3 to avoid X server
diff --git a/src/glut/glx/glut_menu2.c b/src/glut/glx/glut_menu2.c
index 969b8120b4..3a66101bc4 100644
--- a/src/glut/glx/glut_menu2.c
+++ b/src/glut/glx/glut_menu2.c
@@ -25,7 +25,6 @@
#include <X11/Xlib.h>
#include "glutint.h"
-#include "layerutil.h"
/* CENTRY */
/* DEPRICATED, use glutMenuStatusFunc instead. */
diff --git a/src/glut/glx/glut_overlay.c b/src/glut/glx/glut_overlay.c
index 837bbc3cb2..db1abe005d 100644
--- a/src/glut/glx/glut_overlay.c
+++ b/src/glut/glx/glut_overlay.c
@@ -17,7 +17,6 @@
#if !defined(_WIN32)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <X11/Xatom.h> /* for XA_RGB_DEFAULT_MAP atom */
#if defined (__vms)
#include <Xmu/StdCmap.h> /* for XmuLookupStandardColormap */
#else
diff --git a/src/glut/glx/layerutil.c b/src/glut/glx/layerutil.c
index 26ba0b6029..36d43e59f0 100644
--- a/src/glut/glx/layerutil.c
+++ b/src/glut/glx/layerutil.c
@@ -13,7 +13,6 @@
/* SGI optimization introduced in IRIX 6.3 to avoid X server
round trips for interning common X atoms. */
-#include <X11/Xatom.h>
#if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)
#include <X11/SGIFastAtom.h>
#else
diff --git a/src/glx/x11/compsize.c b/src/glx/x11/compsize.c
index eca572feb3..5ba6dc919e 100644
--- a/src/glx/x11/compsize.c
+++ b/src/glx/x11/compsize.c
@@ -29,7 +29,6 @@
*/
#include <GL/gl.h>
-#include "indirect_size.h"
#include "glxclient.h"
/*
diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index 2228958144..7a5740a4d8 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -37,7 +37,6 @@
#include <X11/extensions/Xdamage.h>
#include "glapi.h"
#include "glxclient.h"
-#include "glcontextmodes.h"
#include "xf86dri.h"
#include <dlfcn.h>
#include <fcntl.h>
diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c
index e658644eca..0ff53c324f 100644
--- a/src/glx/x11/dri_glx.c
+++ b/src/glx/x11/dri_glx.c
@@ -38,7 +38,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xdamage.h>
#include "glxclient.h"
-#include "glcontextmodes.h"
#include "xf86dri.h"
#include "dri2.h"
#include "sarea.h"
diff --git a/src/glx/x11/drisw_glx.c b/src/glx/x11/drisw_glx.c
index 6a51d748af..eed9a8c472 100644
--- a/src/glx/x11/drisw_glx.c
+++ b/src/glx/x11/drisw_glx.c
@@ -25,7 +25,6 @@
#include <X11/Xlib.h>
#include "glxclient.h"
-#include "glcontextmodes.h"
#include <dlfcn.h>
#include "dri_common.h"
diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c
index 501500afc3..a0a02238b0 100644
--- a/src/glx/x11/glx_pbuffer.c
+++ b/src/glx/x11/glx_pbuffer.c
@@ -35,9 +35,7 @@
#include <X11/extensions/Xext.h>
#include <assert.h>
#include <string.h>
-#include "glapi.h"
#include "glxextensions.h"
-#include "glcontextmodes.h"
#define WARN_ONCE_GLX_1_3(a, b) { \
static int warned=1; \
diff --git a/src/glx/x11/glxcurrent.c b/src/glx/x11/glxcurrent.c
index 50de7d612b..c28360bdde 100644
--- a/src/glx/x11/glxcurrent.c
+++ b/src/glx/x11/glxcurrent.c
@@ -37,10 +37,6 @@
#include "glapi.h"
#include "indirect_init.h"
-#ifdef GLX_DIRECT_RENDERING
-#include "xf86dri.h"
-#endif
-
/*
** We setup some dummy structures here so that the API can be used
** even if no context is current.
diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c
index 09bb850319..1b4ab71682 100644
--- a/src/glx/x11/glxext.c
+++ b/src/glx/x11/glxext.c
@@ -41,7 +41,6 @@
#include "glxclient.h"
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
-#include "glapi.h"
#include "glxextensions.h"
#include "glcontextmodes.h"
diff --git a/src/glx/x11/glxextensions.c b/src/glx/x11/glxextensions.c
index 25a5c49293..56c69cbfcb 100644
--- a/src/glx/x11/glxextensions.c
+++ b/src/glx/x11/glxextensions.c
@@ -32,7 +32,6 @@
#include <X11/extensions/extutil.h>
#include <X11/extensions/Xext.h>
#include <string.h>
-#include "glapi.h"
#include "glxextensions.h"
diff --git a/src/mesa/drivers/directfb/idirectfbgl_mesa.c b/src/mesa/drivers/directfb/idirectfbgl_mesa.c
index 62a3269d17..85a6f03672 100644
--- a/src/mesa/drivers/directfb/idirectfbgl_mesa.c
+++ b/src/mesa/drivers/directfb/idirectfbgl_mesa.c
@@ -813,7 +813,7 @@ directfbgl_create_context( GLcontext *context,
{
struct dd_function_table functions;
- _mesa_initialize_framebuffer( framebuffer, visual );
+ _mesa_initialize_window_framebuffer( framebuffer, visual );
_mesa_init_driver_functions( &functions );
functions.GetString = dfbGetString;
diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c
index a273bd28ea..15e3b87097 100644
--- a/src/mesa/drivers/dri/i915/i915_fragprog.c
+++ b/src/mesa/drivers/dri/i915/i915_fragprog.c
@@ -1205,7 +1205,7 @@ i915IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
return GL_TRUE;
}
-static void
+static GLboolean
i915ProgramStringNotify(GLcontext * ctx,
GLenum target, struct gl_program *prog)
{
@@ -1223,7 +1223,10 @@ i915ProgramStringNotify(GLcontext * ctx,
}
}
- _tnl_program_string(ctx, target, prog);
+ (void) _tnl_program_string(ctx, target, prog);
+
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
void
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index e3b6fccc49..c78f7b38ae 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -111,9 +111,10 @@ static GLboolean brwIsProgramNative( GLcontext *ctx,
return GL_TRUE;
}
-static void brwProgramStringNotify( GLcontext *ctx,
- GLenum target,
- struct gl_program *prog )
+
+static GLboolean brwProgramStringNotify( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
{
struct brw_context *brw = brw_context(ctx);
@@ -150,6 +151,9 @@ static void brwProgramStringNotify( GLcontext *ctx,
*/
_tnl_program_string(ctx, target, prog);
}
+
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
void brwInitFragProgFuncs( struct dd_function_table *functions )
diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c
index 52cc04fee8..4f4eef85e8 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c
@@ -1438,7 +1438,7 @@ void brw_vs_emit(struct brw_vs_compile *c )
GLuint insn, if_depth = 0, loop_depth = 0;
GLuint end_offset = 0;
struct brw_instruction *end_inst, *last_inst;
- struct brw_instruction *if_inst[MAX_IF_DEPTH], *loop_inst[MAX_LOOP_DEPTH];
+ struct brw_instruction *if_inst[MAX_IF_DEPTH], *loop_inst[MAX_LOOP_DEPTH] = { 0 };
const struct brw_indirect stack_index = brw_indirect(0, 0);
GLuint index;
GLuint file;
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index e8cc202f88..c9ef1647a3 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -202,7 +202,7 @@ intelCreateBuffer(__DRIscreen * driScrnPriv,
if (!fb)
return GL_FALSE;
- _mesa_initialize_framebuffer(fb, mesaVis);
+ _mesa_initialize_window_framebuffer(fb, mesaVis);
if (mesaVis->redBits == 5)
rgbFormat = MESA_FORMAT_RGB565;
diff --git a/src/mesa/drivers/dri/nouveau/Makefile b/src/mesa/drivers/dri/nouveau/Makefile
new file mode 100644
index 0000000000..7c895a2e4b
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/Makefile
@@ -0,0 +1,59 @@
+# src/mesa/drivers/dri/nouveau/Makefile
+
+TOP = ../../../../..
+include $(TOP)/configs/current
+
+CFLAGS += $(shell pkg-config libdrm libdrm_nouveau --cflags)
+DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs)
+
+LIBNAME = nouveau_vieux_dri.so
+
+MINIGLX_SOURCES =
+
+DRIVER_SOURCES = \
+ nouveau_screen.c \
+ nouveau_context.c \
+ nouveau_fbo.c \
+ nouveau_driver.c \
+ nouveau_state.c \
+ nouveau_bufferobj.c \
+ nouveau_span.c \
+ nouveau_bo_state.c \
+ nouveau_texture.c \
+ nouveau_surface.c \
+ nv04_context.c \
+ nv04_screen.c \
+ nv04_render.c \
+ nv04_state_fb.c \
+ nv04_state_raster.c \
+ nv04_state_tex.c \
+ nv04_state_frag.c \
+ nv04_surface.c \
+ nv10_context.c \
+ nv10_screen.c \
+ nv10_render.c \
+ nv10_state_fb.c \
+ nv10_state_polygon.c \
+ nv10_state_raster.c \
+ nv10_state_tex.c \
+ nv10_state_frag.c \
+ nv10_state_tnl.c \
+ nv20_context.c \
+ nv20_screen.c \
+ nv20_render.c \
+ nv20_state_fb.c \
+ nv20_state_polygon.c \
+ nv20_state_raster.c \
+ nv20_state_tex.c \
+ nv20_state_tnl.c
+
+C_SOURCES = \
+ $(COMMON_SOURCES) \
+ $(DRIVER_SOURCES)
+
+ASM_SOURCES =
+
+
+include ../Makefile.template
+
+symlinks:
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c
new file mode 100644
index 0000000000..664632f407
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+
+static GLboolean
+nouveau_bo_marker_emit(GLcontext *ctx, struct nouveau_bo_marker *m,
+ uint32_t flags)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_pushbuf *push = chan->pushbuf;
+ uint32_t packet;
+
+ if (m->gr->bound == NOUVEAU_GROBJ_UNBOUND)
+ nouveau_grobj_autobind(m->gr);
+
+ if (MARK_RING(chan, 2, 2))
+ return GL_FALSE;
+
+ push->remaining -= 2;
+ packet = (m->gr->subc << 13) | (1 << 18) | m->mthd;
+
+ if (flags) {
+ if (nouveau_pushbuf_emit_reloc(chan, push->cur++, m->bo,
+ packet, 0, flags |
+ (m->flags & (NOUVEAU_BO_VRAM |
+ NOUVEAU_BO_GART |
+ NOUVEAU_BO_RDWR)),
+ 0, 0))
+ goto fail;
+ } else {
+ *(push->cur++) = packet;
+ }
+
+ if (nouveau_pushbuf_emit_reloc(chan, push->cur++, m->bo, m->data,
+ m->data2, flags | m->flags,
+ m->vor, m->tor))
+ goto fail;
+
+ return GL_TRUE;
+
+fail:
+ MARK_UNDO(chan);
+ return GL_FALSE;
+}
+
+static GLboolean
+nouveau_bo_context_grow(struct nouveau_bo_context *bctx)
+{
+ struct nouveau_bo_marker *marker = bctx->marker;
+ int allocated = bctx->allocated + 1;
+
+ marker = realloc(marker, allocated * sizeof(struct nouveau_bo_marker));
+ if (!marker)
+ return GL_FALSE;
+
+ bctx->marker = marker;
+ bctx->allocated = allocated;
+
+ return GL_TRUE;
+}
+
+GLboolean
+nouveau_bo_mark(struct nouveau_bo_context *bctx, struct nouveau_grobj *gr,
+ uint32_t mthd, struct nouveau_bo *bo,
+ uint32_t data, uint32_t data2, uint32_t vor, uint32_t tor,
+ uint32_t flags)
+{
+ struct nouveau_bo_state *s = &to_nouveau_context(bctx->ctx)->bo;
+ struct nouveau_bo_marker *m;
+
+ if (bctx->count == bctx->allocated) {
+ if (!nouveau_bo_context_grow(bctx))
+ goto fail;
+ }
+
+ m = &bctx->marker[bctx->count];
+
+ *m = (struct nouveau_bo_marker) {
+ .gr = gr,
+ .mthd = mthd,
+ .data = data,
+ .data2 = data2,
+ .vor = vor,
+ .tor = tor,
+ .flags = flags,
+ };
+ nouveau_bo_ref(bo, &m->bo);
+
+ s->count++;
+ bctx->count++;
+
+ if (!nouveau_bo_marker_emit(bctx->ctx, m, 0))
+ goto fail;
+
+ return GL_TRUE;
+
+fail:
+ nouveau_bo_context_reset(bctx);
+ return GL_FALSE;
+}
+
+void
+nouveau_bo_context_reset(struct nouveau_bo_context *bctx)
+{
+ struct nouveau_bo_state *s = &to_nouveau_context(bctx->ctx)->bo;
+ int i;
+
+ for (i = 0; i < bctx->count; i++)
+ nouveau_bo_ref(NULL, &bctx->marker[i].bo);
+
+ s->count -= bctx->count;
+ bctx->count = 0;
+}
+
+GLboolean
+nouveau_bo_state_emit(GLcontext *ctx)
+{
+ struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
+ int i, j;
+
+ for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++) {
+ struct nouveau_bo_context *bctx = &s->context[i];
+
+ for (j = 0; j < bctx->count; j++) {
+ if (!nouveau_bo_marker_emit(ctx, &bctx->marker[j],
+ NOUVEAU_BO_DUMMY))
+ return GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
+}
+
+void
+nouveau_bo_state_init(GLcontext *ctx)
+{
+ struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
+ int i;
+
+ for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++)
+ s->context[i].ctx = ctx;
+}
+
+void
+nouveau_bo_state_destroy(GLcontext *ctx)
+{
+ struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
+ int i, j;
+
+ for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++) {
+ struct nouveau_bo_context *bctx = &s->context[i];
+
+ for (j = 0; j < bctx->count; j++)
+ nouveau_bo_ref(NULL, &bctx->marker[j].bo);
+
+ if (bctx->marker)
+ free(bctx->marker);
+ }
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h
new file mode 100644
index 0000000000..da0a3a5c6f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_BO_STATE_H__
+#define __NOUVEAU_BO_STATE_H__
+
+enum {
+ NOUVEAU_BO_CONTEXT_FRAMEBUFFER = 0,
+ NOUVEAU_BO_CONTEXT_LMA_DEPTH,
+ NOUVEAU_BO_CONTEXT_SURFACE,
+ NOUVEAU_BO_CONTEXT_TEXTURE0,
+ NOUVEAU_BO_CONTEXT_TEXTURE1,
+ NOUVEAU_BO_CONTEXT_TEXTURE2,
+ NOUVEAU_BO_CONTEXT_TEXTURE3,
+ NOUVEAU_BO_CONTEXT_VERTEX,
+ NUM_NOUVEAU_BO_CONTEXT
+};
+
+struct nouveau_bo_marker {
+ struct nouveau_grobj *gr;
+ uint32_t mthd;
+
+ struct nouveau_bo *bo;
+ uint32_t data;
+ uint32_t data2;
+ uint32_t vor;
+ uint32_t tor;
+ uint32_t flags;
+};
+
+struct nouveau_bo_context {
+ GLcontext *ctx;
+
+ struct nouveau_bo_marker *marker;
+ int allocated;
+ int count;
+};
+
+struct nouveau_bo_state {
+ struct nouveau_bo_context context[NUM_NOUVEAU_BO_CONTEXT];
+ int count;
+};
+
+GLboolean
+nouveau_bo_mark(struct nouveau_bo_context *bctx, struct nouveau_grobj *gr,
+ uint32_t mthd, struct nouveau_bo *bo,
+ uint32_t data, uint32_t data2, uint32_t vor, uint32_t tor,
+ uint32_t flags);
+
+#define nouveau_bo_markl(bctx, gr, mthd, bo, data, flags) \
+ nouveau_bo_mark(bctx, gr, mthd, bo, data, 0, 0, 0, \
+ flags | NOUVEAU_BO_LOW);
+
+#define nouveau_bo_marko(bctx, gr, mthd, bo, flags) \
+ nouveau_bo_mark(bctx, gr, mthd, bo, 0, 0, \
+ context_chan(ctx)->vram->handle, \
+ context_chan(ctx)->gart->handle, \
+ flags | NOUVEAU_BO_OR);
+
+void
+nouveau_bo_context_reset(struct nouveau_bo_context *bctx);
+
+GLboolean
+nouveau_bo_state_emit(GLcontext *ctx);
+
+void
+nouveau_bo_state_init(GLcontext *ctx);
+
+void
+nouveau_bo_state_destroy(GLcontext *ctx);
+
+#define __context_bctx(ctx, i) \
+ ({ \
+ struct nouveau_context *nctx = to_nouveau_context(ctx); \
+ struct nouveau_bo_context *bctx = &nctx->bo.context[i]; \
+ nouveau_bo_context_reset(bctx); \
+ bctx; \
+ })
+#define context_bctx(ctx, s) \
+ __context_bctx(ctx, NOUVEAU_BO_CONTEXT_##s)
+#define context_bctx_i(ctx, s, i) \
+ __context_bctx(ctx, NOUVEAU_BO_CONTEXT_##s##0 + (i))
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
new file mode 100644
index 0000000000..1118b96de1
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_bufferobj.h"
+#include "nouveau_context.h"
+
+#include "main/bufferobj.h"
+
+static struct gl_buffer_object *
+nouveau_bufferobj_new(GLcontext *ctx, GLuint buffer, GLenum target)
+{
+ struct nouveau_bufferobj *nbo;
+
+ nbo = CALLOC_STRUCT(nouveau_bufferobj);
+ if (!nbo)
+ return NULL;
+
+ _mesa_initialize_buffer_object(&nbo->base, buffer, target);
+
+ return &nbo->base;
+}
+
+static void
+nouveau_bufferobj_del(GLcontext *ctx, struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+
+ nouveau_bo_ref(NULL, &nbo->bo);
+ FREE(nbo);
+}
+
+static GLboolean
+nouveau_bufferobj_data(GLcontext *ctx, GLenum target, GLsizeiptrARB size,
+ const GLvoid *data, GLenum usage,
+ struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+ int ret;
+
+ obj->Size = size;
+ obj->Usage = usage;
+
+ nouveau_bo_ref(NULL, &nbo->bo);
+ ret = nouveau_bo_new(context_dev(ctx),
+ NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
+ size, &nbo->bo);
+ assert(!ret);
+
+ if (data) {
+ nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR);
+ _mesa_memcpy(nbo->bo->map, data, size);
+ nouveau_bo_unmap(nbo->bo);
+ }
+
+ return GL_TRUE;
+}
+
+static void
+nouveau_bufferobj_subdata(GLcontext *ctx, GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, const GLvoid *data,
+ struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+
+ nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR);
+ _mesa_memcpy(nbo->bo->map + offset, data, size);
+ nouveau_bo_unmap(nbo->bo);
+}
+
+static void
+nouveau_bufferobj_get_subdata(GLcontext *ctx, GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, GLvoid *data,
+ struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+
+ nouveau_bo_map(nbo->bo, NOUVEAU_BO_RD);
+ _mesa_memcpy(data, nbo->bo->map + offset, size);
+ nouveau_bo_unmap(nbo->bo);
+}
+
+static void *
+nouveau_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access,
+ struct gl_buffer_object *obj)
+{
+ return ctx->Driver.MapBufferRange(ctx, target, 0, obj->Size, access,
+ obj);
+}
+
+static void *
+nouveau_bufferobj_map_range(GLcontext *ctx, GLenum target, GLintptr offset,
+ GLsizeiptr length, GLenum access,
+ struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+ uint32_t flags = 0;
+
+ assert(!obj->Pointer);
+
+ if (!nbo->bo)
+ return NULL;
+
+ if (access == GL_READ_ONLY_ARB ||
+ access == GL_READ_WRITE_ARB)
+ flags |= NOUVEAU_BO_RD;
+ if (access == GL_WRITE_ONLY_ARB ||
+ access == GL_READ_WRITE_ARB)
+ flags |= NOUVEAU_BO_WR;
+
+ nouveau_bo_map_range(nbo->bo, offset, length, flags);
+
+ obj->Pointer = nbo->bo->map;
+ obj->Offset = offset;
+ obj->Length = length;
+ obj->AccessFlags = access;
+
+ return obj->Pointer;
+}
+
+static GLboolean
+nouveau_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+
+ assert(obj->Pointer);
+
+ nouveau_bo_unmap(nbo->bo);
+
+ obj->Pointer = NULL;
+ obj->Offset = 0;
+ obj->Length = 0;
+ obj->AccessFlags = 0;
+
+ return GL_TRUE;
+}
+
+void
+nouveau_bufferobj_functions_init(struct dd_function_table *functions)
+{
+ functions->NewBufferObject = nouveau_bufferobj_new;
+ functions->DeleteBuffer = nouveau_bufferobj_del;
+ functions->BufferData = nouveau_bufferobj_data;
+ functions->BufferSubData = nouveau_bufferobj_subdata;
+ functions->GetBufferSubData = nouveau_bufferobj_get_subdata;
+ functions->MapBuffer = nouveau_bufferobj_map;
+ functions->MapBufferRange = nouveau_bufferobj_map_range;
+ functions->UnmapBuffer = nouveau_bufferobj_unmap;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h
new file mode 100644
index 0000000000..acfc4cb9a9
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_BUFFEROBJ_H__
+#define __NOUVEAU_BUFFEROBJ_H__
+
+struct nouveau_bufferobj {
+ struct gl_buffer_object base;
+ struct nouveau_bo *bo;
+};
+#define to_nouveau_bufferobj(x) ((struct nouveau_bufferobj *)(x))
+
+void
+nouveau_bufferobj_functions_init(struct dd_function_table *functions);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c
new file mode 100644
index 0000000000..b87b8dbdd0
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_bufferobj.h"
+#include "nouveau_fbo.h"
+
+#include "main/dd.h"
+#include "main/framebuffer.h"
+#include "main/light.h"
+#include "main/state.h"
+#include "drivers/common/meta.h"
+#include "drivers/common/driverfuncs.h"
+#include "swrast/swrast.h"
+#include "vbo/vbo.h"
+#include "tnl/tnl.h"
+
+#define need_GL_EXT_framebuffer_object
+#define need_GL_EXT_fog_coord
+
+#include "main/remap_helper.h"
+
+static const struct dri_extension nouveau_extensions[] = {
+ { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions },
+ { "GL_ARB_multitexture", NULL },
+ { "GL_EXT_texture_lod_bias", NULL },
+ { "GL_SGIS_generate_mipmap", NULL },
+ { "GL_ARB_texture_env_combine", NULL },
+ { "GL_ARB_texture_env_dot3", NULL },
+ { "GL_ARB_texture_env_add", NULL },
+ { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
+ { NULL, NULL }
+};
+
+GLboolean
+nouveau_context_create(const __GLcontextModes *visual, __DRIcontext *dri_ctx,
+ void *share_ctx)
+{
+ __DRIscreen *dri_screen = dri_ctx->driScreenPriv;
+ struct nouveau_screen *screen = dri_screen->private;
+ struct nouveau_context *nctx;
+ GLcontext *ctx;
+
+ ctx = screen->driver->context_create(screen, visual, share_ctx);
+ if (!ctx)
+ return GL_FALSE;
+
+ nctx = to_nouveau_context(ctx);
+ nctx->dri_context = dri_ctx;
+ dri_ctx->driverPrivate = ctx;
+
+ return GL_TRUE;
+}
+
+GLboolean
+nouveau_context_init(GLcontext *ctx, struct nouveau_screen *screen,
+ const GLvisual *visual, GLcontext *share_ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct dd_function_table functions;
+
+ nctx->screen = screen;
+ nctx->fallback = HWTNL;
+
+ /* Initialize the function pointers */
+ _mesa_init_driver_functions(&functions);
+ nouveau_driver_functions_init(&functions);
+ nouveau_bufferobj_functions_init(&functions);
+ nouveau_texture_functions_init(&functions);
+ nouveau_fbo_functions_init(&functions);
+
+ /* Initialize the mesa context */
+ _mesa_initialize_context(ctx, visual, share_ctx, &functions, NULL);
+
+ nouveau_state_init(ctx);
+ nouveau_bo_state_init(ctx);
+ _mesa_meta_init(ctx);
+ _swrast_CreateContext(ctx);
+ _vbo_CreateContext(ctx);
+ _tnl_CreateContext(ctx);
+ nouveau_span_functions_init(ctx);
+ _mesa_allow_light_in_model(ctx, GL_FALSE);
+
+ /* Enable any supported extensions */
+ driInitExtensions(ctx, nouveau_extensions, GL_TRUE);
+
+ return GL_TRUE;
+}
+
+void
+nouveau_context_destroy(__DRIcontext *dri_ctx)
+{
+ struct nouveau_context *nctx = dri_ctx->driverPrivate;
+ GLcontext *ctx = &nctx->base;
+
+ if (nctx->screen->context == nctx)
+ nctx->screen->context = NULL;
+
+ _tnl_DestroyContext(ctx);
+ _vbo_DestroyContext(ctx);
+ _swrast_DestroyContext(ctx);
+ _mesa_meta_free(ctx);
+ nouveau_bo_state_destroy(ctx);
+ context_drv(ctx)->context_destroy(ctx);
+}
+
+static void
+nouveau_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
+ unsigned int *stamp)
+{
+ struct nouveau_context *nctx = context->driverPrivate;
+ GLcontext *ctx = &nctx->base;
+ __DRIscreen *screen = context->driScreenPriv;
+ struct gl_framebuffer *fb = drawable->driverPrivate;
+ unsigned int attachments[10];
+ __DRIbuffer *buffers = NULL;
+ int i = 0, count, ret;
+
+ attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
+ if (fb->Visual.doubleBufferMode)
+ attachments[i++] = __DRI_BUFFER_BACK_LEFT;
+ if (fb->Visual.haveDepthBuffer && fb->Visual.haveStencilBuffer)
+ attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
+ else if (fb->Visual.haveDepthBuffer)
+ attachments[i++] = __DRI_BUFFER_DEPTH;
+ else if (fb->Visual.haveStencilBuffer)
+ attachments[i++] = __DRI_BUFFER_STENCIL;
+
+ buffers = (*screen->dri2.loader->getBuffers)(drawable,
+ &drawable->w, &drawable->h,
+ attachments, i, &count,
+ drawable->loaderPrivate);
+ if (buffers == NULL)
+ return;
+
+ for (i = 0; i < count; i++) {
+ struct gl_renderbuffer *rb;
+ struct nouveau_surface *s;
+ uint32_t old_handle;
+ int index;
+
+ switch (buffers[i].attachment) {
+ case __DRI_BUFFER_FRONT_LEFT:
+ case __DRI_BUFFER_FAKE_FRONT_LEFT:
+ index = BUFFER_FRONT_LEFT;
+ break;
+ case __DRI_BUFFER_BACK_LEFT:
+ index = BUFFER_BACK_LEFT;
+ break;
+ case __DRI_BUFFER_DEPTH:
+ case __DRI_BUFFER_DEPTH_STENCIL:
+ index = BUFFER_DEPTH;
+ break;
+ case __DRI_BUFFER_STENCIL:
+ index = BUFFER_STENCIL;
+ break;
+ default:
+ assert(0);
+ }
+
+ rb = fb->Attachment[index].Renderbuffer;
+ s = &to_nouveau_renderbuffer(rb)->surface;
+
+ s->width = drawable->w;
+ s->height = drawable->h;
+ s->pitch = buffers[i].pitch;
+ s->cpp = buffers[i].cpp;
+
+ /* Don't bother to reopen the bo if it happens to be
+ * the same. */
+ if (s->bo) {
+ ret = nouveau_bo_handle_get(s->bo, &old_handle);
+ assert(!ret);
+ }
+
+ if (!s->bo || old_handle != buffers[i].name) {
+ nouveau_bo_ref(NULL, &s->bo);
+ ret = nouveau_bo_handle_ref(context_dev(ctx),
+ buffers[i].name, &s->bo);
+ assert(!ret);
+
+ context_dirty(ctx, FRAMEBUFFER);
+ }
+ }
+
+ _mesa_resize_framebuffer(ctx, fb, drawable->w, drawable->h);
+}
+
+GLboolean
+nouveau_context_make_current(__DRIcontext *dri_ctx, __DRIdrawable *dri_draw,
+ __DRIdrawable *dri_read)
+{
+ if (dri_ctx) {
+ struct nouveau_context *nctx = dri_ctx->driverPrivate;
+ GLcontext *ctx = &nctx->base;
+
+ if (nctx->screen->context != nctx) {
+ nctx->screen->context = nctx;
+ BITSET_ONES(nctx->dirty);
+ }
+
+ /* Ask the X server for new renderbuffers. */
+ nouveau_update_renderbuffers(dri_ctx, dri_draw,
+ &nctx->drawable.d_stamp);
+ if (dri_draw != dri_read)
+ nouveau_update_renderbuffers(dri_ctx, dri_read,
+ &nctx->drawable.r_stamp);
+
+ /* Pass it down to mesa. */
+ _mesa_make_current(ctx, dri_draw->driverPrivate,
+ dri_read->driverPrivate);
+ _mesa_update_state(ctx);
+
+ FIRE_RING(context_chan(ctx));
+
+ } else {
+ _mesa_make_current(NULL, NULL, NULL);
+ }
+
+ return GL_TRUE;
+}
+
+GLboolean
+nouveau_context_unbind(__DRIcontext *dri_ctx)
+{
+ return GL_TRUE;
+}
+
+void
+nouveau_fallback(GLcontext *ctx, enum nouveau_fallback mode)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+
+ nctx->fallback = MAX2(HWTNL, mode);
+
+ if (mode < SWRAST)
+ nouveau_state_emit(ctx);
+ else
+ FIRE_RING(context_chan(ctx));
+}
+
+void
+nouveau_validate_framebuffer(GLcontext *ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+
+ /* Someone's planning to draw something really soon. */
+ nctx->drawable.dirty = GL_TRUE;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.h b/src/mesa/drivers/dri/nouveau/nouveau_context.h
new file mode 100644
index 0000000000..9812963e1a
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_CONTEXT_H__
+#define __NOUVEAU_CONTEXT_H__
+
+#include "nouveau_screen.h"
+#include "nouveau_state.h"
+#include "nouveau_bo_state.h"
+#include "nouveau_render.h"
+
+#include "main/bitset.h"
+
+enum nouveau_fallback {
+ HWTNL = 0,
+ SWTNL,
+ SWRAST,
+};
+
+struct nouveau_drawable_state {
+ GLboolean dirty;
+ unsigned int d_stamp;
+ unsigned int r_stamp;
+};
+
+struct nouveau_context {
+ GLcontext base;
+ __DRIcontext *dri_context;
+ struct nouveau_screen *screen;
+
+ BITSET_DECLARE(dirty, MAX_NOUVEAU_STATE);
+ enum nouveau_fallback fallback;
+
+ struct nouveau_bo_state bo;
+ struct nouveau_render_state render;
+ struct nouveau_drawable_state drawable;
+};
+
+#define to_nouveau_context(ctx) ((struct nouveau_context *)(ctx))
+
+#define context_dev(ctx) \
+ (to_nouveau_context(ctx)->screen->device)
+#define context_chipset(ctx) \
+ (context_dev(ctx)->chipset)
+#define context_chan(ctx) \
+ (to_nouveau_context(ctx)->screen->chan)
+#define context_eng3d(ctx) \
+ (to_nouveau_context(ctx)->screen->eng3d)
+#define context_drv(ctx) \
+ (to_nouveau_context(ctx)->screen->driver)
+#define context_dirty(ctx, s) \
+ BITSET_SET(to_nouveau_context(ctx)->dirty, NOUVEAU_STATE_##s)
+#define context_dirty_i(ctx, s, i) \
+ BITSET_SET(to_nouveau_context(ctx)->dirty, NOUVEAU_STATE_##s##0 + i)
+
+GLboolean
+nouveau_context_create(const __GLcontextModes *visual, __DRIcontext *dri_ctx,
+ void *share_ctx);
+
+GLboolean
+nouveau_context_init(GLcontext *ctx, struct nouveau_screen *screen,
+ const GLvisual *visual, GLcontext *share_ctx);
+
+void
+nouveau_context_destroy(__DRIcontext *dri_ctx);
+
+GLboolean
+nouveau_context_make_current(__DRIcontext *dri_ctx,
+ __DRIdrawable *ddraw,
+ __DRIdrawable *rdraw);
+
+GLboolean
+nouveau_context_unbind(__DRIcontext *dri_ctx);
+
+void
+nouveau_fallback(GLcontext *ctx, enum nouveau_fallback mode);
+
+void
+nouveau_validate_framebuffer(GLcontext *ctx);
+
+#endif
+
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.c b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
new file mode 100644
index 0000000000..bf0e20ca81
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_util.h"
+
+#include "drivers/common/meta.h"
+
+static const GLubyte *
+nouveau_get_string(GLcontext *ctx, GLenum name)
+{
+ static char buffer[128];
+ char hardware_name[32];
+
+ switch (name) {
+ case GL_VENDOR:
+ return (GLubyte *)"Nouveau";
+
+ case GL_RENDERER:
+ sprintf(hardware_name, "nv%02X", context_chipset(ctx));
+ driGetRendererString(buffer, hardware_name, DRIVER_DATE, 0);
+
+ return (GLubyte *)buffer;
+ default:
+ return NULL;
+ }
+}
+
+static void
+nouveau_flush(GLcontext *ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+
+ FIRE_RING(chan);
+
+ if (ctx->DrawBuffer->Name == 0 &&
+ ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
+ __DRIscreen *screen = nctx->screen->dri_screen;
+ __DRIdri2LoaderExtension *dri2 = screen->dri2.loader;
+ __DRIdrawable *drawable = nctx->dri_context->driDrawablePriv;
+
+ dri2->flushFrontBuffer(drawable, drawable->loaderPrivate);
+ }
+
+ nctx->drawable.dirty = GL_FALSE;
+}
+
+static void
+nouveau_finish(GLcontext *ctx)
+{
+ nouveau_flush(ctx);
+}
+
+void
+nouveau_clear(GLcontext *ctx, GLbitfield buffers)
+{
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ int x, y, w, h;
+ int i, buf;
+
+ nouveau_validate_framebuffer(ctx);
+ get_scissors(fb, &x, &y, &w, &h);
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct nouveau_surface *s;
+ unsigned mask, value;
+
+ buf = buffers & (1 << i);
+ if (!buf)
+ continue;
+
+ s = &to_nouveau_renderbuffer(
+ fb->Attachment[i].Renderbuffer->Wrapped)->surface;
+
+ if (buf & BUFFER_BITS_COLOR) {
+ mask = pack_rgba_i(s->format, ctx->Color.ColorMask[0]);
+ value = pack_rgba_f(s->format, ctx->Color.ClearColor);
+
+ if (mask)
+ context_drv(ctx)->surface_fill(
+ ctx, s, mask, value, x, y, w, h);
+
+ buffers &= ~buf;
+
+ } else if (buf & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
+ mask = pack_zs_i(s->format,
+ (buffers & BUFFER_BIT_DEPTH &&
+ ctx->Depth.Mask) ? ~0 : 0,
+ (buffers & BUFFER_BIT_STENCIL &&
+ ctx->Stencil.WriteMask[0]) ? ~0 : 0);
+ value = pack_zs_f(s->format,
+ ctx->Depth.Clear,
+ ctx->Stencil.Clear);
+
+ if (mask)
+ context_drv(ctx)->surface_fill(
+ ctx, s, mask, value, x, y, w, h);
+
+ buffers &= ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
+ }
+ }
+
+ if (buffers)
+ _mesa_meta_Clear(ctx, buffers);
+}
+
+void
+nouveau_driver_functions_init(struct dd_function_table *functions)
+{
+ functions->GetString = nouveau_get_string;
+ functions->Flush = nouveau_flush;
+ functions->Finish = nouveau_finish;
+ functions->Clear = nouveau_clear;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.h b/src/mesa/drivers/dri/nouveau/nouveau_driver.h
new file mode 100644
index 0000000000..3b4d332d74
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_DRIVER_H__
+#define __NOUVEAU_DRIVER_H__
+
+#include "main/imports.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "main/formats.h"
+#include "utils.h"
+#include "dri_util.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#include "nouveau_device.h"
+#include "nouveau_pushbuf.h"
+#include "nouveau_grobj.h"
+#include "nouveau_channel.h"
+#include "nouveau_bo.h"
+#include "nouveau_notifier.h"
+#include "nouveau_screen.h"
+#include "nouveau_state.h"
+#include "nouveau_surface.h"
+
+#define DRIVER_DATE "20091015"
+#define DRIVER_AUTHOR "Nouveau"
+
+struct nouveau_driver {
+ void (*screen_destroy)(struct nouveau_screen *screen);
+
+ GLcontext *(*context_create)(struct nouveau_screen *screen,
+ const GLvisual *visual,
+ GLcontext *share_ctx);
+ void (*context_destroy)(GLcontext *ctx);
+
+ void (*surface_copy)(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ struct nouveau_surface *src,
+ int dx, int dy, int sx, int sy, int w, int h);
+ void (*surface_fill)(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ unsigned mask, unsigned value,
+ int dx, int dy, int w, int h);
+
+ nouveau_state_func *emit;
+ int num_emit;
+};
+
+#define nouveau_error(format, ...) \
+ _mesa_fprintf(stderr, "%s: " format, __func__, ## __VA_ARGS__)
+
+void
+nouveau_clear(GLcontext *ctx, GLbitfield buffers);
+
+void
+nouveau_span_functions_init(GLcontext *ctx);
+
+void
+nouveau_driver_functions_init(struct dd_function_table *functions);
+
+void
+nouveau_texture_functions_init(struct dd_function_table *functions);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fbo.c b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c
new file mode 100644
index 0000000000..91eade8d63
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c
@@ -0,0 +1,277 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_fbo.h"
+#include "nouveau_context.h"
+#include "nouveau_texture.h"
+
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+#include "main/fbobject.h"
+
+static GLboolean
+set_renderbuffer_format(struct gl_renderbuffer *rb, GLenum internalFormat)
+{
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
+
+ rb->InternalFormat = internalFormat;
+
+ switch (internalFormat) {
+ case GL_RGB:
+ case GL_RGB8:
+ rb->_BaseFormat = GL_RGB;
+ rb->Format = MESA_FORMAT_XRGB8888;
+ rb->DataType = GL_UNSIGNED_BYTE;
+ s->cpp = 4;
+ break;
+ case GL_RGBA:
+ case GL_RGBA8:
+ rb->_BaseFormat = GL_RGBA;
+ rb->Format = MESA_FORMAT_ARGB8888;
+ rb->DataType = GL_UNSIGNED_BYTE;
+ s->cpp = 4;
+ break;
+ case GL_RGB5:
+ rb->_BaseFormat = GL_RGB;
+ rb->Format = MESA_FORMAT_RGB565;
+ rb->DataType = GL_UNSIGNED_BYTE;
+ s->cpp = 2;
+ break;
+ case GL_DEPTH_COMPONENT16:
+ rb->_BaseFormat = GL_DEPTH_COMPONENT;
+ rb->Format = MESA_FORMAT_Z16;
+ rb->DataType = GL_UNSIGNED_SHORT;
+ s->cpp = 2;
+ break;
+ case GL_DEPTH_COMPONENT24:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ rb->_BaseFormat = GL_DEPTH_COMPONENT;
+ rb->Format = MESA_FORMAT_Z24_S8;
+ rb->DataType = GL_UNSIGNED_INT;
+ s->cpp = 4;
+ break;
+ default:
+ return GL_FALSE;
+ }
+
+ s->format = rb->Format;
+
+ return GL_TRUE;
+}
+
+static GLboolean
+nouveau_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width, GLuint height)
+{
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
+
+ if (!set_renderbuffer_format(rb, internalFormat))
+ return GL_FALSE;
+
+ rb->Width = width;
+ rb->Height = height;
+
+ nouveau_surface_alloc(ctx, s, TILED, NOUVEAU_BO_VRAM | NOUVEAU_BO_MAP,
+ rb->Format, width, height);
+
+ context_dirty(ctx, FRAMEBUFFER);
+ return GL_TRUE;
+}
+
+static void
+nouveau_renderbuffer_del(struct gl_renderbuffer *rb)
+{
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
+
+ nouveau_surface_ref(NULL, s);
+ FREE(rb);
+}
+
+static struct gl_renderbuffer *
+nouveau_renderbuffer_new(GLcontext *ctx, GLuint name)
+{
+ struct gl_renderbuffer *rb;
+
+ rb = (struct gl_renderbuffer *)
+ CALLOC_STRUCT(nouveau_renderbuffer);
+ if (!rb)
+ return NULL;
+
+ _mesa_init_renderbuffer(rb, name);
+
+ rb->AllocStorage = nouveau_renderbuffer_storage;
+ rb->Delete = nouveau_renderbuffer_del;
+
+ return rb;
+}
+
+static GLboolean
+nouveau_renderbuffer_dri_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width, GLuint height)
+{
+ if (!set_renderbuffer_format(rb, internalFormat))
+ return GL_FALSE;
+
+ rb->Width = width;
+ rb->Height = height;
+
+ context_dirty(ctx, FRAMEBUFFER);
+ return GL_TRUE;
+}
+
+struct gl_renderbuffer *
+nouveau_renderbuffer_dri_new(GLenum format, __DRIdrawable *drawable)
+{
+ struct gl_renderbuffer *rb;
+
+ rb = nouveau_renderbuffer_new(NULL, 0);
+ if (!rb)
+ return NULL;
+
+ rb->AllocStorage = nouveau_renderbuffer_dri_storage;
+
+ if (!set_renderbuffer_format(rb, format)) {
+ nouveau_renderbuffer_del(rb);
+ return NULL;
+ }
+
+ return rb;
+}
+
+static struct gl_framebuffer *
+nouveau_framebuffer_new(GLcontext *ctx, GLuint name)
+{
+ struct nouveau_framebuffer *nfb;
+
+ nfb = CALLOC_STRUCT(nouveau_framebuffer);
+ if (!nfb)
+ return NULL;
+
+ _mesa_initialize_user_framebuffer(&nfb->base, name);
+
+ return &nfb->base;
+}
+
+struct gl_framebuffer *
+nouveau_framebuffer_dri_new(const GLvisual *visual)
+{
+ struct nouveau_framebuffer *nfb;
+
+ nfb = CALLOC_STRUCT(nouveau_framebuffer);
+ if (!nfb)
+ return NULL;
+
+ _mesa_initialize_window_framebuffer(&nfb->base, visual);
+
+ return &nfb->base;
+}
+
+static void
+nouveau_bind_framebuffer(GLcontext *ctx, GLenum target,
+ struct gl_framebuffer *dfb,
+ struct gl_framebuffer *rfb)
+{
+ context_dirty(ctx, FRAMEBUFFER);
+}
+
+static void
+nouveau_framebuffer_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
+ GLenum attachment, struct gl_renderbuffer *rb)
+{
+ _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
+
+ context_dirty(ctx, FRAMEBUFFER);
+}
+
+static GLenum
+get_tex_format(struct gl_texture_image *ti)
+{
+ switch (ti->TexFormat) {
+ case MESA_FORMAT_ARGB8888:
+ return GL_RGBA8;
+ case MESA_FORMAT_RGB565:
+ return GL_RGB5;
+ default:
+ assert(0);
+ }
+}
+
+static void
+nouveau_render_texture(GLcontext *ctx, struct gl_framebuffer *fb,
+ struct gl_renderbuffer_attachment *att)
+{
+ struct gl_renderbuffer *rb = att->Renderbuffer;
+ struct gl_texture_image *ti =
+ att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+ int ret;
+
+ /* Allocate a renderbuffer object for the texture if we
+ * haven't already done so. */
+ if (!rb) {
+ rb = nouveau_renderbuffer_new(ctx, 0);
+ assert(rb);
+
+ rb->AllocStorage = NULL;
+ _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
+ }
+
+ /* Update the renderbuffer fields from the texture. */
+ ret = set_renderbuffer_format(rb, get_tex_format(ti));
+ assert(ret);
+
+ rb->Width = ti->Width;
+ rb->Height = ti->Height;
+ nouveau_surface_ref(&to_nouveau_teximage(ti)->surface,
+ &to_nouveau_renderbuffer(rb)->surface);
+
+ context_dirty(ctx, FRAMEBUFFER);
+}
+
+static void
+nouveau_finish_render_texture(GLcontext *ctx,
+ struct gl_renderbuffer_attachment *att)
+{
+ struct nouveau_renderbuffer *nrb
+ = to_nouveau_renderbuffer(att->Renderbuffer);
+
+ texture_dirty(att->Texture);
+ nouveau_surface_ref(NULL, &nrb->surface);
+}
+
+void
+nouveau_fbo_functions_init(struct dd_function_table *functions)
+{
+ functions->NewFramebuffer = nouveau_framebuffer_new;
+ functions->NewRenderbuffer = nouveau_renderbuffer_new;
+ functions->BindFramebuffer = nouveau_bind_framebuffer;
+ functions->FramebufferRenderbuffer = nouveau_framebuffer_renderbuffer;
+ functions->RenderTexture = nouveau_render_texture;
+ functions->FinishRenderTexture = nouveau_finish_render_texture;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fbo.h b/src/mesa/drivers/dri/nouveau/nouveau_fbo.h
new file mode 100644
index 0000000000..5ae984bbff
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_fbo.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_FBO_H__
+#define __NOUVEAU_FBO_H__
+
+struct nouveau_framebuffer {
+ struct gl_framebuffer base;
+ struct nouveau_bo *lma_bo;
+};
+#define to_nouveau_framebuffer(x) ((struct nouveau_framebuffer *)(x))
+
+struct nouveau_renderbuffer {
+ struct gl_renderbuffer base;
+ struct nouveau_surface surface;
+};
+#define to_nouveau_renderbuffer(x) ((struct nouveau_renderbuffer *)(x))
+
+struct gl_framebuffer *
+nouveau_framebuffer_dri_new(const GLvisual *visual);
+
+struct gl_renderbuffer *
+nouveau_renderbuffer_dri_new(GLenum format, __DRIdrawable *drawable);
+
+void
+nouveau_fbo_functions_init(struct dd_function_table *functions);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_gldefs.h b/src/mesa/drivers/dri/nouveau/nouveau_gldefs.h
new file mode 100644
index 0000000000..00007a9a35
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_gldefs.h
@@ -0,0 +1,263 @@
+/*
+ * Copyright (C) 2007-2010 The Nouveau Project.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_GLDEFS_H__
+#define __NOUVEAU_GLDEFS_H__
+
+static inline unsigned
+nvgl_blend_func(unsigned func)
+{
+ switch (func) {
+ case GL_ZERO:
+ return 0x0000;
+ case GL_ONE:
+ return 0x0001;
+ case GL_SRC_COLOR:
+ return 0x0300;
+ case GL_ONE_MINUS_SRC_COLOR:
+ return 0x0301;
+ case GL_SRC_ALPHA:
+ return 0x0302;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ return 0x0303;
+ case GL_DST_ALPHA:
+ return 0x0304;
+ case GL_ONE_MINUS_DST_ALPHA:
+ return 0x0305;
+ case GL_DST_COLOR:
+ return 0x0306;
+ case GL_ONE_MINUS_DST_COLOR:
+ return 0x0307;
+ case GL_SRC_ALPHA_SATURATE:
+ return 0x0308;
+ case GL_CONSTANT_COLOR:
+ return 0x8001;
+ case GL_ONE_MINUS_CONSTANT_COLOR:
+ return 0x8002;
+ case GL_CONSTANT_ALPHA:
+ return 0x8003;
+ case GL_ONE_MINUS_CONSTANT_ALPHA:
+ return 0x8004;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_blend_eqn(unsigned eqn)
+{
+ switch (eqn) {
+ case GL_FUNC_ADD:
+ return 0x8006;
+ case GL_MIN:
+ return 0x8007;
+ case GL_MAX:
+ return 0x8008;
+ case GL_FUNC_SUBTRACT:
+ return 0x800a;
+ case GL_FUNC_REVERSE_SUBTRACT:
+ return 0x800b;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_logicop_func(unsigned func)
+{
+ switch (func) {
+ case GL_CLEAR:
+ return 0x1500;
+ case GL_NOR:
+ return 0x1508;
+ case GL_AND_INVERTED:
+ return 0x1504;
+ case GL_COPY_INVERTED:
+ return 0x150c;
+ case GL_AND_REVERSE:
+ return 0x1502;
+ case GL_INVERT:
+ return 0x150a;
+ case GL_XOR:
+ return 0x1506;
+ case GL_NAND:
+ return 0x150e;
+ case GL_AND:
+ return 0x1501;
+ case GL_EQUIV:
+ return 0x1509;
+ case GL_NOOP:
+ return 0x1505;
+ case GL_OR_INVERTED:
+ return 0x150d;
+ case GL_COPY:
+ return 0x1503;
+ case GL_OR_REVERSE:
+ return 0x150b;
+ case GL_OR:
+ return 0x1507;
+ case GL_SET:
+ return 0x150f;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_comparison_op(unsigned op)
+{
+ switch (op) {
+ case GL_NEVER:
+ return 0x0200;
+ case GL_LESS:
+ return 0x0201;
+ case GL_EQUAL:
+ return 0x0202;
+ case GL_LEQUAL:
+ return 0x0203;
+ case GL_GREATER:
+ return 0x0204;
+ case GL_NOTEQUAL:
+ return 0x0205;
+ case GL_GEQUAL:
+ return 0x0206;
+ case GL_ALWAYS:
+ return 0x0207;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_polygon_mode(unsigned mode)
+{
+ switch (mode) {
+ case GL_POINT:
+ return 0x1b00;
+ case GL_LINE:
+ return 0x1b01;
+ case GL_FILL:
+ return 0x1b02;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_stencil_op(unsigned op)
+{
+ switch (op) {
+ case GL_ZERO:
+ return 0x0000;
+ case GL_INVERT:
+ return 0x150a;
+ case GL_KEEP:
+ return 0x1e00;
+ case GL_REPLACE:
+ return 0x1e01;
+ case GL_INCR:
+ return 0x1e02;
+ case GL_DECR:
+ return 0x1e03;
+ case GL_INCR_WRAP_EXT:
+ return 0x8507;
+ case GL_DECR_WRAP_EXT:
+ return 0x8508;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_primitive(unsigned prim)
+{
+ switch (prim) {
+ case GL_POINTS:
+ return 0x0001;
+ case GL_LINES:
+ return 0x0002;
+ case GL_LINE_LOOP:
+ return 0x0003;
+ case GL_LINE_STRIP:
+ return 0x0004;
+ case GL_TRIANGLES:
+ return 0x0005;
+ case GL_TRIANGLE_STRIP:
+ return 0x0006;
+ case GL_TRIANGLE_FAN:
+ return 0x0007;
+ case GL_QUADS:
+ return 0x0008;
+ case GL_QUAD_STRIP:
+ return 0x0009;
+ case GL_POLYGON:
+ return 0x000a;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_wrap_mode(unsigned wrap)
+{
+ switch (wrap) {
+ case GL_REPEAT:
+ return 0x1;
+ case GL_MIRRORED_REPEAT:
+ return 0x2;
+ case GL_CLAMP_TO_EDGE:
+ return 0x3;
+ case GL_CLAMP_TO_BORDER:
+ return 0x4;
+ case GL_CLAMP:
+ return 0x5;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+nvgl_filter_mode(unsigned filter)
+{
+ switch (filter) {
+ case GL_NEAREST:
+ return 0x1;
+ case GL_LINEAR:
+ return 0x2;
+ case GL_NEAREST_MIPMAP_NEAREST:
+ return 0x3;
+ case GL_LINEAR_MIPMAP_NEAREST:
+ return 0x4;
+ case GL_NEAREST_MIPMAP_LINEAR:
+ return 0x5;
+ case GL_LINEAR_MIPMAP_LINEAR:
+ return 0x6;
+ default:
+ assert(0);
+ }
+}
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_render.h b/src/mesa/drivers/dri/nouveau/nouveau_render.h
new file mode 100644
index 0000000000..bff0ccfd76
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_render.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_RENDER_H__
+#define __NOUVEAU_RENDER_H__
+
+#include "vbo/vbo_context.h"
+
+struct nouveau_array_state;
+
+typedef void (*dispatch_t)(GLcontext *, unsigned int, int, unsigned int);
+typedef unsigned (*extract_u_t)(struct nouveau_array_state *a, int i, int j);
+typedef float (*extract_f_t)(struct nouveau_array_state *a, int i, int j);
+
+struct nouveau_attr_info {
+ int vbo_index;
+ int imm_method;
+ int imm_fields;
+
+ void (*emit)(GLcontext *, struct nouveau_array_state *, const void *);
+};
+
+struct nouveau_array_state {
+ int attr;
+ int stride, fields, type;
+
+ struct nouveau_bo *bo;
+ unsigned offset;
+ const void *buf;
+
+ extract_u_t extract_u;
+ extract_f_t extract_f;
+};
+
+#define RENDER_SCRATCH_COUNT 32
+#define RENDER_SCRATCH_SIZE 64*1024
+
+struct nouveau_scratch_state {
+ struct nouveau_bo *bo[RENDER_SCRATCH_COUNT];
+
+ int index;
+ int offset;
+ void *buf;
+};
+
+struct nouveau_swtnl_state {
+ struct nouveau_bo *vbo;
+ void *buf;
+ unsigned vertex_count;
+ GLenum primitive;
+};
+
+struct nouveau_render_state {
+ enum {
+ VBO,
+ IMM
+ } mode;
+
+ struct nouveau_array_state ib;
+ struct nouveau_array_state attrs[VERT_ATTRIB_MAX];
+
+ /* Maps a HW VBO index or IMM emission order to an index in
+ * the attrs array above (or -1 if unused). */
+ int map[VERT_ATTRIB_MAX];
+
+ int attr_count;
+ int vertex_size;
+
+ struct nouveau_scratch_state scratch;
+ struct nouveau_swtnl_state swtnl;
+};
+
+#define to_render_state(ctx) (&to_nouveau_context(ctx)->render)
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_render_t.c b/src/mesa/drivers/dri/nouveau/nouveau_render_t.c
new file mode 100644
index 0000000000..c0505781cf
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_render_t.c
@@ -0,0 +1,361 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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.
+ *
+ */
+
+/*
+ * Vertex submission helper definitions shared among the software and
+ * hardware TnL paths.
+ */
+
+#include "nouveau_gldefs.h"
+
+#include "main/light.h"
+#include "vbo/vbo.h"
+#include "tnl/tnl.h"
+
+#define OUT_INDICES_L(r, i, d, n) \
+ BATCH_OUT_L(i + d, n); \
+ (void)r
+#define OUT_INDICES_I16(r, i, d, n) \
+ BATCH_OUT_I16(r->ib.extract_u(&r->ib, 0, i) + d, \
+ r->ib.extract_u(&r->ib, 0, i + 1) + d)
+#define OUT_INDICES_I32(r, i, d, n) \
+ BATCH_OUT_I32(r->ib.extract_u(&r->ib, 0, i) + d)
+
+/*
+ * Emit <n> vertices using BATCH_OUT_<out>, MAX_OUT_<out> at a time,
+ * grouping them in packets of length MAX_PACKET.
+ *
+ * out: hardware index data type.
+ * ctx: GL context.
+ * start: element within the index buffer to begin with.
+ * delta: integer correction that will be added to each index found in
+ * the index buffer.
+ */
+#define EMIT_VBO(out, ctx, start, delta, n) do { \
+ struct nouveau_render_state *render = to_render_state(ctx); \
+ int npush = n; \
+ \
+ while (npush) { \
+ int npack = MIN2(npush, MAX_PACKET * MAX_OUT_##out); \
+ npush -= npack; \
+ \
+ BATCH_PACKET_##out((npack + MAX_OUT_##out - 1) \
+ / MAX_OUT_##out); \
+ while (npack) { \
+ int nout = MIN2(npack, MAX_OUT_##out); \
+ npack -= nout; \
+ \
+ OUT_INDICES_##out(render, start, delta, \
+ nout); \
+ start += nout; \
+ } \
+ } \
+ } while (0)
+
+/*
+ * Emit the <n>-th element of the array <a>, using IMM_OUT.
+ */
+#define EMIT_IMM(ctx, a, n) do { \
+ struct nouveau_attr_info *info = \
+ &TAG(vertex_attrs)[(a)->attr]; \
+ int m; \
+ \
+ if (!info->emit) { \
+ IMM_PACKET(info->imm_method, info->imm_fields); \
+ \
+ for (m = 0; m < (a)->fields; m++) \
+ IMM_OUT((a)->extract_f(a, n, m)); \
+ \
+ for (m = (a)->fields; m < info->imm_fields; m++) \
+ IMM_OUT(((float []){0, 0, 0, 1})[m]); \
+ \
+ } else { \
+ info->emit(ctx, a, (a)->buf + n * (a)->stride); \
+ } \
+ } while (0)
+
+/*
+ * Select an appropriate dispatch function for the given index buffer.
+ */
+static void
+get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch)
+{
+ if (!a->fields) {
+ auto void f(GLcontext *, unsigned int, int, unsigned int);
+
+ void f(GLcontext *ctx, unsigned int start, int delta,
+ unsigned int n) {
+ struct nouveau_channel *chan = context_chan(ctx);
+ RENDER_LOCALS(ctx);
+
+ EMIT_VBO(L, ctx, start, delta, n);
+ };
+
+ *dispatch = f;
+
+ } else if (a->type == GL_UNSIGNED_INT) {
+ auto void f(GLcontext *, unsigned int, int, unsigned int);
+
+ void f(GLcontext *ctx, unsigned int start, int delta,
+ unsigned int n) {
+ struct nouveau_channel *chan = context_chan(ctx);
+ RENDER_LOCALS(ctx);
+
+ EMIT_VBO(I32, ctx, start, delta, n);
+ };
+
+ *dispatch = f;
+
+ } else {
+ auto void f(GLcontext *, unsigned int, int, unsigned int);
+
+ void f(GLcontext *ctx, unsigned int start, int delta,
+ unsigned int n) {
+ struct nouveau_channel *chan = context_chan(ctx);
+ RENDER_LOCALS(ctx);
+
+ EMIT_VBO(I32, ctx, start, delta, n & 1);
+ EMIT_VBO(I16, ctx, start, delta, n & ~1);
+ };
+
+ *dispatch = f;
+ }
+}
+
+/*
+ * Select appropriate element extraction functions for the given
+ * array.
+ */
+static void
+get_array_extract(struct nouveau_array_state *a,
+ extract_u_t *extract_u, extract_f_t *extract_f)
+{
+#define EXTRACT(in_t, out_t, k) \
+ ({ \
+ auto out_t f(struct nouveau_array_state *, int, int); \
+ out_t f(struct nouveau_array_state *a, int i, int j) { \
+ in_t x = ((in_t *)(a->buf + i * a->stride))[j]; \
+ \
+ return (out_t)x / (k); \
+ }; \
+ f; \
+ });
+
+ switch (a->type) {
+ case GL_BYTE:
+ *extract_u = EXTRACT(char, unsigned, 1);
+ *extract_f = EXTRACT(char, float, SCHAR_MAX);
+ break;
+ case GL_UNSIGNED_BYTE:
+ *extract_u = EXTRACT(unsigned char, unsigned, 1);
+ *extract_f = EXTRACT(unsigned char, float, UCHAR_MAX);
+ break;
+ case GL_SHORT:
+ *extract_u = EXTRACT(short, unsigned, 1);
+ *extract_f = EXTRACT(short, float, SHRT_MAX);
+ break;
+ case GL_UNSIGNED_SHORT:
+ *extract_u = EXTRACT(unsigned short, unsigned, 1);
+ *extract_f = EXTRACT(unsigned short, float, USHRT_MAX);
+ break;
+ case GL_INT:
+ *extract_u = EXTRACT(int, unsigned, 1);
+ *extract_f = EXTRACT(int, float, INT_MAX);
+ break;
+ case GL_UNSIGNED_INT:
+ *extract_u = EXTRACT(unsigned int, unsigned, 1);
+ *extract_f = EXTRACT(unsigned int, float, UINT_MAX);
+ break;
+ case GL_FLOAT:
+ *extract_u = EXTRACT(float, unsigned, 1.0 / UINT_MAX);
+ *extract_f = EXTRACT(float, float, 1);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+/*
+ * Returns a pointer to a chunk of <size> bytes long GART memory. <bo>
+ * will be updated with the buffer object the memory is located in.
+ *
+ * If <offset> is provided, it will be updated with the offset within
+ * <bo> of the allocated memory. Otherwise the returned memory will
+ * always be located right at the beginning of <bo>.
+ */
+static inline void *
+get_scratch_vbo(GLcontext *ctx, unsigned size, struct nouveau_bo **bo,
+ unsigned *offset)
+{
+ struct nouveau_scratch_state *scratch = &to_render_state(ctx)->scratch;
+ void *buf;
+
+ if (scratch->buf && offset &&
+ size <= RENDER_SCRATCH_SIZE - scratch->offset) {
+ nouveau_bo_ref(scratch->bo[scratch->index], bo);
+
+ buf = scratch->buf + scratch->offset;
+ *offset = scratch->offset;
+ scratch->offset += size;
+
+ } else if (size <= RENDER_SCRATCH_SIZE) {
+ scratch->index = (scratch->index + 1) % RENDER_SCRATCH_COUNT;
+ nouveau_bo_ref(scratch->bo[scratch->index], bo);
+
+ nouveau_bo_map(*bo, NOUVEAU_BO_WR);
+ buf = scratch->buf = (*bo)->map;
+ nouveau_bo_unmap(*bo);
+
+ if (offset)
+ *offset = 0;
+ scratch->offset = size;
+
+ } else {
+ nouveau_bo_new(context_dev(ctx),
+ NOUVEAU_BO_MAP | NOUVEAU_BO_GART, 0, size, bo);
+
+ nouveau_bo_map(*bo, NOUVEAU_BO_WR);
+ buf = (*bo)->map;
+ nouveau_bo_unmap(*bo);
+
+ if (offset)
+ *offset = 0;
+ }
+
+ return buf;
+}
+
+/*
+ * Returns how many vertices you can draw using <n> pushbuf dwords.
+ */
+static inline unsigned
+get_max_vertices(GLcontext *ctx, const struct _mesa_index_buffer *ib,
+ unsigned n)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+
+ if (render->mode == IMM) {
+ return MAX2(0, n - 4) / (render->vertex_size / 4 +
+ render->attr_count);
+ } else {
+ unsigned max_out;
+
+ if (ib) {
+ switch (ib->type) {
+ case GL_UNSIGNED_INT:
+ max_out = MAX_OUT_I32;
+ break;
+
+ case GL_UNSIGNED_SHORT:
+ max_out = MAX_OUT_I16;
+ break;
+
+ case GL_UNSIGNED_BYTE:
+ max_out = MAX_OUT_I16;
+ break;
+ }
+ } else {
+ max_out = MAX_OUT_L;
+ }
+
+ return MAX2(0, n - 7) * max_out * MAX_PACKET / (1 + MAX_PACKET);
+ }
+}
+
+#include "nouveau_vbo_t.c"
+#include "nouveau_swtnl_t.c"
+
+static void
+TAG(emit_material)(GLcontext *ctx, struct nouveau_array_state *a,
+ const void *v)
+{
+ const int attr = a->attr - VERT_ATTRIB_GENERIC0;
+ const int state = ((int []) {
+ NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE,
+ NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE,
+ NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR,
+ NOUVEAU_STATE_MATERIAL_BACK_SPECULAR,
+ NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_FRONT_SHININESS,
+ NOUVEAU_STATE_MATERIAL_BACK_SHININESS
+ }) [attr];
+
+ COPY_4V(ctx->Light.Material.Attrib[attr], (float *)v);
+ _mesa_update_material(ctx, 1 << attr);
+
+ context_drv(ctx)->emit[state](ctx, state);
+}
+
+static void
+TAG(render_prims)(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index, GLuint max_index)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+
+ nouveau_validate_framebuffer(ctx);
+
+ if (nctx->fallback == HWTNL)
+ TAG(vbo_render_prims)(ctx, arrays, prims, nr_prims, ib,
+ index_bounds_valid, min_index, max_index);
+
+ if (nctx->fallback == SWTNL)
+ _tnl_vbo_draw_prims(ctx, arrays, prims, nr_prims, ib,
+ index_bounds_valid, min_index, max_index);
+}
+
+void
+TAG(render_init)(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_scratch_state *scratch = &render->scratch;
+ int ret, i;
+
+ for (i = 0; i < RENDER_SCRATCH_COUNT; i++) {
+ ret = nouveau_bo_new(context_dev(ctx),
+ NOUVEAU_BO_MAP | NOUVEAU_BO_GART,
+ 0, RENDER_SCRATCH_SIZE, &scratch->bo[i]);
+ assert(!ret);
+ }
+
+ for (i = 0; i < VERT_ATTRIB_MAX; i++)
+ render->map[i] = -1;
+
+ TAG(swtnl_init)(ctx);
+ vbo_set_draw_func(ctx, TAG(render_prims));
+}
+
+void
+TAG(render_destroy)(GLcontext *ctx)
+{
+ TAG(swtnl_destroy)(ctx);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.c b/src/mesa/drivers/dri/nouveau/nouveau_screen.c
new file mode 100644
index 0000000000..de6328251e
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.c
@@ -0,0 +1,269 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_drmif.h"
+#include "nv04_driver.h"
+#include "nv10_driver.h"
+#include "nv20_driver.h"
+
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+
+static const __DRIextension *nouveau_screen_extensions[];
+
+static void
+nouveau_destroy_screen(__DRIscreen *dri_screen);
+
+static void
+nouveau_channel_flush_notify(struct nouveau_channel *chan)
+{
+ struct nouveau_screen *screen = chan->user_private;
+ struct nouveau_context *nctx = screen->context;
+
+ if (nctx && nctx->fallback < SWRAST)
+ nouveau_state_emit(&nctx->base);
+}
+
+static const __DRIconfig **
+nouveau_get_configs(void)
+{
+ __DRIconfig **configs = NULL;
+ int i;
+
+ const uint8_t depth_bits[] = { 0, 16, 24, 24 };
+ const uint8_t stencil_bits[] = { 0, 0, 0, 8 };
+ const uint8_t msaa_samples[] = { 0 };
+
+ const struct {
+ GLenum format;
+ GLenum type;
+ } fb_formats[] = {
+ { GL_RGB , GL_UNSIGNED_SHORT_5_6_5 },
+ { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV },
+ { GL_BGR , GL_UNSIGNED_INT_8_8_8_8_REV },
+ };
+
+ const GLenum back_buffer_modes[] = {
+ GLX_NONE, GLX_SWAP_UNDEFINED_OML
+ };
+
+ for (i = 0; i < Elements(fb_formats); i++) {
+ __DRIconfig **config;
+
+ config = driCreateConfigs(fb_formats[i].format,
+ fb_formats[i].type,
+ depth_bits, stencil_bits,
+ Elements(depth_bits),
+ back_buffer_modes,
+ Elements(back_buffer_modes),
+ msaa_samples,
+ Elements(msaa_samples));
+ assert(config);
+
+ configs = configs ? driConcatConfigs(configs, config)
+ : config;
+ }
+
+ return (const __DRIconfig **)configs;
+}
+
+static const __DRIconfig **
+nouveau_init_screen2(__DRIscreen *dri_screen)
+{
+ const __DRIconfig **configs;
+ struct nouveau_screen *screen;
+ int ret;
+
+ /* Allocate the screen. */
+ screen = CALLOC_STRUCT(nouveau_screen);
+ if (!screen)
+ return NULL;
+
+ dri_screen->private = screen;
+ dri_screen->extensions = nouveau_screen_extensions;
+ screen->dri_screen = dri_screen;
+
+ /* Open the DRM device. */
+ ret = nouveau_device_open_existing(&screen->device, 0, dri_screen->fd,
+ 0);
+ if (ret) {
+ nouveau_error("Error opening the DRM device.\n");
+ goto fail;
+ }
+
+ ret = nouveau_channel_alloc(screen->device, 0xbeef0201, 0xbeef0202,
+ &screen->chan);
+ if (ret) {
+ nouveau_error("Error initializing the FIFO.\n");
+ goto fail;
+ }
+ screen->chan->flush_notify = nouveau_channel_flush_notify;
+ screen->chan->user_private = screen;
+
+ /* Do the card specific initialization */
+ switch (screen->device->chipset & 0xf0) {
+ case 0x00:
+ ret = nv04_screen_init(screen);
+ break;
+ case 0x10:
+ ret = nv10_screen_init(screen);
+ break;
+ case 0x20:
+ ret = nv20_screen_init(screen);
+ break;
+ default:
+ assert(0);
+ }
+ if (!ret) {
+ nouveau_error("Error initializing the hardware.\n");
+ goto fail;
+ }
+
+ configs = nouveau_get_configs();
+ if (!configs) {
+ nouveau_error("Error creating the framebuffer configs.\n");
+ goto fail;
+ }
+
+ return configs;
+fail:
+ nouveau_destroy_screen(dri_screen);
+ return NULL;
+
+}
+
+static void
+nouveau_destroy_screen(__DRIscreen *dri_screen)
+{
+ struct nouveau_screen *screen = dri_screen->private;
+
+ if (!screen)
+ return;
+
+ screen->driver->screen_destroy(screen);
+
+ if (screen->chan) {
+ screen->chan->flush_notify = NULL;
+ nouveau_channel_free(&screen->chan);
+ }
+
+ if (screen->device)
+ nouveau_device_close(&screen->device);
+
+ FREE(screen);
+ dri_screen->private = NULL;
+}
+
+static GLboolean
+nouveau_create_buffer(__DRIscreen *dri_screen,
+ __DRIdrawable *drawable,
+ const __GLcontextModes *visual,
+ GLboolean is_pixmap)
+{
+ struct gl_renderbuffer *rb;
+ struct gl_framebuffer *fb;
+ GLenum color_format;
+
+ if (is_pixmap)
+ return GL_FALSE; /* not implemented */
+
+ if (visual->redBits == 5)
+ color_format = GL_RGB5;
+ else if (visual->alphaBits == 0)
+ color_format = GL_RGB8;
+ else
+ color_format = GL_RGBA8;
+
+ fb = nouveau_framebuffer_dri_new(visual);
+ if (!fb)
+ return GL_FALSE;
+
+ /* Front buffer. */
+ rb = nouveau_renderbuffer_dri_new(color_format, drawable);
+ _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, rb);
+
+ /* Back buffer */
+ if (visual->doubleBufferMode) {
+ rb = nouveau_renderbuffer_dri_new(color_format, drawable);
+ _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, rb);
+ }
+
+ /* Depth/stencil buffer. */
+ if (visual->depthBits == 24 && visual->stencilBits == 8) {
+ rb = nouveau_renderbuffer_dri_new(GL_DEPTH24_STENCIL8_EXT, drawable);
+ _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+ _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
+
+ } else if (visual->depthBits == 24) {
+ rb = nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT24, drawable);
+ _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+
+ } else if (visual->depthBits == 16) {
+ rb = nouveau_renderbuffer_dri_new(GL_DEPTH_COMPONENT16, drawable);
+ _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+ }
+
+ /* Software renderbuffers. */
+ _mesa_add_soft_renderbuffers(fb, GL_FALSE, GL_FALSE, GL_FALSE,
+ visual->accumRedBits > 0,
+ GL_FALSE, GL_FALSE);
+
+ drawable->driverPrivate = fb;
+
+ return GL_TRUE;
+}
+
+static void
+nouveau_destroy_buffer(__DRIdrawable *drawable)
+{
+ _mesa_reference_framebuffer(
+ (struct gl_framebuffer **)&drawable->driverPrivate, NULL);
+}
+
+static const __DRIextension *nouveau_screen_extensions[] = {
+ NULL
+};
+
+const struct __DriverAPIRec driDriverAPI = {
+ .InitScreen2 = nouveau_init_screen2,
+ .DestroyScreen = nouveau_destroy_screen,
+ .CreateBuffer = nouveau_create_buffer,
+ .DestroyBuffer = nouveau_destroy_buffer,
+ .CreateContext = nouveau_context_create,
+ .DestroyContext = nouveau_context_destroy,
+ .MakeCurrent = nouveau_context_make_current,
+ .UnbindContext = nouveau_context_unbind,
+};
+
+/* This is the table of extensions that the loader will dlsym() for. */
+PUBLIC const __DRIextension *__driDriverExtensions[] = {
+ &driCoreExtension.base,
+ &driDRI2Extension.base,
+ NULL
+};
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.h b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
new file mode 100644
index 0000000000..5d45039b9e
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_SCREEN_H__
+#define __NOUVEAU_SCREEN_H__
+
+struct nouveau_context;
+
+struct nouveau_screen {
+ __DRIscreen *dri_screen;
+
+ struct nouveau_device *device;
+ struct nouveau_channel *chan;
+
+ struct nouveau_notifier *ntfy;
+ struct nouveau_grobj *eng3d;
+ struct nouveau_grobj *eng3dm;
+ struct nouveau_grobj *surf3d;
+ struct nouveau_grobj *m2mf;
+ struct nouveau_grobj *surf2d;
+ struct nouveau_grobj *rop;
+ struct nouveau_grobj *patt;
+ struct nouveau_grobj *rect;
+ struct nouveau_grobj *swzsurf;
+ struct nouveau_grobj *sifm;
+
+ const struct nouveau_driver *driver;
+ struct nouveau_context *context;
+};
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.c b/src/mesa/drivers/dri/nouveau/nouveau_span.c
new file mode 100644
index 0000000000..dbbbf15b09
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_span.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_fbo.h"
+#include "nouveau_context.h"
+#include "nouveau_bo.h"
+
+#include "swrast/swrast.h"
+
+#define LOCAL_VARS \
+ struct gl_framebuffer *fb = ctx->DrawBuffer; \
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
+ GLuint p; \
+ (void)p;
+
+#define LOCAL_DEPTH_VARS LOCAL_VARS
+
+#define HW_LOCK()
+#define HW_UNLOCK()
+
+#define HW_CLIPLOOP() { \
+ int minx = 0; \
+ int miny = 0; \
+ int maxx = fb->Width; \
+ int maxy = fb->Height;
+
+#define HW_ENDCLIPLOOP() }
+
+#define Y_FLIP(y) (fb->Name ? (y) : rb->Height - 1 - (y))
+
+/* RGB565 span functions */
+#define SPANTMP_PIXEL_FMT GL_RGB
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
+#define TAG(x) nouveau_##x##_rgb565
+#define TAG2(x, y) nouveau_##x##_rgb565##y
+#define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
+
+#include "spantmp2.h"
+
+/* ARGB8888 span functions */
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
+#define TAG(x) nouveau_##x##_argb8888
+#define TAG2(x, y) nouveau_##x##_argb8888##y
+#define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
+
+#include "spantmp2.h"
+
+/* Z16 span functions */
+#define VALUE_TYPE uint16_t
+#define READ_DEPTH(v, x, y) \
+ v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
+#define WRITE_DEPTH(x, y, v) \
+ *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
+#define TAG(x) nouveau_##x##_z16
+
+#include "depthtmp.h"
+
+/* Z24S8 span functions */
+#define VALUE_TYPE uint32_t
+#define READ_DEPTH(v, x, y) \
+ v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
+#define WRITE_DEPTH(x, y, v) \
+ *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
+#define TAG(x) nouveau_##x##_z24s8
+
+#include "depthtmp.h"
+
+static void
+renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
+{
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
+
+ if (map) {
+ switch (rb->Format) {
+ case MESA_FORMAT_RGB565:
+ nouveau_InitPointers_rgb565(rb);
+ break;
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_ARGB8888:
+ nouveau_InitPointers_argb8888(rb);
+ break;
+ case MESA_FORMAT_Z16:
+ nouveau_InitDepthPointers_z16(rb);
+ break;
+ case MESA_FORMAT_Z24_S8:
+ nouveau_InitDepthPointers_z24s8(rb);
+ break;
+ default:
+ assert(0);
+ }
+
+ nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR);
+ } else {
+ nouveau_bo_unmap(s->bo);
+ }
+}
+
+static void
+texture_unit_map_unmap(GLcontext *ctx, struct gl_texture_unit *u, GLboolean map)
+{
+ if (!u->_ReallyEnabled)
+ return;
+
+ if (map)
+ ctx->Driver.MapTexture(ctx, u->_Current);
+ else
+ ctx->Driver.UnmapTexture(ctx, u->_Current);
+}
+
+static void
+span_map_unmap(GLcontext *ctx, GLboolean map)
+{
+ int i;
+
+ for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++)
+ renderbuffer_map_unmap(ctx->DrawBuffer->_ColorDrawBuffers[i], map);
+
+ renderbuffer_map_unmap(ctx->DrawBuffer->_ColorReadBuffer, map);
+
+ if (ctx->DrawBuffer->_DepthBuffer)
+ renderbuffer_map_unmap(ctx->DrawBuffer->_DepthBuffer->Wrapped, map);
+
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
+ texture_unit_map_unmap(ctx, &ctx->Texture.Unit[i], map);
+}
+
+static void
+nouveau_span_start(GLcontext *ctx)
+{
+ nouveau_fallback(ctx, SWRAST);
+ span_map_unmap(ctx, GL_TRUE);
+}
+
+static void
+nouveau_span_finish(GLcontext *ctx)
+{
+ span_map_unmap(ctx, GL_FALSE);
+ nouveau_fallback(ctx, HWTNL);
+}
+
+void
+nouveau_span_functions_init(GLcontext *ctx)
+{
+ struct swrast_device_driver *swdd =
+ _swrast_GetDeviceDriverReference(ctx);
+
+ swdd->SpanRenderStart = nouveau_span_start;
+ swdd->SpanRenderFinish = nouveau_span_finish;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.c b/src/mesa/drivers/dri/nouveau/nouveau_state.c
new file mode 100644
index 0000000000..d727822175
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c
@@ -0,0 +1,532 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_texture.h"
+#include "nouveau_util.h"
+
+#include "swrast/swrast.h"
+#include "tnl/tnl.h"
+
+static void
+nouveau_alpha_func(GLcontext *ctx, GLenum func, GLfloat ref)
+{
+ context_dirty(ctx, ALPHA_FUNC);
+}
+
+static void
+nouveau_blend_color(GLcontext *ctx, const GLfloat color[4])
+{
+ context_dirty(ctx, BLEND_COLOR);
+}
+
+static void
+nouveau_blend_equation_separate(GLcontext *ctx, GLenum modeRGB, GLenum modeA)
+{
+ context_dirty(ctx, BLEND_EQUATION);
+}
+
+static void
+nouveau_blend_func_separate(GLcontext *ctx, GLenum sfactorRGB,
+ GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA)
+{
+ context_dirty(ctx, BLEND_FUNC);
+}
+
+static void
+nouveau_clip_plane(GLcontext *ctx, GLenum plane, const GLfloat *equation)
+{
+ context_dirty_i(ctx, CLIP_PLANE, plane - GL_CLIP_PLANE0);
+}
+
+static void
+nouveau_color_mask(GLcontext *ctx, GLboolean rmask, GLboolean gmask,
+ GLboolean bmask, GLboolean amask)
+{
+ context_dirty(ctx, COLOR_MASK);
+}
+
+static void
+nouveau_color_material(GLcontext *ctx, GLenum face, GLenum mode)
+{
+ context_dirty(ctx, COLOR_MATERIAL);
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+}
+
+static void
+nouveau_cull_face(GLcontext *ctx, GLenum mode)
+{
+ context_dirty(ctx, CULL_FACE);
+}
+
+static void
+nouveau_front_face(GLcontext *ctx, GLenum mode)
+{
+ context_dirty(ctx, FRONT_FACE);
+}
+
+static void
+nouveau_depth_func(GLcontext *ctx, GLenum func)
+{
+ context_dirty(ctx, DEPTH);
+}
+
+static void
+nouveau_depth_mask(GLcontext *ctx, GLboolean flag)
+{
+ context_dirty(ctx, DEPTH);
+}
+
+static void
+nouveau_depth_range(GLcontext *ctx, GLclampd nearval, GLclampd farval)
+{
+ context_dirty(ctx, VIEWPORT);
+}
+
+static void
+nouveau_draw_buffer(GLcontext *ctx, GLenum buffer)
+{
+ context_dirty(ctx, FRAMEBUFFER);
+}
+
+static void
+nouveau_draw_buffers(GLcontext *ctx, GLsizei n, const GLenum *buffers)
+{
+ context_dirty(ctx, FRAMEBUFFER);
+}
+
+static void
+nouveau_enable(GLcontext *ctx, GLenum cap, GLboolean state)
+{
+ int i;
+
+ switch (cap) {
+ case GL_ALPHA_TEST:
+ context_dirty(ctx, ALPHA_FUNC);
+ break;
+ case GL_BLEND:
+ context_dirty(ctx, BLEND_EQUATION);
+ break;
+ case GL_COLOR_LOGIC_OP:
+ context_dirty(ctx, LOGIC_OPCODE);
+ break;
+ case GL_COLOR_MATERIAL:
+ context_dirty(ctx, COLOR_MATERIAL);
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+ break;
+ case GL_COLOR_SUM_EXT:
+ context_dirty(ctx, FRAG);
+ break;
+ case GL_CULL_FACE:
+ context_dirty(ctx, CULL_FACE);
+ break;
+ case GL_DEPTH_TEST:
+ context_dirty(ctx, DEPTH);
+ break;
+ case GL_DITHER:
+ context_dirty(ctx, DITHER);
+ break;
+ case GL_FOG:
+ context_dirty(ctx, FOG);
+ context_dirty(ctx, FRAG);
+ context_dirty(ctx, MODELVIEW);
+ break;
+ case GL_LIGHT0:
+ case GL_LIGHT1:
+ case GL_LIGHT2:
+ case GL_LIGHT3:
+ case GL_LIGHT4:
+ case GL_LIGHT5:
+ case GL_LIGHT6:
+ case GL_LIGHT7:
+ context_dirty(ctx, MODELVIEW);
+ context_dirty(ctx, LIGHT_ENABLE);
+ context_dirty_i(ctx, LIGHT_SOURCE, cap - GL_LIGHT0);
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+ context_dirty(ctx, MATERIAL_FRONT_SHININESS);
+ context_dirty(ctx, MATERIAL_BACK_SHININESS);
+ break;
+ case GL_LIGHTING:
+ context_dirty(ctx, FRAG);
+ context_dirty(ctx, MODELVIEW);
+ context_dirty(ctx, LIGHT_ENABLE);
+
+ for (i = 0; i < MAX_LIGHTS; i++) {
+ if (ctx->Light.Light[i].Enabled)
+ context_dirty_i(ctx, LIGHT_SOURCE, i);
+ }
+
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+ context_dirty(ctx, MATERIAL_FRONT_SHININESS);
+ context_dirty(ctx, MATERIAL_BACK_SHININESS);
+ break;
+ case GL_LINE_SMOOTH:
+ context_dirty(ctx, LINE_MODE);
+ break;
+ case GL_NORMALIZE:
+ context_dirty(ctx, LIGHT_ENABLE);
+ break;
+ case GL_POINT_SMOOTH:
+ context_dirty(ctx, POINT_MODE);
+ break;
+ case GL_POLYGON_OFFSET_POINT:
+ case GL_POLYGON_OFFSET_LINE:
+ case GL_POLYGON_OFFSET_FILL:
+ context_dirty(ctx, POLYGON_OFFSET);
+ break;
+ case GL_POLYGON_SMOOTH:
+ context_dirty(ctx, POLYGON_MODE);
+ break;
+ case GL_SCISSOR_TEST:
+ context_dirty(ctx, SCISSOR);
+ break;
+ case GL_STENCIL_TEST:
+ context_dirty(ctx, STENCIL_FUNC);
+ break;
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_3D:
+ context_dirty_i(ctx, TEX_ENV, ctx->Texture.CurrentUnit);
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ break;
+ }
+}
+
+static void
+nouveau_fog(GLcontext *ctx, GLenum pname, const GLfloat *params)
+{
+ context_dirty(ctx, FOG);
+}
+
+static void
+nouveau_index_mask(GLcontext *ctx, GLuint mask)
+{
+ context_dirty(ctx, INDEX_MASK);
+}
+
+static void
+nouveau_light(GLcontext *ctx, GLenum light, GLenum pname, const GLfloat *params)
+{
+ switch (pname) {
+ case GL_AMBIENT:
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ break;
+ case GL_DIFFUSE:
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ break;
+ case GL_SPECULAR:
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+ break;
+ case GL_SPOT_CUTOFF:
+ case GL_POSITION:
+ context_dirty(ctx, MODELVIEW);
+ context_dirty(ctx, LIGHT_ENABLE);
+ context_dirty_i(ctx, LIGHT_SOURCE, light - GL_LIGHT0);
+ break;
+ default:
+ context_dirty_i(ctx, LIGHT_SOURCE, light - GL_LIGHT0);
+ break;
+ }
+}
+
+static void
+nouveau_light_model(GLcontext *ctx, GLenum pname, const GLfloat *params)
+{
+ context_dirty(ctx, LIGHT_MODEL);
+ context_dirty(ctx, MODELVIEW);
+}
+
+static void
+nouveau_line_stipple(GLcontext *ctx, GLint factor, GLushort pattern )
+{
+ context_dirty(ctx, LINE_STIPPLE);
+}
+
+static void
+nouveau_line_width(GLcontext *ctx, GLfloat width)
+{
+ context_dirty(ctx, LINE_MODE);
+}
+
+static void
+nouveau_logic_opcode(GLcontext *ctx, GLenum opcode)
+{
+ context_dirty(ctx, LOGIC_OPCODE);
+}
+
+static void
+nouveau_point_parameter(GLcontext *ctx, GLenum pname, const GLfloat *params)
+{
+ context_dirty(ctx, POINT_PARAMETER);
+}
+
+static void
+nouveau_point_size(GLcontext *ctx, GLfloat size)
+{
+ context_dirty(ctx, POINT_MODE);
+}
+
+static void
+nouveau_polygon_mode(GLcontext *ctx, GLenum face, GLenum mode)
+{
+ context_dirty(ctx, POLYGON_MODE);
+}
+
+static void
+nouveau_polygon_offset(GLcontext *ctx, GLfloat factor, GLfloat units)
+{
+ context_dirty(ctx, POLYGON_OFFSET);
+}
+
+static void
+nouveau_polygon_stipple(GLcontext *ctx, const GLubyte *mask)
+{
+ context_dirty(ctx, POLYGON_STIPPLE);
+}
+
+static void
+nouveau_render_mode(GLcontext *ctx, GLenum mode)
+{
+ context_dirty(ctx, RENDER_MODE);
+}
+
+static void
+nouveau_scissor(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+{
+ context_dirty(ctx, SCISSOR);
+}
+
+static void
+nouveau_shade_model(GLcontext *ctx, GLenum mode)
+{
+ context_dirty(ctx, SHADE_MODEL);
+}
+
+static void
+nouveau_stencil_func_separate(GLcontext *ctx, GLenum face, GLenum func,
+ GLint ref, GLuint mask)
+{
+ context_dirty(ctx, STENCIL_FUNC);
+}
+
+static void
+nouveau_stencil_mask_separate(GLcontext *ctx, GLenum face, GLuint mask)
+{
+ context_dirty(ctx, STENCIL_MASK);
+}
+
+static void
+nouveau_stencil_op_separate(GLcontext *ctx, GLenum face, GLenum fail,
+ GLenum zfail, GLenum zpass)
+{
+ context_dirty(ctx, STENCIL_OP);
+}
+
+static void
+nouveau_tex_gen(GLcontext *ctx, GLenum coord, GLenum pname,
+ const GLfloat *params)
+{
+ context_dirty_i(ctx, TEX_GEN, ctx->Texture.CurrentUnit);
+}
+
+static void
+nouveau_tex_env(GLcontext *ctx, GLenum target, GLenum pname,
+ const GLfloat *param)
+{
+ switch (target) {
+ case GL_TEXTURE_FILTER_CONTROL_EXT:
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ break;
+ default:
+ context_dirty_i(ctx, TEX_ENV, ctx->Texture.CurrentUnit);
+ break;
+ }
+}
+
+static void
+nouveau_tex_parameter(GLcontext *ctx, GLenum target,
+ struct gl_texture_object *t, GLenum pname,
+ const GLfloat *params)
+{
+ switch (pname) {
+ case GL_TEXTURE_MIN_FILTER:
+ case GL_TEXTURE_MAG_FILTER:
+ case GL_TEXTURE_WRAP_S:
+ case GL_TEXTURE_WRAP_T:
+ case GL_TEXTURE_WRAP_R:
+ case GL_TEXTURE_MIN_LOD:
+ case GL_TEXTURE_MAX_LOD:
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ case GL_TEXTURE_LOD_BIAS:
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ break;
+
+ case GL_TEXTURE_BASE_LEVEL:
+ case GL_TEXTURE_MAX_LEVEL:
+ texture_dirty(t);
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ break;
+ }
+}
+
+static void
+nouveau_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+{
+ context_dirty(ctx, VIEWPORT);
+}
+
+void
+nouveau_emit_nothing(GLcontext *ctx, int emit)
+{
+}
+
+int
+nouveau_next_dirty_state(GLcontext *ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ int i = BITSET_FFS(nctx->dirty) - 1;
+
+ if (i < 0 || i >= context_drv(ctx)->num_emit)
+ return -1;
+
+ return i;
+}
+
+void
+nouveau_state_emit(GLcontext *ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ const struct nouveau_driver *drv = context_drv(ctx);
+ int i;
+
+ while ((i = nouveau_next_dirty_state(ctx)) >= 0) {
+ BITSET_CLEAR(nctx->dirty, i);
+ drv->emit[i](ctx, i);
+ }
+
+ BITSET_ZERO(nctx->dirty);
+
+ nouveau_bo_state_emit(ctx);
+}
+
+static void
+nouveau_update_state(GLcontext *ctx, GLbitfield new_state)
+{
+ if (new_state & (_NEW_PROJECTION | _NEW_MODELVIEW))
+ context_dirty(ctx, PROJECTION);
+
+ if (new_state & _NEW_MODELVIEW)
+ context_dirty(ctx, MODELVIEW);
+
+ if (new_state & _NEW_CURRENT_ATTRIB &&
+ new_state & _NEW_LIGHT) {
+ context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
+ context_dirty(ctx, MATERIAL_BACK_AMBIENT);
+ context_dirty(ctx, MATERIAL_FRONT_DIFFUSE);
+ context_dirty(ctx, MATERIAL_BACK_DIFFUSE);
+ context_dirty(ctx, MATERIAL_FRONT_SPECULAR);
+ context_dirty(ctx, MATERIAL_BACK_SPECULAR);
+ context_dirty(ctx, MATERIAL_FRONT_SHININESS);
+ context_dirty(ctx, MATERIAL_BACK_SHININESS);
+ }
+
+ _swrast_InvalidateState(ctx, new_state);
+ _tnl_InvalidateState(ctx, new_state);
+
+ nouveau_state_emit(ctx);
+}
+
+void
+nouveau_state_init(GLcontext *ctx)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+
+ ctx->Driver.AlphaFunc = nouveau_alpha_func;
+ ctx->Driver.BlendColor = nouveau_blend_color;
+ ctx->Driver.BlendEquationSeparate = nouveau_blend_equation_separate;
+ ctx->Driver.BlendFuncSeparate = nouveau_blend_func_separate;
+ ctx->Driver.ClipPlane = nouveau_clip_plane;
+ ctx->Driver.ColorMask = nouveau_color_mask;
+ ctx->Driver.ColorMaterial = nouveau_color_material;
+ ctx->Driver.CullFace = nouveau_cull_face;
+ ctx->Driver.FrontFace = nouveau_front_face;
+ ctx->Driver.DepthFunc = nouveau_depth_func;
+ ctx->Driver.DepthMask = nouveau_depth_mask;
+ ctx->Driver.DepthRange = nouveau_depth_range;
+ ctx->Driver.DrawBuffer = nouveau_draw_buffer;
+ ctx->Driver.DrawBuffers = nouveau_draw_buffers;
+ ctx->Driver.Enable = nouveau_enable;
+ ctx->Driver.Fogfv = nouveau_fog;
+ ctx->Driver.IndexMask = nouveau_index_mask;
+ ctx->Driver.Lightfv = nouveau_light;
+ ctx->Driver.LightModelfv = nouveau_light_model;
+ ctx->Driver.LineStipple = nouveau_line_stipple;
+ ctx->Driver.LineWidth = nouveau_line_width;
+ ctx->Driver.LogicOpcode = nouveau_logic_opcode;
+ ctx->Driver.PointParameterfv = nouveau_point_parameter;
+ ctx->Driver.PointSize = nouveau_point_size;
+ ctx->Driver.PolygonMode = nouveau_polygon_mode;
+ ctx->Driver.PolygonOffset = nouveau_polygon_offset;
+ ctx->Driver.PolygonStipple = nouveau_polygon_stipple;
+ ctx->Driver.RenderMode = nouveau_render_mode;
+ ctx->Driver.Scissor = nouveau_scissor;
+ ctx->Driver.ShadeModel = nouveau_shade_model;
+ ctx->Driver.StencilFuncSeparate = nouveau_stencil_func_separate;
+ ctx->Driver.StencilMaskSeparate = nouveau_stencil_mask_separate;
+ ctx->Driver.StencilOpSeparate = nouveau_stencil_op_separate;
+ ctx->Driver.TexGen = nouveau_tex_gen;
+ ctx->Driver.TexEnv = nouveau_tex_env;
+ ctx->Driver.TexParameter = nouveau_tex_parameter;
+ ctx->Driver.Viewport = nouveau_viewport;
+
+ ctx->Driver.UpdateState = nouveau_update_state;
+
+ BITSET_ONES(nctx->dirty);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.h b/src/mesa/drivers/dri/nouveau/nouveau_state.h
new file mode 100644
index 0000000000..d001fa259a
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_state.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_STATE_H__
+#define __NOUVEAU_STATE_H__
+
+enum {
+ NOUVEAU_STATE_ALPHA_FUNC,
+ NOUVEAU_STATE_BLEND_COLOR,
+ NOUVEAU_STATE_BLEND_EQUATION,
+ NOUVEAU_STATE_BLEND_FUNC,
+ NOUVEAU_STATE_CLIP_PLANE0,
+ NOUVEAU_STATE_CLIP_PLANE1,
+ NOUVEAU_STATE_CLIP_PLANE2,
+ NOUVEAU_STATE_CLIP_PLANE3,
+ NOUVEAU_STATE_CLIP_PLANE4,
+ NOUVEAU_STATE_CLIP_PLANE5,
+ NOUVEAU_STATE_COLOR_MASK,
+ NOUVEAU_STATE_COLOR_MATERIAL,
+ NOUVEAU_STATE_CULL_FACE,
+ NOUVEAU_STATE_FRONT_FACE,
+ NOUVEAU_STATE_DEPTH,
+ NOUVEAU_STATE_DITHER,
+ NOUVEAU_STATE_FRAG,
+ NOUVEAU_STATE_FRAMEBUFFER,
+ NOUVEAU_STATE_FOG,
+ NOUVEAU_STATE_INDEX_MASK,
+ NOUVEAU_STATE_LIGHT_ENABLE,
+ NOUVEAU_STATE_LIGHT_MODEL,
+ NOUVEAU_STATE_LIGHT_SOURCE0,
+ NOUVEAU_STATE_LIGHT_SOURCE1,
+ NOUVEAU_STATE_LIGHT_SOURCE2,
+ NOUVEAU_STATE_LIGHT_SOURCE3,
+ NOUVEAU_STATE_LIGHT_SOURCE4,
+ NOUVEAU_STATE_LIGHT_SOURCE5,
+ NOUVEAU_STATE_LIGHT_SOURCE6,
+ NOUVEAU_STATE_LIGHT_SOURCE7,
+ NOUVEAU_STATE_LINE_STIPPLE,
+ NOUVEAU_STATE_LINE_MODE,
+ NOUVEAU_STATE_LOGIC_OPCODE,
+ NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
+ NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE,
+ NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE,
+ NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR,
+ NOUVEAU_STATE_MATERIAL_BACK_SPECULAR,
+ NOUVEAU_STATE_MATERIAL_FRONT_SHININESS,
+ NOUVEAU_STATE_MATERIAL_BACK_SHININESS,
+ NOUVEAU_STATE_MODELVIEW,
+ NOUVEAU_STATE_POINT_MODE,
+ NOUVEAU_STATE_POINT_PARAMETER,
+ NOUVEAU_STATE_POLYGON_MODE,
+ NOUVEAU_STATE_POLYGON_OFFSET,
+ NOUVEAU_STATE_POLYGON_STIPPLE,
+ NOUVEAU_STATE_PROJECTION,
+ NOUVEAU_STATE_RENDER_MODE,
+ NOUVEAU_STATE_SCISSOR,
+ NOUVEAU_STATE_SHADE_MODEL,
+ NOUVEAU_STATE_STENCIL_FUNC,
+ NOUVEAU_STATE_STENCIL_MASK,
+ NOUVEAU_STATE_STENCIL_OP,
+ NOUVEAU_STATE_TEX_ENV0,
+ NOUVEAU_STATE_TEX_ENV1,
+ NOUVEAU_STATE_TEX_ENV2,
+ NOUVEAU_STATE_TEX_ENV3,
+ NOUVEAU_STATE_TEX_GEN0,
+ NOUVEAU_STATE_TEX_GEN1,
+ NOUVEAU_STATE_TEX_GEN2,
+ NOUVEAU_STATE_TEX_GEN3,
+ NOUVEAU_STATE_TEX_OBJ0,
+ NOUVEAU_STATE_TEX_OBJ1,
+ NOUVEAU_STATE_TEX_OBJ2,
+ NOUVEAU_STATE_TEX_OBJ3,
+ NOUVEAU_STATE_VIEWPORT,
+ NUM_NOUVEAU_STATE,
+
+ /* Room for card-specific states. */
+
+ MAX_NOUVEAU_STATE = NUM_NOUVEAU_STATE + 16,
+};
+
+typedef void (*nouveau_state_func)(GLcontext *ctx, int emit);
+
+void
+nouveau_state_init(GLcontext *ctx);
+
+void
+nouveau_emit_nothing(GLcontext *ctx, int emit);
+
+int
+nouveau_next_dirty_state(GLcontext *ctx);
+
+void
+nouveau_state_emit(GLcontext *ctx);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_surface.c b/src/mesa/drivers/dri/nouveau/nouveau_surface.c
new file mode 100644
index 0000000000..33393970a0
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_surface.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_util.h"
+
+void
+nouveau_surface_alloc(GLcontext *ctx, struct nouveau_surface *s,
+ enum nouveau_surface_layout layout,
+ unsigned flags, unsigned format,
+ unsigned width, unsigned height)
+{
+ unsigned tile_mode, cpp = _mesa_get_format_bytes(format);
+ int ret;
+
+ nouveau_bo_ref(NULL, &s->bo);
+
+ *s = (struct nouveau_surface) {
+ .layout = layout,
+ .format = format,
+ .width = width,
+ .height = height,
+ .cpp = cpp,
+ .pitch = width * cpp,
+ };
+
+ if (layout == TILED) {
+ s->pitch = align(s->pitch, 256);
+ tile_mode = s->pitch;
+ } else {
+ s->pitch = align(s->pitch, 64);
+ tile_mode = 0;
+ }
+
+ ret = nouveau_bo_new_tile(context_dev(ctx), flags, 0, s->pitch * height,
+ tile_mode, 0, &s->bo);
+ assert(!ret);
+}
+
+void
+nouveau_surface_ref(struct nouveau_surface *src,
+ struct nouveau_surface *dst)
+{
+ if (src) {
+ dst->offset = src->offset;
+ dst->layout = src->layout;
+ dst->format = src->format;
+ dst->width = src->width;
+ dst->height = src->height;
+ dst->cpp = src->cpp;
+ dst->pitch = src->pitch;
+ nouveau_bo_ref(src->bo, &dst->bo);
+
+ } else {
+ nouveau_bo_ref(NULL, &dst->bo);
+ }
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_surface.h b/src/mesa/drivers/dri/nouveau/nouveau_surface.h
new file mode 100644
index 0000000000..ebdc89afb4
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_surface.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_SURFACE_H__
+#define __NOUVEAU_SURFACE_H__
+
+enum nouveau_surface_layout {
+ LINEAR = 0,
+ TILED,
+ SWIZZLED,
+};
+
+struct nouveau_surface {
+ struct nouveau_bo *bo;
+ unsigned offset;
+
+ enum nouveau_surface_layout layout;
+
+ gl_format format;
+ unsigned cpp, pitch;
+
+ unsigned width, height;
+};
+
+void
+nouveau_surface_alloc(GLcontext *ctx, struct nouveau_surface *s,
+ enum nouveau_surface_layout layout,
+ unsigned flags, unsigned format,
+ unsigned width, unsigned height);
+
+void
+nouveau_surface_ref(struct nouveau_surface *src,
+ struct nouveau_surface *dst);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c
new file mode 100644
index 0000000000..8fa922f422
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+#include "tnl/t_vertex.h"
+
+static enum tnl_attr_format
+swtnl_get_format(int type, int fields) {
+ switch (type) {
+ case GL_FLOAT:
+ switch (fields){
+ case 1:
+ return EMIT_1F;
+ case 2:
+ return EMIT_2F;
+ case 3:
+ return EMIT_3F;
+ case 4:
+ return EMIT_4F;
+ default:
+ assert(0);
+ }
+ case GL_UNSIGNED_BYTE:
+ switch (fields) {
+ case 4:
+ return EMIT_4UB_4F_RGBA;
+ default:
+ assert(0);
+ }
+ default:
+ assert(0);
+ }
+}
+
+static struct swtnl_attr_info {
+ int type;
+ int fields;
+} swtnl_attrs[VERT_ATTRIB_MAX] = {
+ [VERT_ATTRIB_POS] = {
+ .type = GL_FLOAT,
+ .fields = 4,
+ },
+ [VERT_ATTRIB_NORMAL] = {
+ .type = GL_FLOAT,
+ .fields = -1,
+ },
+ [VERT_ATTRIB_COLOR0] = {
+ .type = GL_UNSIGNED_BYTE,
+ .fields = 4,
+ },
+ [VERT_ATTRIB_COLOR1] = {
+ .type = GL_UNSIGNED_BYTE,
+ .fields = 4,
+ },
+ [VERT_ATTRIB_FOG] = {
+ .type = GL_FLOAT,
+ .fields = 1,
+ },
+ [VERT_ATTRIB_TEX0] = {
+ .type = GL_FLOAT,
+ .fields = -1,
+ },
+ [VERT_ATTRIB_TEX1] = {
+ .type = GL_FLOAT,
+ .fields = -1,
+ },
+ [VERT_ATTRIB_TEX2] = {
+ .type = GL_FLOAT,
+ .fields = -1,
+ },
+ [VERT_ATTRIB_TEX3] = {
+ .type = GL_FLOAT,
+ .fields = -1,
+ },
+};
+
+static void
+swtnl_choose_attrs(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct tnl_clipspace *vtx = &tnl->clipspace;
+ static struct tnl_attr_map map[NUM_VERTEX_ATTRS];
+ int fields, i, n = 0;
+
+ render->mode = VBO;
+ render->attr_count = NUM_VERTEX_ATTRS;
+
+ /* We always want non Ndc coords format */
+ tnl->vb.AttribPtr[VERT_ATTRIB_POS] = tnl->vb.ClipPtr;
+
+ for (i = 0; i < VERT_ATTRIB_MAX; i++) {
+ struct nouveau_attr_info *ha = &TAG(vertex_attrs)[i];
+ struct swtnl_attr_info *sa = &swtnl_attrs[i];
+ struct nouveau_array_state *a = &render->attrs[i];
+
+ if (!sa->fields)
+ continue; /* Unsupported attribute. */
+
+ if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, i)) {
+ if (sa->fields > 0)
+ fields = sa->fields;
+ else
+ fields = tnl->vb.AttribPtr[i]->size;
+
+ map[n++] = (struct tnl_attr_map) {
+ .attrib = i,
+ .format = swtnl_get_format(sa->type, fields),
+ };
+
+ render->map[ha->vbo_index] = i;
+ a->attr = i;
+ a->fields = fields;
+ a->type = sa->type;
+ }
+ }
+
+ _tnl_install_attrs(ctx, map, n, NULL, 0);
+
+ for (i = 0; i < vtx->attr_count; i++) {
+ struct tnl_clipspace_attr *ta = &vtx->attr[i];
+ struct nouveau_array_state *a = &render->attrs[ta->attrib];
+
+ a->stride = vtx->vertex_size;
+ a->offset = ta->vertoffset;
+ }
+
+ TAG(render_set_format)(ctx);
+}
+
+static void
+swtnl_alloc_vertices(GLcontext *ctx)
+{
+ struct nouveau_swtnl_state *swtnl = &to_render_state(ctx)->swtnl;
+
+ nouveau_bo_ref(NULL, &swtnl->vbo);
+ swtnl->buf = get_scratch_vbo(ctx, RENDER_SCRATCH_SIZE,
+ &swtnl->vbo, NULL);
+ swtnl->vertex_count = 0;
+}
+
+static void
+swtnl_bind_vertices(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_swtnl_state *swtnl = &render->swtnl;
+ int i;
+
+ for (i = 0; i < render->attr_count; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0)
+ nouveau_bo_ref(swtnl->vbo,
+ &render->attrs[attr].bo);
+ }
+
+ TAG(render_bind_vertices)(ctx);
+}
+
+static void
+swtnl_unbind_vertices(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ for (i = 0; i < render->attr_count; i++) {
+ int *attr = &render->map[i];
+
+ if (*attr >= 0) {
+ nouveau_bo_ref(NULL, &render->attrs[*attr].bo);
+ *attr = -1;
+ }
+ }
+
+ render->attr_count = 0;
+}
+
+static void
+swtnl_flush_vertices(GLcontext *ctx)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_swtnl_state *swtnl = &to_render_state(ctx)->swtnl;
+ unsigned push, start = 0, count = swtnl->vertex_count;
+ RENDER_LOCALS(ctx);
+
+ swtnl_bind_vertices(ctx);
+
+ while (count) {
+ push = get_max_vertices(ctx, NULL, chan->pushbuf->remaining);
+ push = MIN2(push / 12 * 12, count);
+ count -= push;
+
+ if (!push) {
+ FIRE_RING(chan);
+ continue;
+ }
+
+ BATCH_BEGIN(nvgl_primitive(swtnl->primitive));
+ EMIT_VBO(L, ctx, start, 0, push);
+ BATCH_END();
+
+ FIRE_RING(chan);
+ }
+
+ swtnl_alloc_vertices(ctx);
+}
+
+/* TnL renderer entry points */
+
+static void
+swtnl_start(GLcontext *ctx)
+{
+ swtnl_choose_attrs(ctx);
+}
+
+static void
+swtnl_finish(GLcontext *ctx)
+{
+ swtnl_flush_vertices(ctx);
+ swtnl_unbind_vertices(ctx);
+}
+
+static void
+swtnl_primitive(GLcontext *ctx, GLenum mode)
+{
+}
+
+static void
+swtnl_reset_stipple(GLcontext *ctx)
+{
+}
+
+/* Primitive rendering */
+
+#define BEGIN_PRIMITIVE(p, n) \
+ struct nouveau_swtnl_state *swtnl = &to_render_state(ctx)->swtnl; \
+ int vertex_len = TNL_CONTEXT(ctx)->clipspace.vertex_size; \
+ \
+ if (swtnl->vertex_count + (n) > swtnl->vbo->size/vertex_len \
+ || (swtnl->vertex_count && swtnl->primitive != p)) \
+ swtnl_flush_vertices(ctx); \
+ \
+ swtnl->primitive = p;
+
+#define OUT_VERTEX(i) do { \
+ memcpy(swtnl->buf + swtnl->vertex_count * vertex_len, \
+ _tnl_get_vertex(ctx, (i)), vertex_len); \
+ swtnl->vertex_count++; \
+ } while (0)
+
+static void
+swtnl_points(GLcontext *ctx, GLuint first, GLuint last)
+{
+ int i, count;
+
+ while (first < last) {
+ BEGIN_PRIMITIVE(GL_POINTS, last - first);
+
+ count = MIN2(swtnl->vbo->size / vertex_len, last - first);
+ for (i = 0; i < count; i++)
+ OUT_VERTEX(first + i);
+
+ first += count;
+ }
+}
+
+static void
+swtnl_line(GLcontext *ctx, GLuint v1, GLuint v2)
+{
+ BEGIN_PRIMITIVE(GL_LINES, 2);
+ OUT_VERTEX(v1);
+ OUT_VERTEX(v2);
+}
+
+static void
+swtnl_triangle(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3)
+{
+ BEGIN_PRIMITIVE(GL_TRIANGLES, 3);
+ OUT_VERTEX(v1);
+ OUT_VERTEX(v2);
+ OUT_VERTEX(v3);
+}
+
+static void
+swtnl_quad(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4)
+{
+ BEGIN_PRIMITIVE(GL_QUADS, 4);
+ OUT_VERTEX(v1);
+ OUT_VERTEX(v2);
+ OUT_VERTEX(v3);
+ OUT_VERTEX(v4);
+}
+
+/* TnL initialization. */
+static void
+TAG(swtnl_init)(GLcontext *ctx)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+
+ tnl->Driver.RunPipeline = _tnl_run_pipeline;
+ tnl->Driver.Render.Interp = _tnl_interp;
+ tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+ tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
+ tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
+ tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+
+ tnl->Driver.Render.Start = swtnl_start;
+ tnl->Driver.Render.Finish = swtnl_finish;
+ tnl->Driver.Render.PrimitiveNotify = swtnl_primitive;
+ tnl->Driver.Render.ResetLineStipple = swtnl_reset_stipple;
+
+ tnl->Driver.Render.Points = swtnl_points;
+ tnl->Driver.Render.Line = swtnl_line;
+ tnl->Driver.Render.Triangle = swtnl_triangle;
+ tnl->Driver.Render.Quad = swtnl_quad;
+
+ _tnl_init_vertices(ctx, tnl->vb.Size,
+ NUM_VERTEX_ATTRS * 4 * sizeof(GLfloat));
+ _tnl_need_projected_coords(ctx, GL_FALSE);
+ _tnl_allow_vertex_fog(ctx, GL_FALSE);
+ _tnl_wakeup(ctx);
+
+ swtnl_alloc_vertices(ctx);
+}
+
+static void
+TAG(swtnl_destroy)(GLcontext *ctx)
+{
+ nouveau_bo_ref(NULL, &to_render_state(ctx)->swtnl.vbo);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
new file mode 100644
index 0000000000..ab6e93cceb
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -0,0 +1,456 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_texture.h"
+#include "nouveau_util.h"
+
+#include "main/texobj.h"
+#include "main/texstore.h"
+#include "main/texformat.h"
+#include "main/texcompress.h"
+#include "main/texgetimage.h"
+#include "main/mipmap.h"
+#include "main/texfetch.h"
+
+static struct gl_texture_object *
+nouveau_texture_new(GLcontext *ctx, GLuint name, GLenum target)
+{
+ struct nouveau_texture *nt = CALLOC_STRUCT(nouveau_texture);
+
+ _mesa_initialize_texture_object(&nt->base, name, target);
+
+ return &nt->base;
+}
+
+static void
+nouveau_texture_free(GLcontext *ctx, struct gl_texture_object *t)
+{
+ struct nouveau_texture *nt = to_nouveau_texture(t);
+ int i;
+
+ for (i = 0; i < MAX_TEXTURE_LEVELS; i++)
+ nouveau_surface_ref(NULL, &nt->surfaces[i]);
+
+ _mesa_delete_texture_object(ctx, t);
+}
+
+static struct gl_texture_image *
+nouveau_teximage_new(GLcontext *ctx)
+{
+ struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage);
+
+ return &nti->base;
+}
+
+static void
+nouveau_teximage_free(GLcontext *ctx, struct gl_texture_image *ti)
+{
+ struct nouveau_teximage *nti = to_nouveau_teximage(ti);
+
+ nouveau_surface_ref(NULL, &nti->surface);
+}
+
+static void
+nouveau_teximage_map(GLcontext *ctx, struct gl_texture_image *ti)
+{
+ struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+ int ret;
+
+ ret = nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR);
+ assert(!ret);
+
+ ti->Data = s->bo->map;
+}
+
+static void
+nouveau_teximage_unmap(GLcontext *ctx, struct gl_texture_image *ti)
+{
+ struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+
+ nouveau_bo_unmap(s->bo);
+ ti->Data = NULL;
+}
+
+static gl_format
+nouveau_choose_tex_format(GLcontext *ctx, GLint internalFormat,
+ GLenum srcFormat, GLenum srcType)
+{
+ switch (internalFormat) {
+ case 4:
+ case GL_RGBA:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ case GL_RGBA8:
+ case GL_RGB:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ return MESA_FORMAT_ARGB8888;
+ case GL_RGB5_A1:
+ return MESA_FORMAT_ARGB1555;
+ case GL_RGBA2:
+ case GL_RGBA4:
+ return MESA_FORMAT_ARGB4444;
+
+ case 3:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ return MESA_FORMAT_RGB565;
+
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ case GL_ALPHA8:
+ return MESA_FORMAT_A8;
+
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ case GL_LUMINANCE8:
+ return MESA_FORMAT_L8;
+
+ case 2:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE4_ALPHA4:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ case GL_LUMINANCE8_ALPHA8:
+ return MESA_FORMAT_ARGB8888;
+
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ case GL_INTENSITY8:
+ return MESA_FORMAT_ARGB8888;
+
+ case GL_COLOR_INDEX:
+ case GL_COLOR_INDEX1_EXT:
+ case GL_COLOR_INDEX2_EXT:
+ case GL_COLOR_INDEX4_EXT:
+ case GL_COLOR_INDEX12_EXT:
+ case GL_COLOR_INDEX16_EXT:
+ case GL_COLOR_INDEX8_EXT:
+ return MESA_FORMAT_CI8;
+
+ default:
+ assert(0);
+ }
+}
+
+static void
+nouveau_teximage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+ unsigned bo_flags = NOUVEAU_BO_GART | NOUVEAU_BO_RDWR | NOUVEAU_BO_MAP;
+ int ret;
+
+ /* Allocate a new bo for the image. */
+ nouveau_surface_alloc(ctx, s, LINEAR, bo_flags, ti->TexFormat,
+ width, height);
+ ti->RowStride = s->pitch / s->cpp;
+
+ pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
+ format, type, pixels, packing,
+ "glTexImage");
+ if (!pixels)
+ return;
+
+ /* Store the pixel data. */
+ nouveau_teximage_map(ctx, ti);
+
+ ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
+ ti->TexFormat, ti->Data,
+ 0, 0, 0, s->pitch,
+ ti->ImageOffsets,
+ width, height, depth,
+ format, type, pixels, packing);
+ assert(ret);
+
+ nouveau_teximage_unmap(ctx, ti);
+ _mesa_unmap_teximage_pbo(ctx, packing);
+
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ context_dirty_i(ctx, TEX_ENV, ctx->Texture.CurrentUnit);
+ texture_dirty(t);
+}
+
+static void
+nouveau_teximage_1d(GLcontext *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage(ctx, 1, target, level, internalFormat,
+ width, 1, 1, border, format, type, pixels,
+ packing, t, ti);
+}
+
+static void
+nouveau_teximage_2d(GLcontext *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage(ctx, 2, target, level, internalFormat,
+ width, height, 1, border, format, type, pixels,
+ packing, t, ti);
+}
+
+static void
+nouveau_teximage_3d(GLcontext *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage(ctx, 3, target, level, internalFormat,
+ width, height, depth, border, format, type, pixels,
+ packing, t, ti);
+}
+
+static void
+nouveau_texsubimage_3d(GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage_map(ctx, ti);
+ _mesa_store_texsubimage3d(ctx, target, level, xoffset, yoffset, zoffset,
+ width, height, depth, format, type, pixels,
+ packing, t, ti);
+ nouveau_teximage_unmap(ctx, ti);
+
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ texture_dirty(t);
+}
+
+static void
+nouveau_texsubimage_2d(GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint width, GLint height,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage_map(ctx, ti);
+ _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset,
+ width, height, format, type, pixels,
+ packing, t, ti);
+ nouveau_teximage_unmap(ctx, ti);
+
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ texture_dirty(t);
+}
+
+static void
+nouveau_texsubimage_1d(GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint width,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage_map(ctx, ti);
+ _mesa_store_texsubimage1d(ctx, target, level, xoffset,
+ width, format, type, pixels,
+ packing, t, ti);
+ nouveau_teximage_unmap(ctx, ti);
+
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ texture_dirty(t);
+}
+
+static void
+nouveau_get_teximage(GLcontext *ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *t,
+ struct gl_texture_image *ti)
+{
+ nouveau_teximage_map(ctx, ti);
+ _mesa_get_teximage(ctx, target, level, format, type, pixels,
+ t, ti);
+ nouveau_teximage_unmap(ctx, ti);
+}
+
+static void
+nouveau_bind_texture(GLcontext *ctx, GLenum target,
+ struct gl_texture_object *t)
+{
+ context_dirty_i(ctx, TEX_OBJ, ctx->Texture.CurrentUnit);
+ context_dirty_i(ctx, TEX_ENV, ctx->Texture.CurrentUnit);
+}
+
+static void
+nouveau_texture_map(GLcontext *ctx, struct gl_texture_object *t)
+{
+ int i;
+
+ for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
+ if (t->Image[0][i])
+ nouveau_teximage_map(ctx, t->Image[0][i]);
+ }
+}
+
+static void
+nouveau_texture_unmap(GLcontext *ctx, struct gl_texture_object *t)
+{
+ int i;
+
+ for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
+ if (t->Image[0][i])
+ nouveau_teximage_unmap(ctx, t->Image[0][i]);
+ }
+}
+
+static void
+relayout_miptree(GLcontext *ctx, struct gl_texture_object *t)
+{
+ struct nouveau_surface *ss = to_nouveau_texture(t)->surfaces;
+ unsigned last_level, offset = 0;
+ unsigned size;
+ int i, ret;
+
+ if (t->MinFilter == GL_NEAREST ||
+ t->MinFilter == GL_LINEAR)
+ last_level = t->BaseLevel;
+ else
+ last_level = t->_MaxLevel;
+
+ /* Deallocate the old storage. */
+ for (i = 0; i < MAX_TEXTURE_LEVELS; i++)
+ nouveau_bo_ref(NULL, &ss[i].bo);
+
+ /* Relayout the mipmap tree. */
+ for (i = t->BaseLevel; i <= last_level; i++) {
+ struct nouveau_surface *s =
+ &to_nouveau_teximage(t->Image[0][i])->surface;
+
+ size = s->width * s->height * s->cpp;
+
+ /* Images larger than 16B have to be aligned. */
+ if (size > 16)
+ offset = align(offset, 64);
+
+ ss[i] = (struct nouveau_surface) {
+ .offset = offset,
+ .layout = SWIZZLED,
+ .format = s->format,
+ .width = s->width,
+ .height = s->height,
+ .cpp = s->cpp,
+ .pitch = s->width * s->cpp,
+ };
+
+ offset += size;
+ }
+
+ /* Get new storage. */
+ size = align(offset, 64);
+
+ ret = nouveau_bo_new(context_dev(ctx),
+ NOUVEAU_BO_GART | NOUVEAU_BO_VRAM,
+ 0, size, &ss[last_level].bo);
+ assert(!ret);
+
+ for (i = t->BaseLevel; i < last_level; i++)
+ nouveau_bo_ref(ss[last_level].bo, &ss[i].bo);
+}
+
+void
+nouveau_texture_validate(GLcontext *ctx, struct gl_texture_object *t)
+{
+ struct nouveau_texture *nt = to_nouveau_texture(t);
+ int i;
+
+ if (!nt->dirty)
+ return;
+
+ nt->dirty = GL_FALSE;
+
+ relayout_miptree(ctx, t);
+
+ /* Copy the teximages to the actual swizzled miptree. */
+ for (i = t->BaseLevel; i < MAX_TEXTURE_LEVELS; i++) {
+ struct gl_texture_image *ti = t->Image[0][i];
+ struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+
+ if (!nt->surfaces[i].bo)
+ break;
+
+ context_drv(ctx)->surface_copy(ctx, &nt->surfaces[i], s,
+ 0, 0, 0, 0,
+ s->width, s->height);
+ }
+}
+
+void
+nouveau_texture_functions_init(struct dd_function_table *functions)
+{
+ functions->NewTextureObject = nouveau_texture_new;
+ functions->DeleteTexture = nouveau_texture_free;
+ functions->NewTextureImage = nouveau_teximage_new;
+ functions->FreeTexImageData = nouveau_teximage_free;
+ functions->ChooseTextureFormat = nouveau_choose_tex_format;
+ functions->TexImage1D = nouveau_teximage_1d;
+ functions->TexImage2D = nouveau_teximage_2d;
+ functions->TexImage3D = nouveau_teximage_3d;
+ functions->TexSubImage1D = nouveau_texsubimage_1d;
+ functions->TexSubImage2D = nouveau_texsubimage_2d;
+ functions->TexSubImage3D = nouveau_texsubimage_3d;
+ functions->GetTexImage = nouveau_get_teximage;
+ functions->BindTexture = nouveau_bind_texture;
+ functions->MapTexture = nouveau_texture_map;
+ functions->UnmapTexture = nouveau_texture_unmap;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.h b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
new file mode 100644
index 0000000000..695c0897b5
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_TEXTURE_H__
+#define __NOUVEAU_TEXTURE_H__
+
+struct nouveau_teximage {
+ struct gl_texture_image base;
+ struct nouveau_surface surface;
+};
+#define to_nouveau_teximage(x) ((struct nouveau_teximage *)(x))
+
+struct nouveau_texture {
+ struct gl_texture_object base;
+ struct nouveau_surface surfaces[MAX_TEXTURE_LEVELS];
+ GLboolean dirty;
+};
+#define to_nouveau_texture(x) ((struct nouveau_texture *)(x))
+
+#define texture_dirty(t) \
+ to_nouveau_texture(t)->dirty = GL_TRUE;
+
+void
+nouveau_texture_validate(GLcontext *ctx, struct gl_texture_object *t);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_util.h b/src/mesa/drivers/dri/nouveau/nouveau_util.h
new file mode 100644
index 0000000000..076f225fed
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_util.h
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NOUVEAU_UTIL_H__
+#define __NOUVEAU_UTIL_H__
+
+#include "main/formats.h"
+#include "main/colormac.h"
+
+static inline unsigned
+pack_rgba_i(gl_format f, uint8_t c[])
+{
+ switch (f) {
+ case MESA_FORMAT_ARGB8888:
+ return PACK_COLOR_8888(c[ACOMP], c[RCOMP], c[GCOMP], c[BCOMP]);
+ case MESA_FORMAT_ARGB8888_REV:
+ return PACK_COLOR_8888(c[BCOMP], c[GCOMP], c[RCOMP], c[ACOMP]);
+ case MESA_FORMAT_XRGB8888:
+ return PACK_COLOR_8888(0, c[RCOMP], c[GCOMP], c[BCOMP]);
+ case MESA_FORMAT_XRGB8888_REV:
+ return PACK_COLOR_8888(c[BCOMP], c[GCOMP], c[RCOMP], 0);
+ case MESA_FORMAT_RGBA8888:
+ return PACK_COLOR_8888(c[RCOMP], c[GCOMP], c[BCOMP], c[ACOMP]);
+ case MESA_FORMAT_RGBA8888_REV:
+ return PACK_COLOR_8888(c[ACOMP], c[BCOMP], c[GCOMP], c[RCOMP]);
+ case MESA_FORMAT_RGB565:
+ return PACK_COLOR_565(c[RCOMP], c[GCOMP], c[BCOMP]);
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+pack_zs_i(gl_format f, uint32_t z, uint8_t s)
+{
+ switch (f) {
+ case MESA_FORMAT_Z24_S8:
+ return (z & 0xffffff00) | (s & 0xff);
+ case MESA_FORMAT_Z24_X8:
+ return (z & 0xffffff00);
+ case MESA_FORMAT_Z16:
+ return (z & 0xffff0000) >> 16;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+pack_rgba_f(gl_format f, float c[])
+{
+ return pack_rgba_i(f, (uint8_t []) {
+ FLOAT_TO_UBYTE(c[RCOMP]),
+ FLOAT_TO_UBYTE(c[GCOMP]),
+ FLOAT_TO_UBYTE(c[BCOMP]),
+ FLOAT_TO_UBYTE(c[ACOMP]) });
+}
+
+static inline unsigned
+pack_zs_f(gl_format f, float z, uint8_t s)
+{
+ return pack_zs_i(f, FLOAT_TO_UINT(z), s);
+}
+
+/* Integer base-2 logarithm, rounded towards zero. */
+static inline unsigned
+log2i(unsigned i)
+{
+ unsigned r = 0;
+
+ if (i & 0xffff0000) {
+ i >>= 16;
+ r += 16;
+ }
+ if (i & 0x0000ff00) {
+ i >>= 8;
+ r += 8;
+ }
+ if (i & 0x000000f0) {
+ i >>= 4;
+ r += 4;
+ }
+ if (i & 0x0000000c) {
+ i >>= 2;
+ r += 2;
+ }
+ if (i & 0x00000002) {
+ r += 1;
+ }
+ return r;
+}
+
+static inline unsigned
+align(unsigned x, unsigned m)
+{
+ return (x + m - 1) & ~(m - 1);
+}
+
+static inline void
+get_scissors(struct gl_framebuffer *fb, int *x, int *y, int *w, int *h)
+{
+ *w = fb->_Xmax - fb->_Xmin;
+ *h = fb->_Ymax - fb->_Ymin;
+ *x = fb->_Xmin;
+ *y = (fb->Name ? fb->_Ymin :
+ /* Window system FBO: Flip the Y coordinate. */
+ fb->Height - fb->_Ymax);
+}
+
+static inline void
+get_viewport_scale(GLcontext *ctx, float a[16])
+{
+ struct gl_viewport_attrib *vp = &ctx->Viewport;
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+
+ a[MAT_SX] = (float)vp->Width / 2;
+
+ if (fb->Name)
+ a[MAT_SY] = (float)vp->Height / 2;
+ else
+ /* Window system FBO: Flip the Y coordinate. */
+ a[MAT_SY] = - (float)vp->Height / 2;
+
+ a[MAT_SZ] = fb->_DepthMaxF * (vp->Far - vp->Near) / 2;
+}
+
+static inline void
+get_viewport_translate(GLcontext *ctx, float a[4])
+{
+ struct gl_viewport_attrib *vp = &ctx->Viewport;
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+
+ a[0] = (float)vp->Width / 2 + vp->X;
+
+ if (fb->Name)
+ a[1] = (float)vp->Height / 2 + vp->Y;
+ else
+ /* Window system FBO: Flip the Y coordinate. */
+ a[1] = fb->Height - (float)vp->Height / 2 - vp->Y;
+
+ a[2] = fb->_DepthMaxF * (vp->Far + vp->Near) / 2;
+}
+
+static inline void
+OUT_RINGm(struct nouveau_channel *chan, float m[16])
+{
+ int i, j;
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ OUT_RINGf(chan, m[4*j + i]);
+}
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
new file mode 100644
index 0000000000..ba1192a170
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
@@ -0,0 +1,409 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "main/bufferobj.h"
+#include "nouveau_bufferobj.h"
+
+/* Arbitrary pushbuf length we can assume we can get with a single
+ * WAIT_RING. */
+#define PUSHBUF_DWORDS 2048
+
+/* Functions to set up struct nouveau_array_state from something like
+ * a GL array or index buffer. */
+
+static void
+vbo_init_array(struct nouveau_array_state *a, int attr, int stride,
+ int fields, int type, struct gl_buffer_object *obj,
+ const void *ptr, GLboolean map)
+{
+ a->attr = attr;
+ a->stride = stride;
+ a->fields = fields;
+ a->type = type;
+
+ if (_mesa_is_bufferobj(obj)) {
+ nouveau_bo_ref(to_nouveau_bufferobj(obj)->bo, &a->bo);
+ a->offset = (intptr_t)ptr;
+
+ if (map) {
+ nouveau_bo_map(a->bo, NOUVEAU_BO_RD);
+ a->buf = a->bo->map + a->offset;
+ } else {
+ a->buf = NULL;
+ }
+
+ } else {
+ nouveau_bo_ref(NULL, &a->bo);
+ a->offset = 0;
+ a->buf = ptr;
+ }
+
+ if (a->buf)
+ get_array_extract(a, &a->extract_u, &a->extract_f);
+}
+
+static void
+vbo_deinit_array(struct nouveau_array_state *a)
+{
+ if (a->bo) {
+ if (a->bo->map)
+ nouveau_bo_unmap(a->bo);
+ nouveau_bo_ref(NULL, &a->bo);
+ }
+
+ a->buf = NULL;
+ a->fields = 0;
+}
+
+static void
+vbo_init_arrays(GLcontext *ctx, const struct _mesa_index_buffer *ib,
+ const struct gl_client_array **arrays)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ if (ib)
+ vbo_init_array(&render->ib, 0, 0, ib->count, ib->type,
+ ib->obj, ib->ptr, GL_TRUE);
+
+ for (i = 0; i < render->attr_count; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ const struct gl_client_array *array = arrays[attr];
+
+ vbo_init_array(&render->attrs[attr], attr,
+ array->StrideB, array->Size,
+ array->Type, array->BufferObj,
+ array->Ptr, render->mode == IMM);
+ }
+ }
+}
+
+static void
+vbo_deinit_arrays(GLcontext *ctx, const struct _mesa_index_buffer *ib,
+ const struct gl_client_array **arrays)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ if (ib)
+ vbo_deinit_array(&render->ib);
+
+ for (i = 0; i < render->attr_count; i++) {
+ int *attr = &render->map[i];
+
+ if (*attr >= 0) {
+ vbo_deinit_array(&render->attrs[*attr]);
+ *attr = -1;
+ }
+ }
+
+ render->attr_count = 0;
+}
+
+/* Make some rendering decisions from the GL context. */
+
+static void
+vbo_choose_render_mode(GLcontext *ctx, const struct gl_client_array **arrays)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ render->mode = VBO;
+
+ if (ctx->Light.Enabled) {
+ for (i = 0; i < MAT_ATTRIB_MAX; i++) {
+ if (arrays[VERT_ATTRIB_GENERIC0 + i]->StrideB) {
+ render->mode = IMM;
+ break;
+ }
+ }
+ }
+
+ if (render->mode == VBO)
+ render->attr_count = NUM_VERTEX_ATTRS;
+ else
+ render->attr_count = 0;
+}
+
+static void
+vbo_emit_attr(GLcontext *ctx, const struct gl_client_array **arrays, int attr)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_render_state *render = to_render_state(ctx);
+ const struct gl_client_array *array = arrays[attr];
+ struct nouveau_array_state *a = &render->attrs[attr];
+ RENDER_LOCALS(ctx);
+
+ if (!array->StrideB) {
+ if (attr >= VERT_ATTRIB_GENERIC0)
+ /* nouveau_update_state takes care of materials. */
+ return;
+
+ /* Constant attribute. */
+ vbo_init_array(a, attr, array->StrideB, array->Size,
+ array->Type, array->BufferObj, array->Ptr,
+ GL_TRUE);
+ EMIT_IMM(ctx, a, 0);
+ vbo_deinit_array(a);
+
+ } else {
+ /* Varying attribute. */
+ struct nouveau_attr_info *info = &TAG(vertex_attrs)[attr];
+
+ if (render->mode == VBO) {
+ render->map[info->vbo_index] = attr;
+ render->vertex_size += array->_ElementSize;
+ } else {
+ render->map[render->attr_count++] = attr;
+ render->vertex_size += 4 * info->imm_fields;
+ }
+ }
+}
+
+#define MAT(a) (VERT_ATTRIB_GENERIC0 + MAT_ATTRIB_##a)
+
+static void
+vbo_choose_attrs(GLcontext *ctx, const struct gl_client_array **arrays)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ /* Reset the vertex size. */
+ render->vertex_size = 0;
+
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_COLOR0);
+ if (ctx->Fog.ColorSumEnabled && !ctx->Light.Enabled)
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_COLOR1);
+
+ for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
+ if (ctx->Texture._EnabledCoordUnits & (1 << i))
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_TEX0 + i);
+ }
+
+ if (ctx->Fog.Enabled && ctx->Fog.FogCoordinateSource == GL_FOG_COORD)
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_FOG);
+
+ if (ctx->Light.Enabled) {
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_NORMAL);
+
+ vbo_emit_attr(ctx, arrays, MAT(FRONT_AMBIENT));
+ vbo_emit_attr(ctx, arrays, MAT(FRONT_DIFFUSE));
+ vbo_emit_attr(ctx, arrays, MAT(FRONT_SPECULAR));
+ vbo_emit_attr(ctx, arrays, MAT(FRONT_SHININESS));
+
+ if (ctx->Light.Model.TwoSide) {
+ vbo_emit_attr(ctx, arrays, MAT(BACK_AMBIENT));
+ vbo_emit_attr(ctx, arrays, MAT(BACK_DIFFUSE));
+ vbo_emit_attr(ctx, arrays, MAT(BACK_SPECULAR));
+ vbo_emit_attr(ctx, arrays, MAT(BACK_SHININESS));
+ }
+ }
+
+ vbo_emit_attr(ctx, arrays, VERT_ATTRIB_POS);
+}
+
+static void
+TAG(vbo_render_prims)(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index, GLuint max_index);
+
+static GLboolean
+vbo_maybe_split(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLuint min_index, GLuint max_index)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ unsigned pushbuf_avail = PUSHBUF_DWORDS - 2 * nctx->bo.count,
+ vert_avail = get_max_vertices(ctx, NULL, pushbuf_avail),
+ idx_avail = get_max_vertices(ctx, ib, pushbuf_avail);
+
+ if ((ib && ib->count > idx_avail) ||
+ (!ib && max_index - min_index > vert_avail)) {
+ struct split_limits limits = {
+ .max_verts = vert_avail,
+ .max_indices = idx_avail,
+ .max_vb_size = ~0,
+ };
+
+ vbo_split_prims(ctx, arrays, prims, nr_prims, ib, min_index,
+ max_index, TAG(vbo_render_prims), &limits);
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+/* VBO rendering path. */
+
+static void
+vbo_bind_vertices(GLcontext *ctx, const struct gl_client_array **arrays,
+ GLint basevertex, GLuint min_index, GLuint max_index)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ int i;
+
+ for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ const struct gl_client_array *array = arrays[attr];
+ struct nouveau_array_state *a = &render->attrs[attr];
+ unsigned delta = (basevertex + min_index) * a->stride,
+ size = (max_index - min_index + 1) * a->stride;
+
+ if (a->bo) {
+ a->offset = (intptr_t)array->Ptr + delta;
+ } else {
+ void *scratch = get_scratch_vbo(ctx, size,
+ &a->bo,
+ &a->offset);
+
+ memcpy(scratch, a->buf + delta, size);
+ }
+ }
+ }
+
+ TAG(render_bind_vertices)(ctx);
+}
+
+static void
+vbo_draw_vbo(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib, GLuint min_index,
+ GLuint max_index)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ dispatch_t dispatch;
+ int delta = -min_index, basevertex = 0, i;
+ RENDER_LOCALS(ctx);
+
+ get_array_dispatch(&to_render_state(ctx)->ib, &dispatch);
+
+ TAG(render_set_format)(ctx);
+
+ for (i = 0; i < nr_prims; i++) {
+ unsigned start = prims[i].start,
+ count = prims[i].count;
+
+ if (i == 0 || basevertex != prims[i].basevertex) {
+ basevertex = prims[i].basevertex;
+ vbo_bind_vertices(ctx, arrays, basevertex,
+ min_index, max_index);
+ }
+
+ if (count > get_max_vertices(ctx, ib, chan->pushbuf->remaining))
+ WAIT_RING(chan, PUSHBUF_DWORDS);
+
+ BATCH_BEGIN(nvgl_primitive(prims[i].mode));
+ dispatch(ctx, start, delta, count);
+ BATCH_END();
+ }
+
+ FIRE_RING(chan);
+}
+
+/* Immediate rendering path. */
+
+static unsigned
+extract_id(struct nouveau_array_state *a, int i, int j)
+{
+ return j;
+}
+
+static void
+vbo_draw_imm(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib, GLuint min_index,
+ GLuint max_index)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ extract_u_t extract = ib ? render->ib.extract_u : extract_id;
+ int i, j, k;
+ RENDER_LOCALS(ctx);
+
+ for (i = 0; i < nr_prims; i++) {
+ unsigned start = prims[i].start,
+ end = start + prims[i].count;
+
+ if (prims[i].count > get_max_vertices(ctx, ib,
+ chan->pushbuf->remaining))
+ WAIT_RING(chan, PUSHBUF_DWORDS);
+
+ BATCH_BEGIN(nvgl_primitive(prims[i].mode));
+
+ for (; start < end; start++) {
+ j = prims[i].basevertex +
+ extract(&render->ib, 0, start);
+
+ for (k = 0; k < render->attr_count; k++)
+ EMIT_IMM(ctx, &render->attrs[render->map[k]],
+ j);
+ }
+
+ BATCH_END();
+ }
+
+ FIRE_RING(chan);
+}
+
+/* draw_prims entry point when we're doing hw-tnl. */
+
+static void
+TAG(vbo_render_prims)(GLcontext *ctx, const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims, GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index, GLuint max_index)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+
+ if (!index_bounds_valid)
+ vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
+
+ vbo_choose_render_mode(ctx, arrays);
+ vbo_choose_attrs(ctx, arrays);
+
+ if (vbo_maybe_split(ctx, arrays, prims, nr_prims, ib, min_index,
+ max_index))
+ return;
+
+ vbo_init_arrays(ctx, ib, arrays);
+
+ if (render->mode == VBO)
+ vbo_draw_vbo(ctx, arrays, prims, nr_prims, ib, min_index,
+ max_index);
+ else
+ vbo_draw_imm(ctx, arrays, prims, nr_prims, ib, min_index,
+ max_index);
+
+ vbo_deinit_arrays(ctx, ib, arrays);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_context.c b/src/mesa/drivers/dri/nouveau/nv04_context.c
new file mode 100644
index 0000000000..5548286a73
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_context.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+struct nouveau_grobj *
+nv04_context_engine(GLcontext *ctx)
+{
+ struct nv04_context *nctx = to_nv04_context(ctx);
+ struct nouveau_screen *screen = nctx->base.screen;
+ struct nouveau_grobj *fahrenheit;
+
+ if (ctx->Texture.Unit[0].EnvMode == GL_COMBINE ||
+ ctx->Texture.Unit[0].EnvMode == GL_BLEND ||
+ ctx->Texture.Unit[1]._ReallyEnabled ||
+ ctx->Stencil.Enabled)
+ fahrenheit = screen->eng3dm;
+ else
+ fahrenheit = screen->eng3d;
+
+ if (fahrenheit != nctx->eng3d) {
+ nctx->eng3d = fahrenheit;
+
+ if (nv04_mtex_engine(fahrenheit)) {
+ context_dirty_i(ctx, TEX_ENV, 0);
+ context_dirty_i(ctx, TEX_ENV, 1);
+ context_dirty_i(ctx, TEX_OBJ, 0);
+ context_dirty_i(ctx, TEX_OBJ, 1);
+ context_dirty(ctx, CONTROL);
+ context_dirty(ctx, BLEND);
+ } else {
+ context_bctx_i(ctx, TEXTURE, 1);
+ context_dirty_i(ctx, TEX_ENV, 0);
+ context_dirty_i(ctx, TEX_OBJ, 0);
+ context_dirty(ctx, CONTROL);
+ context_dirty(ctx, BLEND);
+ }
+ }
+
+ return fahrenheit;
+}
+
+static void
+init_dummy_texture(GLcontext *ctx)
+{
+ struct nouveau_surface *s = &to_nv04_context(ctx)->dummy_texture;
+
+ nouveau_surface_alloc(ctx, s, SWIZZLED,
+ NOUVEAU_BO_MAP | NOUVEAU_BO_VRAM,
+ MESA_FORMAT_ARGB8888, 1, 1);
+
+ nouveau_bo_map(s->bo, NOUVEAU_BO_WR);
+ *(uint32_t *)s->bo->map = 0xffffffff;
+ nouveau_bo_unmap(s->bo);
+}
+
+GLcontext *
+nv04_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx)
+{
+ struct nv04_context *nctx;
+ GLcontext *ctx;
+
+ nctx = CALLOC_STRUCT(nv04_context);
+ if (!nctx)
+ return NULL;
+
+ ctx = &nctx->base.base;
+ nouveau_context_init(ctx, screen, visual, share_ctx);
+
+ ctx->Const.MaxTextureCoordUnits = NV04_TEXTURE_UNITS;
+ ctx->Const.MaxTextureImageUnits = NV04_TEXTURE_UNITS;
+ ctx->Const.MaxTextureUnits = NV04_TEXTURE_UNITS;
+ ctx->Const.MaxTextureMaxAnisotropy = 2;
+ ctx->Const.MaxTextureLodBias = 15;
+
+ init_dummy_texture(ctx);
+ nv04_render_init(ctx);
+
+ return ctx;
+}
+
+void
+nv04_context_destroy(GLcontext *ctx)
+{
+ nv04_render_destroy(ctx);
+ nouveau_surface_ref(NULL, &to_nv04_context(ctx)->dummy_texture);
+
+ FREE(ctx);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_context.h b/src/mesa/drivers/dri/nouveau/nv04_context.h
new file mode 100644
index 0000000000..ed4eec9865
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_context.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NV04_CONTEXT_H__
+#define __NV04_CONTEXT_H__
+
+#include "nouveau_context.h"
+
+struct nv04_context {
+ struct nouveau_context base;
+ struct nouveau_grobj *eng3d;
+ struct nouveau_surface dummy_texture;
+ float viewport[16];
+};
+#define to_nv04_context(ctx) ((struct nv04_context *)(ctx))
+
+#define nv04_mtex_engine(obj) ((obj)->grclass == NV04_MULTITEX_TRIANGLE)
+
+struct nouveau_grobj *
+nv04_context_engine(GLcontext *ctx);
+
+GLcontext *
+nv04_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx);
+
+void
+nv04_context_destroy(GLcontext *ctx);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nv04_driver.h b/src/mesa/drivers/dri/nouveau/nv04_driver.h
new file mode 100644
index 0000000000..00668710ac
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_driver.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NV04_DRIVER_H__
+#define __NV04_DRIVER_H__
+
+#include "nv04_context.h"
+
+enum {
+ NOUVEAU_STATE_BLEND = NUM_NOUVEAU_STATE,
+ NOUVEAU_STATE_CONTROL,
+ NUM_NV04_STATE
+};
+
+#define NV04_TEXTURE_UNITS 2
+
+/* nv04_screen.c */
+GLboolean
+nv04_screen_init(struct nouveau_screen *screen);
+
+/* nv04_render.c */
+void
+nv04_render_init(GLcontext *ctx);
+
+void
+nv04_render_destroy(GLcontext *ctx);
+
+/* nv04_surface.c */
+GLboolean
+nv04_surface_init(struct nouveau_screen *screen);
+
+void
+nv04_surface_takedown(struct nouveau_screen *screen);
+
+void
+nv04_surface_copy(GLcontext *ctx,
+ struct nouveau_surface *dst, struct nouveau_surface *src,
+ int dx, int dy, int sx, int sy, int w, int h);
+
+void
+nv04_surface_fill(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ unsigned mask, unsigned value,
+ int dx, int dy, int w, int h);
+
+/* nv04_state_fb.c */
+void
+nv04_emit_framebuffer(GLcontext *ctx, int emit);
+
+void
+nv04_emit_scissor(GLcontext *ctx, int emit);
+
+/* nv04_state_raster.c */
+void
+nv04_defer_control(GLcontext *ctx, int emit);
+
+void
+nv04_emit_control(GLcontext *ctx, int emit);
+
+void
+nv04_defer_blend(GLcontext *ctx, int emit);
+
+void
+nv04_emit_blend(GLcontext *ctx, int emit);
+
+/* nv04_state_frag.c */
+void
+nv04_emit_tex_env(GLcontext *ctx, int emit);
+
+/* nv04_state_tex.c */
+void
+nv04_emit_tex_obj(GLcontext *ctx, int emit);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nv04_render.c b/src/mesa/drivers/dri/nouveau/nv04_render.c
new file mode 100644
index 0000000000..b5943d9987
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_render.c
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+#include "tnl/tnl.h"
+#include "tnl/t_pipeline.h"
+#include "tnl/t_vertex.h"
+
+#define NUM_VERTEX_ATTRS 6
+
+static void
+swtnl_update_viewport(GLcontext *ctx)
+{
+ float *viewport = to_nv04_context(ctx)->viewport;
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+
+ get_viewport_scale(ctx, viewport);
+ get_viewport_translate(ctx, &viewport[MAT_TX]);
+
+ /* It wants normalized Z coordinates. */
+ viewport[MAT_SZ] /= fb->_DepthMaxF;
+ viewport[MAT_TZ] /= fb->_DepthMaxF;
+}
+
+static void
+swtnl_emit_attr(GLcontext *ctx, struct tnl_attr_map *m, int attr, int emit)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+
+ if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, attr))
+ *m = (struct tnl_attr_map) {
+ .attrib = attr,
+ .format = emit,
+ };
+ else
+ *m = (struct tnl_attr_map) {
+ .format = EMIT_PAD,
+ .offset = _tnl_format_info[emit].attrsize,
+ };
+}
+
+static void
+swtnl_choose_attrs(GLcontext *ctx)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
+ struct nv04_context *nctx = to_nv04_context(ctx);
+ static struct tnl_attr_map map[NUM_VERTEX_ATTRS];
+ int n = 0;
+
+ tnl->vb.AttribPtr[VERT_ATTRIB_POS] = tnl->vb.NdcPtr;
+
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT);
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA);
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR);
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_FOG, EMIT_1UB_1F);
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX0, EMIT_2F);
+ if (nv04_mtex_engine(fahrenheit))
+ swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX1, EMIT_2F);
+
+ swtnl_update_viewport(ctx);
+
+ _tnl_install_attrs(ctx, map, n, nctx->viewport, 0);
+}
+
+/* TnL renderer entry points */
+
+static void
+swtnl_start(GLcontext *ctx)
+{
+ swtnl_choose_attrs(ctx);
+}
+
+static void
+swtnl_finish(GLcontext *ctx)
+{
+ FIRE_RING(context_chan(ctx));
+}
+
+static void
+swtnl_primitive(GLcontext *ctx, GLenum mode)
+{
+}
+
+static void
+swtnl_reset_stipple(GLcontext *ctx)
+{
+}
+
+/* Primitive rendering */
+
+#define BEGIN_PRIMITIVE(n) \
+ struct nouveau_channel *chan = context_chan(ctx); \
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); \
+ int vertex_len = TNL_CONTEXT(ctx)->clipspace.vertex_size / 4; \
+ \
+ if (nv04_mtex_engine(fahrenheit)) \
+ BEGIN_RING(chan, fahrenheit, \
+ NV04_MULTITEX_TRIANGLE_TLMTVERTEX_SX(0), \
+ n * vertex_len); \
+ else \
+ BEGIN_RING(chan, fahrenheit, \
+ NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0), \
+ n * vertex_len); \
+
+#define OUT_VERTEX(i) \
+ OUT_RINGp(chan, _tnl_get_vertex(ctx, i), vertex_len);
+
+#define END_PRIMITIVE(draw) \
+ if (nv04_mtex_engine(fahrenheit)) { \
+ BEGIN_RING(chan, fahrenheit, \
+ NV04_MULTITEX_TRIANGLE_DRAWPRIMITIVE(0), 1); \
+ OUT_RING(chan, draw); \
+ } else { \
+ BEGIN_RING(chan, fahrenheit, \
+ NV04_TEXTURED_TRIANGLE_DRAWPRIMITIVE(0), 1); \
+ OUT_RING(chan, draw); \
+ }
+
+static void
+swtnl_points(GLcontext *ctx, GLuint first, GLuint last)
+{
+}
+
+static void
+swtnl_line(GLcontext *ctx, GLuint v1, GLuint v2)
+{
+}
+
+static void
+swtnl_triangle(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3)
+{
+ BEGIN_PRIMITIVE(3);
+ OUT_VERTEX(v1);
+ OUT_VERTEX(v2);
+ OUT_VERTEX(v3);
+ END_PRIMITIVE(0x210);
+}
+
+static void
+swtnl_quad(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4)
+{
+ BEGIN_PRIMITIVE(4);
+ OUT_VERTEX(v1);
+ OUT_VERTEX(v2);
+ OUT_VERTEX(v3);
+ OUT_VERTEX(v4);
+ END_PRIMITIVE(0x320210);
+}
+
+/* TnL initialization. */
+void
+nv04_render_init(GLcontext *ctx)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+
+ tnl->Driver.RunPipeline = _tnl_run_pipeline;
+ tnl->Driver.Render.Interp = _tnl_interp;
+ tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+ tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
+ tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
+ tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+
+ tnl->Driver.Render.Start = swtnl_start;
+ tnl->Driver.Render.Finish = swtnl_finish;
+ tnl->Driver.Render.PrimitiveNotify = swtnl_primitive;
+ tnl->Driver.Render.ResetLineStipple = swtnl_reset_stipple;
+
+ tnl->Driver.Render.Points = swtnl_points;
+ tnl->Driver.Render.Line = swtnl_line;
+ tnl->Driver.Render.Triangle = swtnl_triangle;
+ tnl->Driver.Render.Quad = swtnl_quad;
+
+ _tnl_need_projected_coords(ctx, GL_TRUE);
+ _tnl_init_vertices(ctx, tnl->vb.Size,
+ NUM_VERTEX_ATTRS * 4 * sizeof(GLfloat));
+ _tnl_allow_pixel_fog(ctx, GL_FALSE);
+ _tnl_wakeup(ctx);
+}
+
+void
+nv04_render_destroy(GLcontext *ctx)
+{
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_screen.c b/src/mesa/drivers/dri/nouveau/nv04_screen.c
new file mode 100644
index 0000000000..0fc0f4c391
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_screen.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_screen.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+static const struct nouveau_driver nv04_driver;
+
+static void
+nv04_hwctx_init(struct nouveau_screen *screen)
+{
+ struct nouveau_channel *chan = screen->chan;
+ struct nouveau_grobj *surf3d = screen->surf3d;
+ struct nouveau_grobj *eng3d = screen->eng3d;
+ struct nouveau_grobj *eng3dm = screen->eng3dm;
+
+ BIND_RING(chan, surf3d, 7);
+ BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_DMA_NOTIFY, 3);
+ OUT_RING(chan, screen->ntfy->handle);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->vram->handle);
+
+ BEGIN_RING(chan, eng3d, NV04_TEXTURED_TRIANGLE_DMA_NOTIFY, 4);
+ OUT_RING(chan, screen->ntfy->handle);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->gart->handle);
+ OUT_RING(chan, surf3d->handle);
+
+ BEGIN_RING(chan, eng3dm, NV04_MULTITEX_TRIANGLE_DMA_NOTIFY, 4);
+ OUT_RING(chan, screen->ntfy->handle);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->gart->handle);
+ OUT_RING(chan, surf3d->handle);
+
+ FIRE_RING(chan);
+}
+
+static void
+nv04_channel_flush_notify(struct nouveau_channel *chan)
+{
+ struct nouveau_screen *screen = chan->user_private;
+ struct nouveau_context *nctx = screen->context;
+
+ if (nctx && nctx->fallback < SWRAST) {
+ GLcontext *ctx = &nctx->base;
+
+ /* Flushing seems to clobber the engine context. */
+ context_dirty_i(ctx, TEX_OBJ, 0);
+ context_dirty_i(ctx, TEX_OBJ, 1);
+ context_dirty_i(ctx, TEX_ENV, 0);
+ context_dirty_i(ctx, TEX_ENV, 1);
+ context_dirty(ctx, CONTROL);
+ context_dirty(ctx, BLEND);
+
+ nouveau_state_emit(ctx);
+ }
+}
+
+GLboolean
+nv04_screen_init(struct nouveau_screen *screen)
+{
+ int ret;
+
+ screen->driver = &nv04_driver;
+ screen->chan->flush_notify = nv04_channel_flush_notify;
+
+ /* 2D engine. */
+ ret = nv04_surface_init(screen);
+ if (!ret)
+ return GL_FALSE;
+
+ /* 3D engine. */
+ ret = nouveau_grobj_alloc(screen->chan, 0xbeef0001,
+ NV04_TEXTURED_TRIANGLE, &screen->eng3d);
+ if (ret)
+ return GL_FALSE;
+
+ ret = nouveau_grobj_alloc(screen->chan, 0xbeef0002,
+ NV04_MULTITEX_TRIANGLE, &screen->eng3dm);
+ if (ret)
+ return GL_FALSE;
+
+ ret = nouveau_grobj_alloc(screen->chan, 0xbeef0003,
+ NV04_CONTEXT_SURFACES_3D, &screen->surf3d);
+ if (ret)
+ return GL_FALSE;
+
+ nv04_hwctx_init(screen);
+
+ return GL_TRUE;
+}
+
+static void
+nv04_screen_destroy(struct nouveau_screen *screen)
+{
+ if (screen->eng3d)
+ nouveau_grobj_free(&screen->eng3d);
+
+ if (screen->eng3dm)
+ nouveau_grobj_free(&screen->eng3dm);
+
+ if (screen->surf3d)
+ nouveau_grobj_free(&screen->surf3d);
+
+ nv04_surface_takedown(screen);
+}
+
+static const struct nouveau_driver nv04_driver = {
+ .screen_destroy = nv04_screen_destroy,
+ .context_create = nv04_context_create,
+ .context_destroy = nv04_context_destroy,
+ .surface_copy = nv04_surface_copy,
+ .surface_fill = nv04_surface_fill,
+ .emit = (nouveau_state_func[]) {
+ nv04_defer_control,
+ nouveau_emit_nothing,
+ nv04_defer_blend,
+ nv04_defer_blend,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv04_defer_control,
+ nouveau_emit_nothing,
+ nv04_defer_control,
+ nouveau_emit_nothing,
+ nv04_defer_control,
+ nv04_defer_control,
+ nouveau_emit_nothing,
+ nv04_emit_framebuffer,
+ nv04_defer_blend,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv04_emit_scissor,
+ nv04_defer_blend,
+ nv04_defer_control,
+ nv04_defer_control,
+ nv04_defer_control,
+ nv04_emit_tex_env,
+ nv04_emit_tex_env,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv04_emit_tex_obj,
+ nv04_emit_tex_obj,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv04_emit_blend,
+ nv04_emit_control,
+ },
+ .num_emit = NUM_NV04_STATE,
+};
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_fb.c b/src/mesa/drivers/dri/nouveau/nv04_state_fb.c
new file mode 100644
index 0000000000..e97eb2a03b
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_fb.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+static inline unsigned
+get_rt_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_XRGB8888:
+ return 0x05;
+ case MESA_FORMAT_ARGB8888:
+ return 0x08;
+ case MESA_FORMAT_RGB565:
+ return 0x03;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv04_emit_framebuffer(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_screen *screen = to_nouveau_context(ctx)->screen;
+ struct nouveau_grobj *surf3d = screen->surf3d;
+ struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct nouveau_surface *s;
+ uint32_t rt_format = NV04_CONTEXT_SURFACES_3D_FORMAT_TYPE_PITCH;
+ uint32_t rt_pitch = 0, zeta_pitch = 0;
+ unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR;
+
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT)
+ return;
+
+ /* Render target */
+ if (fb->_NumColorDrawBuffers) {
+ s = &to_nouveau_renderbuffer(
+ fb->_ColorDrawBuffers[0])->surface;
+
+ rt_format |= get_rt_format(s->format);
+ zeta_pitch = rt_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, surf3d,
+ NV04_CONTEXT_SURFACES_3D_OFFSET_COLOR,
+ s->bo, 0, bo_flags);
+ }
+
+ /* depth/stencil */
+ if (fb->_DepthBuffer) {
+ s = &to_nouveau_renderbuffer(
+ fb->_DepthBuffer->Wrapped)->surface;
+
+ zeta_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, surf3d,
+ NV04_CONTEXT_SURFACES_3D_OFFSET_ZETA,
+ s->bo, 0, bo_flags);
+ }
+
+ BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_FORMAT, 1);
+ OUT_RING(chan, rt_format);
+ BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_PITCH, 1);
+ OUT_RING(chan, zeta_pitch << 16 | rt_pitch);
+
+ /* Recompute the scissor state. */
+ context_dirty(ctx, SCISSOR);
+}
+
+void
+nv04_emit_scissor(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_screen *screen = to_nouveau_context(ctx)->screen;
+ struct nouveau_grobj *surf3d = screen->surf3d;
+ int x, y, w, h;
+
+ get_scissors(ctx->DrawBuffer, &x, &y, &w, &h);
+
+ BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_CLIP_HORIZONTAL, 2);
+ OUT_RING(chan, w << 16 | x);
+ OUT_RING(chan, h << 16 | y);
+
+ /* Messing with surf3d invalidates some engine state. */
+ context_dirty(ctx, CONTROL);
+ context_dirty(ctx, BLEND);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_frag.c b/src/mesa/drivers/dri/nouveau/nv04_state_frag.c
new file mode 100644
index 0000000000..34ee296202
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_frag.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+#define COMBINER_SHIFT(in) \
+ (NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_ARGUMENT##in##_SHIFT \
+ - NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_ARGUMENT0_SHIFT)
+#define COMBINER_SOURCE(reg) \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_ARGUMENT0_##reg
+#define COMBINER_INVERT \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_INVERSE0
+#define COMBINER_ALPHA \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_ALPHA0
+
+struct combiner_state {
+ int unit;
+ GLboolean alpha;
+
+ /* GL state */
+ GLenum mode;
+ GLenum *source;
+ GLenum *operand;
+ GLuint logscale;
+
+ /* Derived HW state */
+ uint32_t hw;
+};
+
+#define __INIT_COMBINER_ALPHA_A GL_TRUE
+#define __INIT_COMBINER_ALPHA_RGB GL_FALSE
+
+/* Initialize a combiner_state struct from the texture unit
+ * context. */
+#define INIT_COMBINER(chan, rc, i) do { \
+ struct gl_tex_env_combine_state *c = \
+ ctx->Texture.Unit[i]._CurrentCombine; \
+ (rc)->alpha = __INIT_COMBINER_ALPHA_##chan; \
+ (rc)->unit = i; \
+ (rc)->mode = c->Mode##chan; \
+ (rc)->source = c->Source##chan; \
+ (rc)->operand = c->Operand##chan; \
+ (rc)->logscale = c->ScaleShift##chan; \
+ (rc)->hw = 0; \
+ } while (0)
+
+/* Get the combiner source for the specified EXT_texture_env_combine
+ * argument. */
+static uint32_t
+get_arg_source(struct combiner_state *rc, int arg)
+{
+ switch (rc->source[arg]) {
+ case GL_TEXTURE:
+ return rc->unit ? COMBINER_SOURCE(TEXTURE1) :
+ COMBINER_SOURCE(TEXTURE0);
+
+ case GL_TEXTURE0:
+ return COMBINER_SOURCE(TEXTURE0);
+
+ case GL_TEXTURE1:
+ return COMBINER_SOURCE(TEXTURE1);
+
+ case GL_CONSTANT:
+ return COMBINER_SOURCE(CONSTANT);
+
+ case GL_PRIMARY_COLOR:
+ return COMBINER_SOURCE(PRIMARY_COLOR);
+
+ case GL_PREVIOUS:
+ return rc->unit ? COMBINER_SOURCE(PREVIOUS) :
+ COMBINER_SOURCE(PRIMARY_COLOR);
+
+ default:
+ assert(0);
+ }
+}
+
+/* Get the (possibly inverted) combiner input mapping for the
+ * specified argument. */
+#define INVERT 0x1
+
+static uint32_t
+get_arg_mapping(struct combiner_state *rc, int arg, int flags)
+{
+ int map = 0;
+
+ switch (rc->operand[arg]) {
+ case GL_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_COLOR:
+ break;
+
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ map |= rc->alpha ? 0 : COMBINER_ALPHA;
+ break;
+ }
+
+ switch (rc->operand[arg]) {
+ case GL_SRC_COLOR:
+ case GL_SRC_ALPHA:
+ map |= flags & INVERT ? COMBINER_INVERT : 0;
+ break;
+
+ case GL_ONE_MINUS_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ map |= flags & INVERT ? 0 : COMBINER_INVERT;
+ break;
+ }
+
+ return map;
+}
+
+/* Bind the combiner input <in> to the combiner source <src>,
+ * possibly inverted. */
+#define INPUT_SRC(rc, in, src, flags) \
+ (rc)->hw |= ((flags & INVERT ? COMBINER_INVERT : 0) | \
+ COMBINER_SOURCE(src)) << COMBINER_SHIFT(in)
+
+/* Bind the combiner input <in> to the EXT_texture_env_combine
+ * argument <arg>, possibly inverted. */
+#define INPUT_ARG(rc, in, arg, flags) \
+ (rc)->hw |= (get_arg_source(rc, arg) | \
+ get_arg_mapping(rc, arg, flags)) << COMBINER_SHIFT(in)
+
+#define UNSIGNED_OP(rc) \
+ (rc)->hw |= ((rc)->logscale ? \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_MAP_SCALE2 : \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_MAP_IDENTITY)
+#define SIGNED_OP(rc) \
+ (rc)->hw |= ((rc)->logscale ? \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_MAP_BIAS_SCALE2 : \
+ NV04_MULTITEX_TRIANGLE_COMBINE_COLOR_MAP_BIAS)
+
+static void
+setup_combiner(struct combiner_state *rc)
+{
+ switch (rc->mode) {
+ case GL_REPLACE:
+ INPUT_ARG(rc, 0, 0, 0);
+ INPUT_SRC(rc, 1, ZERO, INVERT);
+ INPUT_SRC(rc, 2, ZERO, 0);
+ INPUT_SRC(rc, 3, ZERO, 0);
+ UNSIGNED_OP(rc);
+ break;
+
+ case GL_MODULATE:
+ INPUT_ARG(rc, 0, 0, 0);
+ INPUT_ARG(rc, 1, 1, 0);
+ INPUT_SRC(rc, 2, ZERO, 0);
+ INPUT_SRC(rc, 3, ZERO, 0);
+ UNSIGNED_OP(rc);
+ break;
+
+ case GL_ADD:
+ INPUT_ARG(rc, 0, 0, 0);
+ INPUT_SRC(rc, 1, ZERO, INVERT);
+ INPUT_ARG(rc, 2, 1, 0);
+ INPUT_SRC(rc, 3, ZERO, INVERT);
+ UNSIGNED_OP(rc);
+ break;
+
+ case GL_INTERPOLATE:
+ INPUT_ARG(rc, 0, 0, 0);
+ INPUT_ARG(rc, 1, 2, 0);
+ INPUT_ARG(rc, 2, 1, 0);
+ INPUT_ARG(rc, 3, 2, INVERT);
+ UNSIGNED_OP(rc);
+ break;
+
+ case GL_ADD_SIGNED:
+ INPUT_ARG(rc, 0, 0, 0);
+ INPUT_SRC(rc, 1, ZERO, INVERT);
+ INPUT_ARG(rc, 2, 1, 0);
+ INPUT_SRC(rc, 3, ZERO, INVERT);
+ SIGNED_OP(rc);
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+void
+nv04_emit_tex_env(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_ENV0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
+ struct combiner_state rc_a = {}, rc_c = {};
+
+ if (!nv04_mtex_engine(fahrenheit)) {
+ context_dirty(ctx, BLEND);
+ return;
+ }
+
+ /* Compute the new combiner state. */
+ if (ctx->Texture.Unit[i]._ReallyEnabled) {
+ INIT_COMBINER(A, &rc_a, i);
+ setup_combiner(&rc_a);
+
+ INIT_COMBINER(RGB, &rc_c, i);
+ setup_combiner(&rc_c);
+
+ } else {
+ if (i == 0) {
+ INPUT_SRC(&rc_a, 0, PRIMARY_COLOR, 0);
+ INPUT_SRC(&rc_c, 0, PRIMARY_COLOR, 0);
+ } else {
+ INPUT_SRC(&rc_a, 0, PREVIOUS, 0);
+ INPUT_SRC(&rc_c, 0, PREVIOUS, 0);
+ }
+
+ INPUT_SRC(&rc_a, 1, ZERO, INVERT);
+ INPUT_SRC(&rc_c, 1, ZERO, INVERT);
+ INPUT_SRC(&rc_a, 2, ZERO, 0);
+ INPUT_SRC(&rc_c, 2, ZERO, 0);
+ INPUT_SRC(&rc_a, 3, ZERO, 0);
+ INPUT_SRC(&rc_c, 3, ZERO, 0);
+
+ UNSIGNED_OP(&rc_a);
+ UNSIGNED_OP(&rc_c);
+ }
+
+ /* Write the register combiner state out to the hardware. */
+ BEGIN_RING(chan, fahrenheit,
+ NV04_MULTITEX_TRIANGLE_COMBINE_ALPHA(i), 2);
+ OUT_RING(chan, rc_a.hw);
+ OUT_RING(chan, rc_c.hw);
+
+ BEGIN_RING(chan, fahrenheit,
+ NV04_MULTITEX_TRIANGLE_COMBINE_FACTOR, 1);
+ OUT_RING(chan, pack_rgba_f(MESA_FORMAT_ARGB8888,
+ ctx->Texture.Unit[0].EnvColor));
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_raster.c b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
new file mode 100644
index 0000000000..5e3788d185
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+static unsigned
+get_comparison_op(unsigned op)
+{
+ switch (op) {
+ case GL_NEVER:
+ return 0x1;
+ case GL_LESS:
+ return 0x2;
+ case GL_EQUAL:
+ return 0x3;
+ case GL_LEQUAL:
+ return 0x4;
+ case GL_GREATER:
+ return 0x5;
+ case GL_NOTEQUAL:
+ return 0x6;
+ case GL_GEQUAL:
+ return 0x7;
+ case GL_ALWAYS:
+ return 0x8;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_stencil_op(unsigned op)
+{
+ switch (op) {
+ case GL_KEEP:
+ return 0x1;
+ case GL_INCR:
+ return 0x4;
+ case GL_DECR:
+ return 0x5;
+ case GL_INVERT:
+ return 0x6;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_texenv_mode(unsigned mode)
+{
+ switch (mode) {
+ case GL_REPLACE:
+ return 0x1;
+ case GL_ADD:
+ return 0x2;
+ case GL_DECAL:
+ return 0x3;
+ case GL_MODULATE:
+ return 0x4;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_blend_func(unsigned func)
+{
+ switch (func) {
+ case GL_ZERO:
+ return 0x1;
+ case GL_ONE:
+ return 0x2;
+ case GL_SRC_COLOR:
+ return 0x3;
+ case GL_ONE_MINUS_SRC_COLOR:
+ return 0x4;
+ case GL_SRC_ALPHA:
+ return 0x5;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ return 0x6;
+ case GL_DST_ALPHA:
+ return 0x7;
+ case GL_ONE_MINUS_DST_ALPHA:
+ return 0x8;
+ case GL_DST_COLOR:
+ return 0x9;
+ case GL_ONE_MINUS_DST_COLOR:
+ return 0xa;
+ case GL_SRC_ALPHA_SATURATE:
+ return 0xb;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv04_defer_control(GLcontext *ctx, int emit)
+{
+ context_dirty(ctx, CONTROL);
+}
+
+void
+nv04_emit_control(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
+
+ if (nv04_mtex_engine(fahrenheit)) {
+ int cull_mode = ctx->Polygon.CullFaceMode;
+ int front_face = ctx->Polygon.FrontFace;
+ uint32_t ctrl0 = 1 << 30 |
+ NV04_MULTITEX_TRIANGLE_CONTROL0_ORIGIN;
+ uint32_t ctrl1 = 0, ctrl2 = 0;
+
+ /* Color mask. */
+ if (ctx->Color.ColorMask[0][RCOMP])
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_RED_WRITE;
+ if (ctx->Color.ColorMask[0][GCOMP])
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE;
+ if (ctx->Color.ColorMask[0][BCOMP])
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE;
+ if (ctx->Color.ColorMask[0][ACOMP])
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE;
+
+ /* Dithering. */
+ if (ctx->Color.DitherFlag)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_DITHER_ENABLE;
+
+ /* Cull mode. */
+ if (!ctx->Polygon.CullFlag)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_CULL_MODE_NONE;
+ else if (cull_mode == GL_FRONT_AND_BACK)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_CULL_MODE_BOTH;
+ else
+ ctrl0 |= (cull_mode == GL_FRONT) ^ (front_face == GL_CCW) ?
+ NV04_MULTITEX_TRIANGLE_CONTROL0_CULL_MODE_CW :
+ NV04_MULTITEX_TRIANGLE_CONTROL0_CULL_MODE_CCW;
+
+ /* Depth test. */
+ if (ctx->Depth.Test)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_Z_ENABLE;
+
+ if (ctx->Depth.Mask)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_Z_WRITE;
+
+ ctrl0 |= get_comparison_op(ctx->Depth.Func) << 16;
+
+ /* Alpha test. */
+ if (ctx->Color.AlphaEnabled)
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_ENABLE;
+
+ ctrl0 |= get_comparison_op(ctx->Color.AlphaFunc) << 8 |
+ FLOAT_TO_UBYTE(ctx->Color.AlphaRef);
+
+ /* Stencil test. */
+ if (ctx->Stencil.WriteMask[0])
+ ctrl0 |= NV04_MULTITEX_TRIANGLE_CONTROL0_STENCIL_WRITE;
+
+ if (ctx->Stencil.Enabled)
+ ctrl1 |= NV04_MULTITEX_TRIANGLE_CONTROL1_STENCIL_ENABLE;
+
+ ctrl1 |= get_comparison_op(ctx->Stencil.Function[0]) << 4 |
+ ctx->Stencil.Ref[0] << 8 |
+ ctx->Stencil.ValueMask[0] << 16 |
+ ctx->Stencil.WriteMask[0] << 24;
+
+ ctrl2 |= get_stencil_op(ctx->Stencil.ZPassFunc[0]) << 8 |
+ get_stencil_op(ctx->Stencil.ZFailFunc[0]) << 4 |
+ get_stencil_op(ctx->Stencil.FailFunc[0]);
+
+ BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_CONTROL0, 3);
+ OUT_RING(chan, ctrl0);
+ OUT_RING(chan, ctrl1);
+ OUT_RING(chan, ctrl2);
+
+ } else {
+ int cull_mode = ctx->Polygon.CullFaceMode;
+ int front_face = ctx->Polygon.FrontFace;
+ uint32_t ctrl = 1 << 30 |
+ NV04_TEXTURED_TRIANGLE_CONTROL_ORIGIN;
+
+ /* Dithering. */
+ if (ctx->Color.DitherFlag)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_DITHER_ENABLE;
+
+ /* Cull mode. */
+ if (!ctx->Polygon.CullFlag)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_NONE;
+ else if (cull_mode == GL_FRONT_AND_BACK)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_BOTH;
+ else
+ ctrl |= (cull_mode == GL_FRONT) ^ (front_face == GL_CCW) ?
+ NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CW :
+ NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CCW;
+
+ /* Depth test. */
+ if (ctx->Depth.Test)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_ENABLE;
+ if (ctx->Depth.Mask)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_WRITE;
+
+ ctrl |= get_comparison_op(ctx->Depth.Func) << 16;
+
+ /* Alpha test. */
+ if (ctx->Color.AlphaEnabled)
+ ctrl |= NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_ENABLE;
+
+ ctrl |= get_comparison_op(ctx->Color.AlphaFunc) << 8 |
+ FLOAT_TO_UBYTE(ctx->Color.AlphaRef);
+
+ BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_CONTROL, 1);
+ OUT_RING(chan, ctrl);
+ }
+}
+
+void
+nv04_defer_blend(GLcontext *ctx, int emit)
+{
+ context_dirty(ctx, BLEND);
+}
+
+void
+nv04_emit_blend(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
+
+ if (nv04_mtex_engine(fahrenheit)) {
+ uint32_t blend = 0x2 << 4 |
+ NV04_MULTITEX_TRIANGLE_BLEND_TEXTURE_PERSPECTIVE_ENABLE;
+
+ /* Alpha blending. */
+ blend |= get_blend_func(ctx->Color.BlendDstRGB) << 28 |
+ get_blend_func(ctx->Color.BlendSrcRGB) << 24;
+
+ if (ctx->Color.BlendEnabled)
+ blend |= NV04_MULTITEX_TRIANGLE_BLEND_BLEND_ENABLE;
+
+ /* Shade model. */
+ if (ctx->Light.ShadeModel == GL_SMOOTH)
+ blend |= NV04_MULTITEX_TRIANGLE_BLEND_SHADE_MODE_GOURAUD;
+ else
+ blend |= NV04_MULTITEX_TRIANGLE_BLEND_SHADE_MODE_FLAT;
+
+ /* Fog. */
+ if (ctx->Fog.Enabled)
+ blend |= NV04_MULTITEX_TRIANGLE_BLEND_FOG_ENABLE;
+
+ BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_BLEND, 1);
+ OUT_RING(chan, blend);
+
+ BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_FOGCOLOR, 1);
+ OUT_RING(chan, pack_rgba_f(MESA_FORMAT_ARGB8888,
+ ctx->Fog.Color));
+
+ } else {
+ uint32_t blend = 0x2 << 4 |
+ NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_PERSPECTIVE_ENABLE;
+
+ /* Alpha blending. */
+ blend |= get_blend_func(ctx->Color.BlendDstRGB) << 28 |
+ get_blend_func(ctx->Color.BlendSrcRGB) << 24;
+
+ if (ctx->Color.BlendEnabled)
+ blend |= NV04_TEXTURED_TRIANGLE_BLEND_BLEND_ENABLE;
+
+ /* Shade model. */
+ if (ctx->Light.ShadeModel == GL_SMOOTH)
+ blend |= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_GOURAUD;
+ else
+ blend |= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_FLAT;
+
+ /* Texture environment. */
+ blend |= get_texenv_mode(ctx->Texture.Unit[0].EnvMode);
+
+ /* Fog. */
+ if (ctx->Fog.Enabled)
+ blend |= NV04_TEXTURED_TRIANGLE_BLEND_FOG_ENABLE;
+
+ BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_BLEND, 1);
+ OUT_RING(chan, blend);
+
+ BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FOGCOLOR, 1);
+ OUT_RING(chan, pack_rgba_f(MESA_FORMAT_ARGB8888,
+ ctx->Fog.Color));
+ }
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_tex.c b/src/mesa/drivers/dri/nouveau/nv04_state_tex.c
new file mode 100644
index 0000000000..99ea310c65
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_tex.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_texture.h"
+#include "nouveau_util.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+
+static uint32_t
+get_tex_format(struct gl_texture_image *ti)
+{
+ switch (ti->TexFormat) {
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_Y8;
+ case MESA_FORMAT_ARGB1555:
+ return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A1R5G5B5;
+ case MESA_FORMAT_ARGB4444:
+ return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A4R4G4B4;
+ case MESA_FORMAT_RGB565:
+ return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_R5G6B5;
+ case MESA_FORMAT_ARGB8888:
+ return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8;
+ default:
+ assert(0);
+ }
+}
+
+static inline unsigned
+get_wrap_mode(unsigned wrap)
+{
+ switch (wrap) {
+ case GL_REPEAT:
+ return 0x1;
+ case GL_MIRRORED_REPEAT:
+ return 0x2;
+ case GL_CLAMP:
+ case GL_CLAMP_TO_EDGE:
+ return 0x3;
+ case GL_CLAMP_TO_BORDER:
+ return 0x4;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv04_emit_tex_obj(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_OBJ0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
+ struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i);
+ const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM;
+ struct nouveau_surface *s;
+ uint32_t format = 0xa0, filter = 0x1010;
+
+ if (i && !nv04_mtex_engine(fahrenheit))
+ return;
+
+ if (ctx->Texture.Unit[i]._ReallyEnabled) {
+ struct gl_texture_object *t = ctx->Texture.Unit[i]._Current;
+ struct gl_texture_image *ti = t->Image[0][t->BaseLevel];
+ int lod_max = 1, lod_bias = 0;
+
+ nouveau_texture_validate(ctx, t);
+ s = &to_nouveau_texture(t)->surfaces[t->BaseLevel];
+
+ if (t->MinFilter != GL_NEAREST &&
+ t->MinFilter != GL_LINEAR) {
+ lod_max = CLAMP(MIN2(t->MaxLod, t->_MaxLambda),
+ 0, 15) + 1;
+
+ lod_bias = CLAMP(ctx->Texture.Unit[i].LodBias +
+ t->LodBias, 0, 15);
+ }
+
+ format |= get_wrap_mode(t->WrapT) << 28 |
+ get_wrap_mode(t->WrapS) << 24 |
+ ti->HeightLog2 << 20 |
+ ti->WidthLog2 << 16 |
+ lod_max << 12 |
+ get_tex_format(ti);
+
+ filter |= log2i(t->MaxAnisotropy) << 31 |
+ nvgl_filter_mode(t->MagFilter) << 28 |
+ log2i(t->MaxAnisotropy) << 27 |
+ nvgl_filter_mode(t->MinFilter) << 24 |
+ lod_bias << 16;
+
+ } else {
+ s = &to_nv04_context(ctx)->dummy_texture;
+
+ format |= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT |
+ NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT |
+ 1 << 12 |
+ NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8;
+
+ filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST |
+ NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST;
+ }
+
+ if (nv04_mtex_engine(fahrenheit)) {
+ nouveau_bo_markl(bctx, fahrenheit,
+ NV04_MULTITEX_TRIANGLE_OFFSET(i),
+ s->bo, 0, bo_flags);
+
+ nouveau_bo_mark(bctx, fahrenheit,
+ NV04_MULTITEX_TRIANGLE_FORMAT(i),
+ s->bo, format, 0,
+ NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A,
+ NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B,
+ bo_flags | NOUVEAU_BO_OR);
+
+ BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_FILTER(i), 1);
+ OUT_RING(chan, filter);
+
+ } else {
+ nouveau_bo_markl(bctx, fahrenheit,
+ NV04_TEXTURED_TRIANGLE_OFFSET,
+ s->bo, 0, bo_flags);
+
+ nouveau_bo_mark(bctx, fahrenheit,
+ NV04_TEXTURED_TRIANGLE_FORMAT,
+ s->bo, format, 0,
+ NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A,
+ NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B,
+ bo_flags | NOUVEAU_BO_OR);
+
+ BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_COLORKEY, 1);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FILTER, 1);
+ OUT_RING(chan, filter);
+ }
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv04_surface.c b/src/mesa/drivers/dri/nouveau/nv04_surface.c
new file mode 100644
index 0000000000..0d40349345
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv04_surface.c
@@ -0,0 +1,547 @@
+/*
+ * Copyright (C) 2007-2010 The Nouveau Project.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_class.h"
+#include "nouveau_context.h"
+#include "nouveau_util.h"
+#include "nv04_driver.h"
+
+static inline int
+swzsurf_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_RGB332:
+ case MESA_FORMAT_CI8:
+ return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_Y8;
+
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_RGBA5551:
+ case MESA_FORMAT_ARGB1555_REV:
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ case MESA_FORMAT_Z16:
+ return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_R5G6B5;
+
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z32:
+ return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_A8R8G8B8;
+
+ default:
+ assert(0);
+ }
+}
+
+static inline int
+surf2d_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_RGB332:
+ case MESA_FORMAT_CI8:
+ return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8;
+
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_RGBA5551:
+ case MESA_FORMAT_ARGB1555_REV:
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ case MESA_FORMAT_Z16:
+ return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5;
+
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z32:
+ return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32;
+
+ default:
+ assert(0);
+ }
+}
+
+static inline int
+rect_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_RGB332:
+ case MESA_FORMAT_CI8:
+ return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8;
+
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_RGBA5551:
+ case MESA_FORMAT_ARGB1555_REV:
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ case MESA_FORMAT_Z16:
+ return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5;
+
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z32:
+ return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8;
+
+ default:
+ assert(0);
+ }
+}
+
+static inline int
+sifm_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_RGB332:
+ case MESA_FORMAT_CI8:
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_AY8;
+
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_RGBA5551:
+ case MESA_FORMAT_ARGB1555_REV:
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ case MESA_FORMAT_Z16:
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5;
+
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_S8_Z24:
+ case MESA_FORMAT_Z24_S8:
+ case MESA_FORMAT_Z32:
+ return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8;
+
+ default:
+ assert(0);
+ }
+}
+
+static void
+nv04_surface_copy_swizzle(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ struct nouveau_surface *src,
+ int dx, int dy, int sx, int sy,
+ int w, int h)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_screen *screen = to_nouveau_context(ctx)->screen;
+ struct nouveau_grobj *swzsurf = screen->swzsurf;
+ struct nouveau_grobj *sifm = screen->sifm;
+ struct nouveau_bo_context *bctx = context_bctx(ctx, SURFACE);
+ const unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART;
+ /* Max width & height may not be the same on all HW, but must be POT */
+ const unsigned max_w = 1024;
+ const unsigned max_h = 1024;
+ unsigned sub_w = w > max_w ? max_w : w;
+ unsigned sub_h = h > max_h ? max_h : h;
+ unsigned x, y;
+
+ /* Swizzled surfaces must be POT */
+ assert(_mesa_is_pow_two(dst->width) &&
+ _mesa_is_pow_two(dst->height));
+
+ /* If area is too large to copy in one shot we must copy it in
+ * POT chunks to meet alignment requirements */
+ assert(sub_w == w || _mesa_is_pow_two(sub_w));
+ assert(sub_h == h || _mesa_is_pow_two(sub_h));
+
+ nouveau_bo_marko(bctx, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE,
+ src->bo, bo_flags | NOUVEAU_BO_RD);
+ nouveau_bo_marko(bctx, swzsurf, NV04_SWIZZLED_SURFACE_DMA_IMAGE,
+ dst->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+ nouveau_bo_markl(bctx, swzsurf, NV04_SWIZZLED_SURFACE_OFFSET,
+ dst->bo, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+
+ BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_FORMAT, 1);
+ OUT_RING (chan, swzsurf_format(dst->format) |
+ log2i(dst->width) << 16 |
+ log2i(dst->height) << 24);
+
+ BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE, 1);
+ OUT_RING (chan, swzsurf->handle);
+
+ for (y = 0; y < h; y += sub_h) {
+ sub_h = MIN2(sub_h, h - y);
+
+ for (x = 0; x < w; x += sub_w) {
+ sub_w = MIN2(sub_w, w - x);
+ /* Must be 64-byte aligned */
+ assert(!(dst->offset & 63));
+
+ MARK_RING(chan, 15, 1);
+
+ BEGIN_RING(chan, sifm,
+ NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 8);
+ OUT_RING(chan, sifm_format(src->format));
+ OUT_RING(chan, NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
+ OUT_RING(chan, (y + dy) << 16 | (x + dx));
+ OUT_RING(chan, sub_h << 16 | sub_w);
+ OUT_RING(chan, (y + dy) << 16 | (x + dx));
+ OUT_RING(chan, sub_h << 16 | sub_w);
+ OUT_RING(chan, 1 << 20);
+ OUT_RING(chan, 1 << 20);
+
+ BEGIN_RING(chan, sifm,
+ NV03_SCALED_IMAGE_FROM_MEMORY_SIZE, 4);
+ OUT_RING(chan, sub_h << 16 | sub_w);
+ OUT_RING(chan, src->pitch |
+ NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
+ NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE);
+ OUT_RELOCl(chan, src->bo, src->offset +
+ (y + sy) * src->pitch +
+ (x + sx) * src->cpp,
+ bo_flags | NOUVEAU_BO_RD);
+ OUT_RING(chan, 0);
+ }
+ }
+
+ nouveau_bo_context_reset(bctx);
+
+ if (context_chipset(ctx) < 0x10)
+ FIRE_RING(chan);
+}
+
+static void
+nv04_surface_copy_m2mf(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ struct nouveau_surface *src,
+ int dx, int dy, int sx, int sy,
+ int w, int h)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_screen *screen = to_nouveau_context(ctx)->screen;
+ struct nouveau_grobj *m2mf = screen->m2mf;
+ struct nouveau_bo_context *bctx = context_bctx(ctx, SURFACE);
+ const unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART;
+ unsigned dst_offset = dst->offset + dy * dst->pitch + dx * dst->cpp;
+ unsigned src_offset = src->offset + sy * src->pitch + sx * src->cpp;
+
+ nouveau_bo_marko(bctx, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN,
+ src->bo, bo_flags | NOUVEAU_BO_RD);
+ nouveau_bo_marko(bctx, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_OUT,
+ dst->bo, bo_flags | NOUVEAU_BO_WR);
+
+ while (h) {
+ int count = (h > 2047) ? 2047 : h;
+
+ MARK_RING(chan, 9, 2);
+
+ BEGIN_RING(chan, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
+ OUT_RELOCl(chan, src->bo, src_offset,
+ bo_flags | NOUVEAU_BO_RD);
+ OUT_RELOCl(chan, dst->bo, dst_offset,
+ bo_flags | NOUVEAU_BO_WR);
+ OUT_RING (chan, src->pitch);
+ OUT_RING (chan, dst->pitch);
+ OUT_RING (chan, w * src->cpp);
+ OUT_RING (chan, count);
+ OUT_RING (chan, 0x0101);
+ OUT_RING (chan, 0);
+
+ h -= count;
+ src_offset += src->pitch * count;
+ dst_offset += dst->pitch * count;
+ }
+
+ nouveau_bo_context_reset(bctx);
+
+ if (context_chipset(ctx) < 0x10)
+ FIRE_RING(chan);
+}
+
+void
+nv04_surface_copy(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ struct nouveau_surface *src,
+ int dx, int dy, int sx, int sy,
+ int w, int h)
+{
+ /* Setup transfer to swizzle the texture to vram if needed */
+ if (src->layout != SWIZZLED &&
+ dst->layout == SWIZZLED &&
+ dst->width > 2 && dst->height > 1) {
+ nv04_surface_copy_swizzle(ctx, dst, src,
+ dx, dy, sx, sy, w, h);
+ return;
+ }
+
+ nv04_surface_copy_m2mf(ctx, dst, src, dx, dy, sx, sy, w, h);
+}
+
+void
+nv04_surface_fill(GLcontext *ctx,
+ struct nouveau_surface *dst,
+ unsigned mask, unsigned value,
+ int dx, int dy, int w, int h)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_screen *screen = to_nouveau_context(ctx)->screen;
+ struct nouveau_grobj *surf2d = screen->surf2d;
+ struct nouveau_grobj *patt = screen->patt;
+ struct nouveau_grobj *rect = screen->rect;
+ unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART;
+
+ MARK_RING (chan, 19, 4);
+
+ BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2);
+ OUT_RELOCo(chan, dst->bo, bo_flags | NOUVEAU_BO_WR);
+ OUT_RELOCo(chan, dst->bo, bo_flags | NOUVEAU_BO_WR);
+ BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4);
+ OUT_RING (chan, surf2d_format(dst->format));
+ OUT_RING (chan, (dst->pitch << 16) | dst->pitch);
+ OUT_RELOCl(chan, dst->bo, dst->offset, bo_flags | NOUVEAU_BO_WR);
+ OUT_RELOCl(chan, dst->bo, dst->offset, bo_flags | NOUVEAU_BO_WR);
+
+ BEGIN_RING(chan, patt, NV04_IMAGE_PATTERN_COLOR_FORMAT, 1);
+ OUT_RING (chan, rect_format(dst->format));
+ BEGIN_RING(chan, patt, NV04_IMAGE_PATTERN_MONOCHROME_COLOR1, 1);
+ OUT_RING (chan, mask | ~0 << (8 * dst->cpp));
+
+ BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1);
+ OUT_RING (chan, rect_format(dst->format));
+ BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1);
+ OUT_RING (chan, value);
+ BEGIN_RING(chan, rect,
+ NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(0), 2);
+ OUT_RING (chan, (dx << 16) | dy);
+ OUT_RING (chan, ( w << 16) | h);
+
+ if (context_chipset(ctx) < 0x10)
+ FIRE_RING(chan);
+}
+
+void
+nv04_surface_takedown(struct nouveau_screen *screen)
+{
+ nouveau_grobj_free(&screen->swzsurf);
+ nouveau_grobj_free(&screen->sifm);
+ nouveau_grobj_free(&screen->rect);
+ nouveau_grobj_free(&screen->rop);
+ nouveau_grobj_free(&screen->patt);
+ nouveau_grobj_free(&screen->surf2d);
+ nouveau_grobj_free(&screen->m2mf);
+ nouveau_notifier_free(&screen->ntfy);
+}
+
+GLboolean
+nv04_surface_init(struct nouveau_screen *screen)
+{
+ struct nouveau_channel *chan = screen->chan;
+ const unsigned chipset = screen->device->chipset;
+ unsigned handle = 0x88000000, class;
+ int ret;
+
+ /* Notifier object. */
+ ret = nouveau_notifier_alloc(chan, handle++, 1, &screen->ntfy);
+ if (ret)
+ goto fail;
+
+ /* Memory to memory format. */
+ ret = nouveau_grobj_alloc(chan, handle++, NV04_MEMORY_TO_MEMORY_FORMAT,
+ &screen->m2mf);
+ if (ret)
+ goto fail;
+
+ BEGIN_RING(chan, screen->m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1);
+ OUT_RING (chan, screen->ntfy->handle);
+
+ /* Context surfaces 2D. */
+ if (chan->device->chipset < 0x10)
+ class = NV04_CONTEXT_SURFACES_2D;
+ else
+ class = NV10_CONTEXT_SURFACES_2D;
+
+ ret = nouveau_grobj_alloc(chan, handle++, class, &screen->surf2d);
+ if (ret)
+ goto fail;
+
+ /* Raster op. */
+ ret = nouveau_grobj_alloc(chan, handle++, NV03_CONTEXT_ROP,
+ &screen->rop);
+ if (ret)
+ goto fail;
+
+ BEGIN_RING(chan, screen->rop, NV03_CONTEXT_ROP_DMA_NOTIFY, 1);
+ OUT_RING (chan, screen->ntfy->handle);
+
+ BEGIN_RING(chan, screen->rop, NV03_CONTEXT_ROP_ROP, 1);
+ OUT_RING (chan, 0xca); /* DPSDxax in the GDI speech. */
+
+ /* Image pattern. */
+ ret = nouveau_grobj_alloc(chan, handle++, NV04_IMAGE_PATTERN,
+ &screen->patt);
+ if (ret)
+ goto fail;
+
+ BEGIN_RING(chan, screen->patt,
+ NV04_IMAGE_PATTERN_DMA_NOTIFY, 1);
+ OUT_RING (chan, screen->ntfy->handle);
+
+ BEGIN_RING(chan, screen->patt,
+ NV04_IMAGE_PATTERN_MONOCHROME_FORMAT, 3);
+ OUT_RING (chan, NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_LE);
+ OUT_RING (chan, NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_8X8);
+ OUT_RING (chan, NV04_IMAGE_PATTERN_PATTERN_SELECT_MONO);
+
+ BEGIN_RING(chan, screen->patt,
+ NV04_IMAGE_PATTERN_MONOCHROME_COLOR0, 4);
+ OUT_RING (chan, 0);
+ OUT_RING (chan, 0);
+ OUT_RING (chan, ~0);
+ OUT_RING (chan, ~0);
+
+ /* GDI rectangle text. */
+ ret = nouveau_grobj_alloc(chan, handle++, NV04_GDI_RECTANGLE_TEXT,
+ &screen->rect);
+ if (ret)
+ goto fail;
+
+ BEGIN_RING(chan, screen->rect, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1);
+ OUT_RING (chan, screen->ntfy->handle);
+ BEGIN_RING(chan, screen->rect, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1);
+ OUT_RING (chan, screen->surf2d->handle);
+ BEGIN_RING(chan, screen->rect, NV04_GDI_RECTANGLE_TEXT_ROP, 1);
+ OUT_RING (chan, screen->rop->handle);
+ BEGIN_RING(chan, screen->rect, NV04_GDI_RECTANGLE_TEXT_PATTERN, 1);
+ OUT_RING (chan, screen->patt->handle);
+
+ BEGIN_RING(chan, screen->rect, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1);
+ OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_OPERATION_ROP_AND);
+ BEGIN_RING(chan, screen->rect,
+ NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1);
+ OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE);
+
+ /* Swizzled surface. */
+ switch (chan->device->chipset & 0xf0) {
+ case 0x00:
+ case 0x10:
+ class = NV04_SWIZZLED_SURFACE;
+ break;
+ case 0x20:
+ class = NV20_SWIZZLED_SURFACE;
+ break;
+ case 0x30:
+ class = NV30_SWIZZLED_SURFACE;
+ break;
+ case 0x40:
+ case 0x60:
+ class = NV40_SWIZZLED_SURFACE;
+ break;
+ default:
+ /* Famous last words: this really can't happen.. */
+ assert(0);
+ break;
+ }
+
+ ret = nouveau_grobj_alloc(chan, handle++, class, &screen->swzsurf);
+ if (ret)
+ goto fail;
+
+ /* Scaled image from memory. */
+ switch (chan->device->chipset & 0xf0) {
+ case 0x10:
+ case 0x20:
+ class = NV10_SCALED_IMAGE_FROM_MEMORY;
+ break;
+ case 0x30:
+ class = NV30_SCALED_IMAGE_FROM_MEMORY;
+ break;
+ case 0x40:
+ case 0x60:
+ class = NV40_SCALED_IMAGE_FROM_MEMORY;
+ break;
+ default:
+ class = NV04_SCALED_IMAGE_FROM_MEMORY;
+ break;
+ }
+
+ ret = nouveau_grobj_alloc(chan, handle++, class, &screen->sifm);
+ if (ret)
+ goto fail;
+
+ if (chipset >= 0x10) {
+ BEGIN_RING(chan, screen->sifm,
+ NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 1);
+ OUT_RING(chan, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE);
+ }
+
+ return GL_TRUE;
+
+fail:
+ nv04_surface_takedown(screen);
+ return GL_FALSE;
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_context.c b/src/mesa/drivers/dri/nouveau/nv10_context.c
new file mode 100644
index 0000000000..d1afa87c8a
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_context.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+
+static void
+nv10_clear(GLcontext *ctx, GLbitfield buffers)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(
+ ctx->DrawBuffer);
+
+ nouveau_validate_framebuffer(ctx);
+
+ /* Clear the LMA depth buffer, if present. */
+ if ((buffers & BUFFER_BIT_DEPTH) && ctx->Depth.Mask &&
+ nfb->lma_bo) {
+ struct nouveau_surface *s = &to_nouveau_renderbuffer(
+ nfb->base._DepthBuffer->Wrapped)->surface;
+
+ BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_FILL_VALUE, 1);
+ OUT_RING(chan, pack_zs_f(s->format, ctx->Depth.Clear, 0));
+ BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_BUFFER_CLEAR, 1);
+ OUT_RING(chan, 1);
+ }
+
+ nouveau_clear(ctx, buffers);
+}
+
+GLcontext *
+nv10_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx)
+{
+ struct nouveau_context *nctx;
+ GLcontext *ctx;
+
+ nctx = CALLOC_STRUCT(nouveau_context);
+ if (!nctx)
+ return NULL;
+
+ ctx = &nctx->base;
+ nouveau_context_init(ctx, screen, visual, share_ctx);
+
+ ctx->Const.MaxTextureLevels = 12;
+ ctx->Const.MaxTextureCoordUnits = NV10_TEXTURE_UNITS;
+ ctx->Const.MaxTextureImageUnits = NV10_TEXTURE_UNITS;
+ ctx->Const.MaxTextureUnits = NV10_TEXTURE_UNITS;
+ ctx->Const.MaxTextureMaxAnisotropy = 2;
+ ctx->Const.MaxTextureLodBias = 15;
+ ctx->Driver.Clear = nv10_clear;
+
+ nv10_render_init(ctx);
+
+ return ctx;
+}
+
+void
+nv10_context_destroy(GLcontext *ctx)
+{
+ nv10_render_destroy(ctx);
+ FREE(ctx);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_driver.h b/src/mesa/drivers/dri/nouveau/nv10_driver.h
new file mode 100644
index 0000000000..2a1ef7b08e
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_driver.h
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NV10_DRIVER_H__
+#define __NV10_DRIVER_H__
+
+#define NV10_TEXTURE_UNITS 2
+
+/* nv10_screen.c */
+GLboolean
+nv10_screen_init(struct nouveau_screen *screen);
+
+/* nv10_context.c */
+GLcontext *
+nv10_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx);
+
+void
+nv10_context_destroy(GLcontext *ctx);
+
+/* nv10_render.c */
+void
+nv10_render_init(GLcontext *ctx);
+
+void
+nv10_render_destroy(GLcontext *ctx);
+
+/* nv10_state_fb.c */
+void
+nv10_emit_framebuffer(GLcontext *ctx, int emit);
+
+void
+nv10_emit_render_mode(GLcontext *ctx, int emit);
+
+void
+nv10_emit_scissor(GLcontext *ctx, int emit);
+
+void
+nv10_emit_viewport(GLcontext *ctx, int emit);
+
+/* nv10_state_polygon.c */
+void
+nv10_emit_cull_face(GLcontext *ctx, int emit);
+
+void
+nv10_emit_front_face(GLcontext *ctx, int emit);
+
+void
+nv10_emit_line_mode(GLcontext *ctx, int emit);
+
+void
+nv10_emit_line_stipple(GLcontext *ctx, int emit);
+
+void
+nv10_emit_point_mode(GLcontext *ctx, int emit);
+
+void
+nv10_emit_polygon_mode(GLcontext *ctx, int emit);
+
+void
+nv10_emit_polygon_offset(GLcontext *ctx, int emit);
+
+void
+nv10_emit_polygon_stipple(GLcontext *ctx, int emit);
+
+/* nv10_state_raster.c */
+void
+nv10_emit_alpha_func(GLcontext *ctx, int emit);
+
+void
+nv10_emit_blend_color(GLcontext *ctx, int emit);
+
+void
+nv10_emit_blend_equation(GLcontext *ctx, int emit);
+
+void
+nv10_emit_blend_func(GLcontext *ctx, int emit);
+
+void
+nv10_emit_color_mask(GLcontext *ctx, int emit);
+
+void
+nv10_emit_depth(GLcontext *ctx, int emit);
+
+void
+nv10_emit_dither(GLcontext *ctx, int emit);
+
+void
+nv10_emit_index_mask(GLcontext *ctx, int emit);
+
+void
+nv10_emit_logic_opcode(GLcontext *ctx, int emit);
+
+void
+nv10_emit_shade_model(GLcontext *ctx, int emit);
+
+void
+nv10_emit_stencil_func(GLcontext *ctx, int emit);
+
+void
+nv10_emit_stencil_mask(GLcontext *ctx, int emit);
+
+void
+nv10_emit_stencil_op(GLcontext *ctx, int emit);
+
+/* nv10_state_frag.c */
+void
+nv10_emit_tex_env(GLcontext *ctx, int emit);
+
+void
+nv10_emit_frag(GLcontext *ctx, int emit);
+
+/* nv10_state_tex.c */
+void
+nv10_emit_tex_gen(GLcontext *ctx, int emit);
+
+void
+nv10_emit_tex_obj(GLcontext *ctx, int emit);
+
+/* nv10_state_tnl.c */
+void
+nv10_get_fog_coeff(GLcontext *ctx, float k[3]);
+
+void
+nv10_get_spot_coeff(struct gl_light *l, float k[7]);
+
+void
+nv10_get_shininess_coeff(float s, float k[6]);
+
+void
+nv10_emit_clip_plane(GLcontext *ctx, int emit);
+
+void
+nv10_emit_color_material(GLcontext *ctx, int emit);
+
+void
+nv10_emit_fog(GLcontext *ctx, int emit);
+
+void
+nv10_emit_light_enable(GLcontext *ctx, int emit);
+
+void
+nv10_emit_light_model(GLcontext *ctx, int emit);
+
+void
+nv10_emit_light_source(GLcontext *ctx, int emit);
+
+void
+nv10_emit_material_ambient(GLcontext *ctx, int emit);
+
+void
+nv10_emit_material_diffuse(GLcontext *ctx, int emit);
+
+void
+nv10_emit_material_specular(GLcontext *ctx, int emit);
+
+void
+nv10_emit_material_shininess(GLcontext *ctx, int emit);
+
+void
+nv10_emit_modelview(GLcontext *ctx, int emit);
+
+void
+nv10_emit_point_parameter(GLcontext *ctx, int emit);
+
+void
+nv10_emit_projection(GLcontext *ctx, int emit);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nv10_render.c b/src/mesa/drivers/dri/nouveau/nv10_render.c
new file mode 100644
index 0000000000..54245ea6ba
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_render.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+
+#define NUM_VERTEX_ATTRS 8
+
+static void
+nv10_emit_material(GLcontext *ctx, struct nouveau_array_state *a,
+ const void *v);
+
+/* Vertex attribute format. */
+static struct nouveau_attr_info nv10_vertex_attrs[VERT_ATTRIB_MAX] = {
+ [VERT_ATTRIB_POS] = {
+ .vbo_index = 0,
+ .imm_method = NV10TCL_VERTEX_POS_4F_X,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_COLOR0] = {
+ .vbo_index = 1,
+ .imm_method = NV10TCL_VERTEX_COL_4F_R,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_COLOR1] = {
+ .vbo_index = 2,
+ .imm_method = NV10TCL_VERTEX_COL2_3F_R,
+ .imm_fields = 3,
+ },
+ [VERT_ATTRIB_TEX0] = {
+ .vbo_index = 3,
+ .imm_method = NV10TCL_VERTEX_TX0_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_TEX1] = {
+ .vbo_index = 4,
+ .imm_method = NV10TCL_VERTEX_TX1_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_NORMAL] = {
+ .vbo_index = 5,
+ .imm_method = NV10TCL_VERTEX_NOR_3F_X,
+ .imm_fields = 3,
+ },
+ [VERT_ATTRIB_FOG] = {
+ .vbo_index = 7,
+ .imm_method = NV10TCL_VERTEX_FOG_1F,
+ .imm_fields = 1,
+ },
+ [VERT_ATTRIB_GENERIC0] = {
+ .emit = nv10_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC2] = {
+ .emit = nv10_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC4] = {
+ .emit = nv10_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC6] = {
+ .emit = nv10_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC8] = {
+ .emit = nv10_emit_material,
+ },
+};
+
+static int
+get_hw_format(int type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ return NV10TCL_VTXFMT_TYPE_FLOAT;
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ return NV10TCL_VTXFMT_TYPE_SHORT;
+ case GL_UNSIGNED_BYTE:
+ return NV10TCL_VTXFMT_TYPE_BYTE_RGBA;
+ default:
+ assert(0);
+ }
+}
+
+static void
+nv10_render_set_format(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ int i, hw_format;
+
+ for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ struct nouveau_array_state *a = &render->attrs[attr];
+
+ hw_format = a->stride << 8 |
+ a->fields << 4 |
+ get_hw_format(a->type);
+
+ if (attr == VERT_ATTRIB_POS && a->fields == 4)
+ hw_format |= NV10TCL_VTXFMT_POS_HOMOGENEOUS;
+ } else {
+ /* Unused attribute. */
+ hw_format = NV10TCL_VTXFMT_TYPE_FLOAT;
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_VTXFMT(i), 1);
+ OUT_RING(chan, hw_format);
+ }
+}
+
+static void
+nv10_render_bind_vertices(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ int i;
+
+ for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ struct nouveau_array_state *a = &render->attrs[attr];
+
+ nouveau_bo_markl(bctx, celsius,
+ NV10TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset,
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
+ }
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_VALIDATE, 1);
+ OUT_RING(chan, 0);
+}
+
+/* Vertex array rendering defs. */
+#define RENDER_LOCALS(ctx) \
+ struct nouveau_grobj *celsius = context_eng3d(ctx)
+
+#define BATCH_BEGIN(prim) \
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1); \
+ OUT_RING(chan, prim);
+#define BATCH_END() \
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1); \
+ OUT_RING(chan, 0);
+
+#define MAX_PACKET 0x400
+
+#define MAX_OUT_L 0x100
+#define BATCH_PACKET_L(n) \
+ BEGIN_RING_NI(chan, celsius, NV10TCL_VERTEX_BUFFER_DRAW_ARRAYS, n);
+#define BATCH_OUT_L(i, n) \
+ OUT_RING(chan, ((n) - 1) << 24 | (i));
+
+#define MAX_OUT_I16 0x2
+#define BATCH_PACKET_I16(n) \
+ BEGIN_RING_NI(chan, celsius, NV10TCL_VB_ELEMENT_U16, n);
+#define BATCH_OUT_I16(i0, i1) \
+ OUT_RING(chan, (i1) << 16 | (i0));
+
+#define MAX_OUT_I32 0x1
+#define BATCH_PACKET_I32(n) \
+ BEGIN_RING_NI(chan, celsius, NV10TCL_VB_ELEMENT_U32, n);
+#define BATCH_OUT_I32(i) \
+ OUT_RING(chan, i);
+
+#define IMM_PACKET(m, n) \
+ BEGIN_RING(chan, celsius, m, n);
+#define IMM_OUT(x) \
+ OUT_RINGf(chan, x);
+
+#define TAG(x) nv10_##x
+#include "nouveau_render_t.c"
diff --git a/src/mesa/drivers/dri/nouveau/nv10_screen.c b/src/mesa/drivers/dri/nouveau/nv10_screen.c
new file mode 100644
index 0000000000..8665ad1410
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_screen.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_screen.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+#include "nv10_driver.h"
+
+static const struct nouveau_driver nv10_driver;
+
+static void
+nv10_hwctx_init(struct nouveau_screen *screen)
+{
+ struct nouveau_channel *chan = screen->chan;
+ struct nouveau_grobj *celsius = screen->eng3d;
+ const unsigned chipset = screen->device->chipset;
+ int i;
+
+ BEGIN_RING(chan, celsius, NV10TCL_DMA_NOTIFY, 1);
+ OUT_RING(chan, screen->ntfy->handle);
+
+ BEGIN_RING(chan, celsius, NV10TCL_DMA_IN_MEMORY0, 3);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->gart->handle);
+ OUT_RING(chan, chan->gart->handle);
+ BEGIN_RING(chan, celsius, NV10TCL_DMA_IN_MEMORY2, 2);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->vram->handle);
+
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_RT_HORIZ, 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 1);
+ OUT_RING(chan, 0x7ff << 16 | 0x800);
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_VERT(0), 1);
+ OUT_RING(chan, 0x7ff << 16 | 0x800);
+
+ for (i = 1; i < 8; i++) {
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(i), 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_VERT(i), 1);
+ OUT_RING(chan, 0);
+ }
+
+ BEGIN_RING(chan, celsius, 0x290, 1);
+ OUT_RING(chan, 0x10 << 16 | 1);
+ BEGIN_RING(chan, celsius, 0x3f4, 1);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+
+ if (chipset >= 0x17) {
+ BEGIN_RING(chan, celsius, NV17TCL_DMA_IN_MEMORY4, 2);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->vram->handle);
+
+ BEGIN_RING(chan, celsius, 0xd84, 1);
+ OUT_RING(chan, 0x3);
+
+ BEGIN_RING(chan, celsius, NV17TCL_COLOR_MASK_ENABLE, 1);
+ OUT_RING(chan, 1);
+ }
+
+ if (chipset >= 0x11) {
+ BEGIN_RING(chan, celsius, 0x120, 3);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 1);
+ OUT_RING(chan, 2);
+
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+
+ /* Set state */
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_FUNC, 2);
+ OUT_RING(chan, 0x207);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(0), 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_DITHER_ENABLE, 2);
+ OUT_RING(chan, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_WEIGHT_ENABLE, 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_SRC, 4);
+ OUT_RING(chan, 1);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0x8006);
+ BEGIN_RING(chan, celsius, NV10TCL_STENCIL_MASK, 8);
+ OUT_RING(chan, 0xff);
+ OUT_RING(chan, 0x207);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0xff);
+ OUT_RING(chan, 0x1e00);
+ OUT_RING(chan, 0x1e00);
+ OUT_RING(chan, 0x1e00);
+ OUT_RING(chan, 0x1d01);
+ BEGIN_RING(chan, celsius, NV10TCL_NORMALIZE_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_ENABLE, 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_SEPARATE_SPECULAR_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_ENABLED_LIGHTS, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_FUNC, 1);
+ OUT_RING(chan, 0x201);
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_WRITE_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_TEST_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_FACTOR, 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_POINT_SIZE, 1);
+ OUT_RING(chan, 8);
+ BEGIN_RING(chan, celsius, NV10TCL_POINT_PARAMETERS_ENABLE, 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_LINE_WIDTH, 1);
+ OUT_RING(chan, 8);
+ BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
+ OUT_RING(chan, 0x1b02);
+ OUT_RING(chan, 0x1b02);
+ BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE, 2);
+ OUT_RING(chan, 0x405);
+ OUT_RING(chan, 0x901);
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE_ENABLE, 1);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_TX_GEN_S(0), 8);
+ for (i = 0; i < 8; i++)
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_TX_MATRIX_ENABLE(0), 2);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_EQUATION_CONSTANT, 3);
+ OUT_RING(chan, 0x3fc00000); /* -1.50 */
+ OUT_RING(chan, 0xbdb8aa0a); /* -0.09 */
+ OUT_RING(chan, 0); /* 0.00 */
+
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_MODE, 2);
+ OUT_RING(chan, 0x802);
+ OUT_RING(chan, 2);
+ /* for some reason VIEW_MATRIX_ENABLE need to be 6 instead of 4 when
+ * using texturing, except when using the texture matrix
+ */
+ BEGIN_RING(chan, celsius, NV10TCL_VIEW_MATRIX_ENABLE, 1);
+ OUT_RING(chan, 6);
+ BEGIN_RING(chan, celsius, NV10TCL_COLOR_MASK, 1);
+ OUT_RING(chan, 0x01010101);
+
+ /* Set vertex component */
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_COL_4F_R, 4);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 1.0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_COL2_3F_R, 3);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_NOR_3F_X, 3);
+ OUT_RING(chan, 0);
+ OUT_RING(chan, 0);
+ OUT_RINGf(chan, 1.0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_TX0_4F_S, 4);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 1.0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_TX1_4F_S, 4);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 1.0);
+ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_FOG_1F, 1);
+ OUT_RINGf(chan, 0.0);
+ BEGIN_RING(chan, celsius, NV10TCL_EDGEFLAG_ENABLE, 1);
+ OUT_RING(chan, 1);
+
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_RANGE_NEAR, 2);
+ OUT_RING(chan, 0.0);
+ OUT_RINGf(chan, 16777216.0);
+
+ FIRE_RING(chan);
+}
+
+GLboolean
+nv10_screen_init(struct nouveau_screen *screen)
+{
+ unsigned chipset = screen->device->chipset;
+ unsigned celsius_class;
+ int ret;
+
+ screen->driver = &nv10_driver;
+
+ /* 2D engine. */
+ ret = nv04_surface_init(screen);
+ if (!ret)
+ return GL_FALSE;
+
+ /* 3D engine. */
+ if (chipset >= 0x17)
+ celsius_class = NV17TCL;
+ else if (chipset >= 0x11)
+ celsius_class = NV11TCL;
+ else
+ celsius_class = NV10TCL;
+
+ ret = nouveau_grobj_alloc(screen->chan, 0xbeef0001, celsius_class,
+ &screen->eng3d);
+ if (ret)
+ return GL_FALSE;
+
+ nv10_hwctx_init(screen);
+
+ return GL_TRUE;
+}
+
+static void
+nv10_screen_destroy(struct nouveau_screen *screen)
+{
+ if (screen->eng3d)
+ nouveau_grobj_free(&screen->eng3d);
+
+ nv04_surface_takedown(screen);
+}
+
+static const struct nouveau_driver nv10_driver = {
+ .screen_destroy = nv10_screen_destroy,
+ .context_create = nv10_context_create,
+ .context_destroy = nv10_context_destroy,
+ .surface_copy = nv04_surface_copy,
+ .surface_fill = nv04_surface_fill,
+ .emit = (nouveau_state_func[]) {
+ nv10_emit_alpha_func,
+ nv10_emit_blend_color,
+ nv10_emit_blend_equation,
+ nv10_emit_blend_func,
+ nv10_emit_clip_plane,
+ nv10_emit_clip_plane,
+ nv10_emit_clip_plane,
+ nv10_emit_clip_plane,
+ nv10_emit_clip_plane,
+ nv10_emit_clip_plane,
+ nv10_emit_color_mask,
+ nv10_emit_color_material,
+ nv10_emit_cull_face,
+ nv10_emit_front_face,
+ nv10_emit_depth,
+ nv10_emit_dither,
+ nv10_emit_frag,
+ nv10_emit_framebuffer,
+ nv10_emit_fog,
+ nv10_emit_index_mask,
+ nv10_emit_light_enable,
+ nv10_emit_light_model,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_light_source,
+ nv10_emit_line_stipple,
+ nv10_emit_line_mode,
+ nv10_emit_logic_opcode,
+ nv10_emit_material_ambient,
+ nouveau_emit_nothing,
+ nv10_emit_material_diffuse,
+ nouveau_emit_nothing,
+ nv10_emit_material_specular,
+ nouveau_emit_nothing,
+ nv10_emit_material_shininess,
+ nouveau_emit_nothing,
+ nv10_emit_modelview,
+ nv10_emit_point_mode,
+ nv10_emit_point_parameter,
+ nv10_emit_polygon_mode,
+ nv10_emit_polygon_offset,
+ nv10_emit_polygon_stipple,
+ nv10_emit_projection,
+ nv10_emit_render_mode,
+ nv10_emit_scissor,
+ nv10_emit_shade_model,
+ nv10_emit_stencil_func,
+ nv10_emit_stencil_mask,
+ nv10_emit_stencil_op,
+ nv10_emit_tex_env,
+ nv10_emit_tex_env,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv10_emit_tex_gen,
+ nv10_emit_tex_gen,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv10_emit_tex_obj,
+ nv10_emit_tex_obj,
+ nouveau_emit_nothing,
+ nouveau_emit_nothing,
+ nv10_emit_viewport
+ },
+ .num_emit = NUM_NOUVEAU_STATE,
+};
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_fb.c b/src/mesa/drivers/dri/nouveau/nv10_state_fb.c
new file mode 100644
index 0000000000..05c36b4f8f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_fb.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_class.h"
+#include "nouveau_util.h"
+#include "nv10_driver.h"
+
+static inline unsigned
+get_rt_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_XRGB8888:
+ return 0x05;
+ case MESA_FORMAT_ARGB8888:
+ return 0x08;
+ case MESA_FORMAT_RGB565:
+ return 0x03;
+ case MESA_FORMAT_Z16:
+ return 0x10;
+ case MESA_FORMAT_Z24_S8:
+ return 0x0;
+ default:
+ assert(0);
+ }
+}
+
+static void
+setup_lma_buffer(GLcontext *ctx)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct nouveau_bo_context *bctx = context_bctx(ctx, LMA_DEPTH);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(fb);
+ unsigned pitch = align(fb->Width, 128),
+ height = align(fb->Height, 2),
+ size = pitch * height;
+
+ if (!nfb->lma_bo || nfb->lma_bo->size != size) {
+ nouveau_bo_ref(NULL, &nfb->lma_bo);
+ nouveau_bo_new(context_dev(ctx), NOUVEAU_BO_VRAM, 0, size,
+ &nfb->lma_bo);
+ }
+
+ nouveau_bo_markl(bctx, celsius, NV17TCL_LMA_DEPTH_BUFFER_OFFSET,
+ nfb->lma_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
+
+ BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_WINDOW_X, 4);
+ OUT_RINGf(chan, - 1792);
+ OUT_RINGf(chan, - 2304 + fb->Height);
+ OUT_RINGf(chan, fb->_DepthMaxF / 2);
+ OUT_RINGf(chan, 0);
+
+ BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_BUFFER_PITCH, 1);
+ OUT_RING(chan, pitch);
+
+ BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_ENABLE, 1);
+ OUT_RING(chan, 1);
+}
+
+void
+nv10_emit_framebuffer(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct nouveau_surface *s;
+ unsigned rt_format = NV10TCL_RT_FORMAT_TYPE_LINEAR;
+ unsigned rt_pitch = 0, zeta_pitch = 0;
+ unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR;
+
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT)
+ return;
+
+ /* At least nv11 seems to get sad if we don't do this before
+ * swapping RTs.*/
+ if (context_chipset(ctx) < 0x17) {
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ BEGIN_RING(chan, celsius, NV10TCL_NOP, 1);
+ OUT_RING(chan, 0);
+ }
+ }
+
+ /* Render target */
+ if (fb->_NumColorDrawBuffers) {
+ s = &to_nouveau_renderbuffer(
+ fb->_ColorDrawBuffers[0])->surface;
+
+ rt_format |= get_rt_format(s->format);
+ zeta_pitch = rt_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, celsius, NV10TCL_COLOR_OFFSET,
+ s->bo, 0, bo_flags);
+ }
+
+ /* depth/stencil */
+ if (fb->_DepthBuffer) {
+ s = &to_nouveau_renderbuffer(
+ fb->_DepthBuffer->Wrapped)->surface;
+
+ rt_format |= get_rt_format(s->format);
+ zeta_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, celsius, NV10TCL_ZETA_OFFSET,
+ s->bo, 0, bo_flags);
+
+ if (context_chipset(ctx) >= 0x17)
+ setup_lma_buffer(ctx);
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_RT_FORMAT, 2);
+ OUT_RING(chan, rt_format);
+ OUT_RING(chan, zeta_pitch << 16 | rt_pitch);
+
+ context_dirty(ctx, VIEWPORT);
+ context_dirty(ctx, SCISSOR);
+}
+
+void
+nv10_emit_render_mode(GLcontext *ctx, int emit)
+{
+}
+
+void
+nv10_emit_scissor(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ int x, y, w, h;
+
+ get_scissors(ctx->DrawBuffer, &x, &y, &w, &h);
+
+ BEGIN_RING(chan, celsius, NV10TCL_RT_HORIZ, 2);
+ OUT_RING(chan, w << 16 | x);
+ OUT_RING(chan, h << 16 | y);
+}
+
+void
+nv10_emit_viewport(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ float a[4] = {};
+ int i;
+
+ get_viewport_translate(ctx, a);
+ a[0] -= 2048;
+ a[1] -= 2048;
+
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_TRANSLATE_X, 4);
+ for (i = 0; i < 4; i++)
+ OUT_RINGf(chan, a[i]);
+
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 1);
+ OUT_RING(chan, (fb->Width - 1) << 16 | 0x08000800);
+ BEGIN_RING(chan, celsius, NV10TCL_VIEWPORT_CLIP_VERT(0), 1);
+ OUT_RING(chan, (fb->Height - 1) << 16 | 0x08000800);
+
+ context_dirty(ctx, PROJECTION);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_frag.c b/src/mesa/drivers/dri/nouveau/nv10_state_frag.c
new file mode 100644
index 0000000000..c1df26ecce
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_frag.c
@@ -0,0 +1,416 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nouveau_util.h"
+#include "nv10_driver.h"
+#include "nv20_driver.h"
+
+#define RC_IN_SHIFT_A 24
+#define RC_IN_SHIFT_B 16
+#define RC_IN_SHIFT_C 8
+#define RC_IN_SHIFT_D 0
+#define RC_IN_SHIFT_E 56
+#define RC_IN_SHIFT_F 48
+#define RC_IN_SHIFT_G 40
+
+#define RC_IN_SOURCE(source) \
+ ((uint64_t)NV10TCL_RC_IN_RGB_D_INPUT_##source)
+#define RC_IN_USAGE(usage) \
+ ((uint64_t)NV10TCL_RC_IN_RGB_D_COMPONENT_USAGE_##usage)
+#define RC_IN_MAPPING(mapping) \
+ ((uint64_t)NV10TCL_RC_IN_RGB_D_MAPPING_##mapping)
+
+#define RC_OUT_BIAS NV10TCL_RC_OUT_RGB_BIAS_BIAS_BY_NEGATIVE_ONE_HALF
+#define RC_OUT_SCALE_1 NV10TCL_RC_OUT_RGB_SCALE_NONE
+#define RC_OUT_SCALE_2 NV10TCL_RC_OUT_RGB_SCALE_SCALE_BY_TWO
+#define RC_OUT_SCALE_4 NV10TCL_RC_OUT_RGB_SCALE_SCALE_BY_FOUR
+
+/* Make the combiner do: spare0_i = A_i * B_i */
+#define RC_OUT_AB NV10TCL_RC_OUT_RGB_AB_OUTPUT_SPARE0
+/* spare0_i = dot3(A, B) */
+#define RC_OUT_DOT_AB (NV10TCL_RC_OUT_RGB_AB_OUTPUT_SPARE0 | \
+ NV10TCL_RC_OUT_RGB_AB_DOT_PRODUCT)
+/* spare0_i = A_i * B_i + C_i * D_i */
+#define RC_OUT_SUM NV10TCL_RC_OUT_RGB_SUM_OUTPUT_SPARE0
+
+struct combiner_state {
+ GLcontext *ctx;
+ int unit;
+
+ /* GL state */
+ GLenum mode;
+ GLenum *source;
+ GLenum *operand;
+ GLuint logscale;
+
+ /* Derived HW state */
+ uint64_t in;
+ uint32_t out;
+};
+
+/* Initialize a combiner_state struct from the texture unit
+ * context. */
+#define INIT_COMBINER(chan, ctx, rc, i) do { \
+ struct gl_tex_env_combine_state *c = \
+ ctx->Texture.Unit[i]._CurrentCombine; \
+ (rc)->ctx = ctx; \
+ (rc)->unit = i; \
+ (rc)->mode = c->Mode##chan; \
+ (rc)->source = c->Source##chan; \
+ (rc)->operand = c->Operand##chan; \
+ (rc)->logscale = c->ScaleShift##chan; \
+ (rc)->in = (rc)->out = 0; \
+ } while (0)
+
+/* Get the RC input source for the specified EXT_texture_env_combine
+ * argument. */
+static uint32_t
+get_input_source(struct combiner_state *rc, int arg)
+{
+ switch (rc->source[arg]) {
+ case GL_TEXTURE:
+ return RC_IN_SOURCE(TEXTURE0) + rc->unit;
+
+ case GL_TEXTURE0:
+ return RC_IN_SOURCE(TEXTURE0);
+
+ case GL_TEXTURE1:
+ return RC_IN_SOURCE(TEXTURE1);
+
+ case GL_TEXTURE2:
+ return RC_IN_SOURCE(TEXTURE2);
+
+ case GL_TEXTURE3:
+ return RC_IN_SOURCE(TEXTURE3);
+
+ case GL_CONSTANT:
+ return context_chipset(rc->ctx) >= 0x20 ?
+ RC_IN_SOURCE(CONSTANT_COLOR0) :
+ RC_IN_SOURCE(CONSTANT_COLOR0) + rc->unit;
+
+ case GL_PRIMARY_COLOR:
+ return RC_IN_SOURCE(PRIMARY_COLOR);
+
+ case GL_PREVIOUS:
+ return rc->unit ? RC_IN_SOURCE(SPARE0)
+ : RC_IN_SOURCE(PRIMARY_COLOR);
+
+ default:
+ assert(0);
+ }
+}
+
+/* Get the RC input mapping for the specified argument, possibly
+ * inverted or biased. */
+#define INVERT 0x1
+#define HALF_BIAS 0x2
+
+static uint32_t
+get_input_mapping(struct combiner_state *rc, int arg, int flags)
+{
+ int map = 0;
+
+ switch (rc->operand[arg]) {
+ case GL_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_COLOR:
+ map |= RC_IN_USAGE(RGB);
+ break;
+
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ map |= RC_IN_USAGE(ALPHA);
+ break;
+ }
+
+ switch (rc->operand[arg]) {
+ case GL_SRC_COLOR:
+ case GL_SRC_ALPHA:
+ map |= (flags & INVERT ? RC_IN_MAPPING(UNSIGNED_INVERT) :
+ flags & HALF_BIAS ? RC_IN_MAPPING(HALF_BIAS_NORMAL) :
+ RC_IN_MAPPING(UNSIGNED_IDENTITY));
+ break;
+
+ case GL_ONE_MINUS_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ map |= (flags & INVERT ? RC_IN_MAPPING(UNSIGNED_IDENTITY) :
+ flags & HALF_BIAS ? RC_IN_MAPPING(HALF_BIAS_NEGATE) :
+ RC_IN_MAPPING(UNSIGNED_INVERT));
+ break;
+ }
+
+ return map;
+}
+
+/* Bind the RC input variable <var> to the EXT_texture_env_combine
+ * argument <arg>, possibly inverted or biased. */
+#define INPUT_ARG(rc, var, arg, flags) \
+ (rc)->in |= (get_input_mapping(rc, arg, flags) | \
+ get_input_source(rc, arg)) << RC_IN_SHIFT_##var
+
+/* Bind the RC input variable <var> to the RC source <src>. */
+#define INPUT_SRC(rc, var, src, chan) \
+ (rc)->in |= (RC_IN_SOURCE(src) | \
+ RC_IN_USAGE(chan)) << RC_IN_SHIFT_##var
+
+/* Bind the RC input variable <var> to a constant +/-1 */
+#define INPUT_ONE(rc, var, flags) \
+ (rc)->in |= (RC_IN_SOURCE(ZERO) | \
+ (flags & INVERT ? RC_IN_MAPPING(EXPAND_NORMAL) : \
+ RC_IN_MAPPING(UNSIGNED_INVERT))) << RC_IN_SHIFT_##var
+
+static void
+setup_combiner(struct combiner_state *rc)
+{
+ switch (rc->mode) {
+ case GL_REPLACE:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ONE(rc, B, 0);
+
+ rc->out = RC_OUT_AB;
+ break;
+
+ case GL_MODULATE:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ARG(rc, B, 1, 0);
+
+ rc->out = RC_OUT_AB;
+ break;
+
+ case GL_ADD:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ONE(rc, B, 0);
+ INPUT_ARG(rc, C, 1, 0);
+ INPUT_ONE(rc, D, 0);
+
+ rc->out = RC_OUT_SUM;
+ break;
+
+ case GL_ADD_SIGNED:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ONE(rc, B, 0);
+ INPUT_ARG(rc, C, 1, 0);
+ INPUT_ONE(rc, D, 0);
+
+ rc->out = RC_OUT_SUM | RC_OUT_BIAS;
+ break;
+
+ case GL_INTERPOLATE:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ARG(rc, B, 2, 0);
+ INPUT_ARG(rc, C, 1, 0);
+ INPUT_ARG(rc, D, 2, INVERT);
+
+ rc->out = RC_OUT_SUM;
+ break;
+
+ case GL_SUBTRACT:
+ INPUT_ARG(rc, A, 0, 0);
+ INPUT_ONE(rc, B, 0);
+ INPUT_ARG(rc, C, 1, 0);
+ INPUT_ONE(rc, D, INVERT);
+
+ rc->out = RC_OUT_SUM;
+ break;
+
+ case GL_DOT3_RGB:
+ case GL_DOT3_RGBA:
+ INPUT_ARG(rc, A, 0, HALF_BIAS);
+ INPUT_ARG(rc, B, 1, HALF_BIAS);
+
+ rc->out = RC_OUT_DOT_AB | RC_OUT_SCALE_4;
+
+ assert(!rc->logscale);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ switch (rc->logscale) {
+ case 0:
+ rc->out |= RC_OUT_SCALE_1;
+ break;
+ case 1:
+ rc->out |= RC_OUT_SCALE_2;
+ break;
+ case 2:
+ rc->out |= RC_OUT_SCALE_4;
+ break;
+ default:
+ assert(0);
+ }
+}
+
+/* Write the register combiner state out to the hardware. */
+static void
+nv10_load_combiner(GLcontext *ctx, int i, struct combiner_state *rc_a,
+ struct combiner_state *rc_c, uint32_t rc_const)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ /* Enable the combiners we're going to need. */
+ if (i == 1) {
+ if (rc_c->out || rc_a->out)
+ rc_c->out |= 0x5 << 27;
+ else
+ rc_c->out |= 0x3 << 27;
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_RC_IN_ALPHA(i), 1);
+ OUT_RING(chan, rc_a->in);
+ BEGIN_RING(chan, celsius, NV10TCL_RC_IN_RGB(i), 1);
+ OUT_RING(chan, rc_c->in);
+ BEGIN_RING(chan, celsius, NV10TCL_RC_COLOR(i), 1);
+ OUT_RING(chan, rc_const);
+ BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_ALPHA(i), 1);
+ OUT_RING(chan, rc_a->out);
+ BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_RGB(i), 1);
+ OUT_RING(chan, rc_c->out);
+}
+
+static void
+nv10_load_final(GLcontext *ctx, struct combiner_state *rc, int n)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_RC_FINAL0, 2);
+ OUT_RING(chan, rc->in);
+ OUT_RING(chan, rc->in >> 32);
+}
+
+static void
+nv20_load_combiner(GLcontext *ctx, int i, struct combiner_state *rc_a,
+ struct combiner_state *rc_c, uint32_t rc_const)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_ALPHA(i), 1);
+ OUT_RING(chan, rc_a->in);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_ALPHA(i), 1);
+ OUT_RING(chan, rc_a->out);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_RGB(i), 1);
+ OUT_RING(chan, rc_c->in);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_RGB(i), 1);
+ OUT_RING(chan, rc_c->out);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_CONSTANT_COLOR0(i), 1);
+ OUT_RING(chan, rc_const);
+}
+
+static void
+nv20_load_final(GLcontext *ctx, struct combiner_state *rc, int n)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_FINAL0, 2);
+ OUT_RING(chan, rc->in);
+ OUT_RING(chan, rc->in >> 32);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_ENABLE, 1);
+ OUT_RING(chan, n);
+}
+
+void
+nv10_emit_tex_env(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_ENV0;
+ struct combiner_state rc_a, rc_c;
+ uint32_t rc_const;
+
+ /* Compute the new combiner state. */
+ if (ctx->Texture.Unit[i]._ReallyEnabled) {
+ INIT_COMBINER(RGB, ctx, &rc_c, i);
+
+ if (rc_c.mode == GL_DOT3_RGBA)
+ rc_a = rc_c;
+ else
+ INIT_COMBINER(A, ctx, &rc_a, i);
+
+ setup_combiner(&rc_c);
+ setup_combiner(&rc_a);
+
+ rc_const = pack_rgba_f(MESA_FORMAT_ARGB8888,
+ ctx->Texture.Unit[i].EnvColor);
+
+ } else {
+ rc_a.in = rc_a.out = rc_c.in = rc_c.out = rc_const = 0;
+ }
+
+ if (context_chipset(ctx) >= 0x20)
+ nv20_load_combiner(ctx, i, &rc_a, &rc_c, rc_const);
+ else
+ nv10_load_combiner(ctx, i, &rc_a, &rc_c, rc_const);
+
+ context_dirty(ctx, FRAG);
+}
+
+void
+nv10_emit_frag(GLcontext *ctx, int emit)
+{
+ struct combiner_state rc = {};
+ int n = log2i(ctx->Texture._EnabledUnits) + 1;
+
+ /*
+ * The final fragment value equation is something like:
+ * x_i = A_i * B_i + (1 - A_i) * C_i + D_i
+ * x_alpha = G_alpha
+ * where D_i = E_i * F_i, i one of {red, green, blue}.
+ */
+ if (ctx->Fog.ColorSumEnabled || ctx->Light.Enabled) {
+ INPUT_SRC(&rc, D, E_TIMES_F, RGB);
+ INPUT_SRC(&rc, F, SECONDARY_COLOR, RGB);
+ }
+
+ if (ctx->Fog.Enabled) {
+ INPUT_SRC(&rc, A, FOG, ALPHA);
+ INPUT_SRC(&rc, C, FOG, RGB);
+ INPUT_SRC(&rc, E, FOG, ALPHA);
+ } else {
+ INPUT_ONE(&rc, A, 0);
+ INPUT_ONE(&rc, C, 0);
+ INPUT_ONE(&rc, E, 0);
+ }
+
+ if (ctx->Texture._EnabledUnits) {
+ INPUT_SRC(&rc, B, SPARE0, RGB);
+ INPUT_SRC(&rc, G, SPARE0, ALPHA);
+ } else {
+ INPUT_SRC(&rc, B, PRIMARY_COLOR, RGB);
+ INPUT_SRC(&rc, G, PRIMARY_COLOR, ALPHA);
+ }
+
+ if (context_chipset(ctx) >= 0x20)
+ nv20_load_final(ctx, &rc, n);
+ else
+ nv10_load_final(ctx, &rc, n);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_polygon.c b/src/mesa/drivers/dri/nouveau/nv10_state_polygon.c
new file mode 100644
index 0000000000..deddca1011
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_polygon.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+
+void
+nv10_emit_cull_face(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ GLenum mode = ctx->Polygon.CullFaceMode;
+
+ BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE_ENABLE, 1);
+ OUT_RING(chan, ctx->Polygon.CullFlag ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE, 1);
+ OUT_RING(chan, (mode == GL_FRONT ? NV10TCL_CULL_FACE_FRONT :
+ mode == GL_BACK ? NV10TCL_CULL_FACE_BACK :
+ NV10TCL_CULL_FACE_FRONT_AND_BACK));
+}
+
+void
+nv10_emit_front_face(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_FRONT_FACE, 1);
+ OUT_RING(chan, ctx->Polygon.FrontFace == GL_CW ?
+ NV10TCL_FRONT_FACE_CW : NV10TCL_FRONT_FACE_CCW);
+}
+
+void
+nv10_emit_line_mode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ GLboolean smooth = ctx->Line.SmoothFlag &&
+ ctx->Hint.LineSmooth == GL_NICEST;
+
+ BEGIN_RING(chan, celsius, NV10TCL_LINE_WIDTH, 1);
+ OUT_RING(chan, MAX2(smooth ? 0 : 1,
+ ctx->Line.Width) * 8);
+ BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, smooth ? 1 : 0);
+}
+
+void
+nv10_emit_line_stipple(GLcontext *ctx, int emit)
+{
+}
+
+void
+nv10_emit_point_mode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_POINT_SIZE, 1);
+ OUT_RING(chan, (uint32_t)(ctx->Point.Size * 8));
+
+ BEGIN_RING(chan, celsius, NV10TCL_POINT_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, ctx->Point.SmoothFlag ? 1 : 0);
+}
+
+void
+nv10_emit_polygon_mode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
+ OUT_RING(chan, nvgl_polygon_mode(ctx->Polygon.FrontMode));
+ OUT_RING(chan, nvgl_polygon_mode(ctx->Polygon.BackMode));
+
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_SMOOTH_ENABLE, 1);
+ OUT_RING(chan, ctx->Polygon.SmoothFlag ? 1 : 0);
+}
+
+void
+nv10_emit_polygon_offset(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
+ OUT_RING(chan, ctx->Polygon.OffsetPoint ? 1 : 0);
+ OUT_RING(chan, ctx->Polygon.OffsetLine ? 1 : 0);
+ OUT_RING(chan, ctx->Polygon.OffsetFill ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_FACTOR, 2);
+ OUT_RINGf(chan, ctx->Polygon.OffsetFactor);
+ OUT_RINGf(chan, ctx->Polygon.OffsetUnits);
+}
+
+void
+nv10_emit_polygon_stipple(GLcontext *ctx, int emit)
+{
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_raster.c b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
new file mode 100644
index 0000000000..68882ef05f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+
+void
+nv10_emit_alpha_func(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_ENABLE, 1);
+ OUT_RING(chan, ctx->Color.AlphaEnabled ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_ALPHA_FUNC_FUNC, 2);
+ OUT_RING(chan, nvgl_comparison_op(ctx->Color.AlphaFunc));
+ OUT_RING(chan, FLOAT_TO_UBYTE(ctx->Color.AlphaRef));
+}
+
+void
+nv10_emit_blend_color(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_COLOR, 1);
+ OUT_RING(chan, FLOAT_TO_UBYTE(ctx->Color.BlendColor[3]) << 24 |
+ FLOAT_TO_UBYTE(ctx->Color.BlendColor[0]) << 16 |
+ FLOAT_TO_UBYTE(ctx->Color.BlendColor[1]) << 8 |
+ FLOAT_TO_UBYTE(ctx->Color.BlendColor[2]) << 0);
+}
+
+void
+nv10_emit_blend_equation(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_ENABLE, 1);
+ OUT_RING(chan, ctx->Color.BlendEnabled ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_EQUATION, 1);
+ OUT_RING(chan, nvgl_blend_eqn(ctx->Color.BlendEquationRGB));
+}
+
+void
+nv10_emit_blend_func(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_SRC, 2);
+ OUT_RING(chan, nvgl_blend_func(ctx->Color.BlendSrcRGB));
+ OUT_RING(chan, nvgl_blend_func(ctx->Color.BlendDstRGB));
+}
+
+void
+nv10_emit_color_mask(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_COLOR_MASK, 1);
+ OUT_RING(chan, ((ctx->Color.ColorMask[0][3] ? 1 << 24 : 0) |
+ (ctx->Color.ColorMask[0][0] ? 1 << 16 : 0) |
+ (ctx->Color.ColorMask[0][1] ? 1 << 8 : 0) |
+ (ctx->Color.ColorMask[0][2] ? 1 << 0 : 0)));
+}
+
+void
+nv10_emit_depth(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_TEST_ENABLE, 1);
+ OUT_RING(chan, ctx->Depth.Test ? 1 : 0);
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_WRITE_ENABLE, 1);
+ OUT_RING(chan, ctx->Depth.Mask ? 1 : 0);
+ BEGIN_RING(chan, celsius, NV10TCL_DEPTH_FUNC, 1);
+ OUT_RING(chan, nvgl_comparison_op(ctx->Depth.Func));
+}
+
+void
+nv10_emit_dither(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_DITHER_ENABLE, 1);
+ OUT_RING(chan, ctx->Color.DitherFlag ? 1 : 0);
+}
+
+void
+nv10_emit_index_mask(GLcontext *ctx, int emit)
+{
+}
+
+void
+nv10_emit_logic_opcode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ assert(!ctx->Color.ColorLogicOpEnabled
+ || context_chipset(ctx) >= 0x11);
+
+ BEGIN_RING(chan, celsius, NV11TCL_COLOR_LOGIC_OP_ENABLE, 2);
+ OUT_RING(chan, ctx->Color.ColorLogicOpEnabled ? 1 : 0);
+ OUT_RING(chan, nvgl_logicop_func(ctx->Color.LogicOp));
+}
+
+void
+nv10_emit_shade_model(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_SHADE_MODEL, 1);
+ OUT_RING(chan, ctx->Light.ShadeModel == GL_SMOOTH ?
+ NV10TCL_SHADE_MODEL_SMOOTH : NV10TCL_SHADE_MODEL_FLAT);
+}
+
+void
+nv10_emit_stencil_func(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_STENCIL_ENABLE, 1);
+ OUT_RING(chan, ctx->Stencil.Enabled ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_STENCIL_FUNC_FUNC, 3);
+ OUT_RING(chan, nvgl_comparison_op(ctx->Stencil.Function[0]));
+ OUT_RING(chan, ctx->Stencil.Ref[0]);
+ OUT_RING(chan, ctx->Stencil.ValueMask[0]);
+}
+
+void
+nv10_emit_stencil_mask(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_STENCIL_MASK, 1);
+ OUT_RING(chan, ctx->Stencil.WriteMask[0]);
+}
+
+void
+nv10_emit_stencil_op(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+
+ BEGIN_RING(chan, celsius, NV10TCL_STENCIL_OP_FAIL, 3);
+ OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.FailFunc[0]));
+ OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.ZFailFunc[0]));
+ OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.ZPassFunc[0]));
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_tex.c b/src/mesa/drivers/dri/nouveau/nv10_state_tex.c
new file mode 100644
index 0000000000..e5d4f3d18d
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_tex.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_texture.h"
+#include "nouveau_class.h"
+#include "nouveau_util.h"
+#include "nv10_driver.h"
+
+void
+nv10_emit_tex_gen(GLcontext *ctx, int emit)
+{
+}
+
+static uint32_t
+get_tex_format(struct gl_texture_image *ti)
+{
+ switch (ti->TexFormat) {
+ case MESA_FORMAT_ARGB8888:
+ return NV10TCL_TX_FORMAT_FORMAT_A8R8G8B8;
+
+ case MESA_FORMAT_ARGB1555:
+ return NV10TCL_TX_FORMAT_FORMAT_A1R5G5B5;
+
+ case MESA_FORMAT_ARGB4444:
+ return NV10TCL_TX_FORMAT_FORMAT_A4R4G4B4;
+
+ case MESA_FORMAT_RGB565:
+ return NV10TCL_TX_FORMAT_FORMAT_R5G6B5;
+
+ case MESA_FORMAT_A8:
+ return NV10TCL_TX_FORMAT_FORMAT_A8;
+
+ case MESA_FORMAT_L8:
+ return NV10TCL_TX_FORMAT_FORMAT_L8;
+
+ case MESA_FORMAT_CI8:
+ return NV10TCL_TX_FORMAT_FORMAT_INDEX8;
+
+ default:
+ assert(0);
+ }
+}
+
+void
+nv10_emit_tex_obj(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_OBJ0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i);
+ const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM;
+ struct gl_texture_object *t;
+ struct nouveau_surface *s;
+ struct gl_texture_image *ti;
+ uint32_t tx_format, tx_filter, tx_enable;
+
+ if (!ctx->Texture.Unit[i]._ReallyEnabled) {
+ BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(i), 1);
+ OUT_RING(chan, 0);
+ return;
+ }
+
+ t = ctx->Texture.Unit[i]._Current;
+ s = &to_nouveau_texture(t)->surfaces[t->BaseLevel];
+ ti = t->Image[0][t->BaseLevel];
+
+ nouveau_texture_validate(ctx, t);
+
+ /* Recompute the texturing registers. */
+ tx_format = nvgl_wrap_mode(t->WrapT) << 28
+ | nvgl_wrap_mode(t->WrapS) << 24
+ | ti->HeightLog2 << 20
+ | ti->WidthLog2 << 16
+ | get_tex_format(ti)
+ | 5 << 4 | 1 << 12;
+
+ tx_filter = nvgl_filter_mode(t->MagFilter) << 28
+ | nvgl_filter_mode(t->MinFilter) << 24;
+
+ tx_enable = NV10TCL_TX_ENABLE_ENABLE
+ | log2i(t->MaxAnisotropy) << 4;
+
+ if (t->MinFilter != GL_NEAREST &&
+ t->MinFilter != GL_LINEAR) {
+ int lod_min = t->MinLod;
+ int lod_max = MIN2(t->MaxLod, t->_MaxLambda);
+ int lod_bias = t->LodBias
+ + ctx->Texture.Unit[i].LodBias;
+
+ lod_max = CLAMP(lod_max, 0, 15);
+ lod_min = CLAMP(lod_min, 0, 15);
+ lod_bias = CLAMP(lod_bias, 0, 15);
+
+ tx_format |= NV10TCL_TX_FORMAT_MIPMAP;
+ tx_filter |= lod_bias << 8;
+ tx_enable |= lod_min << 26
+ | lod_max << 14;
+ }
+
+ /* Write it to the hardware. */
+ nouveau_bo_mark(bctx, celsius, NV10TCL_TX_FORMAT(i),
+ s->bo, tx_format, 0,
+ NV10TCL_TX_FORMAT_DMA0,
+ NV10TCL_TX_FORMAT_DMA1,
+ bo_flags | NOUVEAU_BO_OR);
+
+ nouveau_bo_markl(bctx, celsius, NV10TCL_TX_OFFSET(i),
+ s->bo, 0, bo_flags);
+
+ BEGIN_RING(chan, celsius, NV10TCL_TX_FILTER(i), 1);
+ OUT_RING(chan, tx_filter);
+
+ BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(i), 1);
+ OUT_RING(chan, tx_enable);
+}
+
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c b/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
new file mode 100644
index 0000000000..6db14d83b8
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
@@ -0,0 +1,514 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+
+void
+nv10_emit_clip_plane(GLcontext *ctx, int emit)
+{
+}
+
+static inline unsigned
+get_material_bitmask(unsigned m)
+{
+ unsigned ret = 0;
+
+ if (m & MAT_BIT_FRONT_EMISSION)
+ ret |= NV10TCL_COLOR_MATERIAL_EMISSION;
+ if (m & MAT_BIT_FRONT_AMBIENT)
+ ret |= NV10TCL_COLOR_MATERIAL_AMBIENT;
+ if (m & MAT_BIT_FRONT_DIFFUSE)
+ ret |= NV10TCL_COLOR_MATERIAL_DIFFUSE;
+ if (m & MAT_BIT_FRONT_SPECULAR)
+ ret |= NV10TCL_COLOR_MATERIAL_SPECULAR;
+
+ return ret;
+}
+
+void
+nv10_emit_color_material(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ unsigned mask = get_material_bitmask(ctx->Light.ColorMaterialBitmask);
+
+ BEGIN_RING(chan, celsius, NV10TCL_COLOR_MATERIAL, 1);
+ OUT_RING(chan, ctx->Light.ColorMaterialEnabled ? mask : 0);
+}
+
+static unsigned
+get_fog_mode(unsigned mode)
+{
+ switch (mode) {
+ case GL_LINEAR:
+ return NV10TCL_FOG_MODE_LINEAR;
+ case GL_EXP:
+ return NV10TCL_FOG_MODE_EXP;
+ case GL_EXP2:
+ return NV10TCL_FOG_MODE_EXP2;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_fog_source(unsigned source)
+{
+ switch (source) {
+ case GL_FOG_COORDINATE_EXT:
+ return NV10TCL_FOG_COORD_FOG;
+ case GL_FRAGMENT_DEPTH_EXT:
+ return NV10TCL_FOG_COORD_DIST_ORTHOGONAL_ABS;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv10_get_fog_coeff(GLcontext *ctx, float k[3])
+{
+ struct gl_fog_attrib *f = &ctx->Fog;
+
+ switch (f->Mode) {
+ case GL_LINEAR:
+ k[0] = 2 + f->Start / (f->End - f->Start);
+ k[1] = -1 / (f->End - f->Start);
+ break;
+
+ case GL_EXP:
+ k[0] = 1.5;
+ k[1] = -0.09 * f->Density;
+ break;
+
+ case GL_EXP2:
+ k[0] = 1.5;
+ k[1] = -0.21 * f->Density;
+ break;
+
+ default:
+ assert(0);
+ }
+
+ k[2] = 0;
+}
+
+void
+nv10_emit_fog(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct gl_fog_attrib *f = &ctx->Fog;
+ unsigned source = nctx->fallback == HWTNL ?
+ f->FogCoordinateSource : GL_FOG_COORDINATE_EXT;
+ float k[3];
+
+ nv10_get_fog_coeff(ctx, k);
+
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_MODE, 4);
+ OUT_RING(chan, get_fog_mode(f->Mode));
+ OUT_RING(chan, get_fog_source(source));
+ OUT_RING(chan, f->Enabled ? 1 : 0);
+ OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));
+
+ BEGIN_RING(chan, celsius, NV10TCL_FOG_EQUATION_CONSTANT, 3);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+
+ context_dirty(ctx, FRAG);
+}
+
+static inline unsigned
+get_light_mode(struct gl_light *l)
+{
+ if (l->Enabled) {
+ if (l->_Flags & LIGHT_SPOT)
+ return NV10TCL_ENABLED_LIGHTS_0_DIRECTIONAL;
+ else if (l->_Flags & LIGHT_POSITIONAL)
+ return NV10TCL_ENABLED_LIGHTS_0_POSITIONAL;
+ else
+ return NV10TCL_ENABLED_LIGHTS_0_NONPOSITIONAL;
+ } else {
+ return NV10TCL_ENABLED_LIGHTS_0_DISABLED;
+ }
+}
+
+void
+nv10_emit_light_enable(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ uint32_t en_lights = 0;
+ int i;
+
+ if (nctx->fallback != HWTNL) {
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHTING_ENABLE, 1);
+ OUT_RING(chan, 0);
+ return;
+ }
+
+ for (i = 0; i < MAX_LIGHTS; i++)
+ en_lights |= get_light_mode(&ctx->Light.Light[i]) << 2 * i;
+
+ BEGIN_RING(chan, celsius, NV10TCL_ENABLED_LIGHTS, 1);
+ OUT_RING(chan, en_lights);
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHTING_ENABLE, 1);
+ OUT_RING(chan, ctx->Light.Enabled ? 1 : 0);
+ BEGIN_RING(chan, celsius, NV10TCL_NORMALIZE_ENABLE, 1);
+ OUT_RING(chan, ctx->Transform.Normalize ? 1 : 0);
+}
+
+void
+nv10_emit_light_model(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct gl_lightmodel *m = &ctx->Light.Model;
+
+ BEGIN_RING(chan, celsius, NV10TCL_SEPARATE_SPECULAR_ENABLE, 1);
+ OUT_RING(chan, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ? 1 : 0);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL, 1);
+ OUT_RING(chan, ((m->LocalViewer ?
+ NV10TCL_LIGHT_MODEL_LOCAL_VIEWER : 0) |
+ (m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ?
+ NV10TCL_LIGHT_MODEL_SEPARATE_SPECULAR : 0)));
+}
+
+static float
+get_shine(const float p[], float x)
+{
+ const int n = 15;
+ const float *y = &p[1];
+ float f = (n - 1) * (1 - 1 / (1 + p[0] * x))
+ / (1 - 1 / (1 + p[0] * 1024));
+ int i = f;
+
+ /* Linear interpolation in f-space (Faster and somewhat more
+ * accurate than x-space). */
+ if (x == 0)
+ return y[0];
+ else if (i > n - 2)
+ return y[n - 1];
+ else
+ return y[i] + (y[i + 1] - y[i]) * (f - i);
+}
+
+static const float nv10_spot_params[2][16] = {
+ { 0.02, -3.80e-05, -1.77, -2.41, -2.71, -2.88, -2.98, -3.06,
+ -3.11, -3.17, -3.23, -3.28, -3.37, -3.47, -3.83, -5.11 },
+ { 0.02, -0.01, 1.77, 2.39, 2.70, 2.87, 2.98, 3.06,
+ 3.10, 3.16, 3.23, 3.27, 3.37, 3.47, 3.83, 5.11 },
+};
+
+void
+nv10_get_spot_coeff(struct gl_light *l, float k[7])
+{
+ float e = l->SpotExponent;
+ float a0, b0, a1, a2, b2, a3;
+
+ if (e > 0)
+ a0 = -1 - 5.36e-3 / sqrt(e);
+ else
+ a0 = -1;
+ b0 = 1 / (1 + 0.273 * e);
+
+ a1 = get_shine(nv10_spot_params[0], e);
+
+ a2 = get_shine(nv10_spot_params[1], e);
+ b2 = 1 / (1 + 0.273 * e);
+
+ a3 = 0.9 + 0.278 * e;
+
+ if (l->SpotCutoff > 0) {
+ float cutoff = MAX2(a3, 1 / (1 - l->_CosCutoff));
+
+ k[0] = MAX2(0, a0 + b0 * cutoff);
+ k[1] = a1;
+ k[2] = a2 + b2 * cutoff;
+ k[3] = - cutoff * l->_NormSpotDirection[0];
+ k[4] = - cutoff * l->_NormSpotDirection[1];
+ k[5] = - cutoff * l->_NormSpotDirection[2];
+ k[6] = 1 - cutoff;
+
+ } else {
+ k[0] = b0;
+ k[1] = a1;
+ k[2] = a2 + b2;
+ k[3] = - l->_NormSpotDirection[0];
+ k[4] = - l->_NormSpotDirection[1];
+ k[5] = - l->_NormSpotDirection[2];
+ k[6] = -1;
+ }
+}
+
+void
+nv10_emit_light_source(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct gl_light *l = &ctx->Light.Light[i];
+
+ if (l->_Flags & LIGHT_POSITIONAL) {
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_POSITION_X(i), 3);
+ OUT_RINGf(chan, l->_Position[0]);
+ OUT_RINGf(chan, l->_Position[1]);
+ OUT_RINGf(chan, l->_Position[2]);
+
+ BEGIN_RING(chan, celsius,
+ NV10TCL_LIGHT_ATTENUATION_CONSTANT(i), 3);
+ OUT_RINGf(chan, l->ConstantAttenuation);
+ OUT_RINGf(chan, l->LinearAttenuation);
+ OUT_RINGf(chan, l->QuadraticAttenuation);
+
+ } else {
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_DIRECTION_X(i), 3);
+ OUT_RINGf(chan, l->_VP_inf_norm[0]);
+ OUT_RINGf(chan, l->_VP_inf_norm[1]);
+ OUT_RINGf(chan, l->_VP_inf_norm[2]);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_HALF_VECTOR_X(i), 3);
+ OUT_RINGf(chan, l->_h_inf_norm[0]);
+ OUT_RINGf(chan, l->_h_inf_norm[1]);
+ OUT_RINGf(chan, l->_h_inf_norm[2]);
+ }
+
+ if (l->_Flags & LIGHT_SPOT) {
+ float k[7];
+
+ nv10_get_spot_coeff(l, k);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPOT_CUTOFF_A(i), 7);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+ OUT_RINGf(chan, k[3]);
+ OUT_RINGf(chan, k[4]);
+ OUT_RINGf(chan, k[5]);
+ OUT_RINGf(chan, k[6]);
+ }
+}
+
+#define USE_COLOR_MATERIAL(attr) \
+ (ctx->Light.ColorMaterialEnabled && \
+ ctx->Light.ColorMaterialBitmask & (1 << MAT_ATTRIB_FRONT_##attr))
+
+void
+nv10_emit_material_ambient(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ float (*mat)[4] = ctx->Light.Material.Attrib;
+ float c_scene[3], c_factor[3];
+ struct gl_light *l;
+
+ if (USE_COLOR_MATERIAL(AMBIENT)) {
+ COPY_3V(c_scene, ctx->Light.Model.Ambient);
+ COPY_3V(c_factor, mat[MAT_ATTRIB_FRONT_EMISSION]);
+
+ } else if (USE_COLOR_MATERIAL(EMISSION)) {
+ SCALE_3V(c_scene, mat[MAT_ATTRIB_FRONT_AMBIENT],
+ ctx->Light.Model.Ambient);
+ ZERO_3V(c_factor);
+
+ } else {
+ COPY_3V(c_scene, ctx->Light._BaseColor[0]);
+ ZERO_3V(c_factor);
+ }
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL_AMBIENT_R, 3);
+ OUT_RINGf(chan, c_scene[0]);
+ OUT_RINGf(chan, c_scene[1]);
+ OUT_RINGf(chan, c_scene[2]);
+
+ if (ctx->Light.ColorMaterialEnabled) {
+ BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_FACTOR_R, 3);
+ OUT_RINGf(chan, c_factor[0]);
+ OUT_RINGf(chan, c_factor[1]);
+ OUT_RINGf(chan, c_factor[2]);
+ }
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ float *c_light = (USE_COLOR_MATERIAL(AMBIENT) ?
+ l->Ambient :
+ l->_MatAmbient[0]);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_AMBIENT_R(i), 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+void
+nv10_emit_material_diffuse(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
+ struct gl_light *l;
+
+ BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_FACTOR_A, 1);
+ OUT_RINGf(chan, mat[MAT_ATTRIB_FRONT_DIFFUSE][3]);
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ float *c_light = (USE_COLOR_MATERIAL(DIFFUSE) ?
+ l->Diffuse :
+ l->_MatDiffuse[0]);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_DIFFUSE_R(i), 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+void
+nv10_emit_material_specular(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ struct gl_light *l;
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ float *c_light = (USE_COLOR_MATERIAL(SPECULAR) ?
+ l->Specular :
+ l->_MatSpecular[0]);
+
+ BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPECULAR_R(i), 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+static const float nv10_shininess_param[6][16] = {
+ { 0.70, 0.00, 0.06, 0.06, 0.05, 0.04, 0.02, 0.00,
+ -0.06, -0.13, -0.24, -0.36, -0.51, -0.66, -0.82, -1.00 },
+ { 0.01, 1.00, -2.29, -2.77, -2.96, -3.06, -3.12, -3.18,
+ -3.24, -3.29, -3.36, -3.43, -3.51, -3.75, -4.33, -5.11 },
+ { 0.02, 0.00, 2.28, 2.75, 2.94, 3.04, 3.1, 3.15,
+ 3.18, 3.22, 3.27, 3.32, 3.39, 3.48, 3.84, 5.11 },
+ { 0.70, 0.00, 0.05, 0.06, 0.06, 0.06, 0.05, 0.04,
+ 0.02, 0.01, -0.03, -0.12, -0.25, -0.43, -0.68, -0.99 },
+ { 0.01, 1.00, -1.61, -2.35, -2.67, -2.84, -2.96, -3.05,
+ -3.08, -3.14, -3.2, -3.26, -3.32, -3.42, -3.54, -4.21 },
+ { 0.01, 0.00, 2.25, 2.73, 2.92, 3.03, 3.09, 3.15,
+ 3.16, 3.21, 3.25, 3.29, 3.35, 3.43, 3.56, 4.22 },
+};
+
+void
+nv10_get_shininess_coeff(float s, float k[6])
+{
+ int i;
+
+ for (i = 0; i < 6; i++)
+ k[i] = get_shine(nv10_shininess_param[i], s);
+}
+
+void
+nv10_emit_material_shininess(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ float (*mat)[4] = ctx->Light.Material.Attrib;
+ float k[6];
+
+ nv10_get_shininess_coeff(
+ CLAMP(mat[MAT_ATTRIB_FRONT_SHININESS][0], 0, 1024),
+ k);
+
+ BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_SHININESS(0), 6);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+ OUT_RINGf(chan, k[3]);
+ OUT_RINGf(chan, k[4]);
+ OUT_RINGf(chan, k[5]);
+}
+
+void
+nv10_emit_modelview(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ GLmatrix *m = ctx->ModelviewMatrixStack.Top;
+
+ if (nctx->fallback != HWTNL)
+ return;
+
+ if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled) {
+ BEGIN_RING(chan, celsius, NV10TCL_MODELVIEW0_MATRIX(0), 16);
+ OUT_RINGm(chan, m->m);
+ }
+
+ if (ctx->Light.Enabled) {
+ int i, j;
+
+ BEGIN_RING(chan, celsius,
+ NV10TCL_INVERSE_MODELVIEW0_MATRIX(0), 12);
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 4; j++)
+ OUT_RINGf(chan, m->inv[4*i + j]);
+ }
+}
+
+void
+nv10_emit_point_parameter(GLcontext *ctx, int emit)
+{
+}
+
+void
+nv10_emit_projection(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(ctx);
+ GLmatrix m;
+
+ _math_matrix_ctr(&m);
+ get_viewport_scale(ctx, m.m);
+
+ if (nctx->fallback == HWTNL)
+ _math_matrix_mul_matrix(&m, &m, &ctx->_ModelProjectMatrix);
+
+ BEGIN_RING(chan, celsius, NV10TCL_PROJECTION_MATRIX(0), 16);
+ OUT_RINGm(chan, m.m);
+
+ _math_matrix_dtr(&m);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_context.c
new file mode 100644
index 0000000000..698b83431b
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_context.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nv20_driver.h"
+
+GLcontext *
+nv20_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx)
+{
+ struct nouveau_context *nctx;
+ GLcontext *ctx;
+
+ nctx = CALLOC_STRUCT(nouveau_context);
+ if (!nctx)
+ return NULL;
+
+ ctx = &nctx->base;
+ nouveau_context_init(ctx, screen, visual, share_ctx);
+
+ ctx->Const.MaxTextureCoordUnits = NV20_TEXTURE_UNITS;
+ ctx->Const.MaxTextureImageUnits = NV20_TEXTURE_UNITS;
+ ctx->Const.MaxTextureUnits = NV20_TEXTURE_UNITS;
+ ctx->Const.MaxTextureMaxAnisotropy = 8;
+ ctx->Const.MaxTextureLodBias = 15;
+
+ nv20_render_init(ctx);
+
+ return ctx;
+}
+
+void
+nv20_context_destroy(GLcontext *ctx)
+{
+ nv20_render_destroy(ctx);
+ FREE(ctx);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_driver.h b/src/mesa/drivers/dri/nouveau/nv20_driver.h
new file mode 100644
index 0000000000..2de18ee4af
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_driver.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 __NV20_DRIVER_H__
+#define __NV20_DRIVER_H__
+
+enum {
+ NOUVEAU_STATE_TEX_SHADER = NUM_NOUVEAU_STATE,
+ NUM_NV20_STATE
+};
+
+#define NV20_TEXTURE_UNITS 4
+
+/* nv20_screen.c */
+GLboolean
+nv20_screen_init(struct nouveau_screen *screen);
+
+/* nv20_context.c */
+GLcontext *
+nv20_context_create(struct nouveau_screen *screen, const GLvisual *visual,
+ GLcontext *share_ctx);
+
+void
+nv20_context_destroy(GLcontext *ctx);
+
+/* nv20_render.c */
+void
+nv20_render_init(GLcontext *ctx);
+
+void
+nv20_render_destroy(GLcontext *ctx);
+
+/* nv20_state_fb.c */
+void
+nv20_emit_framebuffer(GLcontext *ctx, int emit);
+
+void
+nv20_emit_viewport(GLcontext *ctx, int emit);
+
+/* nv20_state_polygon.c */
+void
+nv20_emit_point_mode(GLcontext *ctx, int emit);
+
+/* nv20_state_raster.c */
+void
+nv20_emit_logic_opcode(GLcontext *ctx, int emit);
+
+/* nv20_state_tex.c */
+void
+nv20_emit_tex_obj(GLcontext *ctx, int emit);
+
+void
+nv20_emit_tex_shader(GLcontext *ctx, int emit);
+
+/* nv20_state_tnl.c */
+void
+nv20_emit_clip_plane(GLcontext *ctx, int emit);
+
+void
+nv20_emit_color_material(GLcontext *ctx, int emit);
+
+void
+nv20_emit_fog(GLcontext *ctx, int emit);
+
+void
+nv20_emit_light_model(GLcontext *ctx, int emit);
+
+void
+nv20_emit_light_source(GLcontext *ctx, int emit);
+
+void
+nv20_emit_material_ambient(GLcontext *ctx, int emit);
+
+void
+nv20_emit_material_diffuse(GLcontext *ctx, int emit);
+
+void
+nv20_emit_material_specular(GLcontext *ctx, int emit);
+
+void
+nv20_emit_material_shininess(GLcontext *ctx, int emit);
+
+void
+nv20_emit_modelview(GLcontext *ctx, int emit);
+
+void
+nv20_emit_projection(GLcontext *ctx, int emit);
+
+#endif
diff --git a/src/mesa/drivers/dri/nouveau/nv20_render.c b/src/mesa/drivers/dri/nouveau/nv20_render.c
new file mode 100644
index 0000000000..a696ac107f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_render.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_class.h"
+#include "nv20_driver.h"
+
+#define NUM_VERTEX_ATTRS 16
+
+static void
+nv20_emit_material(GLcontext *ctx, struct nouveau_array_state *a,
+ const void *v);
+
+/* Vertex attribute format. */
+static struct nouveau_attr_info nv20_vertex_attrs[VERT_ATTRIB_MAX] = {
+ [VERT_ATTRIB_POS] = {
+ .vbo_index = 0,
+ .imm_method = NV20TCL_VERTEX_POS_4F_X,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_NORMAL] = {
+ .vbo_index = 2,
+ .imm_method = NV20TCL_VERTEX_NOR_3F_X,
+ .imm_fields = 3,
+ },
+ [VERT_ATTRIB_COLOR0] = {
+ .vbo_index = 3,
+ .imm_method = NV20TCL_VERTEX_COL_4F_X,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_COLOR1] = {
+ .vbo_index = 4,
+ .imm_method = NV20TCL_VERTEX_COL2_3F_X,
+ .imm_fields = 3,
+ },
+ [VERT_ATTRIB_FOG] = {
+ .vbo_index = 5,
+ .imm_method = NV20TCL_VERTEX_FOG_1F,
+ .imm_fields = 1,
+ },
+ [VERT_ATTRIB_TEX0] = {
+ .vbo_index = 9,
+ .imm_method = NV20TCL_VERTEX_TX0_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_TEX1] = {
+ .vbo_index = 10,
+ .imm_method = NV20TCL_VERTEX_TX1_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_TEX2] = {
+ .vbo_index = 11,
+ .imm_method = NV20TCL_VERTEX_TX2_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_TEX3] = {
+ .vbo_index = 12,
+ .imm_method = NV20TCL_VERTEX_TX3_4F_S,
+ .imm_fields = 4,
+ },
+ [VERT_ATTRIB_GENERIC0] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC1] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC2] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC3] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC4] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC5] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC6] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC7] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC8] = {
+ .emit = nv20_emit_material,
+ },
+ [VERT_ATTRIB_GENERIC9] = {
+ .emit = nv20_emit_material,
+ },
+};
+
+static int
+get_hw_format(int type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ return NV20TCL_VTXFMT_TYPE_FLOAT;
+ case GL_UNSIGNED_SHORT:
+ return NV20TCL_VTXFMT_TYPE_USHORT;
+ case GL_UNSIGNED_BYTE:
+ return NV20TCL_VTXFMT_TYPE_UBYTE;
+ default:
+ assert(0);
+ }
+}
+
+static void
+nv20_render_set_format(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ int i, hw_format;
+
+ for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ struct nouveau_array_state *a = &render->attrs[attr];
+
+ hw_format = a->stride << 8 |
+ a->fields << 4 |
+ get_hw_format(a->type);
+
+ } else {
+ /* Unused attribute. */
+ hw_format = NV10TCL_VTXFMT_TYPE_FLOAT;
+ }
+
+ BEGIN_RING(chan, kelvin, NV20TCL_VTXFMT(i), 1);
+ OUT_RING(chan, hw_format);
+ }
+}
+
+static void
+nv20_render_bind_vertices(GLcontext *ctx)
+{
+ struct nouveau_render_state *render = to_render_state(ctx);
+ struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ int i;
+
+ for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
+ int attr = render->map[i];
+
+ if (attr >= 0) {
+ struct nouveau_array_state *a = &render->attrs[attr];
+
+ nouveau_bo_mark(bctx, kelvin,
+ NV20TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset, 0,
+ 0, NV20TCL_VTXBUF_ADDRESS_DMA1,
+ NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
+ }
+ }
+
+ BEGIN_RING(chan, kelvin, NV20TCL_VTX_CACHE_INVALIDATE, 1);
+ OUT_RING(chan, 0);
+}
+
+/* Vertex array rendering defs. */
+#define RENDER_LOCALS(ctx) \
+ struct nouveau_grobj *kelvin = context_eng3d(ctx)
+
+#define BATCH_BEGIN(prim) \
+ BEGIN_RING(chan, kelvin, NV20TCL_VERTEX_BEGIN_END, 1); \
+ OUT_RING(chan, prim);
+#define BATCH_END() \
+ BEGIN_RING(chan, kelvin, NV20TCL_VERTEX_BEGIN_END, 1); \
+ OUT_RING(chan, 0);
+
+#define MAX_PACKET 0x400
+
+#define MAX_OUT_L 0x100
+#define BATCH_PACKET_L(n) \
+ BEGIN_RING_NI(chan, kelvin, NV20TCL_VB_VERTEX_BATCH, n);
+#define BATCH_OUT_L(i, n) \
+ OUT_RING(chan, ((n) - 1) << 24 | (i));
+
+#define MAX_OUT_I16 0x2
+#define BATCH_PACKET_I16(n) \
+ BEGIN_RING_NI(chan, kelvin, NV20TCL_VB_ELEMENT_U16, n);
+#define BATCH_OUT_I16(i0, i1) \
+ OUT_RING(chan, (i1) << 16 | (i0));
+
+#define MAX_OUT_I32 0x1
+#define BATCH_PACKET_I32(n) \
+ BEGIN_RING_NI(chan, kelvin, NV20TCL_VB_ELEMENT_U32, n);
+#define BATCH_OUT_I32(i) \
+ OUT_RING(chan, i);
+
+#define IMM_PACKET(m, n) \
+ BEGIN_RING(chan, kelvin, m, n);
+#define IMM_OUT(x) \
+ OUT_RINGf(chan, x);
+
+#define TAG(x) nv20_##x
+#include "nouveau_render_t.c"
diff --git a/src/gallium/drivers/nv20/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_screen.c
index 5b80af2d22..1d29fc9976 100644
--- a/src/gallium/drivers/nv20/nv20_context.c
+++ b/src/mesa/drivers/dri/nouveau/nv20_screen.c
@@ -1,65 +1,69 @@
-#include "draw/draw_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-
-#include "nv20_context.h"
-#include "nv20_screen.h"
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_screen.h"
+#include "nouveau_class.h"
+#include "nv04_driver.h"
+#include "nv10_driver.h"
+#include "nv20_driver.h"
+
+static const struct nouveau_driver nv20_driver;
static void
-nv20_flush(struct pipe_context *pipe, unsigned flags,
- struct pipe_fence_handle **fence)
+nv20_hwctx_init(struct nouveau_screen *screen)
{
- struct nv20_context *nv20 = nv20_context(pipe);
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
-
- draw_flush(nv20->draw);
-
- FIRE_RING(chan);
- if (fence)
- *fence = NULL;
-}
-
-static void
-nv20_destroy(struct pipe_context *pipe)
-{
- struct nv20_context *nv20 = nv20_context(pipe);
-
- if (nv20->draw)
- draw_destroy(nv20->draw);
-
- FREE(nv20);
-}
-
-static void nv20_init_hwctx(struct nv20_context *nv20)
-{
- struct nv20_screen *screen = nv20->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *kelvin = screen->kelvin;
+ struct nouveau_channel *chan = screen->chan;
+ struct nouveau_grobj *kelvin = screen->eng3d;
+ const unsigned chipset = screen->device->chipset;
int i;
- float projectionmatrix[16];
- const boolean is_nv25tcl = (kelvin->grclass == NV25TCL);
BEGIN_RING(chan, kelvin, NV20TCL_DMA_NOTIFY, 1);
- OUT_RING (chan, screen->sync->handle);
+ OUT_RING (chan, screen->ntfy->handle);
BEGIN_RING(chan, kelvin, NV20TCL_DMA_TEXTURE0, 2);
OUT_RING (chan, chan->vram->handle);
- OUT_RING (chan, chan->gart->handle); /* TEXTURE1 */
+ OUT_RING (chan, chan->gart->handle);
BEGIN_RING(chan, kelvin, NV20TCL_DMA_COLOR, 2);
OUT_RING (chan, chan->vram->handle);
- OUT_RING (chan, chan->vram->handle); /* ZETA */
+ OUT_RING (chan, chan->vram->handle);
+ BEGIN_RING(chan, kelvin, NV20TCL_DMA_VTXBUF0, 2);
+ OUT_RING(chan, chan->vram->handle);
+ OUT_RING(chan, chan->gart->handle);
BEGIN_RING(chan, kelvin, NV20TCL_DMA_QUERY, 1);
- OUT_RING (chan, 0); /* renouveau: beef0351, unique */
+ OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_RT_HORIZ, 2);
OUT_RING (chan, 0);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_HORIZ(0), 1);
- OUT_RING (chan, (0xfff << 16) | 0x0);
+ OUT_RING (chan, 0xfff << 16 | 0x0);
BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_VERT(0), 1);
- OUT_RING (chan, (0xfff << 16) | 0x0);
+ OUT_RING (chan, 0xfff << 16 | 0x0);
for (i = 1; i < NV20TCL_VIEWPORT_CLIP_HORIZ__SIZE; i++) {
BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_HORIZ(i), 1);
@@ -76,7 +80,7 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RINGf (chan, 0.0);
OUT_RINGf (chan, 1.0);
- if (is_nv25tcl) {
+ if (chipset >= 0x25) {
BEGIN_RING(chan, kelvin, NV20TCL_TX_RCOMP, 1);
OUT_RING (chan, NV20TCL_TX_RCOMP_LEQUAL | 0xdb0);
} else {
@@ -87,7 +91,7 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
}
BEGIN_RING(chan, kelvin, 0x290, 1);
- OUT_RING (chan, (0x10 << 16) | 1);
+ OUT_RING (chan, 0x10 << 16 | 1);
BEGIN_RING(chan, kelvin, 0x9fc, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, 0x1d80, 1);
@@ -99,7 +103,7 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RINGf (chan, 1.0);
OUT_RINGf (chan, 0.0);
- if (is_nv25tcl) {
+ if (chipset >= 0x25) {
BEGIN_RING(chan, kelvin, 0x1d88, 1);
OUT_RING (chan, 3);
@@ -108,21 +112,13 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
BEGIN_RING(chan, kelvin, NV25TCL_DMA_IN_MEMORY8, 1);
OUT_RING (chan, chan->vram->handle);
}
+
BEGIN_RING(chan, kelvin, NV20TCL_DMA_FENCE, 1);
- OUT_RING (chan, 0); /* renouveau: beef1e10 */
+ OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, 0x1e98, 1);
OUT_RING (chan, 0);
-#if 0
- if (is_nv25tcl) {
- BEGIN_RING(chan, NvSub3D, NV25TCL_DMA_IN_MEMORY4, 2);
- OUT_RING (chan, NvDmaTT); /* renouveau: beef0202 */
- OUT_RING (chan, NvDmaFB); /* renouveau: beef0201 */
- BEGIN_RING(chan, NvSub3D, NV20TCL_DMA_TEXTURE1, 1);
- OUT_RING (chan, NvDmaTT); /* renouveau: beef0202 */
- }
-#endif
BEGIN_RING(chan, kelvin, NV20TCL_NOTIFY, 1);
OUT_RING (chan, 0);
@@ -131,53 +127,35 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RING (chan, 1);
OUT_RING (chan, 2);
-/* error: ILLEGAL_MTHD, PROTECTION_FAULT
- BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_TRANSLATE_X, 4);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 512.0);
- OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0);
-*/
-
- if (is_nv25tcl) {
+ if (chipset >= 0x25) {
BEGIN_RING(chan, kelvin, 0x022c, 2);
OUT_RING (chan, 0x280);
OUT_RING (chan, 0x07d28000);
- }
-/* * illegal method, protection fault
- BEGIN_RING(chan, NvSub3D, 0x1c2c, 1);
- OUT_RING (chan, 0); */
-
- if (is_nv25tcl) {
BEGIN_RING(chan, kelvin, 0x1da4, 1);
OUT_RING (chan, 0);
}
-/* * crashes with illegal method, protection fault
- BEGIN_RING(chan, NvSub3D, 0x1c18, 1);
- OUT_RING (chan, 0x200); */
-
BEGIN_RING(chan, kelvin, NV20TCL_RT_HORIZ, 2);
- OUT_RING (chan, (0 << 16) | 0);
- OUT_RING (chan, (0 << 16) | 0);
-
- /* *** Set state *** */
+ OUT_RING (chan, 0 << 16 | 0);
+ OUT_RING (chan, 0 << 16 | 0);
BEGIN_RING(chan, kelvin, NV20TCL_ALPHA_FUNC_ENABLE, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_ALPHA_FUNC_FUNC, 2);
OUT_RING (chan, NV20TCL_ALPHA_FUNC_FUNC_ALWAYS);
- OUT_RING (chan, 0); /* NV20TCL_ALPHA_FUNC_REF */
+ OUT_RING (chan, 0);
- for (i = 0; i < NV20TCL_TX_ENABLE__SIZE; ++i) {
+ for (i = 0; i < NV20TCL_TX_ENABLE__SIZE; i++) {
BEGIN_RING(chan, kelvin, NV20TCL_TX_ENABLE(i), 1);
OUT_RING (chan, 0);
}
+
BEGIN_RING(chan, kelvin, NV20TCL_TX_SHADER_OP, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_TX_SHADER_CULL_MODE, 1);
OUT_RING (chan, 0);
+
BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_ALPHA(0), 4);
OUT_RING (chan, 0x30d410d0);
OUT_RING (chan, 0);
@@ -211,9 +189,9 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RING (chan, 0);
OUT_RING (chan, 0x40002000);
OUT_RING (chan, 0);
+
BEGIN_RING(chan, kelvin, NV20TCL_MULTISAMPLE_CONTROL, 1);
OUT_RING (chan, 0xffff0000);
-
BEGIN_RING(chan, kelvin, NV20TCL_BLEND_FUNC_ENABLE, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_DITHER_ENABLE, 1);
@@ -223,13 +201,13 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
BEGIN_RING(chan, kelvin, NV20TCL_BLEND_FUNC_SRC, 4);
OUT_RING (chan, NV20TCL_BLEND_FUNC_SRC_ONE);
OUT_RING (chan, NV20TCL_BLEND_FUNC_DST_ZERO);
- OUT_RING (chan, 0); /* NV20TCL_BLEND_COLOR */
+ OUT_RING (chan, 0);
OUT_RING (chan, NV20TCL_BLEND_EQUATION_FUNC_ADD);
BEGIN_RING(chan, kelvin, NV20TCL_STENCIL_MASK, 7);
OUT_RING (chan, 0xff);
OUT_RING (chan, NV20TCL_STENCIL_FUNC_FUNC_ALWAYS);
- OUT_RING (chan, 0); /* NV20TCL_STENCIL_FUNC_REF */
- OUT_RING (chan, 0xff); /* NV20TCL_STENCIL_FUNC_MASK */
+ OUT_RING (chan, 0);
+ OUT_RING (chan, 0xff);
OUT_RING (chan, NV20TCL_STENCIL_OP_FAIL_KEEP);
OUT_RING (chan, NV20TCL_STENCIL_OP_ZFAIL_KEEP);
OUT_RING (chan, NV20TCL_STENCIL_OP_ZPASS_KEEP);
@@ -239,14 +217,14 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RING (chan, NV20TCL_COLOR_LOGIC_OP_OP_COPY);
BEGIN_RING(chan, kelvin, 0x17cc, 1);
OUT_RING (chan, 0);
- if (is_nv25tcl) {
+ if (chipset >= 0x25) {
BEGIN_RING(chan, kelvin, 0x1d84, 1);
OUT_RING (chan, 1);
}
BEGIN_RING(chan, kelvin, NV20TCL_LIGHTING_ENABLE, 1);
OUT_RING (chan, 0);
- BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_CONTROL, 1);
- OUT_RING (chan, 0x00020000);
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_MODEL, 1);
+ OUT_RING (chan, NV20TCL_LIGHT_MODEL_VIEWER_NONLOCAL);
BEGIN_RING(chan, kelvin, NV20TCL_SEPARATE_SPECULAR_ENABLE, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_MODEL_TWO_SIDE_ENABLE, 1);
@@ -256,15 +234,15 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
BEGIN_RING(chan, kelvin, NV20TCL_NORMALIZE_ENABLE, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_POLYGON_STIPPLE_PATTERN(0),
- NV20TCL_POLYGON_STIPPLE_PATTERN__SIZE);
- for (i = 0; i < NV20TCL_POLYGON_STIPPLE_PATTERN__SIZE; ++i) {
+ NV20TCL_POLYGON_STIPPLE_PATTERN__SIZE);
+ for (i = 0; i < NV20TCL_POLYGON_STIPPLE_PATTERN__SIZE; i++) {
OUT_RING(chan, 0xffffffff);
}
BEGIN_RING(chan, kelvin, NV20TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
OUT_RING (chan, 0);
- OUT_RING (chan, 0); /* NV20TCL.POLYGON_OFFSET_LINE_ENABLE */
- OUT_RING (chan, 0); /* NV20TCL.POLYGON_OFFSET_FILL_ENABLE */
+ OUT_RING (chan, 0);
+ OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_FUNC, 1);
OUT_RING (chan, NV20TCL_DEPTH_FUNC_LESS);
BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_WRITE_ENABLE, 1);
@@ -273,29 +251,30 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, NV20TCL_POLYGON_OFFSET_FACTOR, 2);
OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 0.0); /* NV20TCL.POLYGON_OFFSET_UNITS */
+ OUT_RINGf (chan, 0.0);
BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_UNK17D8, 1);
OUT_RING (chan, 1);
- if (!is_nv25tcl) {
+ if (chipset < 0x25) {
BEGIN_RING(chan, kelvin, 0x1d84, 1);
OUT_RING (chan, 3);
}
BEGIN_RING(chan, kelvin, NV20TCL_POINT_SIZE, 1);
- if (!is_nv25tcl) {
- OUT_RING (chan, 8);
- } else {
+ if (chipset >= 0x25)
OUT_RINGf (chan, 1.0);
- }
- if (!is_nv25tcl) {
- BEGIN_RING(chan, kelvin, NV20TCL_POINT_PARAMETERS_ENABLE, 2);
- OUT_RING (chan, 0);
- OUT_RING (chan, 0); /* NV20TCL.POINT_SMOOTH_ENABLE */
- } else {
+ else
+ OUT_RING (chan, 8);
+
+ if (chipset >= 0x25) {
BEGIN_RING(chan, kelvin, NV20TCL_POINT_PARAMETERS_ENABLE, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, kelvin, 0x0a1c, 1);
OUT_RING (chan, 0x800);
+ } else {
+ BEGIN_RING(chan, kelvin, NV20TCL_POINT_PARAMETERS_ENABLE, 2);
+ OUT_RING (chan, 0);
+ OUT_RING (chan, 0);
}
+
BEGIN_RING(chan, kelvin, NV20TCL_LINE_WIDTH, 1);
OUT_RING (chan, 8);
BEGIN_RING(chan, kelvin, NV20TCL_LINE_SMOOTH_ENABLE, 1);
@@ -314,33 +293,45 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
OUT_RING (chan, NV20TCL_SHADE_MODEL_SMOOTH);
BEGIN_RING(chan, kelvin, NV20TCL_POLYGON_STIPPLE_ENABLE, 1);
OUT_RING (chan, 0);
- BEGIN_RING(chan, kelvin, NV20TCL_TX_GEN_S(0), 4 * NV20TCL_TX_GEN_S__SIZE);
- for (i=0; i < 4 * NV20TCL_TX_GEN_S__SIZE; ++i) {
+
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_GEN_S(0),
+ 4 * NV20TCL_TX_GEN_S__SIZE);
+ for (i=0; i < 4 * NV20TCL_TX_GEN_S__SIZE; i++)
OUT_RING(chan, 0);
- }
+
BEGIN_RING(chan, kelvin, NV20TCL_FOG_EQUATION_CONSTANT, 3);
OUT_RINGf (chan, 1.5);
- OUT_RINGf (chan, -0.090168); /* NV20TCL.FOG_EQUATION_LINEAR */
- OUT_RINGf (chan, 0.0); /* NV20TCL.FOG_EQUATION_QUADRATIC */
+ OUT_RINGf (chan, -0.090168);
+ OUT_RINGf (chan, 0.0);
BEGIN_RING(chan, kelvin, NV20TCL_FOG_MODE, 2);
OUT_RING (chan, NV20TCL_FOG_MODE_EXP_SIGNED);
OUT_RING (chan, NV20TCL_FOG_COORD_FOG);
BEGIN_RING(chan, kelvin, NV20TCL_FOG_ENABLE, 2);
OUT_RING (chan, 0);
- OUT_RING (chan, 0); /* NV20TCL.FOG_COLOR */
+ OUT_RING (chan, 0);
+
BEGIN_RING(chan, kelvin, NV20TCL_ENGINE, 1);
OUT_RING (chan, NV20TCL_ENGINE_FIXED);
- for (i = 0; i < NV20TCL_TX_MATRIX_ENABLE__SIZE; ++i) {
+ for (i = 0; i < NV20TCL_TX_MATRIX_ENABLE__SIZE; i++) {
BEGIN_RING(chan, kelvin, NV20TCL_TX_MATRIX_ENABLE(i), 1);
OUT_RING (chan, 0);
}
BEGIN_RING(chan, kelvin, NV20TCL_VTX_ATTR_4F_X(1), 4 * 15);
- OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 1.0);
- OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 1.0);
- OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 1.0);
- for (i = 4; i < 16; ++i) {
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 0.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 1.0);
+ OUT_RINGf(chan, 1.0);
+ for (i = 0; i < 12; i++) {
OUT_RINGf(chan, 0.0);
OUT_RINGf(chan, 0.0);
OUT_RINGf(chan, 0.0);
@@ -354,71 +345,139 @@ static void nv20_init_hwctx(struct nv20_context *nv20)
BEGIN_RING(chan, kelvin, NV20TCL_CLEAR_VALUE, 1);
OUT_RING (chan, 0);
- memset(projectionmatrix, 0, sizeof(projectionmatrix));
- projectionmatrix[0*4+0] = 1.0;
- projectionmatrix[1*4+1] = 1.0;
- projectionmatrix[2*4+2] = 16777215.0;
- projectionmatrix[3*4+3] = 1.0;
- BEGIN_RING(chan, kelvin, NV20TCL_PROJECTION_MATRIX(0), 16);
- for (i = 0; i < 16; i++) {
- OUT_RINGf (chan, projectionmatrix[i]);
- }
-
BEGIN_RING(chan, kelvin, NV20TCL_DEPTH_RANGE_NEAR, 2);
OUT_RINGf (chan, 0.0);
- OUT_RINGf (chan, 16777216.0); /* [0, 1] scaled approx to [0, 2^24] */
+ OUT_RINGf (chan, 16777216.0);
BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_TRANSLATE_X, 4);
- OUT_RINGf (chan, 0.0); /* x-offset, w/2 + 1.031250 */
- OUT_RINGf (chan, 0.0); /* y-offset, h/2 + 0.030762 */
+ OUT_RINGf (chan, 0.0);
+ OUT_RINGf (chan, 0.0);
OUT_RINGf (chan, 0.0);
OUT_RINGf (chan, 16777215.0);
BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_SCALE_X, 4);
- OUT_RINGf (chan, 0.0); /* no effect?, w/2 */
- OUT_RINGf (chan, 0.0); /* no effect?, h/2 */
+ OUT_RINGf (chan, 0.0);
+ OUT_RINGf (chan, 0.0);
OUT_RINGf (chan, 16777215.0 * 0.5);
OUT_RINGf (chan, 65535.0);
- FIRE_RING (chan);
+ FIRE_RING(chan);
}
-struct pipe_context *
-nv20_create(struct pipe_screen *pscreen, unsigned pctx_id)
+GLboolean
+nv20_screen_init(struct nouveau_screen *screen)
{
- struct nv20_screen *screen = nv20_screen(pscreen);
- struct pipe_winsys *ws = pscreen->winsys;
- struct nv20_context *nv20;
- struct nouveau_winsys *nvws = screen->nvws;
+ unsigned chipset = screen->device->chipset;
+ unsigned kelvin_class;
+ int ret;
- nv20 = CALLOC(1, sizeof(struct nv20_context));
- if (!nv20)
- return NULL;
- nv20->screen = screen;
- nv20->pctx_id = pctx_id;
+ screen->driver = &nv20_driver;
- nv20->nvws = nvws;
+ /* 2D engine */
+ ret = nv04_surface_init(screen);
+ if (!ret)
+ return GL_FALSE;
- nv20->pipe.winsys = ws;
- nv20->pipe.screen = pscreen;
- nv20->pipe.destroy = nv20_destroy;
- nv20->pipe.draw_arrays = nv20_draw_arrays;
- nv20->pipe.draw_elements = nv20_draw_elements;
- nv20->pipe.clear = nv20_clear;
- nv20->pipe.flush = nv20_flush;
+ /* 3D engine. */
+ if (chipset >= 0x25)
+ kelvin_class = NV25TCL;
+ else
+ kelvin_class = NV20TCL;
- nv20->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nv20->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
+ ret = nouveau_grobj_alloc(screen->chan, 0xbeef0001, kelvin_class,
+ &screen->eng3d);
+ if (ret)
+ return GL_FALSE;
- nv20_init_surface_functions(nv20);
- nv20_init_state_functions(nv20);
+ nv20_hwctx_init(screen);
- nv20->draw = draw_create();
- assert(nv20->draw);
- draw_set_rasterize_stage(nv20->draw, nv20_draw_vbuf_stage(nv20));
+ return GL_TRUE;
+}
- nv20_init_hwctx(nv20);
+static void
+nv20_screen_destroy(struct nouveau_screen *screen)
+{
+ if (screen->eng3d)
+ nouveau_grobj_free(&screen->eng3d);
- return &nv20->pipe;
+ nv04_surface_takedown(screen);
}
+static const struct nouveau_driver nv20_driver = {
+ .screen_destroy = nv20_screen_destroy,
+ .context_create = nv20_context_create,
+ .context_destroy = nv20_context_destroy,
+ .surface_copy = nv04_surface_copy,
+ .surface_fill = nv04_surface_fill,
+ .emit = (nouveau_state_func[]) {
+ nv10_emit_alpha_func,
+ nv10_emit_blend_color,
+ nv10_emit_blend_equation,
+ nv10_emit_blend_func,
+ nv20_emit_clip_plane,
+ nv20_emit_clip_plane,
+ nv20_emit_clip_plane,
+ nv20_emit_clip_plane,
+ nv20_emit_clip_plane,
+ nv20_emit_clip_plane,
+ nv10_emit_color_mask,
+ nv20_emit_color_material,
+ nv10_emit_cull_face,
+ nv10_emit_front_face,
+ nv10_emit_depth,
+ nv10_emit_dither,
+ nv10_emit_frag,
+ nv20_emit_framebuffer,
+ nv20_emit_fog,
+ nv10_emit_index_mask,
+ nv10_emit_light_enable,
+ nv20_emit_light_model,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv20_emit_light_source,
+ nv10_emit_line_stipple,
+ nv10_emit_line_mode,
+ nv20_emit_logic_opcode,
+ nv20_emit_material_ambient,
+ nv20_emit_material_ambient,
+ nv20_emit_material_diffuse,
+ nv20_emit_material_diffuse,
+ nv20_emit_material_specular,
+ nv20_emit_material_specular,
+ nv20_emit_material_shininess,
+ nv20_emit_material_shininess,
+ nv20_emit_modelview,
+ nv20_emit_point_mode,
+ nv10_emit_point_parameter,
+ nv10_emit_polygon_mode,
+ nv10_emit_polygon_offset,
+ nv10_emit_polygon_stipple,
+ nv20_emit_projection,
+ nv10_emit_render_mode,
+ nv10_emit_scissor,
+ nv10_emit_shade_model,
+ nv10_emit_stencil_func,
+ nv10_emit_stencil_mask,
+ nv10_emit_stencil_op,
+ nv10_emit_tex_env,
+ nv10_emit_tex_env,
+ nv10_emit_tex_env,
+ nv10_emit_tex_env,
+ nv10_emit_tex_gen,
+ nv10_emit_tex_gen,
+ nv10_emit_tex_gen,
+ nv10_emit_tex_gen,
+ nv20_emit_tex_obj,
+ nv20_emit_tex_obj,
+ nv20_emit_tex_obj,
+ nv20_emit_tex_obj,
+ nv20_emit_viewport,
+ nv20_emit_tex_shader
+ },
+ .num_emit = NUM_NV20_STATE,
+};
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_fb.c b/src/mesa/drivers/dri/nouveau/nv20_state_fb.c
new file mode 100644
index 0000000000..869acd6e31
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_fb.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_fbo.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv20_driver.h"
+
+static inline unsigned
+get_rt_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_XRGB8888:
+ return 0x05;
+ case MESA_FORMAT_ARGB8888:
+ return 0x08;
+ case MESA_FORMAT_RGB565:
+ return 0x03;
+ case MESA_FORMAT_Z16:
+ return 0x10;
+ case MESA_FORMAT_Z24_S8:
+ return 0x20;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv20_emit_framebuffer(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ struct nouveau_surface *s;
+ unsigned rt_format = NV20TCL_RT_FORMAT_TYPE_LINEAR;
+ unsigned rt_pitch = 0, zeta_pitch = 0;
+ unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR;
+
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT)
+ return;
+
+ /* Render target */
+ if (fb->_NumColorDrawBuffers) {
+ s = &to_nouveau_renderbuffer(
+ fb->_ColorDrawBuffers[0])->surface;
+
+ rt_format |= get_rt_format(s->format);
+ zeta_pitch = rt_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, kelvin, NV20TCL_COLOR_OFFSET,
+ s->bo, 0, bo_flags);
+ }
+
+ /* depth/stencil */
+ if (fb->_DepthBuffer) {
+ s = &to_nouveau_renderbuffer(
+ fb->_DepthBuffer->Wrapped)->surface;
+
+ rt_format |= get_rt_format(s->format);
+ zeta_pitch = s->pitch;
+
+ nouveau_bo_markl(bctx, kelvin, NV20TCL_ZETA_OFFSET,
+ s->bo, 0, bo_flags);
+ }
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RT_FORMAT, 2);
+ OUT_RING(chan, rt_format);
+ OUT_RING(chan, zeta_pitch << 16 | rt_pitch);
+
+ /* Recompute the viewport/scissor state. */
+ context_dirty(ctx, VIEWPORT);
+ context_dirty(ctx, SCISSOR);
+}
+
+void
+nv20_emit_viewport(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct gl_framebuffer *fb = ctx->DrawBuffer;
+ float a[4] = {};
+ int i;
+
+ get_viewport_translate(ctx, a);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_TRANSLATE_X, 4);
+ for (i = 0; i < 4; i++)
+ OUT_RINGf(chan, a[i]);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_HORIZ(0), 1);
+ OUT_RING(chan, (fb->Width - 1) << 16);
+ BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_VERT(0), 1);
+ OUT_RING(chan, (fb->Height - 1) << 16);
+
+ context_dirty(ctx, PROJECTION);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_polygon.c b/src/mesa/drivers/dri/nouveau/nv20_state_polygon.c
new file mode 100644
index 0000000000..3a320e2dac
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_polygon.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nv20_driver.h"
+
+void
+nv20_emit_point_mode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_POINT_SIZE, 1);
+ if (context_chipset(ctx) >= 0x25)
+ OUT_RINGf(chan, ctx->Point.Size);
+ else
+ OUT_RING(chan, (uint32_t)(ctx->Point.Size * 8));
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_raster.c b/src/mesa/drivers/dri/nouveau/nv20_state_raster.c
new file mode 100644
index 0000000000..b43b29bb23
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_raster.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_class.h"
+#include "nv20_driver.h"
+
+void
+nv20_emit_logic_opcode(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_COLOR_LOGIC_OP_ENABLE, 2);
+ OUT_RING(chan, ctx->Color.ColorLogicOpEnabled ? 1 : 0);
+ OUT_RING(chan, nvgl_logicop_func(ctx->Color.LogicOp));
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_tex.c b/src/mesa/drivers/dri/nouveau/nv20_state_tex.c
new file mode 100644
index 0000000000..d01e91f8ee
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_tex.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_texture.h"
+#include "nouveau_class.h"
+#include "nouveau_util.h"
+#include "nv20_driver.h"
+
+static uint32_t
+get_tex_format(struct gl_texture_image *ti)
+{
+ switch (ti->TexFormat) {
+ case MESA_FORMAT_ARGB8888:
+ return NV20TCL_TX_FORMAT_FORMAT_A8R8G8B8;
+
+ case MESA_FORMAT_ARGB1555:
+ return NV20TCL_TX_FORMAT_FORMAT_A1R5G5B5;
+
+ case MESA_FORMAT_ARGB4444:
+ return NV20TCL_TX_FORMAT_FORMAT_A4R4G4B4;
+
+ case MESA_FORMAT_RGB565:
+ return NV20TCL_TX_FORMAT_FORMAT_R5G6B5;
+
+ case MESA_FORMAT_A8:
+ return NV20TCL_TX_FORMAT_FORMAT_A8;
+
+ case MESA_FORMAT_L8:
+ return NV20TCL_TX_FORMAT_FORMAT_L8;
+
+ case MESA_FORMAT_CI8:
+ return NV20TCL_TX_FORMAT_FORMAT_INDEX8;
+
+ default:
+ assert(0);
+ }
+}
+
+void
+nv20_emit_tex_obj(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_OBJ0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i);
+ const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM;
+ struct gl_texture_object *t;
+ struct nouveau_surface *s;
+ struct gl_texture_image *ti;
+ uint32_t tx_format, tx_filter, tx_wrap, tx_enable;
+
+ if (!ctx->Texture.Unit[i]._ReallyEnabled) {
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_ENABLE(i), 1);
+ OUT_RING(chan, 0);
+
+ context_dirty(ctx, TEX_SHADER);
+ return;
+ }
+
+ t = ctx->Texture.Unit[i]._Current;
+ s = &to_nouveau_texture(t)->surfaces[t->BaseLevel];
+ ti = t->Image[0][t->BaseLevel];
+
+ nouveau_texture_validate(ctx, t);
+
+ /* Recompute the texturing registers. */
+ tx_format = ti->DepthLog2 << 28
+ | ti->HeightLog2 << 24
+ | ti->WidthLog2 << 20
+ | get_tex_format(ti)
+ | NV20TCL_TX_FORMAT_DIMS_2D
+ | NV20TCL_TX_FORMAT_NO_BORDER
+ | 1 << 16;
+
+ tx_wrap = nvgl_wrap_mode(t->WrapR) << 16
+ | nvgl_wrap_mode(t->WrapT) << 8
+ | nvgl_wrap_mode(t->WrapS) << 0;
+
+ tx_filter = nvgl_filter_mode(t->MagFilter) << 24
+ | nvgl_filter_mode(t->MinFilter) << 16;
+
+ tx_enable = NV20TCL_TX_ENABLE_ENABLE
+ | log2i(t->MaxAnisotropy) << 4;
+
+ if (t->MinFilter != GL_NEAREST &&
+ t->MinFilter != GL_LINEAR) {
+ int lod_min = t->MinLod;
+ int lod_max = MIN2(t->MaxLod, t->_MaxLambda);
+ int lod_bias = t->LodBias
+ + ctx->Texture.Unit[i].LodBias;
+
+ lod_max = CLAMP(lod_max, 0, 15);
+ lod_min = CLAMP(lod_min, 0, 15);
+ lod_bias = CLAMP(lod_bias, 0, 15);
+
+ tx_format |= NV20TCL_TX_FORMAT_MIPMAP;
+ tx_filter |= lod_bias << 8;
+ tx_enable |= lod_min << 26
+ | lod_max << 14;
+ }
+
+ /* Write it to the hardware. */
+ nouveau_bo_mark(bctx, kelvin, NV20TCL_TX_FORMAT(i),
+ s->bo, tx_format, 0,
+ NV20TCL_TX_FORMAT_DMA0,
+ NV20TCL_TX_FORMAT_DMA1,
+ bo_flags | NOUVEAU_BO_OR);
+
+ nouveau_bo_markl(bctx, kelvin, NV20TCL_TX_OFFSET(i),
+ s->bo, 0, bo_flags);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_WRAP(i), 1);
+ OUT_RING(chan, tx_wrap);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_FILTER(i), 1);
+ OUT_RING(chan, tx_filter);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_ENABLE(i), 1);
+ OUT_RING(chan, tx_enable);
+
+ context_dirty(ctx, TEX_SHADER);
+}
+
+void
+nv20_emit_tex_shader(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ uint32_t tx_shader_op = 0;
+ int i;
+
+ for (i = 0; i < NV20_TEXTURE_UNITS; i++) {
+ if (!ctx->Texture.Unit[i]._ReallyEnabled)
+ continue;
+
+ tx_shader_op |= NV20TCL_TX_SHADER_OP_TX0_TEXTURE_2D << 5 * i;
+ }
+
+ BEGIN_RING(chan, kelvin, NV20TCL_TX_SHADER_OP, 1);
+ OUT_RING(chan, tx_shader_op);
+}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c b/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c
new file mode 100644
index 0000000000..0d566064f6
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c
@@ -0,0 +1,396 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR 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 "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_gldefs.h"
+#include "nouveau_util.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+#include "nv20_driver.h"
+
+void
+nv20_emit_clip_plane(GLcontext *ctx, int emit)
+{
+}
+
+static inline unsigned
+get_material_bitmask(unsigned m)
+{
+ unsigned ret = 0;
+
+ if (m & MAT_BIT_FRONT_EMISSION)
+ ret |= NV20TCL_COLOR_MATERIAL_FRONT_EMISSION_COL1;
+ if (m & MAT_BIT_FRONT_AMBIENT)
+ ret |= NV20TCL_COLOR_MATERIAL_FRONT_AMBIENT_COL1;
+ if (m & MAT_BIT_FRONT_DIFFUSE)
+ ret |= NV20TCL_COLOR_MATERIAL_FRONT_DIFFUSE_COL1;
+ if (m & MAT_BIT_FRONT_SPECULAR)
+ ret |= NV20TCL_COLOR_MATERIAL_FRONT_SPECULAR_COL1;
+
+ if (m & MAT_BIT_BACK_EMISSION)
+ ret |= NV20TCL_COLOR_MATERIAL_BACK_EMISSION_COL1;
+ if (m & MAT_BIT_BACK_AMBIENT)
+ ret |= NV20TCL_COLOR_MATERIAL_BACK_AMBIENT_COL1;
+ if (m & MAT_BIT_BACK_DIFFUSE)
+ ret |= NV20TCL_COLOR_MATERIAL_BACK_DIFFUSE_COL1;
+ if (m & MAT_BIT_BACK_SPECULAR)
+ ret |= NV20TCL_COLOR_MATERIAL_BACK_SPECULAR_COL1;
+
+ return ret;
+}
+
+void
+nv20_emit_color_material(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ unsigned mask = get_material_bitmask(ctx->Light.ColorMaterialBitmask);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_COLOR_MATERIAL, 1);
+ OUT_RING(chan, ctx->Light.ColorMaterialEnabled ? mask : 0);
+}
+
+static unsigned
+get_fog_mode_signed(unsigned mode)
+{
+ switch (mode) {
+ case GL_LINEAR:
+ return NV20TCL_FOG_MODE_LINEAR_SIGNED;
+ case GL_EXP:
+ return NV20TCL_FOG_MODE_EXP_SIGNED;
+ case GL_EXP2:
+ return NV20TCL_FOG_MODE_EXP2_SIGNED;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_fog_mode_unsigned(unsigned mode)
+{
+ switch (mode) {
+ case GL_LINEAR:
+ return NV20TCL_FOG_MODE_LINEAR_UNSIGNED;
+ case GL_EXP:
+ return NV20TCL_FOG_MODE_EXP_UNSIGNED;
+ case GL_EXP2:
+ return NV20TCL_FOG_MODE_EXP2_UNSIGNED;
+ default:
+ assert(0);
+ }
+}
+
+static unsigned
+get_fog_source(unsigned source)
+{
+ switch (source) {
+ case GL_FOG_COORDINATE_EXT:
+ return NV20TCL_FOG_COORD_FOG;
+ case GL_FRAGMENT_DEPTH_EXT:
+ return NV20TCL_FOG_COORD_DIST_ORTHOGONAL_ABS;
+ default:
+ assert(0);
+ }
+}
+
+void
+nv20_emit_fog(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct gl_fog_attrib *f = &ctx->Fog;
+ unsigned source = nctx->fallback == HWTNL ?
+ f->FogCoordinateSource : GL_FOG_COORDINATE_EXT;
+ float k[3];
+
+ nv10_get_fog_coeff(ctx, k);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_FOG_MODE, 4);
+ OUT_RING(chan, (source == GL_FOG_COORDINATE_EXT ?
+ get_fog_mode_signed(f->Mode) :
+ get_fog_mode_unsigned(f->Mode)));
+ OUT_RING(chan, get_fog_source(source));
+ OUT_RING(chan, f->Enabled ? 1 : 0);
+ OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));
+
+ BEGIN_RING(chan, kelvin, NV20TCL_FOG_EQUATION_CONSTANT, 3);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+}
+
+void
+nv20_emit_light_model(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct gl_lightmodel *m = &ctx->Light.Model;
+
+ BEGIN_RING(chan, kelvin, NV20TCL_SEPARATE_SPECULAR_ENABLE, 1);
+ OUT_RING(chan, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ? 1 : 0);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_MODEL, 1);
+ OUT_RING(chan, ((m->LocalViewer ?
+ NV20TCL_LIGHT_MODEL_VIEWER_LOCAL :
+ NV20TCL_LIGHT_MODEL_VIEWER_NONLOCAL) |
+ (m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ?
+ NV20TCL_LIGHT_MODEL_SEPARATE_SPECULAR :
+ 0)));
+
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_MODEL_TWO_SIDE_ENABLE, 1);
+ OUT_RING(chan, ctx->Light.Model.TwoSide ? 1 : 0);
+}
+
+void
+nv20_emit_light_source(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct gl_light *l = &ctx->Light.Light[i];
+
+ if (l->_Flags & LIGHT_POSITIONAL) {
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_POSITION_X(i), 3);
+ OUT_RINGf(chan, l->_Position[0]);
+ OUT_RINGf(chan, l->_Position[1]);
+ OUT_RINGf(chan, l->_Position[2]);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_ATTENUATION_CONSTANT(i), 3);
+ OUT_RINGf(chan, l->ConstantAttenuation);
+ OUT_RINGf(chan, l->LinearAttenuation);
+ OUT_RINGf(chan, l->QuadraticAttenuation);
+
+ } else {
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_DIRECTION_X(i), 3);
+ OUT_RINGf(chan, l->_VP_inf_norm[0]);
+ OUT_RINGf(chan, l->_VP_inf_norm[1]);
+ OUT_RINGf(chan, l->_VP_inf_norm[2]);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_HALF_VECTOR_X(i), 3);
+ OUT_RINGf(chan, l->_h_inf_norm[0]);
+ OUT_RINGf(chan, l->_h_inf_norm[1]);
+ OUT_RINGf(chan, l->_h_inf_norm[2]);
+ }
+
+ if (l->_Flags & LIGHT_SPOT) {
+ float k[7];
+
+ nv10_get_spot_coeff(l, k);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_LIGHT_SPOT_CUTOFF_A(i), 7);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+ OUT_RINGf(chan, k[3]);
+ OUT_RINGf(chan, k[4]);
+ OUT_RINGf(chan, k[5]);
+ OUT_RINGf(chan, k[6]);
+ }
+}
+
+#define USE_COLOR_MATERIAL(attr, side) \
+ (ctx->Light.ColorMaterialEnabled && \
+ ctx->Light.ColorMaterialBitmask & (1 << MAT_ATTRIB_##attr(side)))
+
+void
+nv20_emit_material_ambient(GLcontext *ctx, int emit)
+{
+ const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ float (*mat)[4] = ctx->Light.Material.Attrib;
+ uint32_t m_scene[] = { NV20TCL_LIGHT_MODEL_FRONT_AMBIENT_R,
+ NV20TCL_LIGHT_MODEL_BACK_AMBIENT_R };
+ uint32_t m_factor[] = { NV20TCL_MATERIAL_FACTOR_FRONT_R,
+ NV20TCL_MATERIAL_FACTOR_BACK_R };
+ float c_scene[3], c_factor[3];
+ struct gl_light *l;
+
+ if (USE_COLOR_MATERIAL(AMBIENT, side)) {
+ COPY_3V(c_scene, mat[MAT_ATTRIB_EMISSION(side)]);
+ COPY_3V(c_factor, ctx->Light.Model.Ambient);
+
+ } else if (USE_COLOR_MATERIAL(EMISSION, side)) {
+ SCALE_3V(c_scene, mat[MAT_ATTRIB_AMBIENT(side)],
+ ctx->Light.Model.Ambient);
+ ASSIGN_3V(c_factor, 1, 1, 1);
+
+ } else {
+ COPY_3V(c_scene, ctx->Light._BaseColor[side]);
+ ZERO_3V(c_factor);
+ }
+
+ BEGIN_RING(chan, kelvin, m_scene[side], 3);
+ OUT_RINGf(chan, c_scene[0]);
+ OUT_RINGf(chan, c_scene[1]);
+ OUT_RINGf(chan, c_scene[2]);
+
+ if (ctx->Light.ColorMaterialEnabled) {
+ BEGIN_RING(chan, kelvin, m_factor[side], 3);
+ OUT_RINGf(chan, c_factor[0]);
+ OUT_RINGf(chan, c_factor[1]);
+ OUT_RINGf(chan, c_factor[2]);
+ }
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ uint32_t m_light[] = { NV20TCL_LIGHT_FRONT_AMBIENT_R(i),
+ NV20TCL_LIGHT_BACK_AMBIENT_R(i) };
+ float *c_light = (USE_COLOR_MATERIAL(AMBIENT, side) ?
+ l->Ambient :
+ l->_MatAmbient[side]);
+
+ BEGIN_RING(chan, kelvin, m_light[side], 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+void
+nv20_emit_material_diffuse(GLcontext *ctx, int emit)
+{
+ const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
+ uint32_t m_factor[] = { NV20TCL_MATERIAL_FACTOR_FRONT_A,
+ NV20TCL_MATERIAL_FACTOR_BACK_A };
+ struct gl_light *l;
+
+ BEGIN_RING(chan, kelvin, m_factor[side], 1);
+ OUT_RINGf(chan, mat[MAT_ATTRIB_DIFFUSE(side)][3]);
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ uint32_t m_light[] = { NV20TCL_LIGHT_FRONT_DIFFUSE_R(i),
+ NV20TCL_LIGHT_BACK_DIFFUSE_R(i) };
+ float *c_light = (USE_COLOR_MATERIAL(DIFFUSE, side) ?
+ l->Diffuse :
+ l->_MatDiffuse[side]);
+
+ BEGIN_RING(chan, kelvin, m_light[side], 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+void
+nv20_emit_material_specular(GLcontext *ctx, int emit)
+{
+ const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ struct gl_light *l;
+
+ foreach(l, &ctx->Light.EnabledList) {
+ const int i = l - ctx->Light.Light;
+ uint32_t m_light[] = { NV20TCL_LIGHT_FRONT_SPECULAR_R(i),
+ NV20TCL_LIGHT_BACK_SPECULAR_R(i) };
+ float *c_light = (USE_COLOR_MATERIAL(SPECULAR, side) ?
+ l->Specular :
+ l->_MatSpecular[side]);
+
+ BEGIN_RING(chan, kelvin, m_light[side], 3);
+ OUT_RINGf(chan, c_light[0]);
+ OUT_RINGf(chan, c_light[1]);
+ OUT_RINGf(chan, c_light[2]);
+ }
+}
+
+void
+nv20_emit_material_shininess(GLcontext *ctx, int emit)
+{
+ const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_SHININESS;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ float (*mat)[4] = ctx->Light.Material.Attrib;
+ uint32_t mthd[] = { NV20TCL_FRONT_MATERIAL_SHININESS(0),
+ NV20TCL_BACK_MATERIAL_SHININESS(0) };
+ float k[6];
+
+ nv10_get_shininess_coeff(
+ CLAMP(mat[MAT_ATTRIB_SHININESS(side)][0], 0, 1024),
+ k);
+
+ BEGIN_RING(chan, kelvin, mthd[side], 6);
+ OUT_RINGf(chan, k[0]);
+ OUT_RINGf(chan, k[1]);
+ OUT_RINGf(chan, k[2]);
+ OUT_RINGf(chan, k[3]);
+ OUT_RINGf(chan, k[4]);
+ OUT_RINGf(chan, k[5]);
+}
+
+void
+nv20_emit_modelview(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ GLmatrix *m = ctx->ModelviewMatrixStack.Top;
+
+ if (nctx->fallback != HWTNL)
+ return;
+
+ if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled) {
+ BEGIN_RING(chan, kelvin, NV20TCL_MODELVIEW0_MATRIX(0), 16);
+ OUT_RINGm(chan, m->m);
+ }
+
+ if (ctx->Light.Enabled) {
+ int i, j;
+
+ BEGIN_RING(chan, kelvin,
+ NV20TCL_INVERSE_MODELVIEW0_MATRIX(0), 12);
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 4; j++)
+ OUT_RINGf(chan, m->inv[4*i + j]);
+ }
+}
+
+void
+nv20_emit_projection(GLcontext *ctx, int emit)
+{
+ struct nouveau_context *nctx = to_nouveau_context(ctx);
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ GLmatrix m;
+
+ _math_matrix_ctr(&m);
+ get_viewport_scale(ctx, m.m);
+
+ if (nctx->fallback == HWTNL)
+ _math_matrix_mul_matrix(&m, &m, &ctx->_ModelProjectMatrix);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_PROJECTION_MATRIX(0), 16);
+ OUT_RINGm(chan, m.m);
+
+ _math_matrix_dtr(&m);
+}
diff --git a/src/mesa/drivers/dri/r200/r200_cmdbuf.c b/src/mesa/drivers/dri/r200/r200_cmdbuf.c
index 1d1bea6f5f..2f2b8d94dc 100644
--- a/src/mesa/drivers/dri/r200/r200_cmdbuf.c
+++ b/src/mesa/drivers/dri/r200/r200_cmdbuf.c
@@ -35,15 +35,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/imports.h"
#include "main/macros.h"
#include "main/context.h"
-#include "swrast/swrast.h"
#include "main/simple_list.h"
#include "radeon_common.h"
#include "r200_context.h"
-#include "r200_state.h"
#include "r200_ioctl.h"
-#include "r200_tcl.h"
-#include "r200_sanity.h"
#include "radeon_reg.h"
/* The state atoms will be emitted in the order they appear in the atom list,
@@ -92,6 +88,7 @@ void r200SetUpAtomList( r200ContextPtr rmesa )
insert_at_tail_if( &rmesa->radeon.hw.atomlist, &rmesa->hw.pix[i] );
insert_at_tail_if( &rmesa->radeon.hw.atomlist, &rmesa->hw.afs[0] );
insert_at_tail_if( &rmesa->radeon.hw.atomlist, &rmesa->hw.afs[1] );
+ insert_at_tail_if( &rmesa->radeon.hw.atomlist, &rmesa->hw.stp );
for (i = 0; i < 8; ++i)
insert_at_tail_if( &rmesa->radeon.hw.atomlist, &rmesa->hw.lit[i] );
for (i = 0; i < 3 + mtu; ++i)
diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
index 453c8de220..31910253dd 100644
--- a/src/mesa/drivers/dri/r200/r200_context.c
+++ b/src/mesa/drivers/dri/r200/r200_context.c
@@ -37,10 +37,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/context.h"
#include "main/simple_list.h"
#include "main/imports.h"
-#include "main/matrix.h"
#include "main/extensions.h"
-#include "main/framebuffer.h"
-#include "main/state.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
@@ -58,7 +55,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r200_tex.h"
#include "r200_swtcl.h"
#include "r200_tcl.h"
-#include "r200_maos.h"
#include "r200_vertprog.h"
#include "radeon_queryobj.h"
#include "r200_blit.h"
@@ -80,7 +76,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define DRIVER_DATE "20060602"
-#include "vblank.h"
#include "utils.h"
#include "xmlpool.h" /* for symbolic values of enum-type options */
diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.c b/src/mesa/drivers/dri/r200/r200_ioctl.c
index 66c5d3655a..a1b505707e 100644
--- a/src/mesa/drivers/dri/r200/r200_ioctl.c
+++ b/src/mesa/drivers/dri/r200/r200_ioctl.c
@@ -46,13 +46,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_common.h"
#include "radeon_lock.h"
#include "r200_context.h"
-#include "r200_state.h"
#include "r200_ioctl.h"
-#include "r200_tcl.h"
-#include "r200_sanity.h"
#include "radeon_reg.h"
-#include "drirenderbuffer.h"
#include "vblank.h"
#define R200_TIMEOUT 512
diff --git a/src/mesa/drivers/dri/r200/r200_maos_arrays.c b/src/mesa/drivers/dri/r200/r200_maos_arrays.c
index 249c0bbc11..aecba7f894 100644
--- a/src/mesa/drivers/dri/r200/r200_maos_arrays.c
+++ b/src/mesa/drivers/dri/r200/r200_maos_arrays.c
@@ -74,7 +74,7 @@ static void r200_emit_vecfog(GLcontext *ctx, struct radeon_aos *aos,
GLvoid *data, int stride, int count)
{
radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
- uint32_t *out;
+ GLfloat *out;
int i;
int size = 1;
@@ -91,7 +91,7 @@ static void r200_emit_vecfog(GLcontext *ctx, struct radeon_aos *aos,
aos->count = count;
radeon_bo_map(aos->bo, 1);
- out = (uint32_t*)((char*)aos->bo->ptr + aos->offset);
+ out = (GLfloat*)((char*)aos->bo->ptr + aos->offset);
for (i = 0; i < count; i++) {
out[0] = r200ComputeFogBlendFactor( ctx, *(GLfloat *)data );
out++;
diff --git a/src/mesa/drivers/dri/r200/r200_sanity.c b/src/mesa/drivers/dri/r200/r200_sanity.c
index 1241a926ba..a439fd84ed 100644
--- a/src/mesa/drivers/dri/r200/r200_sanity.c
+++ b/src/mesa/drivers/dri/r200/r200_sanity.c
@@ -38,7 +38,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/imports.h"
#include "r200_context.h"
-#include "r200_ioctl.h"
#include "r200_sanity.h"
#include "radeon_reg.h"
#include "r200_reg.h"
diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c
index 7fe482fe15..d6964484bf 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -57,8 +57,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r200_swtcl.h"
#include "r200_vertprog.h"
-#include "drirenderbuffer.h"
-
/* =============================================================
* Alpha blending
@@ -2466,6 +2464,12 @@ static void r200PolygonStipple( GLcontext *ctx, const GLubyte *mask )
radeon_firevertices(&r200->radeon);
+ radeon_print(RADEON_STATE, RADEON_TRACE,
+ "%s(%p) first 32 bits are %x.\n",
+ __func__,
+ ctx,
+ *(uint32_t*)mask);
+
R200_STATECHANGE(r200, stp);
/* Must flip pattern upside down.
diff --git a/src/mesa/drivers/dri/r200/r200_state_init.c b/src/mesa/drivers/dri/r200/r200_state_init.c
index 80b08dcc99..4e8075eabc 100644
--- a/src/mesa/drivers/dri/r200/r200_state_init.c
+++ b/src/mesa/drivers/dri/r200/r200_state_init.c
@@ -39,7 +39,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "swrast/swrast.h"
#include "vbo/vbo.h"
-#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
#include "swrast_setup/swrast_setup.h"
@@ -48,9 +47,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r200_context.h"
#include "r200_ioctl.h"
#include "r200_state.h"
-#include "r200_tcl.h"
-#include "r200_tex.h"
-#include "r200_swtcl.h"
#include "radeon_queryobj.h"
#include "xmlpool.h"
diff --git a/src/mesa/drivers/dri/r200/r200_swtcl.c b/src/mesa/drivers/dri/r200/r200_swtcl.c
index 4596912ddc..e220e40b01 100644
--- a/src/mesa/drivers/dri/r200/r200_swtcl.c
+++ b/src/mesa/drivers/dri/r200/r200_swtcl.c
@@ -44,7 +44,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "swrast/s_context.h"
#include "swrast/s_fog.h"
#include "swrast_setup/swrast_setup.h"
-#include "math/m_translate.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
#include "tnl/t_pipeline.h"
diff --git a/src/mesa/drivers/dri/r200/r200_tcl.c b/src/mesa/drivers/dri/r200/r200_tcl.c
index e7d48a7f29..f3f558b7de 100644
--- a/src/mesa/drivers/dri/r200/r200_tcl.c
+++ b/src/mesa/drivers/dri/r200/r200_tcl.c
@@ -46,7 +46,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r200_context.h"
#include "r200_state.h"
#include "r200_ioctl.h"
-#include "r200_tex.h"
#include "r200_tcl.h"
#include "r200_swtcl.h"
#include "r200_maos.h"
diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c
index 0916df6476..cea589014f 100644
--- a/src/mesa/drivers/dri/r200/r200_tex.c
+++ b/src/mesa/drivers/dri/r200/r200_tex.c
@@ -44,9 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_mipmap_tree.h"
#include "r200_context.h"
-#include "r200_state.h"
#include "r200_ioctl.h"
-#include "r200_swtcl.h"
#include "r200_tex.h"
#include "xmlpool.h"
diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c b/src/mesa/drivers/dri/r200/r200_vertprog.c
index 4f225a233d..12f869d96f 100644
--- a/src/mesa/drivers/dri/r200/r200_vertprog.c
+++ b/src/mesa/drivers/dri/r200/r200_vertprog.c
@@ -1218,7 +1218,7 @@ r200DeleteProgram(GLcontext *ctx, struct gl_program *prog)
_mesa_delete_program(ctx, prog);
}
-static void
+static GLboolean
r200ProgramStringNotify(GLcontext *ctx, GLenum target, struct gl_program *prog)
{
struct r200_vertex_program *vp = (void *)prog;
@@ -1237,7 +1237,10 @@ r200ProgramStringNotify(GLcontext *ctx, GLenum target, struct gl_program *prog)
break;
}
/* need this for tcl fallbacks */
- _tnl_program_string(ctx, target, prog);
+ (void) _tnl_program_string(ctx, target, prog);
+
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
static GLboolean
diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r300_fragprog.c
index aa69b0fc72..928c15e1e4 100644
--- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog.c
+++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog.c
@@ -297,7 +297,7 @@ void r300FragmentProgramDump(struct rX00_fragment_program_code *c)
if (flags[0] != 0) {
sprintf(tmp, "o%i.%s",
(code->alu.inst[i].
- rgb_addr >> R300_ALU_DSTC_SHIFT) & 31,
+ rgb_addr >> 29) & 3,
flags);
strcat(dstc, tmp);
}
@@ -311,7 +311,7 @@ void r300FragmentProgramDump(struct rX00_fragment_program_code *c)
if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_OUTPUT) {
sprintf(tmp, "o%i.w ",
(code->alu.inst[i].
- alpha_addr >> R300_ALU_DSTA_SHIFT) & 31);
+ alpha_addr >> 25) & 3);
strcat(dsta, tmp);
}
if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_DEPTH) {
diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
index 375838d98e..cc552aee17 100644
--- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
+++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
@@ -176,7 +176,9 @@ static int emit_alu(struct r300_emit_state * emit, struct rc_pair_instruction* i
(inst->RGB.WriteMask << R300_ALU_DSTC_REG_MASK_SHIFT);
}
if (inst->RGB.OutputWriteMask) {
- code->alu.inst[ip].rgb_addr |= (inst->RGB.OutputWriteMask << R300_ALU_DSTC_OUTPUT_MASK_SHIFT);
+ code->alu.inst[ip].rgb_addr |=
+ (inst->RGB.OutputWriteMask << R300_ALU_DSTC_OUTPUT_MASK_SHIFT) |
+ R300_RGB_TARGET(inst->RGB.Target);
emit->node_flags |= R300_RGBA_OUT;
}
@@ -187,7 +189,8 @@ static int emit_alu(struct r300_emit_state * emit, struct rc_pair_instruction* i
R300_ALU_DSTA_REG;
}
if (inst->Alpha.OutputWriteMask) {
- code->alu.inst[ip].alpha_addr |= R300_ALU_DSTA_OUTPUT;
+ code->alu.inst[ip].alpha_addr |= R300_ALU_DSTA_OUTPUT |
+ R300_ALPHA_TARGET(inst->Alpha.Target);
emit->node_flags |= R300_RGBA_OUT;
}
if (inst->Alpha.DepthWriteMask) {
diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
index 5581f25352..c2d5dc27b4 100644
--- a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
+++ b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
@@ -35,7 +35,10 @@ static void dataflow_outputs_mark_use(void * userdata, void * data,
void (*callback)(void *, unsigned int, unsigned int))
{
struct r300_fragment_program_compiler * c = userdata;
- callback(data, c->OutputColor, RC_MASK_XYZW);
+ callback(data, c->OutputColor[0], RC_MASK_XYZW);
+ callback(data, c->OutputColor[1], RC_MASK_XYZW);
+ callback(data, c->OutputColor[2], RC_MASK_XYZW);
+ callback(data, c->OutputColor[3], RC_MASK_XYZW);
callback(data, c->OutputDepth, RC_MASK_W);
}
diff --git a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
index b1b14394b6..c2eb613b23 100644
--- a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
+++ b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
@@ -241,6 +241,9 @@ static void emit_paired(struct r300_fragment_program_compiler *c, struct rc_pair
code->inst[ip].inst4 |= translate_arg_alpha(inst, 1) << R500_ALPHA_SEL_B_SHIFT;
code->inst[ip].inst5 |= translate_arg_alpha(inst, 2) << R500_ALU_RGBA_ALPHA_SEL_C_SHIFT;
+ code->inst[ip].inst3 |= R500_ALU_RGB_TARGET(inst->RGB.Target);
+ code->inst[ip].inst4 |= R500_ALPHA_TARGET(inst->Alpha.Target);
+
if (inst->WriteALUResult) {
code->inst[ip].inst3 |= R500_ALU_RGB_WMASK;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
index f27f858652..6bfda0574f 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
@@ -83,8 +83,10 @@ struct r300_fragment_program_compiler {
struct rX00_fragment_program_code *code;
struct r300_fragment_program_external_state state;
unsigned is_r500;
+ /* Register corresponding to the depthbuffer. */
unsigned OutputDepth;
- unsigned OutputColor;
+ /* Registers corresponding to the four colorbuffers. */
+ unsigned OutputColor[4];
void * UserData;
void (*AllocateHwInputs)(
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_pair_translate.c b/src/mesa/drivers/dri/r300/compiler/radeon_pair_translate.c
index 7211768272..fff5b0c217 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_pair_translate.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_pair_translate.c
@@ -203,12 +203,21 @@ static void set_pair_instruction(struct r300_fragment_program_compiler *c,
/* Destination handling */
if (inst->DstReg.File == RC_FILE_OUTPUT) {
- if (inst->DstReg.Index == c->OutputColor) {
- pair->RGB.OutputWriteMask |= inst->DstReg.WriteMask & RC_MASK_XYZ;
- pair->Alpha.OutputWriteMask |= GET_BIT(inst->DstReg.WriteMask, 3);
- } else if (inst->DstReg.Index == c->OutputDepth) {
- pair->Alpha.DepthWriteMask |= GET_BIT(inst->DstReg.WriteMask, 3);
- }
+ if (inst->DstReg.Index == c->OutputDepth) {
+ pair->Alpha.DepthWriteMask |= GET_BIT(inst->DstReg.WriteMask, 3);
+ } else {
+ for (i = 0; i < 4; i++) {
+ if (inst->DstReg.Index == c->OutputColor[i]) {
+ pair->RGB.Target = i;
+ pair->Alpha.Target = i;
+ pair->RGB.OutputWriteMask |=
+ inst->DstReg.WriteMask & RC_MASK_XYZ;
+ pair->Alpha.OutputWriteMask |=
+ GET_BIT(inst->DstReg.WriteMask, 3);
+ break;
+ }
+ }
+ }
} else {
if (needrgb) {
pair->RGB.DestIndex = inst->DstReg.Index;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h
index 6685ade3ea..511cc707a3 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h
@@ -60,6 +60,7 @@ struct radeon_pair_instruction_rgb {
unsigned int Opcode:8;
unsigned int DestIndex:RC_REGISTER_INDEX_BITS;
unsigned int WriteMask:3;
+ unsigned int Target:2;
unsigned int OutputWriteMask:3;
unsigned int Saturate:1;
@@ -77,6 +78,7 @@ struct radeon_pair_instruction_alpha {
unsigned int Opcode:8;
unsigned int DestIndex:RC_REGISTER_INDEX_BITS;
unsigned int WriteMask:1;
+ unsigned int Target:2;
unsigned int OutputWriteMask:1;
unsigned int DepthWriteMask:1;
unsigned int Saturate:1;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_program_print.c b/src/mesa/drivers/dri/r300/compiler/radeon_program_print.c
index d863b82d53..28fb9eae92 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_program_print.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_program_print.c
@@ -229,7 +229,7 @@ static void rc_print_pair_instruction(FILE * f, struct rc_instruction * fullinst
(inst->RGB.WriteMask & 2) ? "y" : "",
(inst->RGB.WriteMask & 4) ? "z" : "");
if (inst->RGB.OutputWriteMask)
- fprintf(f, " color.%s%s%s",
+ fprintf(f, " color[%i].%s%s%s", inst->RGB.Target,
(inst->RGB.OutputWriteMask & 1) ? "x" : "",
(inst->RGB.OutputWriteMask & 2) ? "y" : "",
(inst->RGB.OutputWriteMask & 4) ? "z" : "");
@@ -255,7 +255,7 @@ static void rc_print_pair_instruction(FILE * f, struct rc_instruction * fullinst
if (inst->Alpha.WriteMask)
fprintf(f, " temp[%i].w", inst->Alpha.DestIndex);
if (inst->Alpha.OutputWriteMask)
- fprintf(f, " color.w");
+ fprintf(f, " color[%i].w", inst->Alpha.Target);
if (inst->Alpha.DepthWriteMask)
fprintf(f, " depth.w");
if (inst->WriteALUResult == RC_ALURESULT_W)
diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c
index e24c7955d4..54ac2510e7 100644
--- a/src/mesa/drivers/dri/r300/r300_blit.c
+++ b/src/mesa/drivers/dri/r300/r300_blit.c
@@ -114,7 +114,7 @@ static void create_fragment_program(struct r300_context *r300)
inst->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_XYZW;
compiler.Base.Program.InputsRead = (1 << FRAG_ATTRIB_TEX0);
- compiler.OutputColor = FRAG_RESULT_COLOR;
+ compiler.OutputColor[0] = FRAG_RESULT_COLOR;
compiler.OutputDepth = FRAG_RESULT_DEPTH;
compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515);
compiler.code = &r300->blit.fp_code;
diff --git a/src/mesa/drivers/dri/r300/r300_emit.c b/src/mesa/drivers/dri/r300/r300_emit.c
index 740c902221..a24d431611 100644
--- a/src/mesa/drivers/dri/r300/r300_emit.c
+++ b/src/mesa/drivers/dri/r300/r300_emit.c
@@ -46,8 +46,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r300_context.h"
#include "r300_emit.h"
-#include "r300_render.h"
-#include "r300_swtcl.h"
GLuint r300VAPInputCntl0(GLcontext * ctx, GLuint InputsRead)
diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_common.c b/src/mesa/drivers/dri/r300/r300_fragprog_common.c
index e41aeff91a..a0e2dd3c09 100644
--- a/src/mesa/drivers/dri/r300/r300_fragprog_common.c
+++ b/src/mesa/drivers/dri/r300/r300_fragprog_common.c
@@ -221,7 +221,8 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
compiler.state = fp->state;
compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) ? GL_TRUE : GL_FALSE;
compiler.OutputDepth = FRAG_RESULT_DEPTH;
- compiler.OutputColor = FRAG_RESULT_COLOR;
+ memset(compiler.OutputColor, 0, 4 * sizeof(unsigned));
+ compiler.OutputColor[0] = FRAG_RESULT_COLOR;
compiler.AllocateHwInputs = &allocate_hw_inputs;
if (compiler.Base.Debug) {
diff --git a/src/mesa/drivers/dri/r300/r300_shader.c b/src/mesa/drivers/dri/r300/r300_shader.c
index a4f9db13ec..3638010e48 100644
--- a/src/mesa/drivers/dri/r300/r300_shader.c
+++ b/src/mesa/drivers/dri/r300/r300_shader.c
@@ -98,7 +98,7 @@ static void r300DeleteProgram(GLcontext * ctx, struct gl_program *prog)
_mesa_delete_program(ctx, prog);
}
-static void
+static GLboolean
r300ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
{
struct r300_vertex_program_cont *vp = (struct r300_vertex_program_cont *)prog;
@@ -116,7 +116,10 @@ r300ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
}
/* need this for tcl fallbacks */
- _tnl_program_string(ctx, target, prog);
+ (void) _tnl_program_string(ctx, target, prog);
+
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
static GLboolean
diff --git a/src/mesa/drivers/dri/r600/r600_blit.c b/src/mesa/drivers/dri/r600/r600_blit.c
index d7cd59ade6..4bb77a398f 100644
--- a/src/mesa/drivers/dri/r600/r600_blit.c
+++ b/src/mesa/drivers/dri/r600/r600_blit.c
@@ -1652,6 +1652,7 @@ unsigned r600_blit(GLcontext *ctx,
CB_ACTION_ENA_bit | (1 << (id + 6)));
/* 5 */
+ /* XXX drm should handle this in fence submit */
r700WaitForIdleClean(context);
radeonFlush(ctx);
diff --git a/src/mesa/drivers/dri/r600/r600_cmdbuf.c b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
index 370bb04f93..afe2d55dc7 100644
--- a/src/mesa/drivers/dri/r600/r600_cmdbuf.c
+++ b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
@@ -39,7 +39,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/macros.h"
#include "main/context.h"
#include "main/simple_list.h"
-#include "swrast/swrast.h"
#include "drm.h"
#include "radeon_drm.h"
@@ -49,7 +48,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r600_cmdbuf.h"
#include "r600_emit.h"
#include "radeon_bocs_wrapper.h"
-#include "radeon_mipmap_tree.h"
#include "radeon_reg.h"
#ifdef HAVE_LIBDRM_RADEON
diff --git a/src/mesa/drivers/dri/r600/r600_context.c b/src/mesa/drivers/dri/r600/r600_context.c
index ab3c7723c9..15f65bae6e 100644
--- a/src/mesa/drivers/dri/r600/r600_context.c
+++ b/src/mesa/drivers/dri/r600/r600_context.c
@@ -40,9 +40,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/context.h"
#include "main/simple_list.h"
#include "main/imports.h"
-#include "main/matrix.h"
#include "main/extensions.h"
-#include "main/state.h"
#include "main/bufferobj.h"
#include "main/texobj.h"
@@ -52,7 +50,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
-#include "tnl/t_vp_build.h"
#include "drivers/common/driverfuncs.h"
@@ -71,9 +68,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r700_ioctl.h"
-#include "vblank.h"
#include "utils.h"
-#include "xmlpool.h" /* for symbolic values of enum-type options */
#define R600_ENABLE_GLSL_TEST 1
diff --git a/src/mesa/drivers/dri/r600/r600_emit.c b/src/mesa/drivers/dri/r600/r600_emit.c
index 5c250c2418..1eb89a5305 100644
--- a/src/mesa/drivers/dri/r600/r600_emit.c
+++ b/src/mesa/drivers/dri/r600/r600_emit.c
@@ -37,10 +37,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/colormac.h"
#include "main/imports.h"
#include "main/macros.h"
-#include "main/image.h"
#include "swrast_setup/swrast_setup.h"
-#include "math/m_translate.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
diff --git a/src/mesa/drivers/dri/r600/r600_tex.c b/src/mesa/drivers/dri/r600/r600_tex.c
index 71dfd7e059..36a6e6e0a1 100644
--- a/src/mesa/drivers/dri/r600/r600_tex.c
+++ b/src/mesa/drivers/dri/r600/r600_tex.c
@@ -41,18 +41,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/mipmap.h"
#include "main/simple_list.h"
#include "main/texstore.h"
-#include "main/teximage.h"
#include "main/texobj.h"
#include "texmem.h"
#include "r600_context.h"
-#include "r700_state.h"
#include "radeon_mipmap_tree.h"
#include "r600_tex.h"
-#include "xmlpool.h"
-
static unsigned int translate_wrap_mode(GLenum wrapmode)
{
diff --git a/src/mesa/drivers/dri/r600/r600_texstate.c b/src/mesa/drivers/dri/r600/r600_texstate.c
index 3289d89c92..8228cd67c8 100644
--- a/src/mesa/drivers/dri/r600/r600_texstate.c
+++ b/src/mesa/drivers/dri/r600/r600_texstate.c
@@ -45,7 +45,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/simple_list.h"
#include "r600_context.h"
-#include "r700_state.h"
#include "radeon_mipmap_tree.h"
#include "r600_tex.h"
#include "r700_fragprog.h"
diff --git a/src/mesa/drivers/dri/r600/r700_chip.c b/src/mesa/drivers/dri/r600/r700_chip.c
index ef25cd93fe..e0be74935b 100644
--- a/src/mesa/drivers/dri/r600/r700_chip.c
+++ b/src/mesa/drivers/dri/r600/r700_chip.c
@@ -32,12 +32,10 @@
#include "r600_context.h"
#include "r600_cmdbuf.h"
-#include "r700_state.h"
#include "r600_tex.h"
#include "r700_oglprog.h"
#include "r700_fragprog.h"
#include "r700_vertprog.h"
-#include "r700_ioctl.h"
#include "radeon_mipmap_tree.h"
diff --git a/src/mesa/drivers/dri/r600/r700_clear.c b/src/mesa/drivers/dri/r600/r700_clear.c
index 98bfdd0937..09c48565b6 100644
--- a/src/mesa/drivers/dri/r600/r700_clear.c
+++ b/src/mesa/drivers/dri/r600/r700_clear.c
@@ -37,7 +37,6 @@
#include "r600_context.h"
#include "r700_shaderinst.h"
-#include "r600_emit.h"
#include "r700_clear.h"
static GLboolean r700ClearFast(context_t *context, GLbitfield mask)
diff --git a/src/mesa/drivers/dri/r600/r700_ioctl.c b/src/mesa/drivers/dri/r600/r700_ioctl.c
index 72a8978976..3bc422f394 100644
--- a/src/mesa/drivers/dri/r600/r700_ioctl.c
+++ b/src/mesa/drivers/dri/r600/r700_ioctl.c
@@ -32,10 +32,8 @@
#include "main/macros.h"
#include "main/context.h"
#include "main/simple_list.h"
-#include "swrast/swrast.h"
#include "radeon_common.h"
-#include "radeon_lock.h"
#include "r600_context.h"
#include "r700_ioctl.h"
diff --git a/src/mesa/drivers/dri/r600/r700_oglprog.c b/src/mesa/drivers/dri/r600/r700_oglprog.c
index 0d476fcd86..2a50361199 100644
--- a/src/mesa/drivers/dri/r600/r700_oglprog.c
+++ b/src/mesa/drivers/dri/r600/r700_oglprog.c
@@ -132,7 +132,7 @@ static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
_mesa_delete_program(ctx, prog);
}
-static void
+static GLboolean
r700ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
{
struct r700_vertex_program_cont *vpc = (struct r700_vertex_program_cont *)prog;
@@ -153,6 +153,8 @@ r700ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
break;
}
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
static GLboolean r700IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
diff --git a/src/mesa/drivers/dri/r600/r700_render.c b/src/mesa/drivers/dri/r600/r700_render.c
index 3a6210c53a..8f14af7472 100644
--- a/src/mesa/drivers/dri/r600/r700_render.c
+++ b/src/mesa/drivers/dri/r600/r700_render.c
@@ -42,7 +42,6 @@
#include "tnl/t_vp_build.h"
#include "tnl/t_context.h"
#include "tnl/t_vertex.h"
-#include "tnl/t_pipeline.h"
#include "vbo/vbo_context.h"
#include "r600_context.h"
@@ -116,8 +115,6 @@ void r700Start3D(context_t *context)
END_BATCH();
COMMIT_BATCH();
-
- r700WaitForIdleClean(context);
}
GLboolean r700SyncSurf(context_t *context,
@@ -422,7 +419,7 @@ static void r700RunRenderPrimitiveImmediate(GLcontext * ctx, int start, int end,
}
/* start 3d, idle, cb/db flush */
-#define PRE_EMIT_STATE_BUFSZ 10 + 5 + 18
+#define PRE_EMIT_STATE_BUFSZ 5 + 5 + 18
static GLuint r700PredictRenderSize(GLcontext* ctx,
const struct _mesa_prim *prim,
@@ -935,6 +932,7 @@ static GLboolean r700TryDrawPrims(GLcontext *ctx,
radeon_debug_remove_indent();
/* Flush render op cached for last several quads. */
+ /* XXX drm should handle this in fence submit */
r700WaitForIdleClean(context);
rrb = radeon_get_colorbuffer(&context->radeon);
diff --git a/src/mesa/drivers/dri/r600/r700_shader.c b/src/mesa/drivers/dri/r600/r700_shader.c
index 2eed1acc2f..67b0d40308 100644
--- a/src/mesa/drivers/dri/r600/r700_shader.c
+++ b/src/mesa/drivers/dri/r600/r700_shader.c
@@ -35,7 +35,6 @@
#include "main/glheader.h"
#include "r600_context.h"
-#include "r700_debug.h"
#include "r700_shader.h"
diff --git a/src/mesa/drivers/dri/r600/r700_state.c b/src/mesa/drivers/dri/r600/r700_state.c
index 20e8afefba..0240eefd5c 100644
--- a/src/mesa/drivers/dri/r600/r700_state.c
+++ b/src/mesa/drivers/dri/r600/r700_state.c
@@ -26,7 +26,6 @@
#include "main/glheader.h"
#include "main/mtypes.h"
-#include "main/state.h"
#include "main/imports.h"
#include "main/enums.h"
#include "main/macros.h"
@@ -36,11 +35,9 @@
#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
-#include "tnl/t_vp_build.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "main/api_arrayelt.h"
-#include "main/state.h"
#include "main/framebuffer.h"
#include "shader/prog_parameter.h"
diff --git a/src/mesa/drivers/dri/r600/r700_vertprog.c b/src/mesa/drivers/dri/r600/r700_vertprog.c
index 782f151f5a..618f7e1be1 100644
--- a/src/mesa/drivers/dri/r600/r700_vertprog.c
+++ b/src/mesa/drivers/dri/r600/r700_vertprog.c
@@ -647,7 +647,7 @@ GLboolean r700SetupVertexProgram(GLcontext * ctx)
/* _mesa_reference_program has already checked glsl shProg is ok and set ctx->VertexProgem._Current */
/* so, use ctx->VertexProgem._Current */
struct gl_program_parameter_list *paramListOrginal =
- paramListOrginal = ctx->VertexProgram._Current->Base.Parameters;
+ ctx->VertexProgram._Current->Base.Parameters;
_mesa_load_state_parameters(ctx, paramList);
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.c b/src/mesa/drivers/dri/radeon/radeon_common_context.c
index b9c29b937e..94f476617b 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.c
@@ -39,7 +39,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "drirenderbuffer.h"
#include "drivers/common/meta.h"
#include "main/context.h"
-#include "main/framebuffer.h"
#include "main/renderbuffer.h"
#include "main/state.h"
#include "main/simple_list.h"
@@ -47,10 +46,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
-#if defined(RADEON_R600)
-#include "r600_context.h"
-#endif
-
#define DRIVER_DATE "20090101"
#ifndef RADEON_DEBUG
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
index 6c08a90bbd..86c91f19bb 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_context.c
@@ -39,10 +39,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/context.h"
#include "main/simple_list.h"
#include "main/imports.h"
-#include "main/matrix.h"
#include "main/extensions.h"
-#include "main/framebuffer.h"
-#include "main/state.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
@@ -61,7 +58,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_tex.h"
#include "radeon_swtcl.h"
#include "radeon_tcl.h"
-#include "radeon_maos.h"
#include "radeon_queryobj.h"
#include "radeon_blit.h"
@@ -74,7 +70,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define DRIVER_DATE "20061018"
-#include "vblank.h"
#include "utils.h"
#include "xmlpool.h" /* for symbolic values of enum-type options */
diff --git a/src/mesa/drivers/dri/radeon/radeon_debug.h b/src/mesa/drivers/dri/radeon/radeon_debug.h
index 26da31c1c4..ef8b9671ac 100644
--- a/src/mesa/drivers/dri/radeon/radeon_debug.h
+++ b/src/mesa/drivers/dri/radeon/radeon_debug.h
@@ -47,7 +47,11 @@ typedef enum radeon_debug_levels {
* errors.
*/
#ifndef RADEON_DEBUG_LEVEL
-#define RADEON_DEBUG_LEVEL RADEON_VERBOSE
+# ifdef DEBUG
+# define RADEON_DEBUG_LEVEL RADEON_TRACE
+# else
+# define RADEON_DEBUG_LEVEL RADEON_VERBOSE
+# endif
#endif
typedef enum radeon_debug_types {
diff --git a/src/mesa/drivers/dri/radeon/radeon_ioctl.c b/src/mesa/drivers/dri/radeon/radeon_ioctl.c
index afe3d9f12e..db0e4f2f7a 100644
--- a/src/mesa/drivers/dri/radeon/radeon_ioctl.c
+++ b/src/mesa/drivers/dri/radeon/radeon_ioctl.c
@@ -38,17 +38,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <errno.h>
#include "main/attrib.h"
-#include "main/enable.h"
-#include "main/blend.h"
#include "main/bufferobj.h"
-#include "main/buffers.h"
-#include "main/depth.h"
-#include "main/shaders.h"
-#include "main/texstate.h"
-#include "main/varray.h"
#include "swrast/swrast.h"
-#include "main/stencil.h"
-#include "main/matrix.h"
#include "main/glheader.h"
#include "main/imports.h"
@@ -57,15 +48,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_context.h"
#include "radeon_common.h"
-#include "radeon_state.h"
#include "radeon_ioctl.h"
-#include "radeon_tcl.h"
-#include "radeon_sanity.h"
#define STANDALONE_MMIO
-#include "radeon_macros.h" /* for INREG() */
-#include "drirenderbuffer.h"
#include "vblank.h"
#define RADEON_TIMEOUT 512
@@ -106,6 +92,7 @@ void radeonSetUpAtomList( r100ContextPtr rmesa )
insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.lit[i]);
for (i = 0; i < 6; ++i)
insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.ucp[i]);
+ insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.stp);
insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.eye);
insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.grd);
insert_at_tail(&rmesa->radeon.hw.atomlist, &rmesa->hw.fog);
diff --git a/src/mesa/drivers/dri/radeon/radeon_lock.c b/src/mesa/drivers/dri/radeon/radeon_lock.c
index 9dee691938..7b6bd36dcf 100644
--- a/src/mesa/drivers/dri/radeon/radeon_lock.c
+++ b/src/mesa/drivers/dri/radeon/radeon_lock.c
@@ -46,7 +46,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_screen.h"
#include "radeon_common.h"
#include "radeon_lock.h"
-#include "drirenderbuffer.h"
/* Update the hardware state. This is called if another context has
* grabbed the hardware lock, which includes the X server. This
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index a1a523931f..90a4e4f00a 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include "main/simple_list.h"
-#include "main/texcompress.h"
#include "main/teximage.h"
#include "main/texobj.h"
#include "radeon_texture.h"
diff --git a/src/mesa/drivers/dri/radeon/radeon_sanity.c b/src/mesa/drivers/dri/radeon/radeon_sanity.c
index 1ab570f507..3e64be83ed 100644
--- a/src/mesa/drivers/dri/radeon/radeon_sanity.c
+++ b/src/mesa/drivers/dri/radeon/radeon_sanity.c
@@ -36,7 +36,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/glheader.h"
#include "radeon_context.h"
-#include "radeon_ioctl.h"
#include "radeon_sanity.h"
/* Set this '1' to get more verbiage.
diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
index 3080a0fcd0..93b6399a66 100644
--- a/src/mesa/drivers/dri/radeon/radeon_screen.c
+++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
@@ -47,7 +47,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_macros.h"
#include "radeon_screen.h"
#include "radeon_common.h"
-#include "radeon_span.h"
#if defined(RADEON_R100)
#include "radeon_context.h"
#include "radeon_tex.h"
@@ -66,7 +65,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "utils.h"
#include "vblank.h"
-#include "drirenderbuffer.h"
#include "radeon_bocs_wrapper.h"
@@ -1481,7 +1479,7 @@ radeonCreateBuffer( __DRIscreen *driScrnPriv,
if (!rfb)
return GL_FALSE;
- _mesa_initialize_framebuffer(&rfb->base, mesaVis);
+ _mesa_initialize_window_framebuffer(&rfb->base, mesaVis);
if (mesaVis->redBits == 5)
rgbFormat = _mesa_little_endian() ? MESA_FORMAT_RGB565 : MESA_FORMAT_RGB565_REV;
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c b/src/mesa/drivers/dri/radeon/radeon_state.c
index 1c9ec36dae..7db745a180 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -37,7 +37,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/api_arrayelt.h"
#include "main/enums.h"
#include "main/light.h"
-#include "main/state.h"
#include "main/context.h"
#include "main/framebuffer.h"
#include "main/simple_list.h"
@@ -54,7 +53,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_tcl.h"
#include "radeon_tex.h"
#include "radeon_swtcl.h"
-#include "drirenderbuffer.h"
static void radeonUpdateSpecular( GLcontext *ctx );
diff --git a/src/mesa/drivers/dri/radeon/radeon_state_init.c b/src/mesa/drivers/dri/radeon/radeon_state_init.c
index dd82888254..91718a4777 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state_init.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state_init.c
@@ -33,7 +33,6 @@
#include "swrast/swrast.h"
#include "vbo/vbo.h"
-#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
#include "swrast_setup/swrast_setup.h"
@@ -41,9 +40,6 @@
#include "radeon_mipmap_tree.h"
#include "radeon_ioctl.h"
#include "radeon_state.h"
-#include "radeon_tcl.h"
-#include "radeon_tex.h"
-#include "radeon_swtcl.h"
#include "radeon_queryobj.h"
#include "../r200/r200_reg.h"
diff --git a/src/mesa/drivers/dri/radeon/radeon_swtcl.c b/src/mesa/drivers/dri/radeon/radeon_swtcl.c
index 8bf1bfbc57..5a71b510fa 100644
--- a/src/mesa/drivers/dri/radeon/radeon_swtcl.c
+++ b/src/mesa/drivers/dri/radeon/radeon_swtcl.c
@@ -41,7 +41,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/simple_list.h"
#include "swrast_setup/swrast_setup.h"
-#include "math/m_translate.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
#include "tnl/t_pipeline.h"
diff --git a/src/mesa/drivers/dri/radeon/radeon_tcl.c b/src/mesa/drivers/dri/radeon/radeon_tcl.c
index cd02bfbcf5..ea796e1a45 100644
--- a/src/mesa/drivers/dri/radeon/radeon_tcl.c
+++ b/src/mesa/drivers/dri/radeon/radeon_tcl.c
@@ -46,7 +46,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_context.h"
#include "radeon_state.h"
#include "radeon_ioctl.h"
-#include "radeon_tex.h"
#include "radeon_tcl.h"
#include "radeon_swtcl.h"
#include "radeon_maos.h"
diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c
index 882ee5c194..c66e5d17b1 100644
--- a/src/mesa/drivers/dri/radeon/radeon_tex.c
+++ b/src/mesa/drivers/dri/radeon/radeon_tex.c
@@ -44,9 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_context.h"
#include "radeon_mipmap_tree.h"
-#include "radeon_state.h"
#include "radeon_ioctl.h"
-#include "radeon_swtcl.h"
#include "radeon_tex.h"
#include "xmlpool.h"
diff --git a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
index 44e144c80f..d6aeb7049f 100644
--- a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
+++ b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
@@ -34,7 +34,6 @@
#include "drivers/common/meta.h"
#include "radeon_mipmap_tree.h"
-#include <main/debug.h>
static GLboolean
do_copy_texsubimage(GLcontext *ctx,
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 8340861aff..4e823669bf 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -368,7 +368,7 @@ driCreateNewDrawable(__DRIscreen *screen,
buf->row = _mesa_malloc(MAX_WIDTH * 4);
/* basic framebuffer setup */
- _mesa_initialize_framebuffer(&buf->Base, &config->modes);
+ _mesa_initialize_window_framebuffer(&buf->Base, &config->modes);
/* add front renderbuffer */
frontrb = swrast_new_renderbuffer(&config->modes, GL_TRUE);
diff --git a/src/mesa/drivers/fbdev/glfbdev.c b/src/mesa/drivers/fbdev/glfbdev.c
index 531558dc4d..1a56b2395f 100644
--- a/src/mesa/drivers/fbdev/glfbdev.c
+++ b/src/mesa/drivers/fbdev/glfbdev.c
@@ -626,7 +626,7 @@ glFBDevCreateBuffer( const struct fb_fix_screeninfo *fixInfo,
return NULL;
/* basic framebuffer setup */
- _mesa_initialize_framebuffer(&buf->glframebuffer, &visual->glvisual);
+ _mesa_initialize_window_framebuffer(&buf->glframebuffer, &visual->glvisual);
/* add front renderbuffer */
frontrb = new_glfbdev_renderbuffer(frontBuffer, visual);
_mesa_add_renderbuffer(&buf->glframebuffer, BUFFER_FRONT_LEFT,
diff --git a/src/mesa/drivers/glslcompiler/Makefile b/src/mesa/drivers/glslcompiler/Makefile
index fa8293d039..080fe475c1 100644
--- a/src/mesa/drivers/glslcompiler/Makefile
+++ b/src/mesa/drivers/glslcompiler/Makefile
@@ -10,6 +10,7 @@ PROGRAM = glslcompiler
OBJECTS = \
glslcompiler.o \
../../glapi/glapi.o \
+ ../../glapi/glapi_nop.o \
../../glapi/glthread.o \
../../main/dispatch.o \
../common/driverfuncs.o \
diff --git a/src/mesa/drivers/windows/gdi/wmesa.c b/src/mesa/drivers/windows/gdi/wmesa.c
index ceeafd5f90..b24b758cfb 100644
--- a/src/mesa/drivers/windows/gdi/wmesa.c
+++ b/src/mesa/drivers/windows/gdi/wmesa.c
@@ -35,7 +35,7 @@ wmesa_new_framebuffer(HDC hdc, GLvisual *visual)
WMesaFramebuffer pwfb
= (WMesaFramebuffer) malloc(sizeof(struct wmesa_framebuffer));
if (pwfb) {
- _mesa_initialize_framebuffer(&pwfb->Base, visual);
+ _mesa_initialize_window_framebuffer(&pwfb->Base, visual);
pwfb->hDC = hdc;
/* insert at head of list */
pwfb->next = FirstFramebuffer;
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index bf767bcedd..1a5456e1be 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -375,7 +375,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
b->type = type;
b->cmap = cmap;
- _mesa_initialize_framebuffer(&b->mesa_buffer, &vis->mesa_visual);
+ _mesa_initialize_window_framebuffer(&b->mesa_buffer, &vis->mesa_visual);
b->mesa_buffer.Delete = xmesa_delete_framebuffer;
/*
diff --git a/src/mesa/es/state_tracker/st_cb_drawtex.c b/src/mesa/es/state_tracker/st_cb_drawtex.c
index 3b98b9c40b..0a5cba9d92 100644
--- a/src/mesa/es/state_tracker/st_cb_drawtex.c
+++ b/src/mesa/es/state_tracker/st_cb_drawtex.c
@@ -31,7 +31,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_tile.h"
#include "util/u_draw_quad.h"
diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c
index c2d8a7fb97..e62c7aa572 100644
--- a/src/mesa/main/api_exec.c
+++ b/src/mesa/main/api_exec.c
@@ -66,14 +66,12 @@
#if FEATURE_EXT_framebuffer_object
#include "fbobject.h"
#endif
-#include "ffvertex_prog.h"
#include "framebuffer.h"
#include "hint.h"
#include "histogram.h"
#include "imports.h"
#include "light.h"
#include "lines.h"
-#include "macros.h"
#include "matrix.h"
#include "multisample.h"
#include "pixel.h"
@@ -83,7 +81,6 @@
#include "queryobj.h"
#include "readpix.h"
#include "scissor.h"
-#include "state.h"
#include "stencil.h"
#include "texenv.h"
#include "texgetimage.h"
@@ -100,8 +97,6 @@
#endif
#if FEATURE_NV_fragment_program
#include "shader/nvprogram.h"
-#include "shader/program.h"
-#include "texenvprogram.h"
#endif
#if FEATURE_ARB_shader_objects
#include "shaders.h"
@@ -109,7 +104,6 @@
#if FEATURE_ARB_sync
#include "syncobj.h"
#endif
-#include "debug.h"
#include "glapi/dispatch.h"
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 013048bbc1..326ad6f909 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -28,7 +28,6 @@
#include "context.h"
#include "imports.h"
#include "mtypes.h"
-#include "state.h"
#include "vbo/vbo.h"
diff --git a/src/mesa/main/bitset.h b/src/mesa/main/bitset.h
index 8bd4526cb6..f2709abc9f 100644
--- a/src/mesa/main/bitset.h
+++ b/src/mesa/main/bitset.h
@@ -27,7 +27,12 @@
* \brief Bitset of arbitrary size definitions.
* \author Michal Krol
*/
-
+
+#ifndef BITSET_H
+#define BITSET_H
+
+#include "imports.h"
+
/****************************************************************************
* generic bitset implementation
*/
@@ -74,6 +79,23 @@
((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \
(assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0))
+/* Get first bit set in a bitset.
+ */
+static INLINE int
+__bitset_ffs(const BITSET_WORD *x, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (x[i])
+ return _mesa_ffs(x[i]) + BITSET_WORDBITS * i;
+ }
+
+ return 0;
+}
+
+#define BITSET_FFS(x) __bitset_ffs(x, Elements(x))
+
/****************************************************************************
* 64-bit bitset implementation
*/
@@ -120,3 +142,4 @@
((x)[BITSET64_BITWORD(b)] &= ~BITSET64_RANGE(b, e)) : \
(assert (!"BITSET64_CLEAR_RANGE: bit range crosses word boundary"), 0))
+#endif
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index eb6bc8e436..74c6ac4990 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -93,13 +93,11 @@
#include "depth.h"
#include "dlist.h"
#include "eval.h"
-#include "enums.h"
#include "extensions.h"
#include "fbobject.h"
#include "feedback.h"
#include "fog.h"
#include "framebuffer.h"
-#include "get.h"
#include "histogram.h"
#include "hint.h"
#include "hash.h"
@@ -124,8 +122,6 @@
#include "state.h"
#include "stencil.h"
#include "texcompress_s3tc.h"
-#include "teximage.h"
-#include "texobj.h"
#include "texstate.h"
#include "mtypes.h"
#include "varray.h"
@@ -137,9 +133,6 @@
#include "shader/program.h"
#include "shader/prog_print.h"
#include "shader/shader_api.h"
-#if FEATURE_ATI_fragment_shader
-#include "shader/atifragshader.h"
-#endif
#if _HAVE_FULL_GL
#include "math/m_matrix.h"
#endif
@@ -584,6 +577,9 @@ _mesa_init_constants(GLcontext *ctx)
ctx->Const.MaxTextureCoordUnits));
ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+ ASSERT(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ ASSERT(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ ASSERT(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 32); /* GLbitfield size limit */
ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 6705c901dd..d98a14e09c 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -581,9 +581,13 @@ struct dd_function_table {
struct gl_program * (*NewProgram)(GLcontext *ctx, GLenum target, GLuint id);
/** Delete a program */
void (*DeleteProgram)(GLcontext *ctx, struct gl_program *prog);
- /** Notify driver that a program string has been specified. */
- void (*ProgramStringNotify)(GLcontext *ctx, GLenum target,
- struct gl_program *prog);
+ /**
+ * Notify driver that a program string (and GPU code) has been specified
+ * or modified. Return GL_TRUE or GL_FALSE to indicate if the program is
+ * supported by the driver.
+ */
+ GLboolean (*ProgramStringNotify)(GLcontext *ctx, GLenum target,
+ struct gl_program *prog);
/** Query if program can be loaded onto hardware */
GLboolean (*IsProgramNative)(GLcontext *ctx, GLenum target,
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index b182bbe0d0..683d062bb9 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -56,11 +56,9 @@
#include "varray.h"
#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
#include "shader/arbprogram.h"
-#include "shader/program.h"
#endif
#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
#include "shader/nvprogram.h"
-#include "shader/program.h"
#endif
#if FEATURE_ATI_fragment_shader
#include "shader/atifragshader.h"
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index d958dbf7d4..96e5344383 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -88,7 +88,7 @@ _mesa_create_framebuffer(const GLvisual *visual)
struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
assert(visual);
if (fb) {
- _mesa_initialize_framebuffer(fb, visual);
+ _mesa_initialize_window_framebuffer(fb, visual);
}
return fb;
}
@@ -109,15 +109,7 @@ _mesa_new_framebuffer(GLcontext *ctx, GLuint name)
assert(name != 0);
fb = CALLOC_STRUCT(gl_framebuffer);
if (fb) {
- fb->Name = name;
- fb->RefCount = 1;
- fb->_NumColorDrawBuffers = 1;
- fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT;
- fb->_ColorDrawBufferIndexes[0] = BUFFER_COLOR0;
- fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT;
- fb->_ColorReadBufferIndex = BUFFER_COLOR0;
- fb->Delete = _mesa_destroy_framebuffer;
- _glthread_INIT_MUTEX(fb->Mutex);
+ _mesa_initialize_user_framebuffer(fb, name);
}
return fb;
}
@@ -126,10 +118,11 @@ _mesa_new_framebuffer(GLcontext *ctx, GLuint name)
/**
* Initialize a gl_framebuffer object. Typically used to initialize
* window system-created framebuffers, not user-created framebuffers.
- * \sa _mesa_create_framebuffer
+ * \sa _mesa_initialize_user_framebuffer
*/
void
-_mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual)
+_mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
+ const GLvisual *visual)
{
assert(fb);
assert(visual);
@@ -167,6 +160,30 @@ _mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual)
/**
+ * Initialize a user-created gl_framebuffer object.
+ * \sa _mesa_initialize_window_framebuffer
+ */
+void
+_mesa_initialize_user_framebuffer(struct gl_framebuffer *fb, GLuint name)
+{
+ assert(fb);
+ assert(name);
+
+ _mesa_bzero(fb, sizeof(struct gl_framebuffer));
+
+ fb->Name = name;
+ fb->RefCount = 1;
+ fb->_NumColorDrawBuffers = 1;
+ fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT;
+ fb->_ColorDrawBufferIndexes[0] = BUFFER_COLOR0;
+ fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT;
+ fb->_ColorReadBufferIndex = BUFFER_COLOR0;
+ fb->Delete = _mesa_destroy_framebuffer;
+ _glthread_INIT_MUTEX(fb->Mutex);
+}
+
+
+/**
* Deallocate buffer and everything attached to it.
* Typically called via the gl_framebuffer->Delete() method.
*/
diff --git a/src/mesa/main/framebuffer.h b/src/mesa/main/framebuffer.h
index ef21dd98e8..960513812c 100644
--- a/src/mesa/main/framebuffer.h
+++ b/src/mesa/main/framebuffer.h
@@ -34,7 +34,11 @@ extern struct gl_framebuffer *
_mesa_new_framebuffer(GLcontext *ctx, GLuint name);
extern void
-_mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual);
+_mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
+ const GLvisual *visual);
+
+extern void
+_mesa_initialize_user_framebuffer(struct gl_framebuffer *fb, GLuint name);
extern void
_mesa_destroy_framebuffer(struct gl_framebuffer *buffer);
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 22cf75f79d..2724774ca2 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -270,11 +270,16 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
break;
case GL_CURRENT_RASTER_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
- params[0] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[texUnit][0]);
- params[1] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[texUnit][1]);
- params[2] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[texUnit][2]);
- params[3] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[texUnit][3]);
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(raster tex coords, unit %u)", unit);
+ return;
+ }
+ params[0] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[unit][0]);
+ params[1] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[unit][1]);
+ params[2] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[unit][2]);
+ params[3] = FLOAT_TO_BOOLEAN(ctx->Current.RasterTexCoords[unit][3]);
}
break;
case GL_CURRENT_RASTER_POSITION_VALID:
@@ -282,12 +287,17 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
break;
case GL_CURRENT_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(current tex coords, unit %u)", unit);
+ return;
+ }
FLUSH_CURRENT(ctx, 0);
- params[0] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][0]);
- params[1] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]);
- params[2] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]);
- params[3] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]);
+ params[0] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0]);
+ params[1] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1]);
+ params[2] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2]);
+ params[3] = FLOAT_TO_BOOLEAN(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3]);
}
break;
case GL_DEPTH_BIAS:
@@ -922,7 +932,14 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
break;
case GL_TEXTURE_MATRIX:
{
- const GLfloat *matrix = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top->m;
+ const GLfloat *matrix;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGet(texture matrix %u)",
+ unit);
+ return;
+ }
+ matrix = ctx->TextureMatrixStack[unit].Top->m;
params[0] = FLOAT_TO_BOOLEAN(matrix[0]);
params[1] = FLOAT_TO_BOOLEAN(matrix[1]);
params[2] = FLOAT_TO_BOOLEAN(matrix[2]);
@@ -942,7 +959,15 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
}
break;
case GL_TEXTURE_STACK_DEPTH:
- params[0] = INT_TO_BOOLEAN(ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1);
+ {
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(texture stack depth, unit %u)", unit);
+ return;
+ }
+ params[0] = INT_TO_BOOLEAN(ctx->TextureMatrixStack[unit].Depth + 1);
+ }
break;
case GL_UNPACK_ALIGNMENT:
params[0] = INT_TO_BOOLEAN(ctx->Unpack.Alignment);
@@ -2114,11 +2139,16 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
break;
case GL_CURRENT_RASTER_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
- params[0] = ctx->Current.RasterTexCoords[texUnit][0];
- params[1] = ctx->Current.RasterTexCoords[texUnit][1];
- params[2] = ctx->Current.RasterTexCoords[texUnit][2];
- params[3] = ctx->Current.RasterTexCoords[texUnit][3];
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(raster tex coords, unit %u)", unit);
+ return;
+ }
+ params[0] = ctx->Current.RasterTexCoords[unit][0];
+ params[1] = ctx->Current.RasterTexCoords[unit][1];
+ params[2] = ctx->Current.RasterTexCoords[unit][2];
+ params[3] = ctx->Current.RasterTexCoords[unit][3];
}
break;
case GL_CURRENT_RASTER_POSITION_VALID:
@@ -2126,12 +2156,17 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
break;
case GL_CURRENT_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(current tex coords, unit %u)", unit);
+ return;
+ }
FLUSH_CURRENT(ctx, 0);
- params[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][0];
- params[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1];
- params[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2];
- params[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3];
+ params[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
+ params[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
+ params[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
+ params[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
}
break;
case GL_DEPTH_BIAS:
@@ -2766,7 +2801,14 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
break;
case GL_TEXTURE_MATRIX:
{
- const GLfloat *matrix = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top->m;
+ const GLfloat *matrix;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGet(texture matrix %u)",
+ unit);
+ return;
+ }
+ matrix = ctx->TextureMatrixStack[unit].Top->m;
params[0] = matrix[0];
params[1] = matrix[1];
params[2] = matrix[2];
@@ -2786,7 +2828,15 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
}
break;
case GL_TEXTURE_STACK_DEPTH:
- params[0] = (GLfloat)(ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1);
+ {
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(texture stack depth, unit %u)", unit);
+ return;
+ }
+ params[0] = (GLfloat)(ctx->TextureMatrixStack[unit].Depth + 1);
+ }
break;
case GL_UNPACK_ALIGNMENT:
params[0] = (GLfloat)(ctx->Unpack.Alignment);
@@ -3958,11 +4008,16 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
break;
case GL_CURRENT_RASTER_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
- params[0] = IROUND(ctx->Current.RasterTexCoords[texUnit][0]);
- params[1] = IROUND(ctx->Current.RasterTexCoords[texUnit][1]);
- params[2] = IROUND(ctx->Current.RasterTexCoords[texUnit][2]);
- params[3] = IROUND(ctx->Current.RasterTexCoords[texUnit][3]);
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(raster tex coords, unit %u)", unit);
+ return;
+ }
+ params[0] = IROUND(ctx->Current.RasterTexCoords[unit][0]);
+ params[1] = IROUND(ctx->Current.RasterTexCoords[unit][1]);
+ params[2] = IROUND(ctx->Current.RasterTexCoords[unit][2]);
+ params[3] = IROUND(ctx->Current.RasterTexCoords[unit][3]);
}
break;
case GL_CURRENT_RASTER_POSITION_VALID:
@@ -3970,12 +4025,17 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
break;
case GL_CURRENT_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(current tex coords, unit %u)", unit);
+ return;
+ }
FLUSH_CURRENT(ctx, 0);
- params[0] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][0]);
- params[1] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]);
- params[2] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]);
- params[3] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]);
+ params[0] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0]);
+ params[1] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1]);
+ params[2] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2]);
+ params[3] = IROUND(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3]);
}
break;
case GL_DEPTH_BIAS:
@@ -4610,7 +4670,14 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
break;
case GL_TEXTURE_MATRIX:
{
- const GLfloat *matrix = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top->m;
+ const GLfloat *matrix;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGet(texture matrix %u)",
+ unit);
+ return;
+ }
+ matrix = ctx->TextureMatrixStack[unit].Top->m;
params[0] = IROUND(matrix[0]);
params[1] = IROUND(matrix[1]);
params[2] = IROUND(matrix[2]);
@@ -4630,7 +4697,15 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
}
break;
case GL_TEXTURE_STACK_DEPTH:
- params[0] = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1;
+ {
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(texture stack depth, unit %u)", unit);
+ return;
+ }
+ params[0] = ctx->TextureMatrixStack[unit].Depth + 1;
+ }
break;
case GL_UNPACK_ALIGNMENT:
params[0] = ctx->Unpack.Alignment;
@@ -5803,11 +5878,16 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
break;
case GL_CURRENT_RASTER_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
- params[0] = IROUND64(ctx->Current.RasterTexCoords[texUnit][0]);
- params[1] = IROUND64(ctx->Current.RasterTexCoords[texUnit][1]);
- params[2] = IROUND64(ctx->Current.RasterTexCoords[texUnit][2]);
- params[3] = IROUND64(ctx->Current.RasterTexCoords[texUnit][3]);
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(raster tex coords, unit %u)", unit);
+ return;
+ }
+ params[0] = IROUND64(ctx->Current.RasterTexCoords[unit][0]);
+ params[1] = IROUND64(ctx->Current.RasterTexCoords[unit][1]);
+ params[2] = IROUND64(ctx->Current.RasterTexCoords[unit][2]);
+ params[3] = IROUND64(ctx->Current.RasterTexCoords[unit][3]);
}
break;
case GL_CURRENT_RASTER_POSITION_VALID:
@@ -5815,12 +5895,17 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
break;
case GL_CURRENT_TEXTURE_COORDS:
{
- const GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(current tex coords, unit %u)", unit);
+ return;
+ }
FLUSH_CURRENT(ctx, 0);
- params[0] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][0]);
- params[1] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]);
- params[2] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]);
- params[3] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]);
+ params[0] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0]);
+ params[1] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1]);
+ params[2] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2]);
+ params[3] = IROUND64(ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3]);
}
break;
case GL_DEPTH_BIAS:
@@ -6455,7 +6540,14 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
break;
case GL_TEXTURE_MATRIX:
{
- const GLfloat *matrix = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top->m;
+ const GLfloat *matrix;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGet(texture matrix %u)",
+ unit);
+ return;
+ }
+ matrix = ctx->TextureMatrixStack[unit].Top->m;
params[0] = IROUND64(matrix[0]);
params[1] = IROUND64(matrix[1]);
params[2] = IROUND64(matrix[2]);
@@ -6475,7 +6567,15 @@ _mesa_GetInteger64v( GLenum pname, GLint64 *params )
}
break;
case GL_TEXTURE_STACK_DEPTH:
- params[0] = (GLint64)(ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1);
+ {
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(texture stack depth, unit %u)", unit);
+ return;
+ }
+ params[0] = (GLint64)(ctx->TextureMatrixStack[unit].Depth + 1);
+ }
break;
case GL_UNPACK_ALIGNMENT:
params[0] = (GLint64)(ctx->Unpack.Alignment);
diff --git a/src/mesa/main/get_gen.py b/src/mesa/main/get_gen.py
index b0beb59207..9ae3ce0096 100644
--- a/src/mesa/main/get_gen.py
+++ b/src/mesa/main/get_gen.py
@@ -166,20 +166,32 @@ StateVars = [
"ctx->Current.RasterSecondaryColor[2]",
"ctx->Current.RasterSecondaryColor[3]"], "", None ),
( "GL_CURRENT_RASTER_TEXTURE_COORDS", GLfloat,
- ["ctx->Current.RasterTexCoords[texUnit][0]",
- "ctx->Current.RasterTexCoords[texUnit][1]",
- "ctx->Current.RasterTexCoords[texUnit][2]",
- "ctx->Current.RasterTexCoords[texUnit][3]"],
- "const GLuint texUnit = ctx->Texture.CurrentUnit;", None ),
+ ["ctx->Current.RasterTexCoords[unit][0]",
+ "ctx->Current.RasterTexCoords[unit][1]",
+ "ctx->Current.RasterTexCoords[unit][2]",
+ "ctx->Current.RasterTexCoords[unit][3]"],
+ """const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(raster tex coords, unit %u)", unit);
+ return;
+ }""",
+ None ),
( "GL_CURRENT_RASTER_POSITION_VALID", GLboolean,
["ctx->Current.RasterPosValid"], "", None ),
( "GL_CURRENT_TEXTURE_COORDS", GLfloat,
- ["ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][0]",
- "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]",
- "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]",
- "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]"],
- """const GLuint texUnit = ctx->Texture.CurrentUnit;
- FLUSH_CURRENT(ctx, 0);""", None ),
+ ["ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0]",
+ "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1]",
+ "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2]",
+ "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3]"],
+ """const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(current tex coords, unit %u)", unit);
+ return;
+ }
+ FLUSH_CURRENT(ctx, 0);""",
+ None ),
( "GL_DEPTH_BIAS", GLfloat, ["ctx->Pixel.DepthBias"], "", None ),
( "GL_DEPTH_BITS", GLint, ["ctx->DrawBuffer->Visual.depthBits"],
"", None ),
@@ -457,9 +469,24 @@ StateVars = [
"matrix[4]", "matrix[5]", "matrix[6]", "matrix[7]",
"matrix[8]", "matrix[9]", "matrix[10]", "matrix[11]",
"matrix[12]", "matrix[13]", "matrix[14]", "matrix[15]" ],
- "const GLfloat *matrix = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top->m;", None ),
+ """const GLfloat *matrix;
+ const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGet(texture matrix %u)",
+ unit);
+ return;
+ }
+ matrix = ctx->TextureMatrixStack[unit].Top->m;""",
+ None ),
( "GL_TEXTURE_STACK_DEPTH", GLint,
- ["ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Depth + 1"], "", None ),
+ ["ctx->TextureMatrixStack[unit].Depth + 1"],
+ """const GLuint unit = ctx->Texture.CurrentUnit;
+ if (unit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGet(texture stack depth, unit %u)", unit);
+ return;
+ }""",
+ None ),
( "GL_UNPACK_ALIGNMENT", GLint, ["ctx->Unpack.Alignment"], "", None ),
( "GL_UNPACK_LSB_FIRST", GLboolean, ["ctx->Unpack.LsbFirst"], "", None ),
( "GL_UNPACK_ROW_LENGTH", GLint, ["ctx->Unpack.RowLength"], "", None ),
diff --git a/src/mesa/main/getstring.c b/src/mesa/main/getstring.c
index c203b046a5..51dd5f7795 100644
--- a/src/mesa/main/getstring.c
+++ b/src/mesa/main/getstring.c
@@ -27,7 +27,6 @@
#include "glheader.h"
#include "context.h"
#include "get.h"
-#include "version.h"
#include "enums.h"
#include "extensions.h"
diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c
index ebc3cbd59c..5c863f6f32 100644
--- a/src/mesa/main/matrix.c
+++ b/src/mesa/main/matrix.c
@@ -726,10 +726,10 @@ void _mesa_init_matrix( GLcontext * ctx )
_NEW_PROJECTION);
init_matrix_stack(&ctx->ColorMatrixStack, MAX_COLOR_STACK_DEPTH,
_NEW_COLOR_MATRIX);
- for (i = 0; i < MAX_TEXTURE_UNITS; i++)
+ for (i = 0; i < Elements(ctx->TextureMatrixStack); i++)
init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH,
_NEW_TEXTURE_MATRIX);
- for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
+ for (i = 0; i < Elements(ctx->ProgramMatrixStack); i++)
init_matrix_stack(&ctx->ProgramMatrixStack[i],
MAX_PROGRAM_MATRIX_STACK_DEPTH, _NEW_TRACK_MATRIX);
ctx->CurrentStack = &ctx->ModelviewMatrixStack;
@@ -754,9 +754,9 @@ void _mesa_free_matrix_data( GLcontext *ctx )
free_matrix_stack(&ctx->ModelviewMatrixStack);
free_matrix_stack(&ctx->ProjectionMatrixStack);
free_matrix_stack(&ctx->ColorMatrixStack);
- for (i = 0; i < MAX_TEXTURE_UNITS; i++)
+ for (i = 0; i < Elements(ctx->TextureMatrixStack); i++)
free_matrix_stack(&ctx->TextureMatrixStack[i]);
- for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
+ for (i = 0; i < Elements(ctx->ProgramMatrixStack); i++)
free_matrix_stack(&ctx->ProgramMatrixStack[i]);
/* combined Modelview*Projection matrix */
_math_matrix_dtr( &ctx->_ModelProjectMatrix );
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 297c5ae878..2640ba5ac4 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -631,7 +631,7 @@ struct gl_current_attrib
GLfloat RasterColor[4];
GLfloat RasterSecondaryColor[4];
GLfloat RasterIndex;
- GLfloat RasterTexCoords[MAX_TEXTURE_UNITS][4];
+ GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
GLboolean RasterPosValid;
/*@}*/
};
@@ -963,7 +963,7 @@ struct gl_point_attrib
GLfloat Threshold; /**< GL_EXT_point_parameters */
GLboolean _Attenuated; /**< True if Params != [1, 0, 0] */
GLboolean PointSprite; /**< GL_NV/ARB_point_sprite */
- GLboolean CoordReplace[MAX_TEXTURE_UNITS]; /**< GL_ARB_point_sprite */
+ GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
GLenum SpriteOrigin; /**< GL_ARB_point_sprite */
};
@@ -1361,7 +1361,7 @@ struct gl_texture_unit
struct gl_texture_attrib
{
GLuint CurrentUnit; /**< GL_ACTIVE_TEXTURE */
- struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
+ struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c
index e743a2e6bd..eab9d13d6d 100644
--- a/src/mesa/main/points.c
+++ b/src/mesa/main/points.c
@@ -266,7 +266,7 @@ _mesa_init_point(GLcontext *ctx)
ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */
ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
- for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
+ for (i = 0; i < Elements(ctx->Point.CoordReplace); i++) {
ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
}
}
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index 703b47ec74..be61dc265d 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -273,6 +273,7 @@ window_pos3f(GLfloat x, GLfloat y, GLfloat z)
{
GLuint texSet;
for (texSet = 0; texSet < ctx->Const.MaxTextureCoordUnits; texSet++) {
+ assert(texSet < Elements(ctx->Current.RasterTexCoords));
COPY_4FV( ctx->Current.RasterTexCoords[texSet],
ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texSet] );
}
@@ -562,7 +563,7 @@ void _mesa_init_rastpos( GLcontext * ctx )
ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 );
ctx->Current.RasterIndex = 1.0;
- for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++)
+ for (i = 0; i < Elements(ctx->Current.RasterTexCoords); i++)
ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
ctx->Current.RasterPosValid = GL_TRUE;
}
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c
index 499b7330d0..414607e228 100644
--- a/src/mesa/main/texenvprogram.c
+++ b/src/mesa/main/texenvprogram.c
@@ -1535,8 +1535,15 @@ create_new_program(GLcontext *ctx, struct state_key *key,
/* Notify driver the fragment program has (actually) changed.
*/
if (ctx->Driver.ProgramStringNotify) {
- ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_PROGRAM_ARB,
- &p.program->Base );
+ GLboolean ok = ctx->Driver.ProgramStringNotify(ctx,
+ GL_FRAGMENT_PROGRAM_ARB,
+ &p.program->Base);
+ /* Driver should be able to handle any texenv programs as long as
+ * the driver correctly reported max number of texture units correctly,
+ * etc.
+ */
+ ASSERT(ok);
+ (void) ok; /* silence unused var warning */
}
if (DISASSEM) {
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index c4f2495018..0fde89b507 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -87,7 +87,7 @@ get_texobj(GLcontext *ctx, GLenum target, GLboolean get)
{
struct gl_texture_unit *texUnit;
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sTexParameter(current unit)", get ? "Get" : "");
return NULL;
@@ -815,7 +815,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetTexLevelParameteriv(current unit)");
return;
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 2b26f651a5..8c4399a430 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -77,7 +77,7 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
dst->Texture.SharedPalette = src->Texture.SharedPalette;
/* per-unit state */
- for (u = 0; u < src->Const.MaxTextureImageUnits; u++) {
+ for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
dst->Texture.Unit[u].Enabled = src->Texture.Unit[u].Enabled;
dst->Texture.Unit[u].EnvMode = src->Texture.Unit[u].EnvMode;
COPY_4V(dst->Texture.Unit[u].EnvColor, src->Texture.Unit[u].EnvColor);
@@ -282,15 +282,23 @@ calculate_derived_texenv( struct gl_tex_env_combine_state *state,
void GLAPIENTRY
_mesa_ActiveTextureARB(GLenum texture)
{
- GET_CURRENT_CONTEXT(ctx);
const GLuint texUnit = texture - GL_TEXTURE0;
+ GLuint k;
+ GET_CURRENT_CONTEXT(ctx);
+
+ /* See OpenGL spec for glActiveTexture: */
+ k = MAX2(ctx->Const.MaxCombinedTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits);
+
+ ASSERT(k <= Elements(ctx->Texture.Unit));
+
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
_mesa_debug(ctx, "glActiveTexture %s\n",
_mesa_lookup_enum_by_nr(texture));
- if (texUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (texUnit >= k) {
_mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(texture=%s)",
_mesa_lookup_enum_by_nr(texture));
return;
@@ -356,6 +364,7 @@ update_texture_matrices( GLcontext *ctx )
ctx->Texture._TexMatEnabled = 0x0;
for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
+ ASSERT(u < Elements(ctx->TextureMatrixStack));
if (_math_matrix_is_dirty(ctx->TextureMatrixStack[u].Top)) {
_math_matrix_analyse( ctx->TextureMatrixStack[u].Top );
@@ -509,7 +518,7 @@ update_texture_state( GLcontext *ctx )
/*
* Update texture unit state.
*/
- for (unit = 0; unit < ctx->Const.MaxTextureImageUnits; unit++) {
+ for (unit = 0; unit < ctx->Const.MaxCombinedTextureImageUnits; unit++) {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
GLbitfield enabledVertTargets = 0x0;
GLbitfield enabledFragTargets = 0x0;
@@ -627,6 +636,7 @@ update_texture_state( GLcontext *ctx )
ctx->Texture._GenFlags |= texUnit->_GenFlags;
}
+ ASSERT(unit < Elements(ctx->TextureMatrixStack));
if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
}
@@ -758,14 +768,15 @@ _mesa_init_texture(GLcontext *ctx)
ctx->Texture.SharedPalette = GL_FALSE;
_mesa_init_colortable(&ctx->Texture.Palette);
- for (u = 0; u < MAX_TEXTURE_UNITS; u++)
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++)
init_texture_unit(ctx, u);
/* After we're done initializing the context's texture state the default
- * texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1.
+ * texture objects' refcounts should be at least
+ * MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1.
*/
assert(ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount
- >= MAX_TEXTURE_UNITS + 1);
+ >= MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1);
/* Allocate proxy textures */
if (!alloc_proxy_textures( ctx ))
@@ -784,7 +795,7 @@ _mesa_free_texture_data(GLcontext *ctx)
GLuint u, tgt;
/* unreference current textures */
- for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
/* The _Current texture could account for another reference */
_mesa_reference_texobj(&ctx->Texture.Unit[u]._Current, NULL);
@@ -797,7 +808,7 @@ _mesa_free_texture_data(GLcontext *ctx)
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
- for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++)
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++)
_mesa_free_colortable_data(&ctx->Texture.Unit[u].ColorTable);
}
@@ -812,7 +823,7 @@ _mesa_update_default_objects_texture(GLcontext *ctx)
{
GLuint u, tex;
- for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u];
for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
_mesa_reference_texobj(&texUnit->CurrentTex[tex],
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 0b6295d5e1..818ed792e3 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -475,6 +475,8 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
return;
}
+ ASSERT(unit < Elements(ctx->Array.ArrayObj->TexCoord));
+
update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit],
_NEW_ARRAY_TEXCOORD(unit),
elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr);
diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c
index 746138071e..7e3040a6ef 100644
--- a/src/mesa/shader/arbprogram.c
+++ b/src/mesa/shader/arbprogram.c
@@ -489,8 +489,13 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
return;
}
- if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
- ctx->Driver.ProgramStringNotify( ctx, target, base );
+ if (ctx->Program.ErrorPos == -1) {
+ /* finally, give the program to the driver for translation/checking */
+ if (!ctx->Driver.ProgramStringNotify(ctx, target, base)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glProgramStringARB(rejected by driver");
+ }
+ }
}
diff --git a/src/mesa/shader/atifragshader.c b/src/mesa/shader/atifragshader.c
index e04a05b22f..ab7b2030d1 100644
--- a/src/mesa/shader/atifragshader.c
+++ b/src/mesa/shader/atifragshader.c
@@ -378,8 +378,11 @@ _mesa_EndFragmentShaderATI(void)
}
if (ctx->ATIFragmentShader.Current->cur_pass > 1)
ctx->ATIFragmentShader.Current->NumPasses = 2;
- else ctx->ATIFragmentShader.Current->NumPasses = 1;
- ctx->ATIFragmentShader.Current->cur_pass=0;
+ else
+ ctx->ATIFragmentShader.Current->NumPasses = 1;
+
+ ctx->ATIFragmentShader.Current->cur_pass = 0;
+
#if MESA_DEBUG_ATI_FS
for (j = 0; j < MAX_NUM_PASSES_ATI; j++) {
for (i = 0; i < MAX_NUM_FRAGMENT_REGISTERS_ATI; i++) {
@@ -402,8 +405,13 @@ _mesa_EndFragmentShaderATI(void)
}
}
#endif
- if (ctx->Driver.ProgramStringNotify)
- ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_SHADER_ATI, NULL );
+
+ if (!ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_SHADER_ATI, NULL)) {
+ ctx->ATIFragmentShader.Current->isValid = GL_FALSE;
+ /* XXX is this the right error? */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glEndFragmentShaderATI(driver rejected shader)");
+ }
}
void GLAPIENTRY
diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c
index 9f9789e010..54fd88ad4f 100644
--- a/src/mesa/shader/prog_print.c
+++ b/src/mesa/shader/prog_print.c
@@ -150,6 +150,10 @@ arb_input_attrib_string(GLint index, GLenum progType)
"fragment.varying[7]"
};
+ /* sanity checks */
+ assert(strcmp(vertAttribs[VERT_ATTRIB_TEX0], "vertex.texcoord[0]") == 0);
+ assert(strcmp(vertAttribs[VERT_ATTRIB_GENERIC15], "vertex.attrib[15]") == 0);
+
if (progType == GL_VERTEX_PROGRAM_ARB) {
assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
return vertAttribs[index];
@@ -162,6 +166,43 @@ arb_input_attrib_string(GLint index, GLenum progType)
/**
+ * Print a vertex program's InputsRead field in human-readable format.
+ * For debugging.
+ */
+void
+_mesa_print_vp_inputs(GLbitfield inputs)
+{
+ _mesa_printf("VP Inputs 0x%x: \n", inputs);
+ while (inputs) {
+ GLint attr = _mesa_ffs(inputs) - 1;
+ const char *name = arb_input_attrib_string(attr,
+ GL_VERTEX_PROGRAM_ARB);
+ _mesa_printf(" %d: %s\n", attr, name);
+ inputs &= ~(1 << attr);
+ }
+}
+
+
+/**
+ * Print a fragment program's InputsRead field in human-readable format.
+ * For debugging.
+ */
+void
+_mesa_print_fp_inputs(GLbitfield inputs)
+{
+ _mesa_printf("FP Inputs 0x%x: \n", inputs);
+ while (inputs) {
+ GLint attr = _mesa_ffs(inputs) - 1;
+ const char *name = arb_input_attrib_string(attr,
+ GL_FRAGMENT_PROGRAM_ARB);
+ _mesa_printf(" %d: %s\n", attr, name);
+ inputs &= ~(1 << attr);
+ }
+}
+
+
+
+/**
* Return ARB_v/f_prog-style output attrib string.
*/
static const char *
diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h
index fc286ded54..9ab7456016 100644
--- a/src/mesa/shader/prog_print.h
+++ b/src/mesa/shader/prog_print.h
@@ -37,6 +37,12 @@ typedef enum {
} gl_prog_print_mode;
+extern void
+_mesa_print_vp_inputs(GLbitfield inputs);
+
+extern void
+_mesa_print_fp_inputs(GLbitfield inputs);
+
extern const char *
_mesa_condcode_string(GLuint condcode);
diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c
index 3a446fd9bb..20321dd01f 100644
--- a/src/mesa/shader/prog_statevars.c
+++ b/src/mesa/shader/prog_statevars.c
@@ -302,9 +302,11 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
matrix = &ctx->_ModelProjectMatrix;
}
else if (mat == STATE_TEXTURE_MATRIX) {
+ ASSERT(index < Elements(ctx->TextureMatrixStack));
matrix = ctx->TextureMatrixStack[index].Top;
}
else if (mat == STATE_PROGRAM_MATRIX) {
+ ASSERT(index < Elements(ctx->ProgramMatrixStack));
matrix = ctx->ProgramMatrixStack[index].Top;
}
else if (mat == STATE_COLOR_MATRIX) {
@@ -1075,7 +1077,9 @@ _mesa_load_tracked_matrices(GLcontext *ctx)
mat = ctx->ProjectionMatrixStack.Top;
}
else if (ctx->VertexProgram.TrackMatrix[i] == GL_TEXTURE) {
- mat = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top;
+ GLuint unit = MIN2(ctx->Texture.CurrentUnit,
+ Elements(ctx->TextureMatrixStack) - 1);
+ mat = ctx->TextureMatrixStack[unit].Top;
}
else if (ctx->VertexProgram.TrackMatrix[i] == GL_COLOR) {
mat = ctx->ColorMatrixStack.Top;
@@ -1087,7 +1091,7 @@ _mesa_load_tracked_matrices(GLcontext *ctx)
else if (ctx->VertexProgram.TrackMatrix[i] >= GL_MATRIX0_NV &&
ctx->VertexProgram.TrackMatrix[i] <= GL_MATRIX7_NV) {
GLuint n = ctx->VertexProgram.TrackMatrix[i] - GL_MATRIX0_NV;
- ASSERT(n < MAX_PROGRAM_MATRICES);
+ ASSERT(n < Elements(ctx->ProgramMatrixStack));
mat = ctx->ProgramMatrixStack[n].Top;
}
else {
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 3e86d0adad..aaf5f96e2a 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -677,6 +677,8 @@ _mesa_combine_programs(GLcontext *ctx,
const GLuint lenB = progB->NumInstructions;
const GLuint numParamsA = _mesa_num_parameters(progA->Parameters);
const GLuint newLength = lenA + lenB;
+ GLboolean usedTemps[MAX_PROGRAM_TEMPS];
+ GLuint firstTemp = 0;
GLbitfield inputsB;
GLuint i;
@@ -698,6 +700,10 @@ _mesa_combine_programs(GLcontext *ctx,
newProg->Instructions = newInst;
newProg->NumInstructions = newLength;
+ /* find used temp regs (we may need new temps below) */
+ _mesa_find_used_registers(newProg, PROGRAM_TEMPORARY,
+ usedTemps, MAX_PROGRAM_TEMPS);
+
if (newProg->Target == GL_FRAGMENT_PROGRAM_ARB) {
struct gl_fragment_program *fprogA, *fprogB, *newFprog;
GLbitfield progB_inputsRead = progB->InputsRead;
@@ -741,12 +747,15 @@ _mesa_combine_programs(GLcontext *ctx,
*/
if ((progA->OutputsWritten & (1 << FRAG_RESULT_COLOR)) &&
(progB_inputsRead & FRAG_BIT_COL0)) {
- GLint tempReg = _mesa_find_free_register(newProg, PROGRAM_TEMPORARY);
+ GLint tempReg = _mesa_find_free_register(usedTemps, MAX_PROGRAM_TEMPS,
+ firstTemp);
if (tempReg < 0) {
_mesa_problem(ctx, "No free temp regs found in "
"_mesa_combine_programs(), using 31");
tempReg = 31;
}
+ firstTemp = tempReg + 1;
+
/* replace writes to result.color[0] with tempReg */
replace_registers(newInst, lenA,
PROGRAM_OUTPUT, FRAG_RESULT_COLOR,
@@ -784,53 +793,64 @@ _mesa_combine_programs(GLcontext *ctx,
}
-
-
/**
- * Scan the given program to find a free register of the given type.
- * \param regFile - PROGRAM_INPUT, PROGRAM_OUTPUT or PROGRAM_TEMPORARY
+ * Populate the 'used' array with flags indicating which registers (TEMPs,
+ * INPUTs, OUTPUTs, etc, are used by the given program.
+ * \param file type of register to scan for
+ * \param used returns true/false flags for in use / free
+ * \param usedSize size of the 'used' array
*/
-GLint
-_mesa_find_free_register(const struct gl_program *prog, GLuint regFile)
+void
+_mesa_find_used_registers(const struct gl_program *prog,
+ gl_register_file file,
+ GLboolean used[], GLuint usedSize)
{
- GLboolean used[MAX_PROGRAM_TEMPS];
- GLuint i, k;
-
- assert(regFile == PROGRAM_INPUT ||
- regFile == PROGRAM_OUTPUT ||
- regFile == PROGRAM_TEMPORARY);
+ GLuint i, j;
- _mesa_memset(used, 0, sizeof(used));
+ _mesa_memset(used, 0, usedSize);
for (i = 0; i < prog->NumInstructions; i++) {
const struct prog_instruction *inst = prog->Instructions + i;
const GLuint n = _mesa_num_inst_src_regs(inst->Opcode);
- /* check dst reg first */
- if (inst->DstReg.File == regFile) {
+ if (inst->DstReg.File == file) {
used[inst->DstReg.Index] = GL_TRUE;
}
- else {
- /* check src regs otherwise */
- for (k = 0; k < n; k++) {
- if (inst->SrcReg[k].File == regFile) {
- used[inst->SrcReg[k].Index] = GL_TRUE;
- break;
- }
+
+ for (j = 0; j < n; j++) {
+ if (inst->SrcReg[j].File == file) {
+ used[inst->SrcReg[j].Index] = GL_TRUE;
}
}
}
+}
- for (i = 0; i < MAX_PROGRAM_TEMPS; i++) {
+
+/**
+ * Scan the given 'used' register flag array for the first entry
+ * that's >= firstReg.
+ * \param used vector of flags indicating registers in use (as returned
+ * by _mesa_find_used_registers())
+ * \param usedSize size of the 'used' array
+ * \param firstReg first register to start searching at
+ * \return index of unused register, or -1 if none.
+ */
+GLint
+_mesa_find_free_register(const GLboolean used[],
+ GLuint usedSize, GLuint firstReg)
+{
+ GLuint i;
+
+ assert(firstReg < usedSize);
+
+ for (i = firstReg; i < usedSize; i++)
if (!used[i])
return i;
- }
return -1;
}
-
/**
* "Post-process" a GPU program. This is intended to be used for debugging.
* Example actions include no-op'ing instructions or changing instruction
diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h
index 56a4191f57..0187a2c55f 100644
--- a/src/mesa/shader/program.h
+++ b/src/mesa/shader/program.h
@@ -119,8 +119,14 @@ _mesa_combine_programs(GLcontext *ctx,
const struct gl_program *progA,
const struct gl_program *progB);
+extern void
+_mesa_find_used_registers(const struct gl_program *prog,
+ gl_register_file file,
+ GLboolean used[], GLuint usedSize);
+
extern GLint
-_mesa_find_free_register(const struct gl_program *prog, GLuint regFile);
+_mesa_find_free_register(const GLboolean used[],
+ GLuint maxRegs, GLuint firstReg);
extern void
_mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog);
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index 9514545709..fb2ebe6338 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -495,6 +495,11 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type)
GLuint i;
GLint outputMap[VERT_RESULT_MAX];
GLuint numVaryingReads = 0;
+ GLboolean usedTemps[MAX_PROGRAM_TEMPS];
+ GLuint firstTemp = 0;
+
+ _mesa_find_used_registers(prog, PROGRAM_TEMPORARY,
+ usedTemps, MAX_PROGRAM_TEMPS);
assert(type == PROGRAM_VARYING || type == PROGRAM_OUTPUT);
assert(prog->Target == GL_VERTEX_PROGRAM_ARB || type != PROGRAM_VARYING);
@@ -513,8 +518,10 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type)
const GLuint var = inst->SrcReg[j].Index;
if (outputMap[var] == -1) {
numVaryingReads++;
- outputMap[var] = _mesa_find_free_register(prog,
- PROGRAM_TEMPORARY);
+ outputMap[var] = _mesa_find_free_register(usedTemps,
+ MAX_PROGRAM_TEMPS,
+ firstTemp);
+ firstTemp = outputMap[var] + 1;
}
inst->SrcReg[j].File = PROGRAM_TEMPORARY;
inst->SrcReg[j].Index = outputMap[var];
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index d53580f5f6..e8eaa9c103 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -1715,7 +1715,11 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program,
*/
FLUSH_VERTICES(ctx, _NEW_TEXTURE | _NEW_PROGRAM);
_mesa_update_shader_textures_used(program);
- ctx->Driver.ProgramStringNotify(ctx, program->Target, program);
+ /* Do we need to care about the return value here?
+ * This should not be the first time the driver was notified of
+ * this program.
+ */
+ (void) ctx->Driver.ProgramStringNotify(ctx, program->Target, program);
}
}
else {
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 21497b34e2..df524ce078 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -719,6 +719,7 @@ _slang_link(GLcontext *ctx,
{
const struct gl_vertex_program *vertProg = NULL;
const struct gl_fragment_program *fragProg = NULL;
+ GLboolean vertNotify = GL_TRUE, fragNotify = GL_TRUE;
GLuint numSamplers = 0;
GLuint i;
@@ -871,8 +872,8 @@ _slang_link(GLcontext *ctx,
_mesa_update_shader_textures_used(&shProg->FragmentProgram->Base);
/* notify driver that a new fragment program has been compiled/linked */
- ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
- &shProg->FragmentProgram->Base);
+ vertNotify = ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
+ &shProg->FragmentProgram->Base);
if (ctx->Shader.Flags & GLSL_DUMP) {
_mesa_printf("Mesa pre-link fragment program:\n");
_mesa_print_program(&fragProg->Base);
@@ -889,8 +890,8 @@ _slang_link(GLcontext *ctx,
_mesa_update_shader_textures_used(&shProg->VertexProgram->Base);
/* notify driver that a new vertex program has been compiled/linked */
- ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
- &shProg->VertexProgram->Base);
+ fragNotify = ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
+ &shProg->VertexProgram->Base);
if (ctx->Shader.Flags & GLSL_DUMP) {
_mesa_printf("Mesa pre-link vertex program:\n");
_mesa_print_program(&vertProg->Base);
@@ -918,6 +919,12 @@ _slang_link(GLcontext *ctx,
}
}
- shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram);
+ if (!vertNotify || !fragNotify) {
+ /* driver rejected one/both of the vertex/fragment programs */
+ link_error(shProg, "Vertex and/or fragment program rejected by driver\n");
+ }
+ else {
+ shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram);
+ }
}
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index d70cf877e8..d975cd66f7 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -37,7 +37,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "st_debug.h"
#include "st_context.h"
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index 8d045f2c6c..fba7bfe2ce 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -40,6 +40,7 @@
#include "cso_cache/cso_context.h"
#include "util/u_rect.h"
#include "util/u_math.h"
+#include "util/u_inlines.h"
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 181f88a334..ea16719ba0 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -37,7 +37,6 @@
#include "main/imports.h"
#include "main/mtypes.h"
-#include "main/macros.h"
#include "shader/program.h"
#include "pipe/p_context.h"
@@ -50,7 +49,6 @@
#include "st_context.h"
#include "st_atom.h"
#include "st_program.h"
-#include "st_atom_shader.h"
@@ -61,26 +59,10 @@ static void
translate_fp(struct st_context *st,
struct st_fragment_program *stfp)
{
- const GLbitfield fragInputsRead = stfp->Base.Base.InputsRead;
-
if (!stfp->state.tokens) {
- GLuint inAttr, numIn = 0;
-
- for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) {
- if (fragInputsRead & (1 << inAttr)) {
- stfp->input_to_slot[inAttr] = numIn;
- numIn++;
- }
- else {
- stfp->input_to_slot[inAttr] = -1;
- }
- }
-
- stfp->num_input_slots = numIn;
-
assert(stfp->Base.Base.NumInstructions > 0);
- st_translate_fragment_program(st, stfp, stfp->input_to_slot);
+ st_translate_fragment_program(st, stfp);
}
}
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 0b68447d21..57b71c1e7b 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -39,6 +39,7 @@
#include "st_texture.h"
#include "st_cb_texture.h"
#include "pipe/p_context.h"
+#include "util/u_inlines.h"
#include "cso_cache/cso_context.h"
diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c
index 27ec2eb033..0b6c34ca2c 100644
--- a/src/mesa/state_tracker/st_atom_viewport.c
+++ b/src/mesa/state_tracker/st_atom_viewport.c
@@ -27,7 +27,6 @@
#include "main/context.h"
-#include "main/colormac.h"
#include "st_context.h"
#include "st_atom.h"
#include "pipe/p_context.h"
@@ -62,9 +61,9 @@ update_viewport( struct st_context *st )
GLfloat x = (GLfloat)ctx->Viewport.X;
GLfloat y = (GLfloat)ctx->Viewport.Y;
GLfloat z = ctx->Viewport.Near;
- GLfloat half_width = (GLfloat)ctx->Viewport.Width / 2.0f;
- GLfloat half_height = (GLfloat)ctx->Viewport.Height / 2.0f;
- GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) / 2.0f;
+ GLfloat half_width = (GLfloat)ctx->Viewport.Width * 0.5f;
+ GLfloat half_height = (GLfloat)ctx->Viewport.Height * 0.5f;
+ GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) * 0.5f;
st->state.viewport.scale[0] = half_width;
st->state.viewport.scale[1] = half_height * yScale;
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index 798081ec89..1be72e729e 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -43,7 +43,7 @@
#include "st_inlines.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_tile.h"
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index d1b35f796e..85420a950f 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -47,7 +47,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
#include "util/u_simple_shaders.h"
#include "shader/prog_instruction.h"
@@ -221,7 +221,7 @@ combined_bitmap_fragment_program(GLcontext *ctx)
#endif
/* translate to TGSI tokens */
- st_translate_fragment_program(st, stfp->bitmap_program, NULL);
+ st_translate_fragment_program(st, stfp->bitmap_program);
}
return stfp->bitmap_program;
diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c
index 65aa2a28ac..36e03018d9 100644
--- a/src/mesa/state_tracker/st_cb_blit.c
+++ b/src/mesa/state_tracker/st_cb_blit.c
@@ -41,8 +41,7 @@
#include "st_cb_fbo.h"
#include "util/u_blit.h"
-
-#include "cso_cache/cso_context.h"
+#include "util/u_inlines.h"
void
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 0102d8a6f7..3ff589034a 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -42,7 +42,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
/**
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 94693d91f3..0c7bcb8597 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -47,7 +47,7 @@
#include "st_inlines.h"
#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "util/u_format.h"
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 7afdc31ede..2a084ca577 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -53,7 +53,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "tgsi/tgsi_ureg.h"
#include "util/u_tile.h"
#include "util/u_draw_quad.h"
@@ -140,7 +140,7 @@ combined_drawpix_fragment_program(GLcontext *ctx)
#endif
/* translate to TGSI tokens */
- st_translate_fragment_program(st, stfp, NULL);
+ st_translate_fragment_program(st, stfp);
/* save new program, update serial numbers */
st->pixel_xfer.xfer_prog_sn = st->pixel_xfer.program->serialNo;
@@ -221,7 +221,7 @@ make_fragment_shader_z(struct st_context *st)
p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */
st->drawpix.z_shader = (struct st_fragment_program *) p;
- st_translate_fragment_program(st, st->drawpix.z_shader, NULL);
+ st_translate_fragment_program(st, st->drawpix.z_shader);
return st->drawpix.z_shader;
}
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index f7350ef1e3..9f2fe7420d 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -50,6 +50,7 @@
#include "util/u_format.h"
#include "util/u_rect.h"
+#include "util/u_inlines.h"
/**
diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c
index 17261f8321..edf26473d4 100644
--- a/src/mesa/state_tracker/st_cb_feedback.c
+++ b/src/mesa/state_tracker/st_cb_feedback.c
@@ -40,7 +40,6 @@
#include "main/imports.h"
#include "main/context.h"
#include "main/feedback.h"
-#include "main/macros.h"
#include "vbo/vbo.h"
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 5138e596a9..82ef5572e1 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -43,7 +43,6 @@
#include "st_context.h"
#include "st_program.h"
-#include "st_atom_shader.h"
#include "st_mesa_to_tgsi.h"
#include "st_cb_program.h"
@@ -178,9 +177,9 @@ static GLboolean st_is_program_native( GLcontext *ctx,
}
-static void st_program_string_notify( GLcontext *ctx,
- GLenum target,
- struct gl_program *prog )
+static GLboolean st_program_string_notify( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
{
struct st_context *st = st_context(ctx);
@@ -212,6 +211,9 @@ static void st_program_string_notify( GLcontext *ctx,
if (st->vp == stvp)
st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
}
+
+ /* XXX check if program is legal, within limits */
+ return GL_TRUE;
}
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 8eb825a6a4..6b1fdf3ecd 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -40,7 +40,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_tile.h"
#include "st_debug.h"
diff --git a/src/mesa/state_tracker/st_cb_strings.c b/src/mesa/state_tracker/st_cb_strings.c
index f22c5369e4..0fcb427f30 100644
--- a/src/mesa/state_tracker/st_cb_strings.c
+++ b/src/mesa/state_tracker/st_cb_strings.c
@@ -35,10 +35,11 @@
#include "main/macros.h"
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
+#include "util/u_string.h"
#include "st_context.h"
#include "st_cb_strings.h"
-#define ST_VERSION_STRING "0.3"
+#define ST_VERSION_STRING "0.4"
static const GLubyte *
st_get_string(GLcontext * ctx, GLenum name)
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index cee2452eaf..13f050900a 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -57,7 +57,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_tile.h"
#include "util/u_blit.h"
@@ -543,22 +543,15 @@ st_TexImage(GLcontext * ctx,
_mesa_align_free(texImage->Data);
}
- if (width == 0 || height == 0 || depth == 0) {
- /* stop after freeing old image */
- return;
- }
-
- /* If this is the only mipmap level in the texture, could call
- * bmBufferData with NULL data to free the old block and avoid
- * waiting on any outstanding fences.
+ /*
+ * See if the new image is somehow incompatible with the existing
+ * mipmap. If so, free the old mipmap.
*/
if (stObj->pt) {
if (stObj->teximage_realloc ||
level > (GLint) stObj->pt->last_level ||
- (stObj->pt->last_level == level &&
- stObj->pt->target != PIPE_TEXTURE_CUBE &&
- !st_texture_match_image(stObj->pt, &stImage->base,
- stImage->face, stImage->level))) {
+ !st_texture_match_image(stObj->pt, &stImage->base,
+ stImage->face, stImage->level)) {
DBG("release it\n");
pipe_texture_reference(&stObj->pt, NULL);
assert(!stObj->pt);
@@ -566,6 +559,11 @@ st_TexImage(GLcontext * ctx,
}
}
+ if (width == 0 || height == 0 || depth == 0) {
+ /* stop after freeing old image */
+ return;
+ }
+
if (!stObj->pt) {
guess_and_alloc_texture(ctx->st, stObj, stImage);
if (!stObj->pt) {
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index a62ff248ce..8f6a0c2423 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -63,6 +63,7 @@
#include "st_gen_mipmap.h"
#include "st_program.h"
#include "pipe/p_context.h"
+#include "util/u_inlines.h"
#include "draw/draw_context.h"
#include "cso_cache/cso_context.h"
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 381c68474d..e1dcb154c1 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -55,7 +55,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
static GLuint double_types[4] = {
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index cdaee2a353..75ad1a97cf 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -39,7 +39,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "draw/draw_private.h"
#include "draw/draw_context.h"
diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c
index 835142e3d4..4e225a123c 100644
--- a/src/mesa/state_tracker/st_framebuffer.c
+++ b/src/mesa/state_tracker/st_framebuffer.c
@@ -35,6 +35,7 @@
#include "st_cb_fbo.h"
#include "st_public.h"
#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
struct st_framebuffer *
@@ -53,7 +54,7 @@ st_create_framebuffer( const __GLcontextModes *visual,
if (visual->sampleBuffers)
samples = visual->samples;
- _mesa_initialize_framebuffer(&stfb->Base, visual);
+ _mesa_initialize_window_framebuffer(&stfb->Base, visual);
if (visual->doubleBufferMode) {
struct gl_renderbuffer *rb
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 3823a59d37..f67d7b4cb5 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -36,7 +36,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_gen_mipmap.h"
#include "util/u_math.h"
diff --git a/src/mesa/state_tracker/st_inlines.h b/src/mesa/state_tracker/st_inlines.h
index dccc46f12d..e105870bc7 100644
--- a/src/mesa/state_tracker/st_inlines.h
+++ b/src/mesa/state_tracker/st_inlines.h
@@ -36,7 +36,7 @@
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "pipe/p_state.h"
#include "st_context.h"
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 4aed2df8c3..6283833463 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -40,7 +40,6 @@
#include "st_context.h"
#include "shader/prog_instruction.h"
#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
#include "util/u_debug.h"
#include "util/u_math.h"
#include "util/u_memory.h"
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 5c87e47ca3..a639003dbd 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -269,24 +269,20 @@ fail:
/**
* Translate a Mesa fragment shader into a TGSI shader.
- * \param inputMapping to map fragment program input registers to TGSI
- * input slots
* \return pointer to cached pipe_shader object.
*/
void
st_translate_fragment_program(struct st_context *st,
- struct st_fragment_program *stfp,
- const GLuint inputMapping[])
+ struct st_fragment_program *stfp )
{
struct pipe_context *pipe = st->pipe;
GLuint outputMapping[FRAG_RESULT_MAX];
- GLuint defaultInputMapping[FRAG_ATTRIB_MAX];
+ GLuint inputMapping[FRAG_ATTRIB_MAX];
GLuint interpMode[16]; /* XXX size? */
GLuint attr;
enum pipe_error error;
const GLbitfield inputsRead = stfp->Base.Base.InputsRead;
struct ureg_program *ureg;
- GLuint vslot = 0;
uint fs_num_inputs = 0;
@@ -294,24 +290,14 @@ st_translate_fragment_program(struct st_context *st,
ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
uint fs_num_outputs = 0;
- /* which vertex output goes to the first fragment input: */
- if (inputsRead & FRAG_BIT_WPOS)
- vslot = 0;
- else
- vslot = 1;
-
/*
* Convert Mesa program inputs to TGSI input register semantics.
*/
for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) {
if (inputsRead & (1 << attr)) {
- const GLuint slot = fs_num_inputs;
-
- defaultInputMapping[attr] = slot;
-
- stfp->input_map[slot] = vslot++;
+ const GLuint slot = fs_num_inputs++;
- fs_num_inputs++;
+ inputMapping[attr] = slot;
switch (attr) {
case FRAG_ATTRIB_WPOS:
@@ -376,6 +362,9 @@ st_translate_fragment_program(struct st_context *st,
break;
}
}
+ else {
+ inputMapping[attr] = -1;
+ }
}
/*
@@ -417,9 +406,6 @@ st_translate_fragment_program(struct st_context *st,
}
}
- if (!inputMapping)
- inputMapping = defaultInputMapping;
-
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
return;
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 6b9a9226df..d9822e50f5 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -52,12 +52,6 @@ struct st_fragment_program
struct gl_fragment_program Base;
GLuint serialNo;
- GLuint input_to_slot[FRAG_ATTRIB_MAX]; /**< Maps FRAG_ATTRIB_x to slot */
- GLuint num_input_slots;
-
- /** map FP input back to VP output */
- GLuint input_map[PIPE_MAX_SHADER_INPUTS];
-
ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
@@ -171,8 +165,7 @@ st_reference_fragprog(struct st_context *st,
extern void
st_translate_fragment_program(struct st_context *st,
- struct st_fragment_program *fp,
- const GLuint inputMapping[]);
+ struct st_fragment_program *fp);
/* Called after program string change, discard all previous
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index b210ac9187..5a45c4358a 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -41,7 +41,7 @@
#include "pipe/p_state.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_rect.h"
#include "util/u_math.h"
diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c
index 5396548666..44b64b17d1 100644
--- a/src/mesa/tnl/t_vb_program.c
+++ b/src/mesa/tnl/t_vb_program.c
@@ -203,13 +203,14 @@ vp_fetch_texel(GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
* Called via ctx->Driver.ProgramStringNotify() after a new vertex program
* string has been parsed.
*/
-void
+GLboolean
_tnl_program_string(GLcontext *ctx, GLenum target, struct gl_program *program)
{
/* No-op.
* If we had derived anything from the program that was private to this
* stage we'd recompute/validate it here.
*/
+ return GL_TRUE;
}
diff --git a/src/mesa/tnl/tnl.h b/src/mesa/tnl/tnl.h
index 9c66d3b019..2c0d1fef73 100644
--- a/src/mesa/tnl/tnl.h
+++ b/src/mesa/tnl/tnl.h
@@ -66,7 +66,7 @@ _tnl_allow_vertex_fog( GLcontext *ctx, GLboolean value );
extern void
_tnl_allow_pixel_fog( GLcontext *ctx, GLboolean value );
-extern void
+extern GLboolean
_tnl_program_string(GLcontext *ctx, GLenum target, struct gl_program *program);
struct _mesa_prim;
diff --git a/src/mesa/vbo/vbo_split_inplace.c b/src/mesa/vbo/vbo_split_inplace.c
index da84eaa6ea..2fc866c577 100644
--- a/src/mesa/vbo/vbo_split_inplace.c
+++ b/src/mesa/vbo/vbo_split_inplace.c
@@ -30,12 +30,15 @@
#include "main/mtypes.h"
#include "main/macros.h"
#include "main/enums.h"
+#include "main/image.h"
#include "vbo_split.h"
#define MAX_PRIM 32
-/* Used for splitting without copying.
+/* Used for splitting without copying. No attempt is made to handle
+ * too large indexed vertex buffers: In general you need to copy to do
+ * that.
*/
struct split_context {
GLcontext *ctx;
@@ -48,6 +51,7 @@ struct split_context {
vbo_draw_func draw;
const struct split_limits *limits;
+ GLuint limit;
struct _mesa_prim dstprim[MAX_PRIM];
GLuint dstprim_nr;
@@ -58,38 +62,38 @@ struct split_context {
static void flush_vertex( struct split_context *split )
{
- GLuint min_index, max_index;
+ struct _mesa_index_buffer ib;
GLuint i;
if (!split->dstprim_nr)
return;
- min_index = split->dstprim[0].start;
- max_index = min_index + split->dstprim[0].count - 1;
+ if (split->ib) {
+ ib = *split->ib;
- for (i = 1; i < split->dstprim_nr; i++) {
- GLuint tmp_min = split->dstprim[i].start;
- GLuint tmp_max = tmp_min + split->dstprim[i].count - 1;
+ ib.count = split->max_index - split->min_index + 1;
+ ib.ptr = (const void *)((const char *)ib.ptr +
+ split->min_index * _mesa_sizeof_type(ib.type));
- if (tmp_min < min_index)
- min_index = tmp_min;
-
- if (tmp_max > max_index)
- max_index = tmp_max;
+ /* Rebase the primitives to save index buffer entries. */
+ for (i = 0; i < split->dstprim_nr; i++)
+ split->dstprim[i].start -= split->min_index;
}
- assert(max_index >= min_index);
+ assert(split->max_index >= split->min_index);
- split->draw( split->ctx,
- split->array,
- split->dstprim,
- split->dstprim_nr,
- NULL,
- GL_TRUE,
- min_index,
- max_index);
+ split->draw(split->ctx,
+ split->array,
+ split->dstprim,
+ split->dstprim_nr,
+ split->ib ? &ib : NULL,
+ !split->ib,
+ split->min_index,
+ split->max_index);
split->dstprim_nr = 0;
+ split->min_index = ~0;
+ split->max_index = 0;
}
@@ -106,62 +110,67 @@ static struct _mesa_prim *next_outprim( struct split_context *split )
}
}
-static int align(int value, int alignment)
+static void update_index_bounds(struct split_context *split,
+ const struct _mesa_prim *prim)
{
- return (value + alignment - 1) & ~(alignment - 1);
+ split->min_index = MIN2(split->min_index, prim->start);
+ split->max_index = MAX2(split->max_index, prim->start + prim->count - 1);
}
-
+/* Return the maximum amount of vertices that can be emitted for a
+ * primitive starting at 'prim->start', depending on the previous
+ * index bounds.
+ */
+static GLuint get_max_vertices(struct split_context *split,
+ const struct _mesa_prim *prim)
+{
+ if ((prim->start > split->min_index &&
+ prim->start - split->min_index >= split->limit) ||
+ (prim->start < split->max_index &&
+ split->max_index - prim->start >= split->limit))
+ /* "prim" starts too far away from the old range. */
+ return 0;
+
+ return MIN2(split->min_index, prim->start) + split->limit - prim->start;
+}
/* Break large primitives into smaller ones. If not possible, convert
* the primitive to indexed and pass to split_elts().
*/
static void split_prims( struct split_context *split)
{
- GLuint csr = 0;
GLuint i;
for (i = 0; i < split->nr_prims; i++) {
const struct _mesa_prim *prim = &split->prim[i];
GLuint first, incr;
GLboolean split_inplace = split_prim_inplace(prim->mode, &first, &incr);
- GLuint count;
-
- /* Always wrap on an even numbered vertex to avoid problems with
- * triangle strips.
- */
- GLuint available = align(split->limits->max_verts - csr - 1, 2);
- assert(split->limits->max_verts >= csr);
+ GLuint available = get_max_vertices(split, prim);
+ GLuint count = prim->count - (prim->count - first) % incr;
if (prim->count < first)
continue;
-
- count = prim->count - (prim->count - first) % incr;
-
- if ((available < count && !split_inplace) ||
+ if ((available < count && !split_inplace) ||
(available < first && split_inplace)) {
flush_vertex(split);
- csr = 0;
- available = align(split->limits->max_verts - csr - 1, 2);
+ available = get_max_vertices(split, prim);
}
if (available >= count) {
struct _mesa_prim *outprim = next_outprim(split);
+
*outprim = *prim;
- csr += prim->count;
- available = align(split->limits->max_verts - csr - 1, 2);
- }
+ update_index_bounds(split, outprim);
+ }
else if (split_inplace) {
GLuint j, nr;
-
for (j = 0 ; j < count ; ) {
GLuint remaining = count - j;
struct _mesa_prim *outprim = next_outprim(split);
nr = MIN2( available, remaining );
-
nr -= (nr - first) % incr;
outprim->mode = prim->mode;
@@ -169,21 +178,20 @@ static void split_prims( struct split_context *split)
outprim->end = (nr == remaining && prim->end);
outprim->start = prim->start + j;
outprim->count = nr;
-
+
+ update_index_bounds(split, outprim);
+
if (nr == remaining) {
/* Finished.
*/
- j += nr;
- csr += nr;
- available = align(split->limits->max_verts - csr - 1, 2);
+ j += nr;
}
else {
/* Wrapped the primitive:
*/
j += nr - (first - incr);
flush_vertex(split);
- csr = 0;
- available = align(split->limits->max_verts - csr - 1, 2);
+ available = get_max_vertices(split, prim);
}
}
}
@@ -260,10 +268,14 @@ void vbo_split_inplace( GLcontext *ctx,
split.prim = prim;
split.nr_prims = nr_prims;
split.ib = ib;
- split.min_index = min_index;
- split.max_index = max_index;
+
+ /* Empty interval, makes calculations simpler. */
+ split.min_index = ~0;
+ split.max_index = 0;
+
split.draw = draw;
split.limits = limits;
+ split.limit = ib ? limits->max_indices : limits->max_verts;
split_prims( &split );
}
diff --git a/src/mesa/x86/sse_xform2.S b/src/mesa/x86/sse_xform2.S
index b490d4c169..a443dad35c 100644
--- a/src/mesa/x86/sse_xform2.S
+++ b/src/mesa/x86/sse_xform2.S
@@ -186,7 +186,7 @@ GLNAME(_mesa_sse_transform_points2_3d_no_rot):
MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */
ADD_L( EDI, ECX ) /* count += dest ptr */
- PXOR( XMM0, XMM0 )
+ XORPS( XMM0, XMM0 ) /* clean the working register */
ALIGNTEXT32
MOVSS ( M(0), XMM1 ) /* - | - | - | m0 */
diff --git a/src/mesa/x86/sse_xform3.S b/src/mesa/x86/sse_xform3.S
index 8a79eeda18..4bc22d8a54 100644
--- a/src/mesa/x86/sse_xform3.S
+++ b/src/mesa/x86/sse_xform3.S
@@ -198,7 +198,7 @@ GLNAME(_mesa_sse_transform_points3_3d_no_rot):
MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */
ADD_L( EDI, ECX ) /* count += dest ptr */
- PXOR( XMM0, XMM0 )
+ XORPS( XMM0, XMM0 ) /* clean the working register */
ALIGNTEXT32
MOVSS ( M(0), XMM1 ) /* - | - | - | m0 */