summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/SConscript74
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c11
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aaline.c8
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aapoint.c9
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_debug.cpp8
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_misc.cpp4
-rw-r--r--src/gallium/auxiliary/indices/u_unfilled_gen.py4
-rw-r--r--src/gallium/auxiliary/indices/u_unfilled_indices.c7
-rw-r--r--src/gallium/auxiliary/os/os_memory.h2
-rw-r--r--src/gallium/auxiliary/os/os_misc.h4
-rw-r--r--src/gallium/auxiliary/os/os_thread.h12
-rw-r--r--src/gallium/auxiliary/os/os_time.c5
-rw-r--r--src/gallium/auxiliary/util/u_debug.c2
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.c46
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.h20
-rw-r--r--src/gallium/auxiliary/util/u_vbuf_mgr.c58
-rw-r--r--src/gallium/auxiliary/util/u_vbuf_mgr.h12
-rw-r--r--src/gallium/drivers/i915/Makefile1
-rw-r--r--src/gallium/drivers/i915/SConscript1
-rw-r--r--src/gallium/drivers/i915/TODO15
-rw-r--r--src/gallium/drivers/i915/i915_clear.c2
-rw-r--r--src/gallium/drivers/i915/i915_context.c25
-rw-r--r--src/gallium/drivers/i915/i915_context.h3
-rw-r--r--src/gallium/drivers/i915/i915_fpc.h5
-rw-r--r--src/gallium/drivers/i915/i915_fpc_emit.c72
-rw-r--r--src/gallium/drivers/i915/i915_fpc_translate.c134
-rw-r--r--src/gallium/drivers/i915/i915_query.c86
-rw-r--r--src/gallium/drivers/i915/i915_query.h36
-rw-r--r--src/gallium/drivers/i915/i915_resource.c4
-rw-r--r--src/gallium/drivers/i915/i915_resource.h12
-rw-r--r--src/gallium/drivers/i915/i915_resource_texture.c196
-rw-r--r--src/gallium/drivers/i915/i915_screen.c15
-rw-r--r--src/gallium/drivers/i915/i915_screen.h6
-rw-r--r--src/gallium/drivers/i915/i915_state.c14
-rw-r--r--src/gallium/drivers/i915/i915_state_derived.c28
-rw-r--r--src/gallium/drivers/i915/i915_state_emit.c94
-rw-r--r--src/gallium/drivers/i915/i915_state_inlines.h25
-rw-r--r--src/gallium/drivers/i915/i915_state_sampler.c52
-rw-r--r--src/gallium/drivers/i915/i915_state_static.c15
-rw-r--r--src/gallium/drivers/llvmpipe/SConscript2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_screen.c2
-rw-r--r--src/gallium/drivers/nouveau/nouveau_screen.c14
-rw-r--r--src/gallium/drivers/nouveau/nouveau_screen.h2
-rw-r--r--src/gallium/drivers/nv50/nv50_context.c8
-rw-r--r--src/gallium/drivers/nv50/nv50_context.h2
-rw-r--r--src/gallium/drivers/nv50/nv50_screen.h2
-rw-r--r--src/gallium/drivers/nv50/nv50_vbo.c15
-rw-r--r--src/gallium/drivers/nvc0/nvc0_context.c8
-rw-r--r--src/gallium/drivers/nvc0/nvc0_context.h2
-rw-r--r--src/gallium/drivers/nvc0/nvc0_screen.h2
-rw-r--r--src/gallium/drivers/nvc0/nvc0_vbo.c15
-rw-r--r--src/gallium/drivers/nvfx/nvfx_context.c16
-rw-r--r--src/gallium/drivers/nvfx/nvfx_screen.c7
-rw-r--r--src/gallium/drivers/nvfx/nvfx_screen.h1
-rw-r--r--src/gallium/drivers/r300/r300_render.c102
-rw-r--r--src/gallium/drivers/r300/r300_texture.c21
-rw-r--r--src/gallium/drivers/r600/SConscript6
-rw-r--r--src/gallium/drivers/r600/eg_state_inlines.h5
-rw-r--r--src/gallium/drivers/r600/evergreen_state.c8
-rw-r--r--src/gallium/drivers/r600/r600.h1
-rw-r--r--src/gallium/drivers/r600/r600_asm.c2
-rw-r--r--src/gallium/drivers/r600/r600_blit.c47
-rw-r--r--src/gallium/drivers/r600/r600_pipe.c11
-rw-r--r--src/gallium/drivers/r600/r600_pipe.h19
-rw-r--r--src/gallium/drivers/r600/r600_query.c3
-rw-r--r--src/gallium/drivers/r600/r600_shader.c206
-rw-r--r--src/gallium/drivers/r600/r600_shader.h2
-rw-r--r--src/gallium/drivers/r600/r600_state.c59
-rw-r--r--src/gallium/drivers/r600/r600_state_common.c112
-rw-r--r--src/gallium/drivers/r600/r600_state_inlines.h4
-rw-r--r--src/gallium/drivers/r600/r600_texture.c11
-rw-r--r--src/gallium/drivers/r600/r600d.h3
-rw-r--r--src/gallium/drivers/svga/svga_context.c8
-rw-r--r--src/gallium/drivers/svga/svga_context.h3
-rw-r--r--src/gallium/drivers/svga/svga_draw.c17
-rw-r--r--src/gallium/drivers/svga/svga_draw.h3
-rw-r--r--src/gallium/drivers/svga/svga_draw_private.h7
-rw-r--r--src/gallium/drivers/svga/svga_pipe_draw.c216
-rw-r--r--src/gallium/drivers/svga/svga_resource_buffer.h12
-rw-r--r--src/gallium/drivers/svga/svga_resource_buffer_upload.c17
-rw-r--r--src/gallium/drivers/svga/svga_state_vdecl.c119
-rw-r--r--src/gallium/include/pipe/p_config.h4
-rw-r--r--src/gallium/include/state_tracker/st_api.h25
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp33
-rw-r--r--src/gallium/state_trackers/dri/common/dri_context.c4
-rw-r--r--src/gallium/state_trackers/dri/common/dri_drawable.c1
-rw-r--r--src/gallium/state_trackers/dri/common/dri_drawable.h1
-rw-r--r--src/gallium/state_trackers/dri/drm/SConscript2
-rw-r--r--src/gallium/state_trackers/dri/drm/dri2.c23
-rw-r--r--src/gallium/state_trackers/dri/sw/drisw.c5
-rw-r--r--src/gallium/state_trackers/egl/Makefile3
-rw-r--r--src/gallium/state_trackers/egl/SConscript5
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c60
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.h8
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_api.c141
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_image.c73
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_loader.h1
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_st.c2
-rw-r--r--src/gallium/state_trackers/egl/common/native.h50
-rw-r--r--src/gallium/state_trackers/egl/common/native_buffer.h31
-rw-r--r--src/gallium/state_trackers/egl/common/native_helper.c117
-rw-r--r--src/gallium/state_trackers/egl/common/native_helper.h14
-rw-r--r--src/gallium/state_trackers/egl/drm/modeset.c36
-rw-r--r--src/gallium/state_trackers/egl/drm/native_drm.c124
-rw-r--r--src/gallium/state_trackers/egl/drm/native_drm.h6
-rw-r--r--src/gallium/state_trackers/egl/fbdev/native_fbdev.c384
-rw-r--r--src/gallium/state_trackers/egl/gdi/native_gdi.c58
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_drm.c34
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_shm.c12
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_wayland.c38
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_wayland.h7
-rw-r--r--src/gallium/state_trackers/egl/x11/native_dri2.c45
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.c20
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.h6
-rw-r--r--src/gallium/state_trackers/egl/x11/native_ximage.c109
-rw-r--r--src/gallium/state_trackers/gbm/Makefile46
-rw-r--r--src/gallium/state_trackers/gbm/gbm_drm.c226
-rw-r--r--src/gallium/state_trackers/gbm/gbm_gallium_drmint.h74
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_api.c15
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_st.c2
-rw-r--r--src/gallium/state_trackers/vega/vg_context.h5
-rw-r--r--src/gallium/state_trackers/vega/vg_manager.c48
-rw-r--r--src/gallium/state_trackers/wgl/stw_context.c6
-rw-r--r--src/gallium/state_trackers/wgl/stw_ext_pbuffer.c2
-rw-r--r--src/gallium/state_trackers/wgl/stw_st.c2
-rw-r--r--src/gallium/state_trackers/xorg/SConscript5
-rw-r--r--src/gallium/state_trackers/xorg/xorg_composite.c6
-rw-r--r--src/gallium/state_trackers/xorg/xorg_crtc.c1
-rw-r--r--src/gallium/targets/Makefile.xorg2
-rw-r--r--src/gallium/targets/SConscript.dri2
-rw-r--r--src/gallium/targets/dri-i915/SConscript4
-rw-r--r--src/gallium/targets/dri-i965/SConscript4
-rw-r--r--src/gallium/targets/dri-swrast/SConscript2
-rw-r--r--src/gallium/targets/egl-static/Makefile201
-rw-r--r--src/gallium/targets/egl-static/SConscript16
-rw-r--r--src/gallium/targets/egl-static/egl.c111
-rw-r--r--src/gallium/targets/egl-static/egl_st.c127
-rw-r--r--src/gallium/targets/egl-static/egl_st.h3
-rw-r--r--src/gallium/targets/egl-static/st_GL.c (renamed from src/gallium/targets/egl/egl.h)22
-rw-r--r--src/gallium/targets/egl/Makefile242
-rw-r--r--src/gallium/targets/egl/egl.c495
-rw-r--r--src/gallium/targets/egl/st_GL.c8
-rw-r--r--src/gallium/targets/egl/st_OpenVG.c8
-rw-r--r--src/gallium/targets/gbm/Makefile169
-rw-r--r--src/gallium/targets/gbm/gbm.c61
-rw-r--r--src/gallium/targets/gbm/pipe_i915.c (renamed from src/gallium/targets/egl/pipe_i915.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_i965.c (renamed from src/gallium/targets/egl/pipe_i965.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_loader.c192
-rw-r--r--src/gallium/targets/gbm/pipe_loader.h48
-rw-r--r--src/gallium/targets/gbm/pipe_nouveau.c (renamed from src/gallium/targets/egl/pipe_nouveau.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_r300.c (renamed from src/gallium/targets/egl/pipe_r300.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_r600.c (renamed from src/gallium/targets/egl/pipe_r600.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_swrast.c (renamed from src/gallium/targets/egl/pipe_swrast.c)0
-rw-r--r--src/gallium/targets/gbm/pipe_vmwgfx.c (renamed from src/gallium/targets/egl/pipe_vmwgfx.c)0
-rw-r--r--src/gallium/targets/libgl-xlib/SConscript2
-rw-r--r--src/gallium/targets/xorg-nouveau/Makefile5
-rw-r--r--src/gallium/targets/xorg-nouveau/nouveau_xorg.c75
-rw-r--r--src/gallium/targets/xorg-vmwgfx/SConscript4
-rw-r--r--src/gallium/tests/trivial/Makefile11
-rw-r--r--src/gallium/tests/trivial/quad-tex.c4
-rw-r--r--src/gallium/tests/trivial/tri.c4
-rw-r--r--src/gallium/winsys/i915/drm/SConscript2
-rw-r--r--src/gallium/winsys/i965/drm/SConscript2
-rw-r--r--src/gallium/winsys/r600/drm/SConscript6
-rw-r--r--src/gallium/winsys/r600/drm/r600_drm.c15
-rw-r--r--src/gallium/winsys/r600/drm/r600_hw_context.c4
-rw-r--r--src/gallium/winsys/radeon/drm/SConscript6
-rw-r--r--src/gallium/winsys/svga/drm/SConscript2
-rw-r--r--src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c71
-rw-r--r--src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h9
-rw-r--r--src/gallium/winsys/sw/wayland/wayland_sw_winsys.h1
171 files changed, 3885 insertions, 2224 deletions
diff --git a/src/gallium/SConscript b/src/gallium/SConscript
index 428bc31f86b..3072ee936f2 100644
--- a/src/gallium/SConscript
+++ b/src/gallium/SConscript
@@ -53,7 +53,7 @@ if env['drm']:
# Needed by some state trackers
SConscript('winsys/sw/null/SConscript')
-if env['platform'] != 'embedded':
+if not env['embedded']:
SConscript('state_trackers/vega/SConscript')
SConscript('state_trackers/egl/SConscript')
@@ -66,8 +66,8 @@ if env['platform'] != 'embedded':
if env['dri'] and env['xorg']:
SConscript('state_trackers/xorg/SConscript')
-if env['platform'] == 'windows':
- SConscript('state_trackers/wgl/SConscript')
+ if env['platform'] == 'windows':
+ SConscript('state_trackers/wgl/SConscript')
#
# Winsys
@@ -83,55 +83,55 @@ SConscript([
'targets/graw-null/SConscript',
])
-if env['platform'] != 'embedded':
+if not env['embedded']:
SConscript([
'targets/egl-static/SConscript'
])
-if env['x11']:
- SConscript([
- 'targets/graw-xlib/SConscript',
- 'targets/libgl-xlib/SConscript',
- ])
+ if env['x11']:
+ SConscript([
+ 'targets/graw-xlib/SConscript',
+ 'targets/libgl-xlib/SConscript',
+ ])
-if env['platform'] == 'windows':
- SConscript([
- 'targets/graw-gdi/SConscript',
- 'targets/libgl-gdi/SConscript',
- ])
+ if env['platform'] == 'windows':
+ SConscript([
+ 'targets/graw-gdi/SConscript',
+ 'targets/libgl-gdi/SConscript',
+ ])
-if env['dri']:
- SConscript([
- 'targets/SConscript.dri',
- 'targets/dri-swrast/SConscript',
- 'targets/dri-vmwgfx/SConscript',
- #'targets/dri-nouveau/SConscript',
- ])
- if env['drm_intel']:
+ if env['dri']:
SConscript([
- 'targets/dri-i915/SConscript',
- 'targets/dri-i965/SConscript',
+ 'targets/SConscript.dri',
+ 'targets/dri-swrast/SConscript',
+ 'targets/dri-vmwgfx/SConscript',
+ #'targets/dri-nouveau/SConscript',
])
- if env['drm_radeon']:
+ if env['drm_intel']:
+ SConscript([
+ 'targets/dri-i915/SConscript',
+ 'targets/dri-i965/SConscript',
+ ])
+ if env['drm_radeon']:
+ SConscript([
+ 'targets/dri-r300/SConscript',
+ 'targets/dri-r600/SConscript',
+ ])
+
+ if env['xorg'] and env['drm']:
SConscript([
- 'targets/dri-r300/SConscript',
- 'targets/dri-r600/SConscript',
+ #'targets/xorg-i915/SConscript',
+ #'targets/xorg-i965/SConscript',
+ #'targets/xorg-nouveau/SConscript',
+ #'targets/xorg-radeon/SConscript',
+ 'targets/xorg-vmwgfx/SConscript',
])
-if env['xorg'] and env['drm']:
- SConscript([
- #'targets/xorg-i915/SConscript',
- #'targets/xorg-i965/SConscript',
- #'targets/xorg-nouveau/SConscript',
- #'targets/xorg-radeon/SConscript',
- 'targets/xorg-vmwgfx/SConscript',
- ])
-
#
# Unit tests & tools
#
-if env['platform'] != 'embedded':
+if not env['embedded']:
SConscript('tests/unit/SConscript')
SConscript('tests/graw/SConscript')
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 56c26f57cce..f33c9078c9c 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -1163,6 +1163,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
struct lp_build_loop_state lp_loop;
const int max_vertices = 4;
LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
+ LLVMValueRef fetch_max;
void *code;
struct lp_build_sampler_soa *sampler = 0;
LLVMValueRef ret, ret_ptr;
@@ -1234,6 +1235,10 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
draw_llvm_variant_key_samplers(&variant->key),
context_ptr);
+ fetch_max = LLVMBuildSub(builder, count,
+ lp_build_const_int32(gallivm, 1),
+ "fetch_max");
+
#if DEBUG_STORE
lp_build_printf(builder, "start = %d, end = %d, step = %d\n",
start, end, step);
@@ -1257,6 +1262,12 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
builder,
lp_loop.counter,
lp_build_const_int32(gallivm, i), "");
+
+ /* make sure we're not out of bounds which can happen
+ * if fetch_count % 4 != 0, because on the last iteration
+ * a few of the 4 vertex fetches will be out of bounds */
+ true_index = lp_build_min(&bld, true_index, fetch_max);
+
for (j = 0; j < draw->pt.nr_vertex_elements; ++j) {
struct pipe_vertex_element *velem = &draw->pt.vertex_element[j];
LLVMValueRef vb_index = lp_build_const_int32(gallivm, velem->vertex_buffer_index);
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
index 32af29ae144..458f85def2c 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
@@ -784,6 +784,14 @@ aaline_destroy(struct draw_stage *stage)
draw_free_temp_verts( stage );
+ /* restore the old entry points */
+ pipe->create_fs_state = aaline->driver_create_fs_state;
+ pipe->bind_fs_state = aaline->driver_bind_fs_state;
+ pipe->delete_fs_state = aaline->driver_delete_fs_state;
+
+ pipe->bind_fragment_sampler_states = aaline->driver_bind_sampler_states;
+ pipe->set_fragment_sampler_views = aaline->driver_set_sampler_views;
+
FREE( stage );
}
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
index 60f6380c503..9265c379de8 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c
@@ -768,7 +768,16 @@ aapoint_reset_stipple_counter(struct draw_stage *stage)
static void
aapoint_destroy(struct draw_stage *stage)
{
+ struct aapoint_stage* aapoint = aapoint_stage(stage);
+ struct pipe_context *pipe = stage->draw->pipe;
+
draw_free_temp_verts( stage );
+
+ /* restore the old entry points */
+ pipe->create_fs_state = aapoint->driver_create_fs_state;
+ pipe->bind_fs_state = aapoint->driver_bind_fs_state;
+ pipe->delete_fs_state = aapoint->driver_delete_fs_state;
+
FREE( stage );
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
index 0b724a34948..01e660ef7d9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
@@ -207,7 +207,11 @@ lp_disassemble(const void* func)
}
raw_debug_ostream Out;
+#if HAVE_LLVM >= 0x0300
+ TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "");
+#else
TargetMachine *TM = T->createTargetMachine(Triple, "");
+#endif
#if HAVE_LLVM >= 0x0300
unsigned int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
@@ -287,7 +291,11 @@ lp_disassemble(const void* func)
pc += Size;
+#if HAVE_LLVM >= 0x0300
+ const MCInstrDesc &TID = TII->get(Inst.getOpcode());
+#else
const TargetInstrDesc &TID = TII->get(Inst.getOpcode());
+#endif
/*
* Keep track of forward jumps to a nearby address.
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index d2d7eccd92f..85fabc574b2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -83,8 +83,12 @@ lp_set_target_options(void)
* to only assume a 4 bytes alignment for backwards compatibility.
*/
#if defined(PIPE_ARCH_X86)
+#if HAVE_LLVM >= 0x0300
+ llvm::StackAlignmentOverride = 4;
+#else
llvm::StackAlignment = 4;
#endif
+#endif
#if defined(DEBUG) || defined(PROFILE)
llvm::NoFramePointerElim = true;
diff --git a/src/gallium/auxiliary/indices/u_unfilled_gen.py b/src/gallium/auxiliary/indices/u_unfilled_gen.py
index 36896ce605d..085c47a114a 100644
--- a/src/gallium/auxiliary/indices/u_unfilled_gen.py
+++ b/src/gallium/auxiliary/indices/u_unfilled_gen.py
@@ -167,8 +167,8 @@ def trifan(intype, outtype):
def polygon(intype, outtype):
preamble(intype, outtype, prim='polygon')
- print ' for (j = i = 0; j < nr; j+=6, i++) { '
- do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
+ print ' for (j = i = 0; j < nr; j+=2, i++) { '
+ line( intype, outtype, 'out+j', 'i', '(i+1)%(nr/2)' )
print ' }'
postamble()
diff --git a/src/gallium/auxiliary/indices/u_unfilled_indices.c b/src/gallium/auxiliary/indices/u_unfilled_indices.c
index 26c5d4d4c72..c353717d656 100644
--- a/src/gallium/auxiliary/indices/u_unfilled_indices.c
+++ b/src/gallium/auxiliary/indices/u_unfilled_indices.c
@@ -71,6 +71,11 @@ static void generate_linear_uint( unsigned nr,
}
+/**
+ * Given a primitive type and number of vertices, return the number of vertices
+ * needed to draw the primitive with fill mode = PIPE_POLYGON_MODE_LINE using
+ * separate lines (PIPE_PRIM_LINES).
+ */
static unsigned nr_lines( unsigned prim,
unsigned nr )
{
@@ -86,7 +91,7 @@ static unsigned nr_lines( unsigned prim,
case PIPE_PRIM_QUAD_STRIP:
return (nr - 2) / 2 * 8;
case PIPE_PRIM_POLYGON:
- return (nr - 2) * 6;
+ return 2 * nr; /* a line (two verts) for each polygon edge */
default:
assert(0);
return 0;
diff --git a/src/gallium/auxiliary/os/os_memory.h b/src/gallium/auxiliary/os/os_memory.h
index 556662d35e1..91a84a24bc8 100644
--- a/src/gallium/auxiliary/os/os_memory.h
+++ b/src/gallium/auxiliary/os/os_memory.h
@@ -39,7 +39,7 @@
#include "pipe/p_compiler.h"
-#if defined(PIPE_OS_EMBEDDED)
+#if defined(PIPE_SUBSYSTEM_EMBEDDED)
#ifdef __cplusplus
extern "C" {
diff --git a/src/gallium/auxiliary/os/os_misc.h b/src/gallium/auxiliary/os/os_misc.h
index d59f9819fec..48522dac4d7 100644
--- a/src/gallium/auxiliary/os/os_misc.h
+++ b/src/gallium/auxiliary/os/os_misc.h
@@ -58,8 +58,6 @@ extern "C" {
# 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
@@ -70,8 +68,6 @@ void os_break(void);
*/
#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
diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 6b4281ad661..8f1245bff55 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -40,7 +40,7 @@
#include "util/u_debug.h" /* for assert */
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
#include <pthread.h> /* POSIX threads headers */
#include <stdio.h> /* for perror() */
@@ -314,7 +314,7 @@ typedef int64_t pipe_condvar;
* pipe_barrier
*/
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU)
typedef pthread_barrier_t pipe_barrier;
@@ -442,7 +442,7 @@ pipe_semaphore_wait(pipe_semaphore *sema)
*/
typedef struct {
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
pthread_key_t key;
#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
DWORD key;
@@ -457,7 +457,7 @@ typedef struct {
static INLINE void
pipe_tsd_init(pipe_tsd *tsd)
{
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) {
perror("pthread_key_create(): failed to allocate key for thread specific data");
exit(-1);
@@ -474,7 +474,7 @@ pipe_tsd_get(pipe_tsd *tsd)
if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) {
pipe_tsd_init(tsd);
}
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
return pthread_getspecific(tsd->key);
#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
assert(0);
@@ -491,7 +491,7 @@ pipe_tsd_set(pipe_tsd *tsd, void *value)
if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) {
pipe_tsd_init(tsd);
}
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
if (pthread_setspecific(tsd->key, value) != 0) {
perror("pthread_set_specific() failed");
exit(-1);
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
index 325f316784c..73d86296d91 100644
--- a/src/gallium/auxiliary/os/os_time.c
+++ b/src/gallium/auxiliary/os/os_time.c
@@ -35,8 +35,6 @@
#include "pipe/p_config.h"
-#if !defined(PIPE_OS_EMBEDDED)
-
#if defined(PIPE_OS_UNIX)
# include <sys/time.h> /* timeval */
#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
@@ -123,6 +121,3 @@ os_time_sleep(int64_t usecs)
}
#endif
-
-
-#endif /* !PIPE_OS_EMBEDDED */
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 36ce4b57713..004df439ff5 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -48,7 +48,7 @@
void _debug_vprintf(const char *format, va_list ap)
{
-#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_EMBEDDED)
+#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
/* We buffer until we find a newline. */
static char buf[4096] = {'\0'};
size_t len = strlen(buf);
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index 9562acb8210..e50db6d67fe 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -72,6 +72,22 @@ struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
return upload;
}
+void u_upload_unmap( struct u_upload_mgr *upload )
+{
+ if (upload->transfer) {
+ struct pipe_box *box = &upload->transfer->box;
+ if (upload->offset > box->x) {
+
+ pipe_buffer_flush_mapped_range(upload->pipe, upload->transfer,
+ box->x, upload->offset - box->x);
+ }
+ pipe_transfer_unmap(upload->pipe, upload->transfer);
+ pipe_transfer_destroy(upload->pipe, upload->transfer);
+ upload->transfer = NULL;
+ upload->map = NULL;
+ }
+}
+
/* Release old buffer.
*
* This must usually be called prior to firing the command stream
@@ -84,15 +100,7 @@ struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
void u_upload_flush( struct u_upload_mgr *upload )
{
/* Unmap and unreference the upload buffer. */
- if (upload->transfer) {
- if (upload->offset) {
- pipe_buffer_flush_mapped_range(upload->pipe, upload->transfer,
- 0, upload->offset);
- }
- pipe_transfer_unmap(upload->pipe, upload->transfer);
- pipe_transfer_destroy(upload->pipe, upload->transfer);
- upload->transfer = NULL;
- }
+ u_upload_unmap(upload);
pipe_resource_reference( &upload->buffer, NULL );
upload->size = 0;
}
@@ -172,6 +180,15 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
offset = MAX2(upload->offset, alloc_offset);
+ if (!upload->map) {
+ upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer,
+ offset, upload->size - offset,
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_FLUSH_EXPLICIT |
+ PIPE_TRANSFER_UNSYNCHRONIZED,
+ &upload->transfer);
+ }
+
assert(offset < upload->buffer->width0);
assert(offset + size <= upload->buffer->width0);
assert(size);
@@ -223,10 +240,11 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
struct pipe_transfer *transfer = NULL;
const char *map = NULL;
- map = (const char *)pipe_buffer_map(upload->pipe,
- inbuf,
- PIPE_TRANSFER_READ,
- &transfer);
+ map = (const char *)pipe_buffer_map_range(upload->pipe,
+ inbuf,
+ offset, size,
+ PIPE_TRANSFER_READ,
+ &transfer);
if (map == NULL) {
ret = PIPE_ERROR_OUT_OF_MEMORY;
@@ -239,7 +257,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
ret = u_upload_data( upload,
min_out_offset,
size,
- map + offset,
+ map,
out_offset,
outbuf, flushed );
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.h b/src/gallium/auxiliary/util/u_upload_mgr.h
index c9a2ffeb572..98915139801 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.h
+++ b/src/gallium/auxiliary/util/u_upload_mgr.h
@@ -56,15 +56,27 @@ struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
*/
void u_upload_destroy( struct u_upload_mgr *upload );
-/* Unmap and release old buffer.
+/* Unmap and release old upload buffer.
*
+ * This is like u_upload_unmap() except the upload buffer is released for
+ * recycling. This should be called on real hardware flushes on systems
+ * that don't support the PIPE_TRANSFER_UNSYNCHRONIZED flag, as otherwise
+ * the next u_upload_buffer will cause a sync on the buffer.
+ */
+
+void u_upload_flush( struct u_upload_mgr *upload );
+
+/**
+ * Unmap upload buffer
+ *
+ * \param upload Upload manager
+ *
* This must usually be called prior to firing the command stream
* which references the upload buffer, as many memory managers either
* don't like firing a mapped buffer or cause subsequent maps of a
- * fired buffer to wait. For now, it's easiest just to grab a new
- * buffer.
+ * fired buffer to wait.
*/
-void u_upload_flush( struct u_upload_mgr *upload );
+void u_upload_unmap( struct u_upload_mgr *upload );
/**
* Sub-allocate new memory from the upload buffer.
diff --git a/src/gallium/auxiliary/util/u_vbuf_mgr.c b/src/gallium/auxiliary/util/u_vbuf_mgr.c
index 04149525ea7..374fc336b83 100644
--- a/src/gallium/auxiliary/util/u_vbuf_mgr.c
+++ b/src/gallium/auxiliary/util/u_vbuf_mgr.c
@@ -152,9 +152,9 @@ void u_vbuf_mgr_destroy(struct u_vbuf_mgr *mgrb)
}
-static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
- int min_index, int max_index,
- boolean *upload_flushed)
+static enum u_vbuf_return_flags
+u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
+ int min_index, int max_index)
{
struct translate_key key;
struct translate_element *te;
@@ -166,6 +166,7 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
struct pipe_resource *out_buffer = NULL;
unsigned i, num_verts, out_offset;
struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS];
+ boolean upload_flushed = FALSE;
memset(&key, 0, sizeof(key));
memset(tr_elem_index, 0xff, sizeof(tr_elem_index));
@@ -248,7 +249,7 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
u_upload_alloc(mgr->b.uploader,
key.output_stride * min_index,
key.output_stride * num_verts,
- &out_offset, &out_buffer, upload_flushed,
+ &out_offset, &out_buffer, &upload_flushed,
(void**)&out_map);
out_offset -= key.output_stride * min_index;
@@ -308,6 +309,8 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
}
pipe_resource_reference(&out_buffer, NULL);
+
+ return upload_flushed ? U_VBUF_UPLOAD_FLUSHED : 0;
}
static void u_vbuf_translate_end(struct u_vbuf_mgr_priv *mgr)
@@ -510,14 +513,15 @@ void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgrb,
mgr->b.nr_real_vertex_buffers = count;
}
-static void u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
- int min_index, int max_index,
- unsigned instance_count,
- boolean *upload_flushed)
+static enum u_vbuf_return_flags
+u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
+ int min_index, int max_index,
+ unsigned instance_count)
{
unsigned i, nr = mgr->ve->count;
unsigned count = max_index + 1 - min_index;
boolean uploaded[PIPE_MAX_ATTRIBS] = {0};
+ enum u_vbuf_return_flags retval = 0;
for (i = 0; i < nr; i++) {
unsigned index = mgr->ve->ve[i].vertex_buffer_index;
@@ -537,6 +541,11 @@ static void u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
} else if (vb->stride) {
first = vb->stride * min_index;
size = vb->stride * count;
+
+ /* Unusual case when stride is smaller than the format size.
+ * XXX This won't work with interleaved arrays. */
+ if (mgr->ve->native_format_size[i] > vb->stride)
+ size += mgr->ve->native_format_size[i] - vb->stride;
} else {
first = 0;
size = mgr->ve->native_format_size[i];
@@ -551,11 +560,14 @@ static void u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
vb->buffer_offset -= first;
uploaded[index] = TRUE;
- *upload_flushed = *upload_flushed || flushed;
+ if (flushed)
+ retval |= U_VBUF_UPLOAD_FLUSHED;
} else {
assert(mgr->b.real_vertex_buffer[index]);
}
}
+
+ return retval;
}
static void u_vbuf_mgr_compute_max_index(struct u_vbuf_mgr_priv *mgr)
@@ -597,14 +609,13 @@ static void u_vbuf_mgr_compute_max_index(struct u_vbuf_mgr_priv *mgr)
}
}
-void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
- const struct pipe_draw_info *info,
- boolean *buffers_updated,
- boolean *uploader_flushed)
+enum u_vbuf_return_flags
+u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
+ const struct pipe_draw_info *info)
{
struct u_vbuf_mgr_priv *mgr = (struct u_vbuf_mgr_priv*)mgrb;
- boolean bufs_updated = FALSE, upload_flushed = FALSE;
int min_index, max_index;
+ enum u_vbuf_return_flags retval = 0;
u_vbuf_mgr_compute_max_index(mgr);
@@ -617,27 +628,20 @@ void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
/* Translate vertices with non-native layouts or formats. */
if (mgr->incompatible_vb_layout || mgr->ve->incompatible_layout) {
- u_vbuf_translate_begin(mgr, min_index, max_index, &upload_flushed);
+ retval |= u_vbuf_translate_begin(mgr, min_index, max_index);
if (mgr->fallback_ve) {
- bufs_updated = TRUE;
+ retval |= U_VBUF_BUFFERS_UPDATED;
}
}
/* Upload user buffers. */
if (mgr->any_user_vbs) {
- u_vbuf_upload_buffers(mgr, min_index, max_index, info->instance_count,
- &upload_flushed);
- bufs_updated = TRUE;
- }
-
- /* Set the return values. */
- if (buffers_updated) {
- *buffers_updated = bufs_updated;
- }
- if (uploader_flushed) {
- *uploader_flushed = upload_flushed;
+ retval |= u_vbuf_upload_buffers(mgr, min_index, max_index,
+ info->instance_count);
+ retval |= U_VBUF_BUFFERS_UPDATED;
}
+ return retval;
}
void u_vbuf_mgr_draw_end(struct u_vbuf_mgr *mgrb)
diff --git a/src/gallium/auxiliary/util/u_vbuf_mgr.h b/src/gallium/auxiliary/util/u_vbuf_mgr.h
index 9380dce4f72..4e6372435d8 100644
--- a/src/gallium/auxiliary/util/u_vbuf_mgr.h
+++ b/src/gallium/auxiliary/util/u_vbuf_mgr.h
@@ -78,6 +78,11 @@ enum u_fetch_alignment {
U_VERTEX_FETCH_DWORD_ALIGNED
};
+enum u_vbuf_return_flags {
+ U_VBUF_BUFFERS_UPDATED = 1,
+ U_VBUF_UPLOAD_FLUSHED = 2
+};
+
struct u_vbuf_mgr *
u_vbuf_mgr_create(struct pipe_context *pipe,
@@ -105,10 +110,9 @@ void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgr,
unsigned count,
const struct pipe_vertex_buffer *bufs);
-void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgr,
- const struct pipe_draw_info *info,
- boolean *buffers_updated,
- boolean *uploader_flushed);
+enum u_vbuf_return_flags
+u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgr,
+ const struct pipe_draw_info *info);
void u_vbuf_mgr_draw_end(struct u_vbuf_mgr *mgr);
diff --git a/src/gallium/drivers/i915/Makefile b/src/gallium/drivers/i915/Makefile
index b3f387f9335..778124728bb 100644
--- a/src/gallium/drivers/i915/Makefile
+++ b/src/gallium/drivers/i915/Makefile
@@ -21,6 +21,7 @@ C_SOURCES = \
i915_screen.c \
i915_prim_emit.c \
i915_prim_vbuf.c \
+ i915_query.c \
i915_resource.c \
i915_resource_texture.c \
i915_resource_buffer.c \
diff --git a/src/gallium/drivers/i915/SConscript b/src/gallium/drivers/i915/SConscript
index 8f5deed64a9..98370601b7f 100644
--- a/src/gallium/drivers/i915/SConscript
+++ b/src/gallium/drivers/i915/SConscript
@@ -16,6 +16,7 @@ i915 = env.ConvenienceLibrary(
'i915_fpc_translate.c',
'i915_prim_emit.c',
'i915_prim_vbuf.c',
+ 'i915_query.c',
'i915_screen.c',
'i915_state.c',
'i915_state_derived.c',
diff --git a/src/gallium/drivers/i915/TODO b/src/gallium/drivers/i915/TODO
index fba180064c3..c26db198d20 100644
--- a/src/gallium/drivers/i915/TODO
+++ b/src/gallium/drivers/i915/TODO
@@ -26,5 +26,20 @@ Random list of problems with i915g:
- src/xvmc/i915_structs.h in xf86-video-intel has a few more bits of various
commands defined. Scavenge them and see what's useful.
+- Do smarter remapping. Right now we send everything onto tex coords 0-7.
+ We could also use diffuse/specular and pack two sets of 2D coords in a single
+ 4D. Is it a big problem though? We're more limited by the # of texture
+ indirections and the # of instructions.
+
+- Leverage draw to enable more caps:
+ * PIPE_CAP_TGSI_INSTANCEID
+ * PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS
+
+- Finish front/back face. We need to add face support to lp_build_system_values_array and use it in draw_llvm.c.
+
+- Replace constants and immediates which are 0,1,-1 or a combination of those with a swizzle.
+
+- i915_delete_fs_state doesn't call draw_delete_fragment_shader. Why?
+
Other bugs can be found here:
https://bugs.freedesktop.org/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&component=Drivers/Gallium/i915g
diff --git a/src/gallium/drivers/i915/i915_clear.c b/src/gallium/drivers/i915/i915_clear.c
index 4a97746e981..fcb208d6dae 100644
--- a/src/gallium/drivers/i915/i915_clear.c
+++ b/src/gallium/drivers/i915/i915_clear.c
@@ -66,7 +66,7 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *rgba,
else
clear_color = (u_color.ui & 0xffff) | (u_color.ui << 16);
- util_pack_color(rgba, PIPE_FORMAT_B8G8R8A8_UNORM, &u_color);
+ util_pack_color(rgba, cbuf->format, &u_color);
clear_color8888 = u_color.ui;
} else
clear_color = clear_color8888 = 0;
diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c
index 7a98ef73c1f..28ff40a2328 100644
--- a/src/gallium/drivers/i915/i915_context.c
+++ b/src/gallium/drivers/i915/i915_context.c
@@ -29,6 +29,7 @@
#include "i915_state.h"
#include "i915_screen.h"
#include "i915_surface.h"
+#include "i915_query.h"
#include "i915_batch.h"
#include "i915_resource.h"
@@ -53,13 +54,11 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
struct i915_context *i915 = i915_context(pipe);
struct draw_context *draw = i915->draw;
void *mapped_indices = NULL;
- unsigned cbuf_dirty;
/*
* Ack vs contants here, helps ipers a lot.
*/
- cbuf_dirty = i915->dirty & I915_NEW_VS_CONSTANTS;
i915->dirty &= ~I915_NEW_VS_CONSTANTS;
if (i915->dirty)
@@ -72,15 +71,13 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
mapped_indices = i915_buffer(i915->index_buffer.buffer)->data;
draw_set_mapped_index_buffer(draw, mapped_indices);
- if (cbuf_dirty) {
- if (i915->constants[PIPE_SHADER_VERTEX])
- draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
- i915_buffer(i915->constants[PIPE_SHADER_VERTEX])->data,
- (i915->current.num_user_constants[PIPE_SHADER_VERTEX] *
- 4 * sizeof(float)));
- else
- draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, NULL, 0);
- }
+ if (i915->constants[PIPE_SHADER_VERTEX])
+ draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
+ i915_buffer(i915->constants[PIPE_SHADER_VERTEX])->data,
+ (i915->current.num_user_constants[PIPE_SHADER_VERTEX] *
+ 4 * sizeof(float)));
+ else
+ draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, NULL, 0);
/*
* Do the drawing
@@ -106,7 +103,7 @@ static void i915_destroy(struct pipe_context *pipe)
if (i915->blitter)
util_blitter_destroy(i915->blitter);
-
+
if(i915->batch)
i915->iws->batchbuffer_destroy(i915->batch);
@@ -150,6 +147,8 @@ i915_create_context(struct pipe_screen *screen, void *priv)
/* init this before draw */
util_slab_create(&i915->transfer_pool, sizeof(struct pipe_transfer),
16, UTIL_SLAB_SINGLETHREADED);
+ util_slab_create(&i915->texture_transfer_pool, sizeof(struct i915_transfer),
+ 16, UTIL_SLAB_SINGLETHREADED);
/* Batch stream debugging is a bit hacked up at the moment:
*/
@@ -170,9 +169,11 @@ i915_create_context(struct pipe_screen *screen, void *priv)
i915_init_state_functions(i915);
i915_init_flush_functions(i915);
i915_init_resource_functions(i915);
+ i915_init_query_functions(i915);
draw_install_aaline_stage(i915->draw, &i915->base);
draw_install_aapoint_stage(i915->draw, &i915->base);
+ draw_enable_point_sprites(i915->draw, TRUE);
/* augmented draw pipeline clobbers state functions */
i915_init_fixup_state_functions(i915);
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h
index 964948edc0e..c964208fedd 100644
--- a/src/gallium/drivers/i915/i915_context.h
+++ b/src/gallium/drivers/i915/i915_context.h
@@ -102,6 +102,8 @@ struct i915_fragment_shader
struct tgsi_shader_info info;
+ struct draw_fragment_shader *draw_data;
+
uint *program;
uint program_len;
@@ -260,6 +262,7 @@ struct i915_context {
int num_validation_buffers;
struct util_slab_mempool transfer_pool;
+ struct util_slab_mempool texture_transfer_pool;
/** blitter/hw-clear */
struct blitter_context* blitter;
diff --git a/src/gallium/drivers/i915/i915_fpc.h b/src/gallium/drivers/i915/i915_fpc.h
index 2f0f99d0468..509395cf1f5 100644
--- a/src/gallium/drivers/i915/i915_fpc.h
+++ b/src/gallium/drivers/i915/i915_fpc.h
@@ -37,6 +37,9 @@
#define I915_PROGRAM_SIZE 192
+/* Use those indices for pos/face routing, must be >= I915_TEX_UNITS */
+#define I915_SEMANTIC_POS 10
+#define I915_SEMANTIC_FACE 11
/**
@@ -67,13 +70,13 @@ struct i915_fp_compile {
uint temp_flag; /**< Tracks temporary regs which are in use */
uint utemp_flag; /**< Tracks TYPE_U temporary regs which are in use */
+ uint register_phases[16];
uint nr_tex_indirect;
uint nr_tex_insn;
uint nr_alu_insn;
uint nr_decl_insn;
boolean error; /**< Set if i915_program_error() is called */
- uint wpos_tex;
uint NumNativeInstructions;
uint NumNativeAluInstructions;
uint NumNativeTexInstructions;
diff --git a/src/gallium/drivers/i915/i915_fpc_emit.c b/src/gallium/drivers/i915/i915_fpc_emit.c
index 76c24d2b2fd..d28595e0fd3 100644
--- a/src/gallium/drivers/i915/i915_fpc_emit.c
+++ b/src/gallium/drivers/i915/i915_fpc_emit.c
@@ -67,7 +67,7 @@ i915_get_temp(struct i915_fp_compile *p)
{
int bit = ffs(~p->temp_flag);
if (!bit) {
- i915_program_error(p, "i915_get_temp: out of temporaries\n");
+ i915_program_error(p, "i915_get_temp: out of temporaries");
return 0;
}
@@ -92,7 +92,7 @@ i915_get_utemp(struct i915_fp_compile * p)
{
int bit = ffs(~p->utemp_flag);
if (!bit) {
- i915_program_error(p, "i915_get_utemp: out of temporaries\n");
+ i915_program_error(p, "i915_get_utemp: out of temporaries");
return 0;
}
@@ -128,9 +128,13 @@ i915_emit_decl(struct i915_fp_compile *p,
else
return reg;
- *(p->decl++) = (D0_DCL | D0_DEST(reg) | d0_flags);
- *(p->decl++) = D1_MBZ;
- *(p->decl++) = D2_MBZ;
+ if (p->decl< p->declarations + I915_PROGRAM_SIZE) {
+ *(p->decl++) = (D0_DCL | D0_DEST(reg) | d0_flags);
+ *(p->decl++) = D1_MBZ;
+ *(p->decl++) = D2_MBZ;
+ }
+ else
+ i915_program_error(p, "Out of declarations");
p->nr_decl_insn++;
return reg;
@@ -187,9 +191,16 @@ i915_emit_arith(struct i915_fp_compile * p,
p->utemp_flag = old_utemp_flag; /* restore */
}
- *(p->csr++) = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0));
- *(p->csr++) = (A1_SRC0(src0) | A1_SRC1(src1));
- *(p->csr++) = (A2_SRC1(src1) | A2_SRC2(src2));
+ if (p->csr< p->program + I915_PROGRAM_SIZE) {
+ *(p->csr++) = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0));
+ *(p->csr++) = (A1_SRC0(src0) | A1_SRC1(src1));
+ *(p->csr++) = (A2_SRC1(src1) | A2_SRC2(src2));
+ }
+ else
+ i915_program_error(p, "Out of instructions");
+
+ if (GET_UREG_TYPE(dest) == REG_TYPE_R)
+ p->register_phases[GET_UREG_NR(dest)] = p->nr_tex_indirect;
p->nr_alu_insn++;
return dest;
@@ -245,17 +256,31 @@ uint i915_emit_texld( struct i915_fp_compile *p,
assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST);
assert(dest == UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)));
- /* is the sampler coord a texcoord input reg? */
- if (GET_UREG_TYPE(coord) != REG_TYPE_T) {
- p->nr_tex_indirect++;
- }
+ /* Output register being oC or oD defines a phase boundary */
+ if (GET_UREG_TYPE(dest) == REG_TYPE_OC ||
+ GET_UREG_TYPE(dest) == REG_TYPE_OD)
+ p->nr_tex_indirect++;
- *(p->csr++) = (opcode |
- T0_DEST( dest ) |
- T0_SAMPLER( sampler ));
+ /* Reading from an r# register whose contents depend on output of the
+ * current phase defines a phase boundary.
+ */
+ if (GET_UREG_TYPE(coord) == REG_TYPE_R &&
+ p->register_phases[GET_UREG_NR(coord)] == p->nr_tex_indirect)
+ p->nr_tex_indirect++;
+
+ if (p->csr< p->program + I915_PROGRAM_SIZE) {
+ *(p->csr++) = (opcode |
+ T0_DEST( dest ) |
+ T0_SAMPLER( sampler ));
+
+ *(p->csr++) = T1_ADDRESS_REG( coord );
+ *(p->csr++) = T2_MBZ;
+ }
+ else
+ i915_program_error(p, "Out of instructions");
- *(p->csr++) = T1_ADDRESS_REG( coord );
- *(p->csr++) = T2_MBZ;
+ if (GET_UREG_TYPE(dest) == REG_TYPE_R)
+ p->register_phases[GET_UREG_NR(dest)] = p->nr_tex_indirect;
p->nr_tex_insn++;
}
@@ -293,7 +318,7 @@ i915_emit_const1f(struct i915_fp_compile * p, float c0)
}
}
- i915_program_error(p, "i915_emit_const1f: out of constants\n");
+ i915_program_error(p, "i915_emit_const1f: out of constants");
return 0;
}
@@ -313,6 +338,8 @@ i915_emit_const2f(struct i915_fp_compile * p, float c0, float c1)
if (c1 == 1.0)
return swizzle(i915_emit_const1f(p, c0), X, ONE, Z, W);
+ // XXX emit swizzle here for 0, 1, -1 and any combination thereof
+ // we can use swizzle + neg for that
for (reg = 0; reg < I915_MAX_CONSTANT; reg++) {
if (ifs->constant_flags[reg] == 0xf ||
ifs->constant_flags[reg] == I915_CONSTFLAG_USER)
@@ -329,12 +356,10 @@ i915_emit_const2f(struct i915_fp_compile * p, float c0, float c1)
}
}
- i915_program_error(p, "i915_emit_const2f: out of constants\n");
+ i915_program_error(p, "i915_emit_const2f: out of constants");
return 0;
}
-
-
uint
i915_emit_const4f(struct i915_fp_compile * p,
float c0, float c1, float c2, float c3)
@@ -342,6 +367,9 @@ i915_emit_const4f(struct i915_fp_compile * p,
struct i915_fragment_shader *ifs = p->shader;
unsigned reg;
+ // XXX emit swizzle here for 0, 1, -1 and any combination thereof
+ // we can use swizzle + neg for that
+ printf("const %f %f %f %f\n",c0,c1,c2,c3);
for (reg = 0; reg < I915_MAX_CONSTANT; reg++) {
if (ifs->constant_flags[reg] == 0xf &&
ifs->constants[reg][0] == c0 &&
@@ -363,7 +391,7 @@ i915_emit_const4f(struct i915_fp_compile * p,
}
}
- i915_program_error(p, "i915_emit_const4f: out of constants\n");
+ i915_program_error(p, "i915_emit_const4f: out of constants");
return 0;
}
diff --git a/src/gallium/drivers/i915/i915_fpc_translate.c b/src/gallium/drivers/i915/i915_fpc_translate.c
index 27f100843bf..0cbd4f2d748 100644
--- a/src/gallium/drivers/i915/i915_fpc_translate.c
+++ b/src/gallium/drivers/i915/i915_fpc_translate.c
@@ -41,6 +41,9 @@
#include "draw/draw_vertex.h"
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
/**
* Simple pass-through fragment shader to use when we don't have
@@ -72,19 +75,33 @@ static unsigned passthrough[] =
/* 1, -1/3!, 1/5!, -1/7! */
-static const float sin_constants[4] = { 1.0,
+static const float scs_sin_constants[4] = { 1.0,
-1.0f / (3 * 2 * 1),
1.0f / (5 * 4 * 3 * 2 * 1),
-1.0f / (7 * 6 * 5 * 4 * 3 * 2 * 1)
};
/* 1, -1/2!, 1/4!, -1/6! */
-static const float cos_constants[4] = { 1.0,
+static const float scs_cos_constants[4] = { 1.0,
-1.0f / (2 * 1),
1.0f / (4 * 3 * 2 * 1),
-1.0f / (6 * 5 * 4 * 3 * 2 * 1)
};
+/* 2*pi, -(2*pi)^3/3!, (2*pi)^5/5!, -(2*pi)^7/7! */
+static const float sin_constants[4] = { 2.0 * M_PI,
+ -8.0f * M_PI * M_PI * M_PI / (3 * 2 * 1),
+ 32.0f * M_PI * M_PI * M_PI * M_PI * M_PI / (5 * 4 * 3 * 2 * 1),
+ -128.0f * M_PI * M_PI * M_PI * M_PI * M_PI * M_PI * M_PI / (7 * 6 * 5 * 4 * 3 * 2 * 1)
+};
+
+/* 1, -(2*pi)^2/2!, (2*pi)^4/4!, -(2*pi)^6/6! */
+static const float cos_constants[4] = { 1.0,
+ -4.0f * M_PI * M_PI / (2 * 1),
+ 16.0f * M_PI * M_PI * M_PI * M_PI / (4 * 3 * 2 * 1),
+ -64.0f * M_PI * M_PI * M_PI * M_PI * M_PI * M_PI / (6 * 5 * 4 * 3 * 2 * 1)
+};
+
/**
@@ -185,12 +202,12 @@ src_vector(struct i915_fp_compile *p,
switch (sem_name) {
case TGSI_SEMANTIC_POSITION:
- debug_printf("SKIP SEM POS\n");
- /*
- assert(p->wpos_tex != -1);
- src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL);
- */
- break;
+ {
+ /* for fragcoord */
+ int real_tex_unit = get_mapping(fs, I915_SEMANTIC_POS);
+ src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, D0_CHANNEL_ALL);
+ break;
+ }
case TGSI_SEMANTIC_COLOR:
if (sem_ind == 0) {
src = i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL);
@@ -212,6 +229,13 @@ src_vector(struct i915_fp_compile *p,
src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, D0_CHANNEL_ALL);
break;
}
+ case TGSI_SEMANTIC_FACE:
+ {
+ /* for back/front faces */
+ int real_tex_unit = get_mapping(fs, I915_SEMANTIC_FACE);
+ src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, D0_CHANNEL_X);
+ break;
+ }
default:
i915_program_error(p, "Bad source->Index");
return 0;
@@ -237,7 +261,6 @@ src_vector(struct i915_fp_compile *p,
source->Register.SwizzleZ,
source->Register.SwizzleW);
-
/* There's both negate-all-components and per-component negation.
* Try to handle both here.
*/
@@ -252,6 +275,9 @@ src_vector(struct i915_fp_compile *p,
/* XXX enable these assertions, or fix things */
assert(!source->Register.Absolute);
#endif
+ if (source->Register.Absolute)
+ debug_printf("Unhandled absolute value\n");
+
return src;
}
@@ -419,11 +445,6 @@ emit_simple_arith_swap2(struct i915_fp_compile *p,
emit_simple_arith(p, &inst2, opcode, numArgs, fs);
}
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
/*
* Translate TGSI instruction to i915 instruction.
*
@@ -477,13 +498,6 @@ i915_translate_instruction(struct i915_fp_compile *p,
i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0);
- /* By choosing different taylor constants, could get rid of this mul:
- */
- i915_emit_arith(p,
- A0_MUL,
- tmp, A0_DEST_CHANNEL_X, 0,
- tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0);
-
/*
* t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
* t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, 1
@@ -516,6 +530,18 @@ i915_translate_instruction(struct i915_fp_compile *p,
i915_emit_const4fv(p, cos_constants), 0);
break;
+ case TGSI_OPCODE_DDX:
+ case TGSI_OPCODE_DDY:
+ /* XXX We just output 0 here */
+ debug_printf("Punting DDX/DDX\n");
+ src0 = get_result_vector(p, &inst->Dst[0]);
+ i915_emit_arith(p,
+ A0_MOV,
+ get_result_vector(p, &inst->Dst[0]),
+ get_result_flags(inst), 0,
+ swizzle(src0, ZERO, ZERO, ZERO, ZERO), 0, 0);
+ break;
+
case TGSI_OPCODE_DP2:
src0 = src_vector(p, &inst->Src[0], fs);
src1 = src_vector(p, &inst->Src[1], fs);
@@ -754,9 +780,9 @@ i915_translate_instruction(struct i915_fp_compile *p,
* t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
* t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
* t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x
- * scs.x = DP4 t1, sin_constants
+ * scs.x = DP4 t1, scs_sin_constants
* t1 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1
- * scs.y = DP4 t1, cos_constants
+ * scs.y = DP4 t1, scs_cos_constants
*/
i915_emit_arith(p,
A0_MUL,
@@ -791,7 +817,7 @@ i915_translate_instruction(struct i915_fp_compile *p,
get_result_vector(p, &inst->Dst[0]),
A0_DEST_CHANNEL_Y, 0,
swizzle(tmp1, W, Z, Y, X),
- i915_emit_const4fv(p, sin_constants), 0);
+ i915_emit_const4fv(p, scs_sin_constants), 0);
}
if (writemask & TGSI_WRITEMASK_X) {
@@ -806,7 +832,7 @@ i915_translate_instruction(struct i915_fp_compile *p,
get_result_vector(p, &inst->Dst[0]),
A0_DEST_CHANNEL_X, 0,
swizzle(tmp, ONE, Z, Y, X),
- i915_emit_const4fv(p, cos_constants), 0);
+ i915_emit_const4fv(p, scs_cos_constants), 0);
}
break;
@@ -853,13 +879,6 @@ i915_translate_instruction(struct i915_fp_compile *p,
i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0);
- /* By choosing different taylor constants, could get rid of this mul:
- */
- i915_emit_arith(p,
- A0_MUL,
- tmp, A0_DEST_CHANNEL_X, 0,
- tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0);
-
/*
* t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
* t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
@@ -907,7 +926,7 @@ i915_translate_instruction(struct i915_fp_compile *p,
break;
case TGSI_OPCODE_SNE:
- /* if we're neither < nor > then we're != */
+ /* if we're < or > then we're != */
src0 = src_vector(p, &inst->Src[0], fs);
src1 = src_vector(p, &inst->Src[1], fs);
tmp = i915_get_utemp(p);
@@ -1070,9 +1089,11 @@ i915_translate_instructions(struct i915_fp_compile *p,
for (i = parse.FullToken.FullDeclaration.Range.First;
i <= parse.FullToken.FullDeclaration.Range.Last;
i++) {
- assert(i < I915_MAX_TEMPORARY);
- /* XXX just use shader->info->file_mask[TGSI_FILE_TEMPORARY] */
- p->temp_flag |= (1 << i); /* mark temp as used */
+ if (i >= I915_MAX_TEMPORARY)
+ debug_printf("Too many temps (%d)\n",i);
+ else
+ /* XXX just use shader->info->file_mask[TGSI_FILE_TEMPORARY] */
+ p->temp_flag |= (1 << i); /* mark temp as used */
}
}
break;
@@ -1144,6 +1165,8 @@ i915_init_compile(struct i915_context *i915,
ifs->num_constants = 0;
memset(ifs->constant_flags, 0, sizeof(ifs->constant_flags));
+ memset(&p->register_phases, 0, sizeof(p->register_phases));
+
for (i = 0; i < I915_TEX_UNITS; i++)
ifs->generic_mapping[i] = -1;
@@ -1161,8 +1184,6 @@ i915_init_compile(struct i915_context *i915,
p->temp_flag = ~0x0 << I915_MAX_TEMPORARY;
p->utemp_flag = ~0x7;
- p->wpos_tex = -1;
-
/* initialize the first program word */
*(p->decl++) = _3DSTATE_PIXEL_SHADER_PROGRAM;
@@ -1181,7 +1202,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p)
unsigned long decl_size = (unsigned long) (p->decl - p->declarations);
if (p->nr_tex_indirect > I915_MAX_TEX_INDIRECT)
- i915_program_error(p, "Exceeded max nr indirect texture lookups");
+ debug_printf("Exceeded max nr indirect texture lookups\n");
if (p->nr_tex_insn > I915_MAX_TEX_INSN)
i915_program_error(p, "Exceeded max TEX instructions");
@@ -1234,40 +1255,6 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p)
}
-/**
- * Find an unused texture coordinate slot to use for fragment WPOS.
- * Update p->fp->wpos_tex with the result (-1 if no used texcoord slot is found).
- */
-static void
-i915_find_wpos_space(struct i915_fp_compile *p)
-{
-#if 0
- const uint inputs
- = p->shader->inputs_read | (1 << TGSI_ATTRIB_POS); /*XXX hack*/
- uint i;
-
- p->wpos_tex = -1;
-
- if (inputs & (1 << TGSI_ATTRIB_POS)) {
- for (i = 0; i < I915_TEX_UNITS; i++) {
- if ((inputs & (1 << (TGSI_ATTRIB_TEX0 + i))) == 0) {
- p->wpos_tex = i;
- return;
- }
- }
-
- i915_program_error(p, "No free texcoord for wpos value");
- }
-#else
- if (p->shader->info.input_semantic_name[0] == TGSI_SEMANTIC_POSITION) {
- /* frag shader using the fragment position input */
-#if 0
- assert(0);
-#endif
- }
-#endif
-}
-
@@ -1314,7 +1301,6 @@ i915_translate_fragment_program( struct i915_context *i915,
}
p = i915_init_compile(i915, fs);
- i915_find_wpos_space(p);
i915_translate_instructions(p, tokens, fs);
i915_fixup_depth_write(p);
diff --git a/src/gallium/drivers/i915/i915_query.c b/src/gallium/drivers/i915/i915_query.c
new file mode 100644
index 00000000000..c886df74bad
--- /dev/null
+++ b/src/gallium/drivers/i915/i915_query.c
@@ -0,0 +1,86 @@
+/**************************************************************************
+ *
+ * Copyright 2011 The Chromium OS authors.
+ * 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 GOOGLE 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.
+ *
+ **************************************************************************/
+
+/* Fake occlusion queries which return 0, it's better than crashing */
+
+#include "pipe/p_compiler.h"
+
+#include "util/u_memory.h"
+
+#include "i915_context.h"
+#include "i915_query.h"
+
+struct i915_query
+{
+ unsigned query;
+};
+
+static struct pipe_query *i915_create_query(struct pipe_context *ctx,
+ unsigned query_type)
+{
+ struct i915_query *query = CALLOC_STRUCT( i915_query );
+
+ return (struct pipe_query *)query;
+}
+
+static void i915_destroy_query(struct pipe_context *ctx,
+ struct pipe_query *query)
+{
+ FREE(query);
+}
+
+static void i915_begin_query(struct pipe_context *ctx,
+ struct pipe_query *query)
+{
+}
+
+static void i915_end_query(struct pipe_context *ctx, struct pipe_query *query)
+{
+}
+
+static boolean i915_get_query_result(struct pipe_context *ctx,
+ struct pipe_query *query,
+ boolean wait,
+ void *vresult)
+{
+ uint64_t *result = (uint64_t*)vresult;
+
+ /* 2* viewport Max */
+ *result = 512*1024*1024;
+ return TRUE;
+}
+
+void
+i915_init_query_functions(struct i915_context *i915)
+{
+ i915->base.create_query = i915_create_query;
+ i915->base.destroy_query = i915_destroy_query;
+ i915->base.begin_query = i915_begin_query;
+ i915->base.end_query = i915_end_query;
+ i915->base.get_query_result = i915_get_query_result;
+}
+
diff --git a/src/gallium/drivers/i915/i915_query.h b/src/gallium/drivers/i915/i915_query.h
new file mode 100644
index 00000000000..2c689ea6b1c
--- /dev/null
+++ b/src/gallium/drivers/i915/i915_query.h
@@ -0,0 +1,36 @@
+/**************************************************************************
+ *
+ * Copyright 2011 The Chromium OS authors.
+ * 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 GOOGLE 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 I915_QUERY_H
+#define I915_QUERY_H
+
+struct i915_context;
+struct pipe_context;
+
+void i915_init_query_functions( struct i915_context *i915 );
+
+#endif /* I915_QUERY_H */
diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c
index 7f52ba11d61..b4719af1fb6 100644
--- a/src/gallium/drivers/i915/i915_resource.c
+++ b/src/gallium/drivers/i915/i915_resource.c
@@ -7,12 +7,12 @@
static struct pipe_resource *
i915_resource_create(struct pipe_screen *screen,
- const struct pipe_resource *template)
+ const struct pipe_resource *template)
{
if (template->target == PIPE_BUFFER)
return i915_buffer_create(screen, template);
else
- return i915_texture_create(screen, template);
+ return i915_texture_create(screen, template, FALSE);
}
diff --git a/src/gallium/drivers/i915/i915_resource.h b/src/gallium/drivers/i915/i915_resource.h
index c15ecdfc22a..14eed2c4a79 100644
--- a/src/gallium/drivers/i915/i915_resource.h
+++ b/src/gallium/drivers/i915/i915_resource.h
@@ -45,6 +45,15 @@ struct i915_buffer {
boolean free_on_destroy;
};
+
+/* Texture transfer. */
+struct i915_transfer {
+ /* Base class. */
+ struct pipe_transfer b;
+ struct pipe_resource *staging_texture;
+};
+
+
#define I915_MAX_TEXTURE_2D_LEVELS 12 /* max 2048x2048 */
#define I915_MAX_TEXTURE_3D_LEVELS 9 /* max 256x256x256 */
@@ -101,7 +110,8 @@ static INLINE struct i915_buffer *i915_buffer(struct pipe_resource *resource)
struct pipe_resource *
i915_texture_create(struct pipe_screen *screen,
- const struct pipe_resource *template);
+ const struct pipe_resource *template,
+ boolean force_untiled);
struct pipe_resource *
i915_texture_from_handle(struct pipe_screen * screen,
diff --git a/src/gallium/drivers/i915/i915_resource_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c
index b74b19d0fe4..0b6424f8d16 100644
--- a/src/gallium/drivers/i915/i915_resource_texture.c
+++ b/src/gallium/drivers/i915/i915_resource_texture.c
@@ -37,6 +37,7 @@
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_rect.h"
#include "i915_context.h"
#include "i915_resource.h"
@@ -710,7 +711,7 @@ i915_texture_destroy(struct pipe_screen *screen,
FREE(tex);
}
-static struct pipe_transfer *
+static struct pipe_transfer *
i915_texture_get_transfer(struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned level,
@@ -719,19 +720,45 @@ i915_texture_get_transfer(struct pipe_context *pipe,
{
struct i915_context *i915 = i915_context(pipe);
struct i915_texture *tex = i915_texture(resource);
- struct pipe_transfer *transfer = util_slab_alloc(&i915->transfer_pool);
+ struct i915_transfer *transfer = util_slab_alloc(&i915->texture_transfer_pool);
+ boolean use_staging_texture = FALSE;
if (transfer == NULL)
return NULL;
- transfer->resource = resource;
- transfer->level = level;
- transfer->usage = usage;
- transfer->box = *box;
- transfer->stride = tex->stride;
- /* FIXME: layer_stride */
+ transfer->b.resource = resource;
+ transfer->b.level = level;
+ transfer->b.usage = usage;
+ transfer->b.box = *box;
+ transfer->b.stride = tex->stride;
+ transfer->staging_texture = NULL;
+ /* XXX: handle depth textures everyhwere*/
+ transfer->b.layer_stride = 0;
+ transfer->b.data = NULL;
+
+ /* if we use staging transfers, only support textures we can render to,
+ * because we need that for u_blitter */
+ if (i915->blitter &&
+ i915_is_format_supported(NULL, /* screen */
+ transfer->b.resource->format,
+ 0, /* target */
+ 1, /* sample count */
+ PIPE_BIND_RENDER_TARGET) &&
+ (usage & PIPE_TRANSFER_WRITE) &&
+ !(usage & (PIPE_TRANSFER_READ | PIPE_TRANSFER_DONTBLOCK | PIPE_TRANSFER_UNSYNCHRONIZED)))
+ use_staging_texture = TRUE;
+
+ use_staging_texture = FALSE;
+
+ if (use_staging_texture) {
+ /*
+ * Allocate the untiled staging texture.
+ * If the alloc fails, transfer->staging_texture is NULL and we fallback to a map()
+ */
+ transfer->staging_texture = i915_texture_create(pipe->screen, resource, TRUE);
+ }
- return transfer;
+ return (struct pipe_transfer*)transfer;
}
static void
@@ -739,17 +766,33 @@ i915_transfer_destroy(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
struct i915_context *i915 = i915_context(pipe);
- util_slab_free(&i915->transfer_pool, transfer);
+ struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
+
+ if ((itransfer->staging_texture) &&
+ (transfer->usage & PIPE_TRANSFER_WRITE)) {
+ struct pipe_box sbox;
+
+ u_box_origin_2d(itransfer->b.box.width, itransfer->b.box.height, &sbox);
+ pipe->resource_copy_region(pipe, itransfer->b.resource, itransfer->b.level,
+ itransfer->b.box.x, itransfer->b.box.y, itransfer->b.box.z,
+ itransfer->staging_texture,
+ 0, &sbox);
+ pipe->flush(pipe, NULL);
+ pipe_resource_reference(&itransfer->staging_texture, NULL);
+ }
+
+ util_slab_free(&i915->texture_transfer_pool, itransfer);
}
static void *
i915_texture_transfer_map(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- struct pipe_resource *resource = transfer->resource;
- struct i915_texture *tex = i915_texture(resource);
+ struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
+ struct pipe_resource *resource = itransfer->b.resource;
+ struct i915_texture *tex = NULL;
struct i915_winsys *iws = i915_screen(pipe->screen)->iws;
- struct pipe_box *box = &transfer->box;
+ struct pipe_box *box = &itransfer->b.box;
enum pipe_format format = resource->format;
unsigned offset;
char *map;
@@ -757,18 +800,25 @@ i915_texture_transfer_map(struct pipe_context *pipe,
if (resource->target != PIPE_TEXTURE_3D &&
resource->target != PIPE_TEXTURE_CUBE)
assert(box->z == 0);
- offset = i915_texture_offset(tex, transfer->level, box->z);
- /* TODO this is a sledgehammer */
- pipe->flush(pipe, NULL);
+ if (itransfer->staging_texture) {
+ tex = i915_texture(itransfer->staging_texture);
+ } else {
+ /* TODO this is a sledgehammer */
+ tex = i915_texture(resource);
+ pipe->flush(pipe, NULL);
+ }
+
+ offset = i915_texture_offset(tex, itransfer->b.level, box->z);
map = iws->buffer_map(iws, tex->buffer,
- (transfer->usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE);
- if (map == NULL)
+ (itransfer->b.usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE);
+ if (map == NULL) {
return NULL;
+ }
return map + offset +
- box->y / util_format_get_blockheight(format) * transfer->stride +
+ box->y / util_format_get_blockheight(format) * itransfer->b.stride +
box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
@@ -776,14 +826,106 @@ static void
i915_texture_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- struct i915_texture *tex = i915_texture(transfer->resource);
+ struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
+ struct i915_texture *tex = i915_texture(itransfer->b.resource);
struct i915_winsys *iws = i915_screen(tex->b.b.screen)->iws;
+
+ if (itransfer->staging_texture)
+ tex = i915_texture(itransfer->staging_texture);
+
iws->buffer_unmap(iws, tex->buffer);
}
+static void i915_transfer_inline_write( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride)
+{
+ struct pipe_transfer *transfer = NULL;
+ struct i915_transfer *itransfer = NULL;
+ const uint8_t *src_data = data;
+ unsigned i;
+
+ transfer = pipe->get_transfer(pipe,
+ resource,
+ level,
+ usage,
+ box );
+ if (transfer == NULL)
+ goto out;
+
+ itransfer = (struct i915_transfer*)transfer;
+
+ if (itransfer->staging_texture) {
+ struct i915_texture *tex = i915_texture(itransfer->staging_texture);
+ enum pipe_format format = tex->b.b.format;
+ struct i915_winsys *iws = i915_screen(tex->b.b.screen)->iws;
+ size_t offset;
+ size_t size;
+
+ offset = i915_texture_offset(tex, transfer->level, transfer->box.z);
+
+ for (i = 0; i < box->depth; i++) {
+ if (!tex->b.b.last_level &&
+ tex->b.b.width0 == transfer->box.width) {
+ unsigned nby = util_format_get_nblocksy(format, transfer->box.y);
+ assert(!offset);
+ assert(!transfer->box.x);
+ assert(tex->stride == transfer->stride);
+
+ offset += tex->stride * nby;
+ size = util_format_get_2d_size(format, transfer->stride,
+ transfer->box.height);
+ iws->buffer_write(iws, tex->buffer, offset, size, transfer->data);
+
+ } else {
+ unsigned nby = util_format_get_nblocksy(format, transfer->box.y);
+ int i;
+ offset += util_format_get_stride(format, transfer->box.x);
+ size = transfer->stride;
+
+ for (i = 0; i < nby; i++) {
+ iws->buffer_write(iws, tex->buffer, offset, size, transfer->data);
+ offset += tex->stride;
+ }
+ }
+ offset += layer_stride;
+ }
+ } else {
+ uint8_t *map = pipe_transfer_map(pipe, &itransfer->b);
+ if (map == NULL)
+ goto nomap;
+
+ for (i = 0; i < box->depth; i++) {
+ util_copy_rect(map,
+ resource->format,
+ itransfer->b.stride, /* bytes */
+ 0, 0,
+ box->width,
+ box->height,
+ src_data,
+ stride, /* bytes */
+ 0, 0);
+ map += itransfer->b.layer_stride;
+ src_data += layer_stride;
+ }
+nomap:
+ if (map)
+ pipe_transfer_unmap(pipe, &itransfer->b);
+ }
+
+out:
+ if (itransfer)
+ pipe_transfer_destroy(pipe, &itransfer->b);
+}
-struct u_resource_vtbl i915_texture_vtbl =
+
+struct u_resource_vtbl i915_texture_vtbl =
{
i915_texture_get_handle, /* get_handle */
i915_texture_destroy, /* resource_destroy */
@@ -792,7 +934,7 @@ struct u_resource_vtbl i915_texture_vtbl =
i915_texture_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
i915_texture_transfer_unmap, /* transfer_unmap */
- u_default_transfer_inline_write /* transfer_inline_write */
+ i915_transfer_inline_write /* transfer_inline_write */
};
@@ -800,7 +942,8 @@ struct u_resource_vtbl i915_texture_vtbl =
struct pipe_resource *
i915_texture_create(struct pipe_screen *screen,
- const struct pipe_resource *template)
+ const struct pipe_resource *template,
+ boolean force_untiled)
{
struct i915_screen *is = i915_screen(screen);
struct i915_winsys *iws = is->iws;
@@ -815,7 +958,10 @@ i915_texture_create(struct pipe_screen *screen,
pipe_reference_init(&tex->b.b.reference, 1);
tex->b.b.screen = screen;
- tex->tiling = i915_texture_tiling(is, tex);
+ if (force_untiled)
+ tex->tiling = I915_TILE_NONE;
+ else
+ tex->tiling = i915_texture_tiling(is, tex);
if (is->is_i945) {
if (!i945_texture_layout(tex))
@@ -836,7 +982,7 @@ i915_texture_create(struct pipe_screen *screen,
buf_usage = I915_NEW_TEXTURE;
tex->buffer = iws->buffer_create_tiled(iws, &tex->stride, tex->total_nblocksy,
- &tex->tiling, buf_usage);
+ &tex->tiling, buf_usage);
if (!tex->buffer)
goto fail;
diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
index c86baa58b28..e743f6031eb 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -109,17 +109,17 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
case PIPE_CAP_ANISOTROPIC_FILTER:
case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
case PIPE_CAP_NPOT_TEXTURES:
+ case PIPE_CAP_POINT_SPRITE:
case PIPE_CAP_PRIMITIVE_RESTART: /* draw module */
case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
case PIPE_CAP_TEXTURE_SHADOW_MAP:
case PIPE_CAP_TWO_SIDED_STENCIL:
+ case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
return 1;
/* Features that should be supported (boolean caps). */
/* XXX: Just test the code */
case PIPE_CAP_BLEND_EQUATION_SEPARATE:
- /* XXX: No code but hw supports it */
- case PIPE_CAP_POINT_SPRITE:
/* Also lie about these when asked to (needed for GLSL / GL 2.0) */
return is->debug.lie ? 1 : 0;
@@ -129,7 +129,6 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
case PIPE_CAP_INDEP_BLEND_ENABLE:
case PIPE_CAP_INDEP_BLEND_FUNC:
case PIPE_CAP_TGSI_INSTANCEID:
- case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
case PIPE_CAP_SHADER_STENCIL_EXPORT:
case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
case PIPE_CAP_TEXTURE_SWIZZLE:
@@ -254,7 +253,7 @@ i915_get_paramf(struct pipe_screen *screen, enum pipe_cap cap)
}
}
-static boolean
+boolean
i915_is_format_supported(struct pipe_screen *screen,
enum pipe_format format,
enum pipe_texture_target target,
@@ -264,7 +263,10 @@ i915_is_format_supported(struct pipe_screen *screen,
static const enum pipe_format tex_supported[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_B8G8R8X8_UNORM,
+ PIPE_FORMAT_R8G8B8A8_UNORM,
+ PIPE_FORMAT_R8G8B8X8_UNORM,
PIPE_FORMAT_B5G6R5_UNORM,
+ PIPE_FORMAT_B10G10R10A2_UNORM,
PIPE_FORMAT_L8_UNORM,
PIPE_FORMAT_A8_UNORM,
PIPE_FORMAT_I8_UNORM,
@@ -283,7 +285,12 @@ i915_is_format_supported(struct pipe_screen *screen,
};
static const enum pipe_format render_supported[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_FORMAT_B5G6R5_UNORM,
+ PIPE_FORMAT_B10G10R10A2_UNORM,
+ PIPE_FORMAT_L8_UNORM,
+ PIPE_FORMAT_A8_UNORM,
+ PIPE_FORMAT_I8_UNORM,
PIPE_FORMAT_NONE /* list terminator */
};
static const enum pipe_format depth_supported[] = {
diff --git a/src/gallium/drivers/i915/i915_screen.h b/src/gallium/drivers/i915/i915_screen.h
index cfc585b5350..9f2004eb942 100644
--- a/src/gallium/drivers/i915/i915_screen.h
+++ b/src/gallium/drivers/i915/i915_screen.h
@@ -65,5 +65,11 @@ i915_screen(struct pipe_screen *pscreen)
return (struct i915_screen *) pscreen;
}
+boolean
+i915_is_format_supported(struct pipe_screen *screen,
+ enum pipe_format format,
+ enum pipe_texture_target target,
+ unsigned sample_count,
+ unsigned tex_usage);
#endif /* I915_SCREEN_H */
diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c
index 1b57c5776f2..f412626955d 100644
--- a/src/gallium/drivers/i915/i915_state.c
+++ b/src/gallium/drivers/i915/i915_state.c
@@ -146,6 +146,7 @@ i915_create_blend_state(struct pipe_context *pipe,
if (blend->dither)
cso_data->LIS5 |= S5_COLOR_DITHER_ENABLE;
+ /* XXX here take the target fixup into account */
if ((blend->rt[0].colormask & PIPE_MASK_R) == 0)
cso_data->LIS5 |= S5_WRITEDISABLE_RED;
@@ -246,7 +247,7 @@ i915_create_sampler_state(struct pipe_context *pipe,
if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE)
{
cso->state[0] |= (SS2_SHADOW_ENABLE |
- i915_translate_compare_func(sampler->compare_func));
+ i915_translate_shadow_compare_func(sampler->compare_func));
minFilt = FILTER_4X4_FLAT;
magFilt = FILTER_4X4_FLAT;
@@ -466,6 +467,7 @@ i915_create_fs_state(struct pipe_context *pipe,
if (!ifs)
return NULL;
+ ifs->draw_data = draw_create_fragment_shader(i915->draw, templ);
ifs->state.tokens = tgsi_dup_tokens(templ->tokens);
tgsi_scan_shader(templ->tokens, &ifs->info);
@@ -495,6 +497,8 @@ i915_bind_fs_state(struct pipe_context *pipe, void *shader)
i915->fs = (struct i915_fragment_shader*) shader;
+ draw_bind_fragment_shader(i915->draw, (i915->fs ? i915->fs->draw_data : NULL));
+
i915->dirty |= I915_NEW_FS;
}
@@ -503,12 +507,14 @@ void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
{
struct i915_fragment_shader *ifs = (struct i915_fragment_shader *) shader;
- if (ifs->program)
+ if (ifs->program) {
FREE(ifs->program);
+ ifs->program = NULL;
+ FREE((struct tgsi_token *)ifs->state.tokens);
+ ifs->state.tokens = NULL;
+ }
ifs->program_len = 0;
- FREE((struct tgsi_token *)ifs->state.tokens);
-
FREE(ifs);
}
diff --git a/src/gallium/drivers/i915/i915_state_derived.c b/src/gallium/drivers/i915/i915_state_derived.c
index 392ba191140..e01f16e715c 100644
--- a/src/gallium/drivers/i915/i915_state_derived.c
+++ b/src/gallium/drivers/i915/i915_state_derived.c
@@ -33,6 +33,7 @@
#include "i915_context.h"
#include "i915_state.h"
#include "i915_debug.h"
+#include "i915_fpc.h"
#include "i915_reg.h"
static uint find_mapping(const struct i915_fragment_shader* fs, int unit)
@@ -58,12 +59,12 @@ static void calculate_vertex_layout(struct i915_context *i915)
const struct i915_fragment_shader *fs = i915->fs;
const enum interp_mode colorInterp = i915->rasterizer->color_interp;
struct vertex_info vinfo;
- boolean texCoords[I915_TEX_UNITS], colors[2], fog, needW;
+ boolean texCoords[I915_TEX_UNITS], colors[2], fog, needW, face;
uint i;
int src;
memset(texCoords, 0, sizeof(texCoords));
- colors[0] = colors[1] = fog = needW = FALSE;
+ colors[0] = colors[1] = fog = needW = face = FALSE;
memset(&vinfo, 0, sizeof(vinfo));
/* Determine which fragment program inputs are needed. Setup HW vertex
@@ -72,6 +73,10 @@ static void calculate_vertex_layout(struct i915_context *i915)
for (i = 0; i < fs->info.num_inputs; i++) {
switch (fs->info.input_semantic_name[i]) {
case TGSI_SEMANTIC_POSITION:
+ {
+ uint unit = I915_SEMANTIC_POS;
+ texCoords[find_mapping(fs, unit)] = TRUE;
+ }
break;
case TGSI_SEMANTIC_COLOR:
assert(fs->info.input_semantic_index[i] < 2);
@@ -80,7 +85,6 @@ static void calculate_vertex_layout(struct i915_context *i915)
case TGSI_SEMANTIC_GENERIC:
{
/* texcoords/varyings/other generic */
- /* XXX handle back/front face and point size */
uint unit = fs->info.input_semantic_index[i];
texCoords[find_mapping(fs, unit)] = TRUE;
@@ -90,7 +94,11 @@ static void calculate_vertex_layout(struct i915_context *i915)
case TGSI_SEMANTIC_FOG:
fog = TRUE;
break;
+ case TGSI_SEMANTIC_FACE:
+ face = TRUE;
+ break;
default:
+ debug_printf("Unknown input type %d\n", fs->info.input_semantic_name[i]);
assert(0);
}
}
@@ -147,6 +155,20 @@ static void calculate_vertex_layout(struct i915_context *i915)
vinfo.hwfmt[1] |= hwtc << (i * 4);
}
+ /* front/back face */
+ if (face) {
+ uint slot = find_mapping(fs, I915_SEMANTIC_FACE);
+ debug_printf("Front/back face is broken\n");
+ /* XXX Because of limitations in the draw module, currently src will be 0
+ * for SEMANTIC_FACE, so this aliases to POS. We need to fix in the draw
+ * module by adding an extra shader output.
+ */
+ src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_FACE, 0);
+ draw_emit_vertex_attr(&vinfo, EMIT_1F, INTERP_CONSTANT, src);
+ vinfo.hwfmt[1] &= ~(TEXCOORDFMT_NOT_PRESENT << (slot * 4));
+ vinfo.hwfmt[1] |= TEXCOORDFMT_1D << (slot * 4);
+ }
+
draw_compute_vertex_size(&vinfo);
if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) {
diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c
index 0155cd83510..39fb13aec7e 100644
--- a/src/gallium/drivers/i915/i915_state_emit.c
+++ b/src/gallium/drivers/i915/i915_state_emit.c
@@ -34,7 +34,9 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "pipe/p_format.h"
+#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
@@ -128,7 +130,7 @@ validate_immediate(struct i915_context *i915, unsigned *batch_space)
static void
emit_immediate(struct i915_context *i915)
{
- /* remove unwatned bits and S7 */
+ /* remove unwanted bits and S7 */
unsigned dirty = (1 << I915_IMMEDIATE_S0 | 1 << I915_IMMEDIATE_S1 |
1 << I915_IMMEDIATE_S2 | 1 << I915_IMMEDIATE_S3 |
1 << I915_IMMEDIATE_S3 | 1 << I915_IMMEDIATE_S4 |
@@ -341,6 +343,59 @@ emit_constants(struct i915_context *i915)
}
}
+static const struct
+{
+ enum pipe_format format;
+ uint hw_shift_R;
+ uint hw_shift_G;
+ uint hw_shift_B;
+ uint hw_shift_A;
+} fixup_formats[] = {
+ { PIPE_FORMAT_R8G8B8A8_UNORM, 20, 24, 28, 16 /* BGRA */},
+ { PIPE_FORMAT_L8_UNORM, 28, 28, 28, 16 /* RRRA */},
+ { PIPE_FORMAT_I8_UNORM, 28, 28, 28, 16 /* RRRA */},
+ { PIPE_FORMAT_A8_UNORM, 16, 16, 16, 16 /* AAAA */},
+ { PIPE_FORMAT_NONE, 0, 0, 0, 0},
+};
+
+static boolean need_fixup(struct pipe_surface* p)
+{
+ enum pipe_format f;
+
+ /* if we don't have a surface bound yet, we don't need to fixup the shader */
+ if (!p)
+ return FALSE;
+
+ f = p->format;
+ for(int i=0; fixup_formats[i].format != PIPE_FORMAT_NONE; i++)
+ if (fixup_formats[i].format == f)
+ return TRUE;
+
+ return FALSE;
+}
+
+static uint fixup_swizzle(enum pipe_format f, uint v)
+{
+ int i;
+
+ for(i=0; fixup_formats[i].format != PIPE_FORMAT_NONE; i++)
+ if (fixup_formats[i].format == f)
+ break;
+
+ if (fixup_formats[i].format == PIPE_FORMAT_NONE)
+ return v;
+
+ uint rgba = v & 0xFFFF0000;
+
+ v &= 0xFFFF;
+ v |= ((rgba >> fixup_formats[i].hw_shift_R) & 0xF) << 28;
+ v |= ((rgba >> fixup_formats[i].hw_shift_G) & 0xF) << 24;
+ v |= ((rgba >> fixup_formats[i].hw_shift_B) & 0xF) << 20;
+ v |= ((rgba >> fixup_formats[i].hw_shift_A) & 0xF) << 16;
+
+ return v;
+}
+
static void
validate_program(struct i915_context *i915, unsigned *batch_space)
{
@@ -350,12 +405,39 @@ validate_program(struct i915_context *i915, unsigned *batch_space)
static void
emit_program(struct i915_context *i915)
{
- uint i;
- /* we should always have, at least, a pass-through program */
- assert(i915->fs->program_len > 0);
- for (i = 0; i < i915->fs->program_len; i++) {
- OUT_BATCH(i915->fs->program[i]);
+ struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
+ boolean need_format_fixup = need_fixup(cbuf_surface);
+ int i;
+ int fixup_offset = -1;
+
+ /* we should always have, at least, a pass-through program */
+ assert(i915->fs->program_len > 0);
+
+ if (need_format_fixup) {
+ /* Find where we emit the output color */
+ for (i = i915->fs->program_len - 3; i>0; i-=3) {
+ uint instr = i915->fs->program[i];
+ if ((instr & (REG_NR_MASK << A0_DEST_TYPE_SHIFT)) ==
+ (REG_TYPE_OC << A0_DEST_TYPE_SHIFT) ) {
+ /* Found it! */
+ fixup_offset = i + 1;
+ break;
+ }
+ }
+ if (fixup_offset == -1) {
+ need_format_fixup = FALSE;
+ debug_printf("couldn't find fixup offset\n");
}
+ }
+
+ /* emit the program to the hw */
+ for (i = 0; i < i915->fs->program_len; i++) {
+ if (need_format_fixup && (i == fixup_offset) ) {
+ uint v = fixup_swizzle(cbuf_surface->format, i915->fs->program[i]);
+ OUT_BATCH(v);
+ } else
+ OUT_BATCH(i915->fs->program[i]);
+ }
}
static void
diff --git a/src/gallium/drivers/i915/i915_state_inlines.h b/src/gallium/drivers/i915/i915_state_inlines.h
index b589117fbfe..aa992f75c51 100644
--- a/src/gallium/drivers/i915/i915_state_inlines.h
+++ b/src/gallium/drivers/i915/i915_state_inlines.h
@@ -60,6 +60,31 @@ i915_translate_compare_func(unsigned func)
}
static INLINE unsigned
+i915_translate_shadow_compare_func(unsigned func)
+{
+ switch (func) {
+ case PIPE_FUNC_NEVER:
+ return COMPAREFUNC_ALWAYS;
+ case PIPE_FUNC_LESS:
+ return COMPAREFUNC_LEQUAL;
+ case PIPE_FUNC_LEQUAL:
+ return COMPAREFUNC_LESS;
+ case PIPE_FUNC_GREATER:
+ return COMPAREFUNC_GEQUAL;
+ case PIPE_FUNC_GEQUAL:
+ return COMPAREFUNC_GREATER;
+ case PIPE_FUNC_NOTEQUAL:
+ return COMPAREFUNC_EQUAL;
+ case PIPE_FUNC_EQUAL:
+ return COMPAREFUNC_NOTEQUAL;
+ case PIPE_FUNC_ALWAYS:
+ return COMPAREFUNC_NEVER;
+ default:
+ return COMPAREFUNC_NEVER;
+ }
+}
+
+static INLINE unsigned
i915_translate_stencil_op(unsigned op)
{
switch (op) {
diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c
index be70e7a92c9..0103f7c3530 100644
--- a/src/gallium/drivers/i915/i915_state_sampler.c
+++ b/src/gallium/drivers/i915/i915_state_sampler.c
@@ -62,6 +62,7 @@ static void update_map(struct i915_context *i915,
uint unit,
const struct i915_texture *tex,
const struct i915_sampler_state *sampler,
+ const struct pipe_sampler_view* view,
uint state[2]);
@@ -161,9 +162,10 @@ static void update_samplers(struct i915_context *i915)
i915->current.sampler[unit]); /* the result */
update_map(i915,
unit,
- texture, /* texture */
- i915->sampler[unit], /* sampler state */
- i915->current.texbuffer[unit]); /* the result */
+ texture, /* texture */
+ i915->sampler[unit], /* sampler state */
+ i915->fragment_sampler_views[unit], /* sampler view */
+ i915->current.texbuffer[unit]); /* the result */
i915->current.sampler_enable_nr++;
i915->current.sampler_enable_flags |= (1 << unit);
@@ -180,13 +182,21 @@ struct i915_tracked_state i915_hw_samplers = {
};
-
/***********************************************************************
* Sampler views
*/
-static uint translate_texture_format(enum pipe_format pipeFormat)
+static uint translate_texture_format(enum pipe_format pipeFormat,
+ const struct pipe_sampler_view* view)
{
+ if ( (view->swizzle_r != PIPE_SWIZZLE_RED ||
+ view->swizzle_g != PIPE_SWIZZLE_GREEN ||
+ view->swizzle_b != PIPE_SWIZZLE_BLUE ||
+ view->swizzle_a != PIPE_SWIZZLE_ALPHA ) &&
+ pipeFormat != PIPE_FORMAT_Z24_UNORM_S8_USCALED &&
+ pipeFormat != PIPE_FORMAT_Z24X8_UNORM )
+ debug_printf("i915: unsupported texture swizzle for format %d\n", pipeFormat);
+
switch (pipeFormat) {
case PIPE_FORMAT_L8_UNORM:
return MAPSURF_8BIT | MT_8BIT_L8;
@@ -202,16 +212,16 @@ static uint translate_texture_format(enum pipe_format pipeFormat)
return MAPSURF_16BIT | MT_16BIT_ARGB1555;
case PIPE_FORMAT_B4G4R4A4_UNORM:
return MAPSURF_16BIT | MT_16BIT_ARGB4444;
+ case PIPE_FORMAT_B10G10R10A2_UNORM:
+ return MAPSURF_32BIT | MT_32BIT_ARGB2101010;
case PIPE_FORMAT_B8G8R8A8_UNORM:
return MAPSURF_32BIT | MT_32BIT_ARGB8888;
case PIPE_FORMAT_B8G8R8X8_UNORM:
return MAPSURF_32BIT | MT_32BIT_XRGB8888;
case PIPE_FORMAT_R8G8B8A8_UNORM:
return MAPSURF_32BIT | MT_32BIT_ABGR8888;
-#if 0
case PIPE_FORMAT_R8G8B8X8_UNORM:
return MAPSURF_32BIT | MT_32BIT_XBGR8888;
-#endif
case PIPE_FORMAT_YUYV:
return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
case PIPE_FORMAT_UYVY:
@@ -232,7 +242,25 @@ static uint translate_texture_format(enum pipe_format pipeFormat)
return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
case PIPE_FORMAT_Z24X8_UNORM:
- return (MAPSURF_32BIT | MT_32BIT_xI824);
+ {
+ if ( view->swizzle_r == PIPE_SWIZZLE_RED &&
+ view->swizzle_g == PIPE_SWIZZLE_RED &&
+ view->swizzle_b == PIPE_SWIZZLE_RED &&
+ view->swizzle_a == PIPE_SWIZZLE_ONE)
+ return (MAPSURF_32BIT | MT_32BIT_xA824);
+ if ( view->swizzle_r == PIPE_SWIZZLE_RED &&
+ view->swizzle_g == PIPE_SWIZZLE_RED &&
+ view->swizzle_b == PIPE_SWIZZLE_RED &&
+ view->swizzle_a == PIPE_SWIZZLE_RED)
+ return (MAPSURF_32BIT | MT_32BIT_xI824);
+ if ( view->swizzle_r == PIPE_SWIZZLE_ZERO &&
+ view->swizzle_g == PIPE_SWIZZLE_ZERO &&
+ view->swizzle_b == PIPE_SWIZZLE_ZERO &&
+ view->swizzle_a == PIPE_SWIZZLE_RED)
+ return (MAPSURF_32BIT | MT_32BIT_xL824);
+ debug_printf("i915: unsupported depth swizzle\n");
+ return (MAPSURF_32BIT | MT_32BIT_xL824);
+ }
default:
debug_printf("i915: translate_texture_format() bad image format %x\n",
pipeFormat);
@@ -262,6 +290,7 @@ static void update_map(struct i915_context *i915,
uint unit,
const struct i915_texture *tex,
const struct i915_sampler_state *sampler,
+ const struct pipe_sampler_view* view,
uint state[2])
{
const struct pipe_resource *pt = &tex->b.b;
@@ -275,7 +304,7 @@ static void update_map(struct i915_context *i915,
assert(height);
assert(depth);
- format = translate_texture_format(pt->format);
+ format = translate_texture_format(pt->format, view);
pitch = tex->stride;
assert(format);
@@ -318,8 +347,9 @@ static void update_maps(struct i915_context *i915)
update_map(i915,
unit,
- texture, /* texture */
- i915->sampler[unit], /* sampler state */
+ texture, /* texture */
+ i915->sampler[unit], /* sampler state */
+ i915->fragment_sampler_views[unit], /* sampler view */
i915->current.texbuffer[unit]);
}
}
diff --git a/src/gallium/drivers/i915/i915_state_static.c b/src/gallium/drivers/i915/i915_state_static.c
index 2865298318c..0e4000bc2ab 100644
--- a/src/gallium/drivers/i915/i915_state_static.c
+++ b/src/gallium/drivers/i915/i915_state_static.c
@@ -42,6 +42,18 @@ static unsigned translate_format(enum pipe_format format)
return COLOR_BUF_ARGB8888;
case PIPE_FORMAT_B5G6R5_UNORM:
return COLOR_BUF_RGB565;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ return COLOR_BUF_ARGB1555;
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
+ return COLOR_BUF_ARGB8888;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ return COLOR_BUF_ARGB4444;
+ case PIPE_FORMAT_B10G10R10A2_UNORM:
+ return COLOR_BUF_ARGB2101010;
+ case PIPE_FORMAT_L8_UNORM:
+ case PIPE_FORMAT_A8_UNORM:
+ case PIPE_FORMAT_I8_UNORM:
+ return COLOR_BUF_8BIT;
default:
assert(0);
return 0;
@@ -137,7 +149,8 @@ static void update_framebuffer(struct i915_context *i915)
i915->static_dirty |= I915_DST_RECT;
}
- i915->hardware_dirty |= I915_HW_STATIC;
+ /* we also send a new program to make sure the fixup for RGBA surfaces happens */
+ i915->hardware_dirty |= I915_HW_STATIC | I915_HW_PROGRAM;
/* flush the cache in case we sample from the old renderbuffers */
i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript
index c10a8cbc12c..d6b20ceb5ce 100644
--- a/src/gallium/drivers/llvmpipe/SConscript
+++ b/src/gallium/drivers/llvmpipe/SConscript
@@ -79,7 +79,7 @@ llvmpipe = env.ConvenienceLibrary(
env.Alias('llvmpipe', llvmpipe)
-if env['platform'] != 'embedded':
+if not env['embedded']:
env = env.Clone()
env.Prepend(LIBS = [llvmpipe] + gallium)
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
index 036a6e0c379..4b2ae1436ea 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -423,7 +423,7 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
lp_jit_screen_init(screen);
screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0;
-#ifdef PIPE_OS_EMBEDDED
+#ifdef PIPE_SUBSYSTEM_EMBEDDED
screen->num_threads = 0;
#endif
screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads);
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
index 401155bba6e..223e7682ccd 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.c
+++ b/src/gallium/drivers/nouveau/nouveau_screen.c
@@ -81,20 +81,6 @@ nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment,
return bo;
}
-struct nouveau_bo *
-nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes)
-{
- struct nouveau_device *dev = nouveau_screen(pscreen)->device;
- struct nouveau_bo *bo = NULL;
- int ret;
-
- ret = nouveau_bo_user(dev, ptr, bytes, &bo);
- if (ret)
- return NULL;
-
- return bo;
-}
-
void *
nouveau_screen_bo_map(struct pipe_screen *pscreen,
struct nouveau_bo *bo,
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h
index 186ada39677..d910809a0ec 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.h
+++ b/src/gallium/drivers/nouveau/nouveau_screen.h
@@ -47,8 +47,6 @@ nouveau_screen(struct pipe_screen *pscreen)
struct nouveau_bo *
nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment,
unsigned usage, unsigned bind, unsigned size);
-struct nouveau_bo *
-nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes);
void *
nouveau_screen_bo_map(struct pipe_screen *pscreen,
struct nouveau_bo *pb,
diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c
index 632ca4daf74..ceb83f6e684 100644
--- a/src/gallium/drivers/nv50/nv50_context.c
+++ b/src/gallium/drivers/nv50/nv50_context.c
@@ -168,6 +168,7 @@ nv50_bufctx_add_resident(struct nv50_context *nv50, int ctx,
if (!resource->bo)
return;
+ nv50->residents_size += sizeof(struct resident);
/* We don't need to reference the resource here, it will be referenced
* in the context/state, and bufctx will be reset when state changes.
@@ -189,6 +190,7 @@ nv50_bufctx_del_resident(struct nv50_context *nv50, int ctx,
top = util_dynarray_pop_ptr(&nv50->residents[ctx], struct resident);
if (rsd != top)
*rsd = *top;
+ nv50->residents_size -= sizeof(struct resident);
break;
}
}
@@ -201,11 +203,15 @@ nv50_bufctx_emit_relocs(struct nv50_context *nv50)
struct util_dynarray *array;
unsigned ctx, i, n;
+ n = nv50->residents_size / sizeof(struct resident);
+ n += NV50_SCREEN_RESIDENT_BO_COUNT;
+
+ MARK_RING(nv50->screen->base.channel, n, n);
+
for (ctx = 0; ctx < NV50_BUFCTX_COUNT; ++ctx) {
array = &nv50->residents[ctx];
n = array->size / sizeof(struct resident);
- MARK_RING(nv50->screen->base.channel, n, n);
for (i = 0; i < n; ++i) {
rsd = util_dynarray_element(array, struct resident, i);
diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h
index 3f031994f0a..b4af24f6bce 100644
--- a/src/gallium/drivers/nv50/nv50_context.h
+++ b/src/gallium/drivers/nv50/nv50_context.h
@@ -64,6 +64,7 @@ struct nv50_context {
struct nv50_screen *screen;
struct util_dynarray residents[NV50_BUFCTX_COUNT];
+ unsigned residents_size;
uint32_t dirty;
@@ -156,6 +157,7 @@ void nv50_bufctx_del_resident(struct nv50_context *, int ctx,
static INLINE void
nv50_bufctx_reset(struct nv50_context *nv50, int ctx)
{
+ nv50->residents_size -= nv50->residents[ctx].size;
util_dynarray_resize(&nv50->residents[ctx], 0);
}
diff --git a/src/gallium/drivers/nv50/nv50_screen.h b/src/gallium/drivers/nv50/nv50_screen.h
index aea434b8679..64ad209a728 100644
--- a/src/gallium/drivers/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nv50/nv50_screen.h
@@ -19,6 +19,8 @@ struct nv50_context;
#define NV50_SCRATCH_SIZE (2 << 20)
#define NV50_SCRATCH_NR_BUFFERS 2
+#define NV50_SCREEN_RESIDENT_BO_COUNT 5
+
struct nv50_screen {
struct nouveau_screen base;
struct nouveau_winsys *nvws;
diff --git a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c
index abdb9ce2f93..bb08941c243 100644
--- a/src/gallium/drivers/nv50/nv50_vbo.c
+++ b/src/gallium/drivers/nv50/nv50_vbo.c
@@ -404,9 +404,6 @@ nv50_draw_arrays(struct nv50_context *nv50,
struct nouveau_channel *chan = nv50->screen->base.channel;
unsigned prim;
- chan->flush_notify = nv50_draw_vbo_flush_notify;
- chan->user_private = nv50;
-
prim = nv50_prim_gl(mode);
while (instance_count--) {
@@ -420,8 +417,6 @@ nv50_draw_arrays(struct nv50_context *nv50,
prim |= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
}
-
- chan->flush_notify = nv50_default_flush_notify;
}
static void
@@ -523,9 +518,6 @@ nv50_draw_elements(struct nv50_context *nv50, boolean shorten,
unsigned prim;
const unsigned index_size = nv50->idxbuf.index_size;
- chan->flush_notify = nv50_draw_vbo_flush_notify;
- chan->user_private = nv50;
-
prim = nv50_prim_gl(mode);
if (index_bias != nv50->state.index_bias) {
@@ -631,8 +623,6 @@ nv50_draw_elements(struct nv50_context *nv50, boolean shorten,
prim |= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
}
}
-
- chan->flush_notify = nv50_default_flush_notify;
}
void
@@ -659,8 +649,12 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
nv50_state_validate(nv50);
+ chan->flush_notify = nv50_draw_vbo_flush_notify;
+ chan->user_private = nv50;
+
if (nv50->vbo_fifo) {
nv50_push_vbo(nv50, info);
+ chan->flush_notify = nv50_default_flush_notify;
return;
}
@@ -712,6 +706,7 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
info->mode, info->start, info->count,
info->instance_count, info->index_bias);
}
+ chan->flush_notify = nv50_default_flush_notify;
nv50_release_user_vbufs(nv50);
}
diff --git a/src/gallium/drivers/nvc0/nvc0_context.c b/src/gallium/drivers/nvc0/nvc0_context.c
index 2f2a3da7c44..2679b7f86aa 100644
--- a/src/gallium/drivers/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nvc0/nvc0_context.c
@@ -169,6 +169,7 @@ nvc0_bufctx_add_resident(struct nvc0_context *nvc0, int ctx,
if (!resource->bo)
return;
+ nvc0->residents_size += sizeof(struct resident);
/* We don't need to reference the resource here, it will be referenced
* in the context/state, and bufctx will be reset when state changes.
@@ -190,6 +191,7 @@ nvc0_bufctx_del_resident(struct nvc0_context *nvc0, int ctx,
top = util_dynarray_pop_ptr(&nvc0->residents[ctx], struct resident);
if (rsd != top)
*rsd = *top;
+ nvc0->residents_size -= sizeof(struct resident);
break;
}
}
@@ -202,11 +204,15 @@ nvc0_bufctx_emit_relocs(struct nvc0_context *nvc0)
struct util_dynarray *array;
unsigned ctx, i, n;
+ n = nvc0->residents_size / sizeof(struct resident);
+ n += NVC0_SCREEN_RESIDENT_BO_COUNT;
+
+ MARK_RING(nvc0->screen->base.channel, n, n);
+
for (ctx = 0; ctx < NVC0_BUFCTX_COUNT; ++ctx) {
array = &nvc0->residents[ctx];
n = array->size / sizeof(struct resident);
- MARK_RING(nvc0->screen->base.channel, n, n);
for (i = 0; i < n; ++i) {
rsd = util_dynarray_element(array, struct resident, i);
diff --git a/src/gallium/drivers/nvc0/nvc0_context.h b/src/gallium/drivers/nvc0/nvc0_context.h
index f97141dd46e..b05cc337d5d 100644
--- a/src/gallium/drivers/nvc0/nvc0_context.h
+++ b/src/gallium/drivers/nvc0/nvc0_context.h
@@ -62,6 +62,7 @@ struct nvc0_context {
struct nvc0_screen *screen;
struct util_dynarray residents[NVC0_BUFCTX_COUNT];
+ unsigned residents_size;
uint32_t dirty;
@@ -163,6 +164,7 @@ void nvc0_bufctx_del_resident(struct nvc0_context *, int ctx,
static INLINE void
nvc0_bufctx_reset(struct nvc0_context *nvc0, int ctx)
{
+ nvc0->residents_size -= nvc0->residents[ctx].size;
util_dynarray_resize(&nvc0->residents[ctx], 0);
}
diff --git a/src/gallium/drivers/nvc0/nvc0_screen.h b/src/gallium/drivers/nvc0/nvc0_screen.h
index 94bf0cf3481..015807e2f5d 100644
--- a/src/gallium/drivers/nvc0/nvc0_screen.h
+++ b/src/gallium/drivers/nvc0/nvc0_screen.h
@@ -16,6 +16,8 @@ struct nvc0_context;
#define NVC0_SCRATCH_SIZE (2 << 20)
#define NVC0_SCRATCH_NR_BUFFERS 2
+#define NVC0_SCREEN_RESIDENT_BO_COUNT 5
+
struct nvc0_screen {
struct nouveau_screen base;
struct nouveau_winsys *nvws;
diff --git a/src/gallium/drivers/nvc0/nvc0_vbo.c b/src/gallium/drivers/nvc0/nvc0_vbo.c
index 6bbcf2447ec..41079104b39 100644
--- a/src/gallium/drivers/nvc0/nvc0_vbo.c
+++ b/src/gallium/drivers/nvc0/nvc0_vbo.c
@@ -382,9 +382,6 @@ nvc0_draw_arrays(struct nvc0_context *nvc0,
struct nouveau_channel *chan = nvc0->screen->base.channel;
unsigned prim;
- chan->flush_notify = nvc0_draw_vbo_flush_notify;
- chan->user_private = nvc0;
-
prim = nvc0_prim_gl(mode);
while (instance_count--) {
@@ -397,8 +394,6 @@ nvc0_draw_arrays(struct nvc0_context *nvc0,
prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
}
-
- chan->flush_notify = nvc0_default_flush_notify;
}
static void
@@ -500,9 +495,6 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
unsigned prim;
const unsigned index_size = nvc0->idxbuf.index_size;
- chan->flush_notify = nvc0_draw_vbo_flush_notify;
- chan->user_private = nvc0;
-
prim = nvc0_prim_gl(mode);
if (index_bias != nvc0->state.index_bias) {
@@ -568,8 +560,6 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
}
}
-
- chan->flush_notify = nvc0_default_flush_notify;
}
void
@@ -596,8 +586,12 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
nvc0_state_validate(nvc0);
+ chan->flush_notify = nvc0_draw_vbo_flush_notify;
+ chan->user_private = nvc0;
+
if (nvc0->vbo_fifo) {
nvc0_push_vbo(nvc0, info);
+ chan->flush_notify = nvc0_default_flush_notify;
return;
}
@@ -648,6 +642,7 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
info->mode, info->start, info->count,
info->instance_count, info->index_bias);
}
+ chan->flush_notify = nvc0_default_flush_notify;
nvc0_release_user_vbufs(nvc0);
}
diff --git a/src/gallium/drivers/nvfx/nvfx_context.c b/src/gallium/drivers/nvfx/nvfx_context.c
index 2b1510264a1..98603bedde1 100644
--- a/src/gallium/drivers/nvfx/nvfx_context.c
+++ b/src/gallium/drivers/nvfx/nvfx_context.c
@@ -24,9 +24,21 @@ nvfx_flush(struct pipe_context *pipe,
OUT_RING(chan, 1);
}*/
- FIRE_RING(chan);
- if (fence)
+ if (fence) {
+ /* horrific hack to make glFinish() work in the absence of
+ * having proper fences in nvfx. a pending rewrite will
+ * fix this properly, but may be a while off.
+ */
+ MARK_RING(chan, 1, 1);
+ OUT_RELOC(chan, screen->fence, 0, NOUVEAU_BO_WR |
+ NOUVEAU_BO_DUMMY, 0, 0);
+ FIRE_RING(chan);
+ nouveau_bo_map(screen->fence, NOUVEAU_BO_RDWR);
+ nouveau_bo_unmap(screen->fence);
*fence = NULL;
+ } else {
+ FIRE_RING(chan);
+ }
}
static void
diff --git a/src/gallium/drivers/nvfx/nvfx_screen.c b/src/gallium/drivers/nvfx/nvfx_screen.c
index 475138c3c32..7a013a916b9 100644
--- a/src/gallium/drivers/nvfx/nvfx_screen.c
+++ b/src/gallium/drivers/nvfx/nvfx_screen.c
@@ -304,6 +304,7 @@ nvfx_screen_destroy(struct pipe_screen *pscreen)
nouveau_notifier_free(&screen->sync);
nouveau_grobj_free(&screen->eng3d);
nvfx_screen_surface_takedown(pscreen);
+ nouveau_bo_ref(NULL, &screen->fence);
nouveau_screen_fini(&screen->base);
@@ -468,6 +469,12 @@ nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
pscreen->is_format_supported = nvfx_screen_is_format_supported;
pscreen->context_create = nvfx_create;
+ ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 4096, &screen->fence);
+ if (ret) {
+ nvfx_screen_destroy(pscreen);
+ return NULL;
+ }
+
switch (dev->chipset & 0xf0) {
case 0x30:
if (NV30_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f)))
diff --git a/src/gallium/drivers/nvfx/nvfx_screen.h b/src/gallium/drivers/nvfx/nvfx_screen.h
index b1f07187c78..02e7c5d1cad 100644
--- a/src/gallium/drivers/nvfx/nvfx_screen.h
+++ b/src/gallium/drivers/nvfx/nvfx_screen.h
@@ -11,6 +11,7 @@ struct nvfx_screen {
struct nouveau_screen base;
struct nouveau_winsys *nvws;
+ struct nouveau_bo *fence;
struct nvfx_context *cur_ctx;
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index d9399d78ef9..b31141a518e 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -175,8 +175,8 @@ static void r300_split_index_bias(struct r300_context *r300, int index_bias,
enum r300_prepare_flags {
PREP_EMIT_STATES = (1 << 0), /* call emit_dirty_state and friends? */
PREP_VALIDATE_VBOS = (1 << 1), /* validate VBOs? */
- PREP_EMIT_AOS = (1 << 2), /* call emit_vertex_arrays? */
- PREP_EMIT_AOS_SWTCL = (1 << 3), /* call emit_vertex_arrays_swtcl? */
+ PREP_EMIT_VARRAYS = (1 << 2), /* call emit_vertex_arrays? */
+ PREP_EMIT_VARRAYS_SWTCL = (1 << 3), /* call emit_vertex_arrays_swtcl? */
PREP_INDEXED = (1 << 4) /* is this draw_elements? */
};
@@ -193,23 +193,22 @@ static boolean r300_reserve_cs_dwords(struct r300_context *r300,
unsigned cs_dwords)
{
boolean flushed = FALSE;
- boolean first_draw = flags & PREP_EMIT_STATES;
- boolean emit_vertex_arrays = flags & PREP_EMIT_AOS;
- boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_AOS_SWTCL;
+ boolean emit_states = flags & PREP_EMIT_STATES;
+ boolean emit_vertex_arrays = flags & PREP_EMIT_VARRAYS;
+ boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_VARRAYS_SWTCL;
/* Add dirty state, index offset, and AOS. */
- if (first_draw) {
+ if (emit_states)
cs_dwords += r300_get_num_dirty_dwords(r300);
- if (r300->screen->caps.is_r500)
- cs_dwords += 2; /* emit_index_offset */
+ if (r300->screen->caps.is_r500)
+ cs_dwords += 2; /* emit_index_offset */
- if (emit_vertex_arrays)
- cs_dwords += 55; /* emit_vertex_arrays */
+ if (emit_vertex_arrays)
+ cs_dwords += 55; /* emit_vertex_arrays */
- if (emit_vertex_arrays_swtcl)
- cs_dwords += 7; /* emit_vertex_arrays_swtcl */
- }
+ if (emit_vertex_arrays_swtcl)
+ cs_dwords += 7; /* emit_vertex_arrays_swtcl */
cs_dwords += r300_get_num_cs_end_dwords(r300);
@@ -238,46 +237,48 @@ static boolean r300_emit_states(struct r300_context *r300,
int buffer_offset,
int index_bias, int instance_id)
{
- boolean first_draw = flags & PREP_EMIT_STATES;
- boolean emit_vertex_arrays = flags & PREP_EMIT_AOS;
- boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_AOS_SWTCL;
+ boolean emit_states = flags & PREP_EMIT_STATES;
+ boolean emit_vertex_arrays = flags & PREP_EMIT_VARRAYS;
+ boolean emit_vertex_arrays_swtcl = flags & PREP_EMIT_VARRAYS_SWTCL;
boolean indexed = flags & PREP_INDEXED;
boolean validate_vbos = flags & PREP_VALIDATE_VBOS;
/* Validate buffers and emit dirty state if needed. */
- if (first_draw) {
+ if (emit_states || (emit_vertex_arrays && validate_vbos)) {
if (!r300_emit_buffer_validate(r300, validate_vbos,
index_buffer)) {
fprintf(stderr, "r300: CS space validation failed. "
"(not enough memory?) Skipping rendering.\n");
return FALSE;
}
+ }
+ if (emit_states)
r300_emit_dirty_state(r300);
- if (r300->screen->caps.is_r500) {
- if (r300->screen->caps.has_tcl)
- r500_emit_index_bias(r300, index_bias);
- else
- r500_emit_index_bias(r300, 0);
- }
- if (emit_vertex_arrays &&
- (r300->vertex_arrays_dirty ||
- r300->vertex_arrays_indexed != indexed ||
- r300->vertex_arrays_offset != buffer_offset ||
- r300->vertex_arrays_instance_id != instance_id)) {
- r300_emit_vertex_arrays(r300, buffer_offset, indexed, instance_id);
-
- r300->vertex_arrays_dirty = FALSE;
- r300->vertex_arrays_indexed = indexed;
- r300->vertex_arrays_offset = buffer_offset;
- r300->vertex_arrays_instance_id = instance_id;
- }
+ if (r300->screen->caps.is_r500) {
+ if (r300->screen->caps.has_tcl)
+ r500_emit_index_bias(r300, index_bias);
+ else
+ r500_emit_index_bias(r300, 0);
+ }
- if (emit_vertex_arrays_swtcl)
- r300_emit_vertex_arrays_swtcl(r300, indexed);
+ if (emit_vertex_arrays &&
+ (r300->vertex_arrays_dirty ||
+ r300->vertex_arrays_indexed != indexed ||
+ r300->vertex_arrays_offset != buffer_offset ||
+ r300->vertex_arrays_instance_id != instance_id)) {
+ r300_emit_vertex_arrays(r300, buffer_offset, indexed, instance_id);
+
+ r300->vertex_arrays_dirty = FALSE;
+ r300->vertex_arrays_indexed = indexed;
+ r300->vertex_arrays_offset = buffer_offset;
+ r300->vertex_arrays_instance_id = instance_id;
}
+ if (emit_vertex_arrays_swtcl)
+ r300_emit_vertex_arrays_swtcl(r300, indexed);
+
return TRUE;
}
@@ -540,7 +541,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
/* 19 dwords for r300_draw_elements_immediate. Give up if the function fails. */
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_AOS |
+ PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_VARRAYS |
PREP_INDEXED, NULL, 2+count_dwords, 0, info->index_bias, -1))
return;
@@ -662,7 +663,7 @@ static void r300_draw_elements(struct r300_context *r300,
/* 19 dwords for emit_draw_elements. Give up if the function fails. */
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_AOS |
+ PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_VARRAYS |
PREP_INDEXED, indexBuffer, 19, buffer_offset, info->index_bias,
instance_id))
goto done;
@@ -689,7 +690,7 @@ static void r300_draw_elements(struct r300_context *r300,
/* 15 dwords for emit_draw_elements */
if (count) {
if (!r300_prepare_for_rendering(r300,
- PREP_VALIDATE_VBOS | PREP_EMIT_AOS | PREP_INDEXED,
+ PREP_VALIDATE_VBOS | PREP_EMIT_VARRAYS | PREP_INDEXED,
indexBuffer, 19, buffer_offset, info->index_bias,
instance_id))
goto done;
@@ -715,7 +716,7 @@ static void r300_draw_arrays(struct r300_context *r300,
/* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_AOS,
+ PREP_EMIT_STATES | PREP_VALIDATE_VBOS | PREP_EMIT_VARRAYS,
NULL, 9, start, 0, instance_id))
return;
@@ -736,7 +737,7 @@ static void r300_draw_arrays(struct r300_context *r300,
/* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */
if (count) {
if (!r300_prepare_for_rendering(r300,
- PREP_VALIDATE_VBOS | PREP_EMIT_AOS, NULL, 9,
+ PREP_VALIDATE_VBOS | PREP_EMIT_VARRAYS, NULL, 9,
start, 0, instance_id))
return;
}
@@ -767,7 +768,6 @@ static void r300_draw_vbo(struct pipe_context* pipe,
{
struct r300_context* r300 = r300_context(pipe);
struct pipe_draw_info info = *dinfo;
- boolean buffers_updated, uploader_flushed;
info.indexed = info.indexed && r300->index_buffer.buffer;
@@ -779,9 +779,7 @@ static void r300_draw_vbo(struct pipe_context* pipe,
r300_update_derived_state(r300);
/* Start the vbuf manager and update buffers if needed. */
- u_vbuf_mgr_draw_begin(r300->vbuf_mgr, &info,
- &buffers_updated, &uploader_flushed);
- if (buffers_updated) {
+ if (u_vbuf_mgr_draw_begin(r300->vbuf_mgr, &info) & U_VBUF_BUFFERS_UPDATED) {
r300->vertex_arrays_dirty = TRUE;
}
@@ -843,7 +841,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
r300_update_derived_state(r300);
r300_reserve_cs_dwords(r300,
- PREP_EMIT_STATES | PREP_EMIT_AOS_SWTCL |
+ PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL |
(indexed ? PREP_INDEXED : 0),
indexed ? 256 : 6);
@@ -1025,12 +1023,12 @@ static void r300_render_draw_arrays(struct vbuf_render* render,
if (r300->draw_first_emitted) {
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_STATES | PREP_EMIT_AOS_SWTCL,
+ PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL,
NULL, dwords, 0, 0, -1))
return;
} else {
if (!r300_emit_states(r300,
- PREP_EMIT_STATES | PREP_EMIT_AOS_SWTCL,
+ PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL,
NULL, 0, 0, -1))
return;
}
@@ -1065,12 +1063,12 @@ static void r300_render_draw_elements(struct vbuf_render* render,
if (r300->draw_first_emitted) {
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_STATES | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
+ PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED,
NULL, 256, 0, 0, -1))
return;
} else {
if (!r300_emit_states(r300,
- PREP_EMIT_STATES | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
+ PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED,
NULL, 0, 0, -1))
return;
}
@@ -1107,7 +1105,7 @@ static void r300_render_draw_elements(struct vbuf_render* render,
if (count) {
if (!r300_prepare_for_rendering(r300,
- PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
+ PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED,
NULL, 256, 0, 0, -1))
return;
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index 38ca9a24e45..62c2f1fff6c 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -447,16 +447,8 @@ static uint32_t r300_translate_colorformat(enum pipe_format format)
/*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
case PIPE_FORMAT_B8G8R8X8_UNORM:
/*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- /*case PIPE_FORMAT_A8R8G8B8_SNORM:*/
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- /*case PIPE_FORMAT_X8R8G8B8_SNORM:*/
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- /*case PIPE_FORMAT_A8B8G8R8_SNORM:*/
case PIPE_FORMAT_R8G8B8A8_UNORM:
case PIPE_FORMAT_R8G8B8A8_SNORM:
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- /*case PIPE_FORMAT_X8B8G8R8_SNORM:*/
case PIPE_FORMAT_R8G8B8X8_UNORM:
/*case PIPE_FORMAT_R8G8B8X8_SNORM:*/
/* These formats work fine with ARGB8888 if US_OUT_FMT is set
@@ -662,10 +654,6 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format)
R300_C2_SEL_R | R300_C3_SEL_A;
/* ARGB outputs. */
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- /*case PIPE_FORMAT_A8R8G8B8_SNORM:*/
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- /*case PIPE_FORMAT_X8R8G8B8_SNORM:*/
case PIPE_FORMAT_A16_UNORM:
case PIPE_FORMAT_A16_SNORM:
case PIPE_FORMAT_A16_FLOAT:
@@ -674,15 +662,6 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format)
R300_C0_SEL_A | R300_C1_SEL_R |
R300_C2_SEL_G | R300_C3_SEL_B;
- /* ABGR outputs. */
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- /*case PIPE_FORMAT_A8B8G8R8_SNORM:*/
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- /*case PIPE_FORMAT_X8B8G8R8_SNORM:*/
- return modifier |
- R300_C0_SEL_A | R300_C1_SEL_B |
- R300_C2_SEL_G | R300_C3_SEL_R;
-
/* RGBA outputs. */
case PIPE_FORMAT_R8G8B8X8_UNORM:
/*case PIPE_FORMAT_R8G8B8X8_SNORM:*/
diff --git a/src/gallium/drivers/r600/SConscript b/src/gallium/drivers/r600/SConscript
index 0135808f10a..19f07b2bef8 100644
--- a/src/gallium/drivers/r600/SConscript
+++ b/src/gallium/drivers/r600/SConscript
@@ -2,11 +2,7 @@ Import('*')
env = env.Clone()
-try:
- env.ParseConfig('pkg-config --cflags libdrm_radeon')
-except OSError:
- print 'warning: not building r600'
- Return()
+env.PkgUseModules('DRM_RADEON')
env.Append(CPPPATH = [
'#/include',
diff --git a/src/gallium/drivers/r600/eg_state_inlines.h b/src/gallium/drivers/r600/eg_state_inlines.h
index f8891781be8..b5590116e8f 100644
--- a/src/gallium/drivers/r600/eg_state_inlines.h
+++ b/src/gallium/drivers/r600/eg_state_inlines.h
@@ -327,6 +327,7 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format)
return V_028C70_SWAP_STD;
case PIPE_FORMAT_R16_UNORM:
+ case PIPE_FORMAT_R16_FLOAT:
return V_028C70_SWAP_STD;
/* 32-bit buffers. */
@@ -343,6 +344,7 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format)
case PIPE_FORMAT_X8R8G8B8_UNORM:
return V_028C70_SWAP_ALT_REV;
case PIPE_FORMAT_R8G8B8A8_SNORM:
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
case PIPE_FORMAT_R8G8B8X8_UNORM:
return V_028C70_SWAP_STD;
@@ -429,6 +431,9 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format)
case PIPE_FORMAT_R16_UNORM:
return V_028C70_COLOR_16;
+ case PIPE_FORMAT_R16_FLOAT:
+ return V_028C70_COLOR_16_FLOAT;
+
/* 32-bit buffers. */
case PIPE_FORMAT_A8B8G8R8_SRGB:
case PIPE_FORMAT_A8B8G8R8_UNORM:
diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index f86e4d4e3af..dc182611482 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -256,6 +256,8 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
}
rstate = &rs->rstate;
+ rs->clamp_vertex_color = state->clamp_vertex_color;
+ rs->clamp_fragment_color = state->clamp_fragment_color;
rs->flatshade = state->flatshade;
rs->sprite_coord_enable = state->sprite_coord_enable;
@@ -883,6 +885,7 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx,
/* build states */
rctx->have_depth_fb = 0;
+ rctx->nr_cbufs = state->nr_cbufs;
for (int i = 0; i < state->nr_cbufs; i++) {
evergreen_cb(rctx, rstate, state, i);
}
@@ -1629,7 +1632,10 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
rshader->output[i].name == TGSI_SEMANTIC_STENCIL)
exports_ps |= 1;
else if (rshader->output[i].name == TGSI_SEMANTIC_COLOR) {
- num_cout++;
+ if (rshader->fs_write_all)
+ num_cout = rshader->nr_cbufs;
+ else
+ num_cout++;
}
}
exports_ps |= S_02884C_EXPORT_COLORS(num_cout);
diff --git a/src/gallium/drivers/r600/r600.h b/src/gallium/drivers/r600/r600.h
index 225c17c2540..151e831e5c6 100644
--- a/src/gallium/drivers/r600/r600.h
+++ b/src/gallium/drivers/r600/r600.h
@@ -245,6 +245,7 @@ struct r600_context {
unsigned pm4_cdwords;
unsigned pm4_dirty_cdwords;
unsigned ctx_pm4_ndwords;
+ unsigned init_dwords;
unsigned nreloc;
unsigned creloc;
struct r600_reloc *reloc;
diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c
index c447a031063..065f955ebcb 100644
--- a/src/gallium/drivers/r600/r600_asm.c
+++ b/src/gallium/drivers/r600/r600_asm.c
@@ -1863,6 +1863,8 @@ void r600_bc_dump(struct r600_bc *bc)
break;
case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
+ case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
+ case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
fprintf(stderr, "%04d %08X EXPORT ", id, bc->bytecode[id]);
fprintf(stderr, "GPR:%X ", cf->output.gpr);
fprintf(stderr, "ELEM_SIZE:%X ", cf->output.elem_size);
diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index e9f35c10ac1..6171d285bb9 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -27,9 +27,18 @@
enum r600_blitter_op /* bitmask */
{
- R600_CLEAR = 1,
- R600_CLEAR_SURFACE = 2,
- R600_COPY = 4
+ R600_SAVE_TEXTURES = 1,
+ R600_SAVE_FRAMEBUFFER = 2,
+ R600_DISABLE_RENDER_COND = 4,
+
+ R600_CLEAR = 0,
+
+ R600_CLEAR_SURFACE = R600_SAVE_FRAMEBUFFER,
+
+ R600_COPY = R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
+ R600_DISABLE_RENDER_COND,
+
+ R600_DECOMPRESS = R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND,
};
static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op)
@@ -58,10 +67,10 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
rctx->vbuf_mgr->nr_vertex_buffers,
rctx->vbuf_mgr->vertex_buffer);
- if (op & (R600_CLEAR_SURFACE | R600_COPY))
+ if (op & R600_SAVE_FRAMEBUFFER)
util_blitter_save_framebuffer(rctx->blitter, &rctx->framebuffer);
- if (op & R600_COPY) {
+ if (op & R600_SAVE_TEXTURES) {
util_blitter_save_fragment_sampler_states(
rctx->blitter, rctx->ps_samplers.n_samplers,
(void**)rctx->ps_samplers.samplers);
@@ -71,11 +80,23 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
(struct pipe_sampler_view**)rctx->ps_samplers.views);
}
+ if ((op & R600_DISABLE_RENDER_COND) && rctx->current_render_cond) {
+ rctx->saved_render_cond = rctx->current_render_cond;
+ rctx->saved_render_cond_mode = rctx->current_render_cond_mode;
+ rctx->context.render_condition(&rctx->context, NULL, 0);
+ }
+
}
static void r600_blitter_end(struct pipe_context *ctx)
{
struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
+ if (rctx->saved_render_cond) {
+ rctx->context.render_condition(&rctx->context,
+ rctx->saved_render_cond,
+ rctx->saved_render_cond_mode);
+ rctx->saved_render_cond = NULL;
+ }
r600_context_queries_resume(&rctx->ctx);
rctx->blit = false;
}
@@ -107,7 +128,7 @@ void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_t
rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635)
depth = 0.0f;
- r600_blitter_begin(ctx, R600_CLEAR_SURFACE);
+ r600_blitter_begin(ctx, R600_DECOMPRESS);
util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth);
r600_blitter_end(ctx);
@@ -273,6 +294,8 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
{
struct r600_resource_texture *rsrc = (struct r600_resource_texture*)src;
struct texture_orig_info orig_info[2];
+ struct pipe_box sbox;
+ const struct pipe_box *psbox;
boolean restore_orig[2];
/* Fallback for buffers. */
@@ -290,7 +313,15 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
if (util_format_is_compressed(src->format)) {
r600_compressed_to_blittable(src, src_level, &orig_info[0]);
restore_orig[0] = TRUE;
- }
+ sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x);
+ sbox.y = util_format_get_nblocksy(orig_info[0].format, src_box->y);
+ sbox.z = src_box->z;
+ sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width);
+ sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height);
+ sbox.depth = src_box->depth;
+ psbox=&sbox;
+ } else
+ psbox=src_box;
if (util_format_is_compressed(dst->format)) {
r600_compressed_to_blittable(dst, dst_level, &orig_info[1]);
@@ -301,7 +332,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
}
r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
- src, src_level, src_box);
+ src, src_level, psbox);
if (restore_orig[0])
r600_reset_blittable_to_compressed(src, src_level, &orig_info[0]);
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 16fe6c54a15..8f3a175587e 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -126,9 +126,6 @@ static void r600_flush(struct pipe_context *ctx,
if (rfence)
*rfence = r600_create_fence(rctx);
- if (!rctx->ctx.pm4_cdwords)
- return;
-
#if 0
sprintf(dname, "gallium-%08d.bof", dc);
if (dc < 20) {
@@ -376,6 +373,8 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
case PIPE_CAP_SM3:
+ case PIPE_CAP_SEAMLESS_CUBE_MAP:
+ case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
return 1;
/* Supported except the original R600. */
@@ -385,14 +384,12 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
return family == CHIP_R600 ? 0 : 1;
/* Supported on Evergreen. */
- case PIPE_CAP_SEAMLESS_CUBE_MAP:
case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
return family >= CHIP_CEDAR ? 1 : 0;
/* Unsupported features. */
case PIPE_CAP_STREAM_OUTPUT:
case PIPE_CAP_PRIMITIVE_RESTART:
- case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
case PIPE_CAP_TGSI_INSTANCEID:
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
@@ -481,9 +478,9 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, e
return 8; /* FIXME */
case PIPE_SHADER_CAP_MAX_INPUTS:
if(shader == PIPE_SHADER_FRAGMENT)
- return 10;
+ return 34;
else
- return 16;
+ return 32;
case PIPE_SHADER_CAP_MAX_TEMPS:
return 256; /* Max native temporaries. */
case PIPE_SHADER_CAP_MAX_ADDRS:
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 5e534ca905c..2667c80bcef 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -50,6 +50,7 @@ enum r600_pipe_state_id {
R600_PIPE_STATE_BLEND = 0,
R600_PIPE_STATE_BLEND_COLOR,
R600_PIPE_STATE_CONFIG,
+ R600_PIPE_STATE_SEAMLESS_CUBEMAP,
R600_PIPE_STATE_CLIP,
R600_PIPE_STATE_SCISSOR,
R600_PIPE_STATE_VIEWPORT,
@@ -87,6 +88,8 @@ struct r600_pipe_sampler_view {
struct r600_pipe_rasterizer {
struct r600_pipe_state rstate;
+ boolean clamp_vertex_color;
+ boolean clamp_fragment_color;
boolean flatshade;
unsigned sprite_coord_enable;
float offset_units;
@@ -124,6 +127,12 @@ struct r600_pipe_shader {
struct r600_bo *bo;
struct r600_bo *bo_fetch;
struct r600_vertex_element vertex_elements;
+ struct tgsi_token *tokens;
+};
+
+struct r600_pipe_sampler_state {
+ struct r600_pipe_state rstate;
+ boolean seamless_cube_map;
};
/* needed for blitter save */
@@ -191,12 +200,20 @@ struct r600_pipe_context {
struct r600_pipe_rasterizer *rasterizer;
struct r600_pipe_state vgt;
struct r600_pipe_state spi;
+ struct pipe_query *current_render_cond;
+ unsigned current_render_cond_mode;
+ struct pipe_query *saved_render_cond;
+ unsigned saved_render_cond_mode;
/* shader information */
+ boolean clamp_vertex_color;
+ boolean clamp_fragment_color;
+ boolean spi_dirty;
unsigned sprite_coord_enable;
boolean flatshade;
boolean export_16bpc;
unsigned alpha_ref;
boolean alpha_ref_dirty;
+ unsigned nr_cbufs;
struct r600_textures_info ps_samplers;
struct r600_pipe_fences fences;
@@ -254,7 +271,7 @@ void r600_init_query_functions(struct r600_pipe_context *rctx);
void r600_init_context_resource_functions(struct r600_pipe_context *r600);
/* r600_shader.c */
-int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens);
+int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader);
void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
int r600_find_vs_semantic_index(struct r600_shader *vs,
struct r600_shader *ps, int id);
diff --git a/src/gallium/drivers/r600/r600_query.c b/src/gallium/drivers/r600/r600_query.c
index 181ea3f9e49..bedb48b6031 100644
--- a/src/gallium/drivers/r600/r600_query.c
+++ b/src/gallium/drivers/r600/r600_query.c
@@ -75,6 +75,9 @@ static void r600_render_condition(struct pipe_context *ctx,
struct r600_query *rquery = (struct r600_query *)query;
int wait_flag = 0;
+ rctx->current_render_cond = query;
+ rctx->current_render_cond_mode = mode;
+
if (!query) {
rctx->ctx.predicate_drawing = false;
r600_query_predication(&rctx->ctx, NULL, PREDICATION_OP_CLEAR, 1);
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index b8a86b03143..f83d7079b29 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -118,9 +118,9 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *s
return 0;
}
-static int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader);
+static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pipe_shader *pipeshader);
-int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens)
+int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader)
{
static int dump_shaders = -1;
struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
@@ -133,10 +133,10 @@ int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *s
if (dump_shaders) {
fprintf(stderr, "--------------------------------------------------------------\n");
- tgsi_dump(tokens, 0);
+ tgsi_dump(shader->tokens, 0);
}
shader->shader.family = r600_get_family(rctx->radeon);
- r = r600_shader_from_tgsi(tokens, &shader->shader);
+ r = r600_shader_from_tgsi(rctx, shader);
if (r) {
R600_ERR("translation from TGSI failed !\n");
return r;
@@ -159,6 +159,8 @@ void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader
r600_bo_reference(rctx->radeon, &shader->bo, NULL);
r600_bc_clear(&shader->shader.bc);
+
+ memset(&shader->shader,0,sizeof(struct r600_shader));
}
/*
@@ -594,15 +596,17 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx)
return 0;
}
-static int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader)
+static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pipe_shader *pipeshader)
{
+ struct r600_shader *shader = &pipeshader->shader;
+ struct tgsi_token *tokens = pipeshader->tokens;
struct tgsi_full_immediate *immediate;
struct tgsi_full_property *property;
struct r600_shader_ctx ctx;
struct r600_bc_output output[32];
unsigned output_done, noutput;
unsigned opcode;
- int i, r = 0, pos0;
+ int i, j, r = 0, pos0;
ctx.bc = &shader->bc;
ctx.shader = shader;
@@ -616,6 +620,11 @@ static int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_sh
shader->processor_type = ctx.type;
ctx.bc->type = shader->processor_type;
+ shader->clamp_color = (((ctx.type == TGSI_PROCESSOR_FRAGMENT) && rctx->clamp_fragment_color) ||
+ ((ctx.type == TGSI_PROCESSOR_VERTEX) && rctx->clamp_vertex_color));
+
+ shader->nr_cbufs = rctx->nr_cbufs;
+
/* register allocations */
/* Values [0,127] correspond to GPR[0..127].
* Values [128,159] correspond to constant buffer bank 0
@@ -725,52 +734,103 @@ static int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_sh
goto out_err;
}
}
- /* export output */
+
noutput = shader->noutput;
+
+ /* clamp color outputs */
+ if (shader->clamp_color) {
+ for (i = 0; i < noutput; i++) {
+ if (shader->output[i].name == TGSI_SEMANTIC_COLOR ||
+ shader->output[i].name == TGSI_SEMANTIC_BCOLOR) {
+
+ int j;
+ for (j = 0; j < 4; j++) {
+ struct r600_bc_alu alu;
+ memset(&alu, 0, sizeof(struct r600_bc_alu));
+
+ /* MOV_SAT R, R */
+ alu.inst = BC_INST(ctx.bc, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
+ alu.dst.sel = shader->output[i].gpr;
+ alu.dst.chan = j;
+ alu.dst.write = 1;
+ alu.dst.clamp = 1;
+ alu.src[0].sel = alu.dst.sel;
+ alu.src[0].chan = j;
+
+ if (j == 3) {
+ alu.last = 1;
+ }
+ r = r600_bc_add_alu(ctx.bc, &alu);
+ if (r)
+ return r;
+ }
+ }
+ }
+ }
+
+ /* export output */
+ j = 0;
for (i = 0, pos0 = 0; i < noutput; i++) {
memset(&output[i], 0, sizeof(struct r600_bc_output));
- output[i].gpr = shader->output[i].gpr;
- output[i].elem_size = 3;
- output[i].swizzle_x = 0;
- output[i].swizzle_y = 1;
- output[i].swizzle_z = 2;
- output[i].swizzle_w = 3;
- output[i].burst_count = 1;
- output[i].barrier = 1;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
- output[i].array_base = i - pos0;
- output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+ output[i + j].gpr = shader->output[i].gpr;
+ output[i + j].elem_size = 3;
+ output[i + j].swizzle_x = 0;
+ output[i + j].swizzle_y = 1;
+ output[i + j].swizzle_z = 2;
+ output[i + j].swizzle_w = 3;
+ output[i + j].burst_count = 1;
+ output[i + j].barrier = 1;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+ output[i + j].array_base = i - pos0;
+ output[i + j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
switch (ctx.type) {
case TGSI_PROCESSOR_VERTEX:
if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
- output[i].array_base = 60;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
+ output[i + j].array_base = 60;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
/* position doesn't count in array_base */
pos0++;
}
if (shader->output[i].name == TGSI_SEMANTIC_PSIZE) {
- output[i].array_base = 61;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
+ output[i + j].array_base = 61;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
/* position doesn't count in array_base */
pos0++;
}
break;
case TGSI_PROCESSOR_FRAGMENT:
if (shader->output[i].name == TGSI_SEMANTIC_COLOR) {
- output[i].array_base = shader->output[i].sid;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+ output[i + j].array_base = shader->output[i].sid;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+ if (shader->fs_write_all && (shader->family >= CHIP_CEDAR)) {
+ for (j = 1; j < shader->nr_cbufs; j++) {
+ memset(&output[i + j], 0, sizeof(struct r600_bc_output));
+ output[i + j].gpr = shader->output[i].gpr;
+ output[i + j].elem_size = 3;
+ output[i + j].swizzle_x = 0;
+ output[i + j].swizzle_y = 1;
+ output[i + j].swizzle_z = 2;
+ output[i + j].swizzle_w = 3;
+ output[i + j].burst_count = 1;
+ output[i + j].barrier = 1;
+ output[i + j].array_base = shader->output[i].sid + j;
+ output[i + j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+ }
+ j--;
+ }
} else if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
- output[i].array_base = 61;
- output[i].swizzle_x = 2;
- output[i].swizzle_y = 7;
- output[i].swizzle_z = output[i].swizzle_w = 7;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+ output[i + j].array_base = 61;
+ output[i + j].swizzle_x = 2;
+ output[i + j].swizzle_y = 7;
+ output[i + j].swizzle_z = output[i + j].swizzle_w = 7;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
} else if (shader->output[i].name == TGSI_SEMANTIC_STENCIL) {
- output[i].array_base = 61;
- output[i].swizzle_x = 7;
- output[i].swizzle_y = 1;
- output[i].swizzle_z = output[i].swizzle_w = 7;
- output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+ output[i + j].array_base = 61;
+ output[i + j].swizzle_x = 7;
+ output[i + j].swizzle_y = 1;
+ output[i + j].swizzle_z = output[i + j].swizzle_w = 7;
+ output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
} else {
R600_ERR("unsupported fragment output name %d\n", shader->output[i].name);
r = -EINVAL;
@@ -783,6 +843,7 @@ static int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_sh
goto out_err;
}
}
+ noutput += j;
/* add fake param output for vertex shader if no param is exported */
if (ctx.type == TGSI_PROCESSOR_VERTEX) {
for (i = 0, pos0 = 0; i < noutput; i++) {
@@ -1303,41 +1364,6 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
struct r600_bc_alu alu;
int r;
- /* dst.x, <- 1.0 */
- memset(&alu, 0, sizeof(struct r600_bc_alu));
- alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
- alu.src[0].sel = V_SQ_ALU_SRC_1; /*1.0*/
- alu.src[0].chan = 0;
- tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst);
- alu.dst.write = (inst->Dst[0].Register.WriteMask >> 0) & 1;
- r = r600_bc_add_alu(ctx->bc, &alu);
- if (r)
- return r;
-
- /* dst.y = max(src.x, 0.0) */
- memset(&alu, 0, sizeof(struct r600_bc_alu));
- alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX);
- r600_bc_src(&alu.src[0], &ctx->src[0], 0);
- alu.src[1].sel = V_SQ_ALU_SRC_0; /*0.0*/
- alu.src[1].chan = 0;
- tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst);
- alu.dst.write = (inst->Dst[0].Register.WriteMask >> 1) & 1;
- r = r600_bc_add_alu(ctx->bc, &alu);
- if (r)
- return r;
-
- /* dst.w, <- 1.0 */
- memset(&alu, 0, sizeof(struct r600_bc_alu));
- alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
- alu.src[0].sel = V_SQ_ALU_SRC_1;
- alu.src[0].chan = 0;
- tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst);
- alu.dst.write = (inst->Dst[0].Register.WriteMask >> 3) & 1;
- alu.last = 1;
- r = r600_bc_add_alu(ctx->bc, &alu);
- if (r)
- return r;
-
if (inst->Dst[0].Register.WriteMask & (1 << 2))
{
int chan;
@@ -1366,7 +1392,9 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
memset(&alu, 0, sizeof(struct r600_bc_alu));
alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED);
r600_bc_src(&alu.src[0], &ctx->src[0], 1);
- tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst);
+ alu.dst.sel = ctx->temp_reg;
+ alu.dst.chan = 2;
+ alu.dst.write = 1;
alu.last = 1;
r = r600_bc_add_alu(ctx->bc, &alu);
if (r)
@@ -1423,6 +1451,42 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
return r;
}
}
+
+ /* dst.x, <- 1.0 */
+ memset(&alu, 0, sizeof(struct r600_bc_alu));
+ alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
+ alu.src[0].sel = V_SQ_ALU_SRC_1; /*1.0*/
+ alu.src[0].chan = 0;
+ tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst);
+ alu.dst.write = (inst->Dst[0].Register.WriteMask >> 0) & 1;
+ r = r600_bc_add_alu(ctx->bc, &alu);
+ if (r)
+ return r;
+
+ /* dst.y = max(src.x, 0.0) */
+ memset(&alu, 0, sizeof(struct r600_bc_alu));
+ alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX);
+ r600_bc_src(&alu.src[0], &ctx->src[0], 0);
+ alu.src[1].sel = V_SQ_ALU_SRC_0; /*0.0*/
+ alu.src[1].chan = 0;
+ tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst);
+ alu.dst.write = (inst->Dst[0].Register.WriteMask >> 1) & 1;
+ r = r600_bc_add_alu(ctx->bc, &alu);
+ if (r)
+ return r;
+
+ /* dst.w, <- 1.0 */
+ memset(&alu, 0, sizeof(struct r600_bc_alu));
+ alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
+ alu.src[0].sel = V_SQ_ALU_SRC_1;
+ alu.src[0].chan = 0;
+ tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst);
+ alu.dst.write = (inst->Dst[0].Register.WriteMask >> 3) & 1;
+ alu.last = 1;
+ r = r600_bc_add_alu(ctx->bc, &alu);
+ if (r)
+ return r;
+
return 0;
}
@@ -3266,7 +3330,7 @@ static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = {
{TGSI_OPCODE_MOV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
{TGSI_OPCODE_LIT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit},
{TGSI_OPCODE_RCP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE, tgsi_trans_srcx_replicate},
- {TGSI_OPCODE_RSQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_trans_srcx_replicate},
+ {TGSI_OPCODE_RSQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_rsq},
{TGSI_OPCODE_EXP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp},
{TGSI_OPCODE_LOG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_log},
{TGSI_OPCODE_MUL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2},
diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h
index 8f96ce5085c..76aebf2b1ea 100644
--- a/src/gallium/drivers/r600/r600_shader.h
+++ b/src/gallium/drivers/r600/r600_shader.h
@@ -46,6 +46,8 @@ struct r600_shader {
enum radeon_family family;
boolean uses_kill;
boolean fs_write_all;
+ boolean clamp_color;
+ unsigned nr_cbufs;
};
#endif
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index d927e4a945e..be07f5feff8 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -299,6 +299,8 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
}
rstate = &rs->rstate;
+ rs->clamp_vertex_color = state->clamp_vertex_color;
+ rs->clamp_fragment_color = state->clamp_fragment_color;
rs->flatshade = state->flatshade;
rs->sprite_coord_enable = state->sprite_coord_enable;
@@ -369,14 +371,17 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
static void *r600_create_sampler_state(struct pipe_context *ctx,
const struct pipe_sampler_state *state)
{
- struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+ struct r600_pipe_sampler_state *ss = CALLOC_STRUCT(r600_pipe_sampler_state);
+ struct r600_pipe_state *rstate;
union util_color uc;
unsigned aniso_flag_offset = state->max_anisotropy > 1 ? 4 : 0;
- if (rstate == NULL) {
+ if (ss == NULL) {
return NULL;
}
+ ss->seamless_cube_map = state->seamless_cube_map;
+ rstate = &ss->rstate;
rstate->id = R600_PIPE_STATE_SAMPLER;
util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
r600_pipe_state_add_reg_noblock(rstate, R_03C000_SQ_TEX_SAMPLER_WORD0_0,
@@ -559,27 +564,57 @@ static void r600_set_ps_sampler_view(struct pipe_context *ctx, unsigned count,
rctx->ps_samplers.n_views = count;
}
+static void r600_set_seamless_cubemap(struct r600_pipe_context *rctx, boolean enable)
+{
+ struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+ if (rstate == NULL)
+ return;
+
+ rstate->id = R600_PIPE_STATE_SEAMLESS_CUBEMAP;
+ r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX,
+ (enable ? 0 : S_009508_DISABLE_CUBE_WRAP(1)),
+ 1, NULL);
+
+ free(rctx->states[R600_PIPE_STATE_SEAMLESS_CUBEMAP]);
+ rctx->states[R600_PIPE_STATE_SEAMLESS_CUBEMAP] = rstate;
+ r600_context_pipe_state_set(&rctx->ctx, rstate);
+}
+
static void r600_bind_ps_sampler(struct pipe_context *ctx, unsigned count, void **states)
{
struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
- struct r600_pipe_state **rstates = (struct r600_pipe_state **)states;
+ struct r600_pipe_sampler_state **sstates = (struct r600_pipe_sampler_state **)states;
+ int seamless = -1;
memcpy(rctx->ps_samplers.samplers, states, sizeof(void*) * count);
rctx->ps_samplers.n_samplers = count;
for (int i = 0; i < count; i++) {
- r600_context_pipe_state_set_ps_sampler(&rctx->ctx, rstates[i], i);
+ r600_context_pipe_state_set_ps_sampler(&rctx->ctx, &sstates[i]->rstate, i);
+
+ if (sstates[i])
+ seamless = sstates[i]->seamless_cube_map;
}
+
+ if (seamless != -1)
+ r600_set_seamless_cubemap(rctx, seamless);
}
static void r600_bind_vs_sampler(struct pipe_context *ctx, unsigned count, void **states)
{
struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
- struct r600_pipe_state **rstates = (struct r600_pipe_state **)states;
+ struct r600_pipe_sampler_state **sstates = (struct r600_pipe_sampler_state **)states;
+ int seamless = -1;
for (int i = 0; i < count; i++) {
- r600_context_pipe_state_set_vs_sampler(&rctx->ctx, rstates[i], i);
+ r600_context_pipe_state_set_vs_sampler(&rctx->ctx, &sstates[i]->rstate, i);
+
+ if (sstates[i])
+ seamless = sstates[i]->seamless_cube_map;
}
+
+ if (seamless != -1)
+ r600_set_seamless_cubemap(rctx, seamless);
}
static void r600_set_clip_state(struct pipe_context *ctx,
@@ -1290,14 +1325,22 @@ void r600_init_config(struct r600_pipe_context *rctx)
if (family >= CHIP_RV770) {
r600_pipe_state_add_reg(rstate, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0x00004000, 0xFFFFFFFF, NULL);
- r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX, 0x07000002, 0xFFFFFFFF, NULL);
+ r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX,
+ S_009508_DISABLE_CUBE_ANISO(1) |
+ S_009508_SYNC_GRADIENT(1) |
+ S_009508_SYNC_WALKER(1) |
+ S_009508_SYNC_ALIGNER(1), 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_009830_DB_DEBUG, 0x00000000, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_009838_DB_WATERMARKS, 0x00420204, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_0286C8_SPI_THREAD_GROUPING, 0x00000000, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_028A4C_PA_SC_MODE_CNTL, 0x00514002, 0xFFFFFFFF, NULL);
} else {
r600_pipe_state_add_reg(rstate, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0x00000000, 0xFFFFFFFF, NULL);
- r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX, 0x07000003, 0xFFFFFFFF, NULL);
+ r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX,
+ S_009508_DISABLE_CUBE_ANISO(1) |
+ S_009508_SYNC_GRADIENT(1) |
+ S_009508_SYNC_WALKER(1) |
+ S_009508_SYNC_ALIGNER(1), 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_009830_DB_DEBUG, 0x82000000, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_009838_DB_WATERMARKS, 0x01020204, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_0286C8_SPI_THREAD_GROUPING, 0x00000001, 0xFFFFFFFF, NULL);
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index fa0c5cb89d7..d9140403e5a 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -28,6 +28,7 @@
#include <util/u_format.h>
#include <pipebuffer/pb_buffer.h>
#include "pipe/p_shader_tokens.h"
+#include "tgsi/tgsi_parse.h"
#include "r600_formats.h"
#include "r600_pipe.h"
#include "r600d.h"
@@ -99,6 +100,8 @@ void r600_bind_rs_state(struct pipe_context *ctx, void *state)
if (state == NULL)
return;
+ rctx->clamp_vertex_color = rs->clamp_vertex_color;
+ rctx->clamp_fragment_color = rs->clamp_fragment_color;
rctx->flatshade = rs->flatshade;
rctx->sprite_coord_enable = rs->sprite_coord_enable;
rctx->rasterizer = rs;
@@ -112,7 +115,7 @@ void r600_bind_rs_state(struct pipe_context *ctx, void *state)
r600_polygon_offset_update(rctx);
}
if (rctx->ps_shader && rctx->vs_shader)
- r600_spi_update(rctx);
+ rctx->spi_dirty = true;
}
void r600_delete_rs_state(struct pipe_context *ctx, void *state)
@@ -257,7 +260,9 @@ void *r600_create_shader_state(struct pipe_context *ctx,
struct r600_pipe_shader *shader = CALLOC_STRUCT(r600_pipe_shader);
int r;
- r = r600_pipe_shader_create(ctx, shader, state->tokens);
+ shader->tokens = tgsi_dup_tokens(state->tokens);
+
+ r = r600_pipe_shader_create(ctx, shader);
if (r) {
return NULL;
}
@@ -274,7 +279,7 @@ void r600_bind_ps_shader(struct pipe_context *ctx, void *state)
r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_shader->rstate);
}
if (rctx->ps_shader && rctx->vs_shader) {
- r600_spi_update(rctx);
+ rctx->spi_dirty = true;
r600_adjust_gprs(rctx);
}
}
@@ -289,7 +294,7 @@ void r600_bind_vs_shader(struct pipe_context *ctx, void *state)
r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_shader->rstate);
}
if (rctx->ps_shader && rctx->vs_shader) {
- r600_spi_update(rctx);
+ rctx->spi_dirty = true;
r600_adjust_gprs(rctx);
}
}
@@ -303,6 +308,7 @@ void r600_delete_ps_shader(struct pipe_context *ctx, void *state)
rctx->ps_shader = NULL;
}
+ free(shader->tokens);
r600_pipe_shader_destroy(ctx, shader);
free(shader);
}
@@ -316,6 +322,7 @@ void r600_delete_vs_shader(struct pipe_context *ctx, void *state)
rctx->vs_shader = NULL;
}
+ free(shader->tokens);
r600_pipe_shader_destroy(ctx, shader);
free(shader);
}
@@ -351,7 +358,7 @@ static void r600_spi_update(struct r600_pipe_context *rctx)
struct r600_pipe_shader *shader = rctx->ps_shader;
struct r600_pipe_state *rstate = &rctx->spi;
struct r600_shader *rshader = &shader->shader;
- unsigned i, tmp;
+ unsigned i, tmp, sid;
if (rctx->spi.id == 0)
r600_spi_block_init(rctx, &rctx->spi);
@@ -360,9 +367,14 @@ static void r600_spi_update(struct r600_pipe_context *rctx)
for (i = 0; i < rshader->ninput; i++) {
if (rshader->input[i].name == TGSI_SEMANTIC_POSITION ||
rshader->input[i].name == TGSI_SEMANTIC_FACE)
- continue;
+ if (rctx->family >= CHIP_CEDAR)
+ continue;
+ else
+ sid=0;
+ else
+ sid=r600_find_vs_semantic_index(&rctx->vs_shader->shader, rshader, i);
- tmp = S_028644_SEMANTIC(r600_find_vs_semantic_index(&rctx->vs_shader->shader, rshader, i));
+ tmp = S_028644_SEMANTIC(sid);
if (rshader->input[i].name == TGSI_SEMANTIC_COLOR ||
rshader->input[i].name == TGSI_SEMANTIC_BCOLOR ||
@@ -386,6 +398,7 @@ static void r600_spi_update(struct r600_pipe_context *rctx)
r600_pipe_state_mod_reg(rstate, tmp);
}
+ rctx->spi_dirty = false;
r600_context_pipe_state_set(&rctx->ctx, rstate);
}
@@ -525,24 +538,39 @@ static void r600_vertex_buffer_update(struct r600_pipe_context *rctx)
}
}
+static int r600_shader_rebuild(struct pipe_context * ctx, struct r600_pipe_shader * shader)
+{
+ struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
+ int r;
+
+ r600_pipe_shader_destroy(ctx, shader);
+ r = r600_pipe_shader_create(ctx, shader);
+ if (r) {
+ return r;
+ }
+ r600_context_pipe_state_set(&rctx->ctx, &shader->rstate);
+
+ return 0;
+}
+
void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
{
struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
struct r600_resource *rbuffer;
- u32 vgt_dma_index_type, vgt_dma_swap_mode, vgt_draw_initiator, mask;
struct r600_draw rdraw;
- struct r600_drawl draw = {};
- unsigned prim;
+ struct r600_drawl draw;
+ unsigned prim, mask;
if (!rctx->blit) {
if (rctx->have_depth_fb || rctx->have_depth_texture)
r600_flush_depth_textures(rctx);
}
- u_vbuf_mgr_draw_begin(rctx->vbuf_mgr, info, NULL, NULL);
+ u_vbuf_mgr_draw_begin(rctx->vbuf_mgr, info);
r600_vertex_buffer_update(rctx);
draw.info = *info;
draw.ctx = ctx;
+ draw.index_buffer = NULL;
if (info->indexed && rctx->index_buffer.buffer) {
draw.info.start += rctx->index_buffer.offset / rctx->index_buffer.index_size;
pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer);
@@ -560,57 +588,29 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
r600_upload_index_buffer(rctx, &draw);
}
} else {
+ draw.index_size = 0;
+ draw.index_buffer_offset = 0;
draw.info.index_bias = info->start;
}
- vgt_dma_swap_mode = 0;
- switch (draw.index_size) {
- case 2:
- vgt_draw_initiator = 0;
- vgt_dma_index_type = 0;
- if (R600_BIG_ENDIAN) {
- vgt_dma_swap_mode = ENDIAN_8IN16;
- }
- break;
- case 4:
- vgt_draw_initiator = 0;
- vgt_dma_index_type = 1;
- if (R600_BIG_ENDIAN) {
- vgt_dma_swap_mode = ENDIAN_8IN32;
- }
- break;
- case 0:
- vgt_draw_initiator = 2;
- vgt_dma_index_type = 0;
- break;
- default:
- R600_ERR("unsupported index size %d\n", draw.index_size);
- return;
- }
if (r600_conv_pipe_prim(draw.info.mode, &prim))
return;
- if (unlikely(rctx->ps_shader == NULL)) {
- R600_ERR("missing vertex shader\n");
- return;
- }
- if (unlikely(rctx->vs_shader == NULL)) {
- R600_ERR("missing vertex shader\n");
- return;
- }
- /* there should be enough input */
- if (rctx->vertex_elements->count < rctx->vs_shader->shader.bc.nresource) {
- R600_ERR("%d resources provided, expecting %d\n",
- rctx->vertex_elements->count, rctx->vs_shader->shader.bc.nresource);
- return;
- }
+
+ if (rctx->vs_shader->shader.clamp_color != rctx->clamp_vertex_color)
+ r600_shader_rebuild(ctx, rctx->vs_shader);
+
+ if ((rctx->ps_shader->shader.clamp_color != rctx->clamp_fragment_color) ||
+ ((rctx->family >= CHIP_CEDAR) && rctx->ps_shader->shader.fs_write_all &&
+ (rctx->ps_shader->shader.nr_cbufs != rctx->nr_cbufs)))
+ r600_shader_rebuild(ctx, rctx->ps_shader);
+
+ if (rctx->spi_dirty)
+ r600_spi_update(rctx);
if (rctx->alpha_ref_dirty)
r600_update_alpha_ref(rctx);
- mask = 0;
- for (int i = 0; i < rctx->framebuffer.nr_cbufs; i++) {
- mask |= (0xF << (i * 4));
- }
+ mask = (1ULL << ((unsigned)rctx->framebuffer.nr_cbufs * 4)) - 1;
if (rctx->vgt.id != R600_PIPE_STATE_VGT) {
rctx->vgt.id = R600_PIPE_STATE_VGT;
@@ -644,8 +644,10 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
rdraw.vgt_num_indices = draw.info.count;
rdraw.vgt_num_instances = draw.info.instance_count;
- rdraw.vgt_index_type = vgt_dma_index_type | (vgt_dma_swap_mode << 2);
- rdraw.vgt_draw_initiator = vgt_draw_initiator;
+ rdraw.vgt_index_type = ((draw.index_size == 4) ? 1 : 0);
+ if (R600_BIG_ENDIAN)
+ rdraw.vgt_index_type |= (draw.index_size >> 1) << 2;
+ rdraw.vgt_draw_initiator = draw.index_size ? 0 : 2;
rdraw.indices = NULL;
if (draw.index_buffer) {
rbuffer = (struct r600_resource*)draw.index_buffer;
diff --git a/src/gallium/drivers/r600/r600_state_inlines.h b/src/gallium/drivers/r600/r600_state_inlines.h
index 5418570756f..eb6fb6594b2 100644
--- a/src/gallium/drivers/r600/r600_state_inlines.h
+++ b/src/gallium/drivers/r600/r600_state_inlines.h
@@ -319,6 +319,7 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format)
return V_0280A0_SWAP_STD;
case PIPE_FORMAT_R16_UNORM:
+ case PIPE_FORMAT_R16_FLOAT:
return V_0280A0_SWAP_STD;
/* 32-bit buffers. */
@@ -423,6 +424,9 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format)
case PIPE_FORMAT_R16_UNORM:
return V_0280A0_COLOR_16;
+ case PIPE_FORMAT_R16_FLOAT:
+ return V_0280A0_COLOR_16_FLOAT;
+
/* 32-bit buffers. */
case PIPE_FORMAT_A8B8G8R8_SRGB:
case PIPE_FORMAT_A8B8G8R8_UNORM:
diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c
index 470d26e2c9f..8e75d847dc5 100644
--- a/src/gallium/drivers/r600/r600_texture.c
+++ b/src/gallium/drivers/r600/r600_texture.c
@@ -243,10 +243,11 @@ static void r600_setup_miptree(struct pipe_screen *screen,
struct radeon *radeon = (struct radeon *)screen->winsys;
enum chip_class chipc = r600_get_family_class(radeon);
unsigned size, layer_size, i, offset;
- unsigned nblocksx, nblocksy;
+ unsigned nblocksx, nblocksy, extra_size = 0;
for (i = 0, offset = 0; i <= ptex->last_level; i++) {
unsigned blocksize = util_format_get_blocksize(ptex->format);
+ unsigned base_align = r600_get_base_alignment(screen, ptex->format, array_mode);
r600_texture_set_array_mode(screen, rtex, i, array_mode);
@@ -265,9 +266,13 @@ static void r600_setup_miptree(struct pipe_screen *screen,
else
size = layer_size * ptex->array_size;
+ /* evergreen stores depth and stencil separately */
+ if ((chipc >= EVERGREEN) && util_format_is_depth_or_stencil(ptex->format))
+ extra_size = align(extra_size + (nblocksx * nblocksy * 1), base_align);
+
/* align base image and start of miptree */
if ((i == 0) || (i == 1))
- offset = align(offset, r600_get_base_alignment(screen, ptex->format, array_mode));
+ offset = align(offset, base_align);
rtex->offset[i] = offset;
rtex->layer_size[i] = layer_size;
rtex->pitch_in_blocks[i] = nblocksx; /* CB talks in elements */
@@ -275,7 +280,7 @@ static void r600_setup_miptree(struct pipe_screen *screen,
offset += size;
}
- rtex->size = offset;
+ rtex->size = offset + extra_size;
}
/* Figure out whether u_blitter will fallback to a transfer operation.
diff --git a/src/gallium/drivers/r600/r600d.h b/src/gallium/drivers/r600/r600d.h
index 6373572b65f..f6eec24cc05 100644
--- a/src/gallium/drivers/r600/r600d.h
+++ b/src/gallium/drivers/r600/r600d.h
@@ -2556,6 +2556,9 @@
#define S_009508_DISABLE_CUBE_WRAP(x) (((x) & 0x1) << 0)
#define G_009508_DISABLE_CUBE_WRAP(x) (((x) >> 0) & 0x1)
#define C_009508_DISABLE_CUBE_WRAP 0xFFFFFFFE
+#define S_009508_DISABLE_CUBE_ANISO(x) (((x) & 0x1) << 1)
+#define G_009508_DISABLE_CUBE_ANISO(x) (((x) >> 1) & 0x1)
+#define C_009508_DISABLE_CUBE_ANISO (~(1 << 1))
#define S_009508_SYNC_GRADIENT(x) (((x) & 0x1) << 24)
#define G_009508_SYNC_GRADIENT(x) (((x) >> 24) & 0x1)
#define C_009508_SYNC_GRADIENT 0xFEFFFFFF
diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index dbbc249258d..cfb1b9d8d0d 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -207,6 +207,14 @@ void svga_context_flush( struct svga_context *svga,
svga->curr.nr_fbs = 0;
+ /* Flush the upload managers to ensure recycling of upload buffers
+ * without throttling. This should really be conditioned on
+ * pipe_buffer_map_range not supporting PIPE_TRANSFER_UNSYNCHRONIZED.
+ */
+
+ u_upload_flush(svga->upload_vb);
+ u_upload_flush(svga->upload_ib);
+
/* Ensure that texture dma uploads are processed
* before submitting commands.
*/
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index eca529d262e..34b9e85c1a3 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -372,9 +372,6 @@ struct svga_context
/** List of buffers with queued transfers */
struct list_head dirty_buffers;
-
- /** Was the previous draw done with the SW path? */
- boolean prev_draw_swtnl;
};
/* A flag for each state_tracker state object:
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index d8af615ede1..aa096692888 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -145,7 +145,7 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl )
unsigned i;
/* Unmap upload manager vertex buffers */
- u_upload_flush(svga->upload_vb);
+ u_upload_unmap(svga->upload_vb);
for (i = 0; i < hwtnl->cmd.vdecl_count; i++) {
handle = svga_buffer_handle(svga, hwtnl->cmd.vdecl_vb[i]);
@@ -156,7 +156,7 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl )
}
/* Unmap upload manager index buffers */
- u_upload_flush(svga->upload_ib);
+ u_upload_unmap(svga->upload_ib);
for (i = 0; i < hwtnl->cmd.prim_count; i++) {
if (hwtnl->cmd.prim_ib[i]) {
@@ -242,6 +242,11 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl )
}
+void svga_hwtnl_set_index_bias( struct svga_hwtnl *hwtnl,
+ int index_bias)
+{
+ hwtnl->index_bias = index_bias;
+}
@@ -265,15 +270,16 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl,
unsigned size = vb ? vb->width0 : 0;
unsigned offset = hwtnl->cmd.vdecl[i].array.offset;
unsigned stride = hwtnl->cmd.vdecl[i].array.stride;
- unsigned index_bias = range->indexBias;
+ int index_bias = (int) range->indexBias + hwtnl->index_bias;
unsigned width;
assert(vb);
assert(size);
assert(offset < size);
- assert(index_bias >= 0);
assert(min_index <= max_index);
- assert(offset + index_bias*stride < size);
+ if (index_bias >= 0) {
+ assert(offset + index_bias*stride < size);
+ }
if (min_index != ~0) {
assert(offset + (index_bias + min_index) * stride < size);
}
@@ -394,6 +400,7 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl,
hwtnl->cmd.max_index[hwtnl->cmd.prim_count] = max_index;
hwtnl->cmd.prim[hwtnl->cmd.prim_count] = *range;
+ hwtnl->cmd.prim[hwtnl->cmd.prim_count].indexBias += hwtnl->index_bias;
pipe_resource_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib);
hwtnl->cmd.prim_count++;
diff --git a/src/gallium/drivers/svga/svga_draw.h b/src/gallium/drivers/svga/svga_draw.h
index a2403d802be..1dac17421e1 100644
--- a/src/gallium/drivers/svga/svga_draw.h
+++ b/src/gallium/drivers/svga/svga_draw.h
@@ -79,5 +79,8 @@ svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl,
enum pipe_error
svga_hwtnl_flush( struct svga_hwtnl *hwtnl );
+void svga_hwtnl_set_index_bias( struct svga_hwtnl *hwtnl,
+ int index_bias);
+
#endif /* SVGA_DRAW_H_ */
diff --git a/src/gallium/drivers/svga/svga_draw_private.h b/src/gallium/drivers/svga/svga_draw_private.h
index ca658ac6745..8126f7ee23c 100644
--- a/src/gallium/drivers/svga/svga_draw_private.h
+++ b/src/gallium/drivers/svga/svga_draw_private.h
@@ -116,6 +116,13 @@ struct draw_cmd {
struct svga_hwtnl {
struct svga_context *svga;
struct u_upload_mgr *upload_ib;
+
+ /* Additional negative index bias due to partial buffer uploads
+ * This is compensated for in the offset associated with all
+ * vertex buffers.
+ */
+
+ int index_bias;
/* Flatshade information:
*/
diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c
index 2093bcae101..d53edcb23c5 100644
--- a/src/gallium/drivers/svga/svga_pipe_draw.c
+++ b/src/gallium/drivers/svga/svga_pipe_draw.c
@@ -25,6 +25,7 @@
#include "svga_cmd.h"
+#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_prim.h"
#include "util/u_time.h"
@@ -37,6 +38,178 @@
#include "svga_state.h"
#include "svga_swtnl.h"
#include "svga_debug.h"
+#include "svga_resource_buffer.h"
+#include "util/u_upload_mgr.h"
+
+/**
+ * Determine the ranges to upload for the user-buffers referenced
+ * by the next draw command.
+ *
+ * TODO: It might be beneficial to support multiple ranges. In that case,
+ * the struct svga_buffer::uploaded member should be made an array or a
+ * list, since we need to account for the possibility that different ranges
+ * may be uploaded to different hardware buffers chosen by the utility
+ * upload manager.
+ */
+
+static void
+svga_user_buffer_range(struct svga_context *svga,
+ unsigned start,
+ unsigned count,
+ unsigned instance_count)
+{
+ const struct pipe_vertex_element *ve = svga->curr.velems->velem;
+ int i;
+
+ /*
+ * Release old uploaded range (if not done already) and
+ * initialize new ranges.
+ */
+
+ for (i=0; i < svga->curr.velems->count; i++) {
+ struct pipe_vertex_buffer *vb =
+ &svga->curr.vb[ve[i].vertex_buffer_index];
+
+ if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
+ struct svga_buffer *buffer = svga_buffer(vb->buffer);
+
+ pipe_resource_reference(&buffer->uploaded.buffer, NULL);
+ buffer->uploaded.start = ~0;
+ buffer->uploaded.end = 0;
+ }
+ }
+
+ for (i=0; i < svga->curr.velems->count; i++) {
+ struct pipe_vertex_buffer *vb =
+ &svga->curr.vb[ve[i].vertex_buffer_index];
+
+ if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
+ struct svga_buffer *buffer = svga_buffer(vb->buffer);
+ unsigned first, size;
+ unsigned instance_div = ve[i].instance_divisor;
+ unsigned elemSize = util_format_get_blocksize(ve[i].src_format);
+
+ svga->dirty |= SVGA_NEW_VBUFFER;
+
+ if (instance_div) {
+ first = ve[i].src_offset;
+ count = (instance_count + instance_div - 1) / instance_div;
+ size = vb->stride * (count - 1) + elemSize;
+ } else if (vb->stride) {
+ first = vb->stride * start + ve[i].src_offset;
+ size = vb->stride * (count - 1) + elemSize;
+ } else {
+ /* Only a single vertex!
+ * Upload with the largest vertex size the hw supports,
+ * if possible.
+ */
+ first = ve[i].src_offset;
+ size = MIN2(16, vb->buffer->width0);
+ }
+
+ buffer->uploaded.start = MIN2(buffer->uploaded.start, first);
+ buffer->uploaded.end = MAX2(buffer->uploaded.end, first + size);
+ }
+ }
+}
+
+/**
+ * svga_upload_user_buffers - upload parts of user buffers
+ *
+ * This function streams a part of a user buffer to hw and fills
+ * svga_buffer::uploaded with information on the upload.
+ */
+
+static int
+svga_upload_user_buffers(struct svga_context *svga,
+ unsigned start,
+ unsigned count,
+ unsigned instance_count)
+{
+ const struct pipe_vertex_element *ve = svga->curr.velems->velem;
+ unsigned i;
+ int ret;
+
+ svga_user_buffer_range(svga, start, count, instance_count);
+
+ for (i=0; i < svga->curr.velems->count; i++) {
+ struct pipe_vertex_buffer *vb =
+ &svga->curr.vb[ve[i].vertex_buffer_index];
+
+ if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
+ struct svga_buffer *buffer = svga_buffer(vb->buffer);
+ boolean flushed;
+
+ /*
+ * Check if already uploaded. Otherwise go ahead and upload.
+ */
+
+ if (buffer->uploaded.buffer)
+ continue;
+
+ ret = u_upload_buffer( svga->upload_vb,
+ 0,
+ buffer->uploaded.start,
+ buffer->uploaded.end - buffer->uploaded.start,
+ &buffer->b.b,
+ &buffer->uploaded.offset,
+ &buffer->uploaded.buffer,
+ &flushed);
+
+ if (ret)
+ return ret;
+
+ if (0)
+ debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sofs %d"
+ " sz %d\n",
+ __FUNCTION__,
+ i,
+ buffer,
+ buffer->uploaded.buffer,
+ buffer->uploaded.offset,
+ buffer->uploaded.start,
+ buffer->uploaded.end - buffer->uploaded.start);
+
+ vb->buffer_offset = buffer->uploaded.offset;
+ }
+ }
+
+ return PIPE_OK;
+}
+
+/**
+ * svga_release_user_upl_buffers - release uploaded parts of user buffers
+ *
+ * This function releases the hw copy of the uploaded fraction of the
+ * user-buffer. It's important to do this as soon as all draw calls
+ * affecting the uploaded fraction are issued, as this allows for
+ * efficient reuse of the hardware surface backing the uploaded fraction.
+ *
+ * svga_buffer::source_offset is set to 0, and svga_buffer::uploaded::buffer
+ * is set to 0.
+ */
+
+static void
+svga_release_user_upl_buffers(struct svga_context *svga)
+{
+ unsigned i;
+ unsigned nr;
+
+ nr = svga->curr.num_vertex_buffers;
+
+ for (i = 0; i < nr; ++i) {
+ struct pipe_vertex_buffer *vb = &svga->curr.vb[i];
+
+ if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
+ struct svga_buffer *buffer = svga_buffer(vb->buffer);
+
+ buffer->uploaded.start = ~0;
+ buffer->uploaded.end = 0;
+ if (buffer->uploaded.buffer)
+ pipe_resource_reference(&buffer->uploaded.buffer, NULL);
+ }
+ }
+}
@@ -50,6 +223,7 @@ retry_draw_range_elements( struct svga_context *svga,
unsigned prim,
unsigned start,
unsigned count,
+ unsigned instance_count,
boolean do_retry )
{
enum pipe_error ret = 0;
@@ -61,6 +235,10 @@ retry_draw_range_elements( struct svga_context *svga,
svga->curr.rast->templ.flatshade,
svga->curr.rast->templ.flatshade_first );
+ ret = svga_upload_user_buffers( svga, min_index + index_bias,
+ max_index - min_index + 1, instance_count );
+ if (ret != PIPE_OK)
+ goto retry;
ret = svga_update_state( svga, SVGA_STATE_HW_DRAW );
if (ret)
@@ -84,7 +262,7 @@ retry:
index_buffer, index_size, index_bias,
min_index, max_index,
prim, start, count,
- FALSE );
+ instance_count, FALSE );
}
return ret;
@@ -96,6 +274,7 @@ retry_draw_arrays( struct svga_context *svga,
unsigned prim,
unsigned start,
unsigned count,
+ unsigned instance_count,
boolean do_retry )
{
enum pipe_error ret;
@@ -107,6 +286,11 @@ retry_draw_arrays( struct svga_context *svga,
svga->curr.rast->templ.flatshade,
svga->curr.rast->templ.flatshade_first );
+ ret = svga_upload_user_buffers( svga, start, count, instance_count );
+
+ if (ret != PIPE_OK)
+ goto retry;
+
ret = svga_update_state( svga, SVGA_STATE_HW_DRAW );
if (ret)
goto retry;
@@ -127,6 +311,7 @@ retry:
prim,
start,
count,
+ instance_count,
FALSE );
}
@@ -141,18 +326,11 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
unsigned reduced_prim = u_reduced_prim( info->mode );
unsigned count = info->count;
enum pipe_error ret = 0;
+ boolean needed_swtnl;
if (!u_trim_pipe_prim( info->mode, &count ))
return;
- if (svga->state.sw.need_swtnl != svga->prev_draw_swtnl) {
- /* We're switching between SW and HW drawing. Do a flush to avoid
- * mixing HW and SW rendering with the same vertex buffer.
- */
- pipe->flush(pipe, NULL);
- svga->prev_draw_swtnl = svga->state.sw.need_swtnl;
- }
-
/*
* Mark currently bound target surfaces as dirty
* doesn't really matter if it is done before drawing.
@@ -167,6 +345,8 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
svga->dirty |= SVGA_NEW_REDUCED_PRIMITIVE;
}
+ needed_swtnl = svga->state.sw.need_swtnl;
+
svga_update_state_retry( svga, SVGA_STATE_NEED_SWTNL );
#ifdef DEBUG
@@ -176,6 +356,20 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
#endif
if (svga->state.sw.need_swtnl) {
+ if (!needed_swtnl) {
+ /*
+ * We're switching from HW to SW TNL. SW TNL will require mapping all
+ * currently bound vertex buffers, some of which may already be
+ * referenced in the current command buffer as result of previous HW
+ * TNL. So flush now, to prevent the context to flush while a referred
+ * vertex buffer is mapped.
+ */
+
+ svga_context_flush(svga, NULL);
+ }
+
+ /* Avoid leaking the previous hwtnl bias to swtnl */
+ svga_hwtnl_set_index_bias( svga->hwtnl, 0 );
ret = svga_swtnl_draw_vbo( svga, info );
}
else {
@@ -194,6 +388,7 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
info->mode,
info->start + offset,
info->count,
+ info->instance_count,
TRUE );
}
else {
@@ -201,10 +396,13 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
info->mode,
info->start,
info->count,
+ info->instance_count,
TRUE );
}
}
+ svga_release_user_upl_buffers( svga );
+
if (SVGA_DEBUG & DEBUG_FLUSH) {
svga_hwtnl_flush_retry( svga );
svga_context_flush(svga, NULL);
diff --git a/src/gallium/drivers/svga/svga_resource_buffer.h b/src/gallium/drivers/svga/svga_resource_buffer.h
index 95032213fa5..ca8c8d1f5ea 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.h
+++ b/src/gallium/drivers/svga/svga_resource_buffer.h
@@ -129,6 +129,12 @@ struct svga_buffer
* is the relative offset within that buffer.
*/
unsigned offset;
+
+ /**
+ * Range of user buffer that is uploaded in @buffer at @offset.
+ */
+ unsigned start;
+ unsigned end;
} uploaded;
/**
@@ -193,7 +199,11 @@ svga_buffer(struct pipe_resource *buffer)
static INLINE boolean
svga_buffer_is_user_buffer( struct pipe_resource *buffer )
{
- return svga_buffer(buffer)->user;
+ if (buffer) {
+ return svga_buffer(buffer)->user;
+ } else {
+ return FALSE;
+ }
}
diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c
index 923958674b4..a657a8bc224 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer_upload.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c
@@ -651,8 +651,6 @@ svga_redefine_user_buffer(struct pipe_context *pipe,
unsigned offset,
unsigned size)
{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_context *svga = svga_context(pipe);
struct svga_buffer *sbuf = svga_buffer(resource);
assert(sbuf->user);
@@ -661,19 +659,8 @@ svga_redefine_user_buffer(struct pipe_context *pipe,
assert(!sbuf->hwbuf);
/*
- * Release any uploaded user buffer.
- *
- * TODO: As an optimization, we could try to update the uploaded buffer
- * instead.
+ * We always treat the contents of user-buffers as volatile,
+ * so no particular action needed here.
*/
- pipe_resource_reference(&sbuf->uploaded.buffer, NULL);
-
- pipe_mutex_lock(ss->swc_mutex);
-
- sbuf->key.size.width = sbuf->b.b.width0 = offset + size;
-
- pipe_mutex_unlock(ss->swc_mutex);
-
- svga->dirty |= SVGA_NEW_VBUFFER | SVGA_NEW_VELEMENT;
}
diff --git a/src/gallium/drivers/svga/svga_state_vdecl.c b/src/gallium/drivers/svga/svga_state_vdecl.c
index 7c393a1da8d..47eab1a9739 100644
--- a/src/gallium/drivers/svga/svga_state_vdecl.c
+++ b/src/gallium/drivers/svga/svga_state_vdecl.c
@@ -38,57 +38,6 @@
#include "svga_hw_reg.h"
-static int
-upload_user_buffers( struct svga_context *svga )
-{
- enum pipe_error ret = PIPE_OK;
- int i;
- int nr;
-
- if (0)
- debug_printf("%s: %d\n", __FUNCTION__, svga->curr.num_vertex_buffers);
-
- nr = svga->curr.num_vertex_buffers;
-
- for (i = 0; i < nr; i++)
- {
- if (svga_buffer_is_user_buffer(svga->curr.vb[i].buffer))
- {
- struct svga_buffer *buffer = svga_buffer(svga->curr.vb[i].buffer);
-
- if (!buffer->uploaded.buffer) {
- boolean flushed;
- ret = u_upload_buffer( svga->upload_vb,
- 0, 0,
- buffer->b.b.width0,
- &buffer->b.b,
- &buffer->uploaded.offset,
- &buffer->uploaded.buffer,
- &flushed);
- if (ret)
- return ret;
-
- if (0)
- debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sz %d\n",
- __FUNCTION__,
- i,
- buffer,
- buffer->uploaded.buffer,
- buffer->uploaded.offset,
- buffer->b.b.width0);
- }
-
- svga->curr.vb[i].buffer_offset = buffer->uploaded.offset;
- }
- }
-
- if (0)
- debug_printf("%s: DONE\n", __FUNCTION__);
-
- return ret;
-}
-
-
/***********************************************************************
*/
@@ -99,6 +48,7 @@ static int emit_hw_vs_vdecl( struct svga_context *svga,
const struct pipe_vertex_element *ve = svga->curr.velems->velem;
SVGA3dVertexDecl decl;
unsigned i;
+ unsigned neg_bias = 0;
assert(svga->curr.velems->count >=
svga->curr.vs->base.info.file_count[TGSI_FILE_INPUT]);
@@ -106,12 +56,50 @@ static int emit_hw_vs_vdecl( struct svga_context *svga,
svga_hwtnl_reset_vdecl( svga->hwtnl,
svga->curr.velems->count );
+ /**
+ * We can't set the VDECL offset to something negative, so we
+ * must calculate a common negative additional index bias, and modify
+ * the VDECL offsets accordingly so they *all* end up positive.
+ *
+ * Note that the exact value of the negative index bias is not that
+ * important, since we compensate for it when we calculate the vertex
+ * buffer offset below. The important thing is that all vertex buffer
+ * offsets remain positive.
+ *
+ * Note that we use a negative bias variable in order to make the
+ * rounding maths more easy to follow, and to avoid int / unsigned
+ * confusion.
+ */
+
for (i = 0; i < svga->curr.velems->count; i++) {
- const struct pipe_vertex_buffer *vb = &svga->curr.vb[ve[i].vertex_buffer_index];
+ const struct pipe_vertex_buffer *vb =
+ &svga->curr.vb[ve[i].vertex_buffer_index];
+ struct svga_buffer *buffer;
+ unsigned int offset = vb->buffer_offset + ve[i].src_offset;
+ unsigned tmp_neg_bias = 0;
+
+ if (!vb->buffer)
+ continue;
+
+ buffer = svga_buffer(vb->buffer);
+ if (buffer->uploaded.start > offset) {
+ tmp_neg_bias = buffer->uploaded.start - offset;
+ if (vb->stride)
+ tmp_neg_bias = (tmp_neg_bias + vb->stride - 1) / vb->stride;
+ neg_bias = MAX2(neg_bias, tmp_neg_bias);
+ }
+ }
+
+ for (i = 0; i < svga->curr.velems->count; i++) {
+ const struct pipe_vertex_buffer *vb =
+ &svga->curr.vb[ve[i].vertex_buffer_index];
unsigned usage, index;
- struct svga_buffer *buffer = svga_buffer(vb->buffer);
+ struct svga_buffer *buffer;
+ if (!vb->buffer)
+ continue;
+ buffer= svga_buffer(vb->buffer);
svga_generate_vdecl_semantics( i, &usage, &index );
/* SVGA_NEW_VELEMENT
@@ -121,8 +109,16 @@ static int emit_hw_vs_vdecl( struct svga_context *svga,
decl.identity.usage = usage;
decl.identity.usageIndex = index;
decl.array.stride = vb->stride;
- decl.array.offset = (vb->buffer_offset +
- ve[i].src_offset);
+
+ /* Compensate for partially uploaded vbo, and
+ * for the negative index bias.
+ */
+ decl.array.offset = (vb->buffer_offset
+ + ve[i].src_offset
+ + neg_bias * vb->stride
+ - buffer->uploaded.start);
+
+ assert(decl.array.offset >= 0);
svga_hwtnl_vdecl( svga->hwtnl,
i,
@@ -131,6 +127,7 @@ static int emit_hw_vs_vdecl( struct svga_context *svga,
vb->buffer );
}
+ svga_hwtnl_set_index_bias( svga->hwtnl, -neg_bias );
return 0;
}
@@ -138,23 +135,11 @@ static int emit_hw_vs_vdecl( struct svga_context *svga,
static int emit_hw_vdecl( struct svga_context *svga,
unsigned dirty )
{
- int ret = 0;
-
/* SVGA_NEW_NEED_SWTNL
*/
if (svga->state.sw.need_swtnl)
return 0; /* Do not emit during swtnl */
- /* If we get to here, we know that we're going to draw. Upload
- * userbuffers now and try to combine multiple userbuffers from
- * multiple draw calls into a single host buffer for performance.
- */
- if (svga->curr.any_user_vertex_buffers) {
- ret = upload_user_buffers( svga );
- if (ret)
- return ret;
- }
-
return emit_hw_vs_vdecl( svga, dirty );
}
diff --git a/src/gallium/include/pipe/p_config.h b/src/gallium/include/pipe/p_config.h
index 40f6f2bcb5f..eea3d79e64b 100644
--- a/src/gallium/include/pipe/p_config.h
+++ b/src/gallium/include/pipe/p_config.h
@@ -134,8 +134,6 @@
#error Unknown Endianness
#endif
-#if !defined(PIPE_OS_EMBEDDED)
-
/*
* Auto-detect the operating system family.
*
@@ -222,7 +220,5 @@
#endif
#endif /* PIPE_OS_WINDOWS */
-#endif /* !PIPE_OS_EMBEDDED */
-
#endif /* P_CONFIG_H_ */
diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index 04fc7c6c5de..f7cc2437747 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -253,6 +253,12 @@ struct st_context_attribs
struct st_framebuffer_iface
{
/**
+ * Atomic stamp which changes when framebuffers need to be updated.
+ */
+
+ int32_t stamp;
+
+ /**
* Available for the state tracker manager to use.
*/
void *st_manager_private;
@@ -315,25 +321,6 @@ struct st_context_iface
void (*destroy)(struct st_context_iface *stctxi);
/**
- * Invalidate the current textures that was taken from a framebuffer.
- *
- * The state tracker manager calls this function to let the rendering
- * context know that it should update the textures it got from
- * st_framebuffer_iface::validate. It should do so at the latest time possible.
- * Possible right before sending triangles to the pipe context.
- *
- * For certain platforms this function might be called from a thread other
- * than the thread that the context is currently bound in, and must
- * therefore be thread safe. But it is the state tracker manager's
- * responsibility to make sure that the framebuffer is bound to the context
- * and the API context is current for the duration of this call.
- *
- * Thus reducing the sync primitive needed to a single atomic flag.
- */
- void (*notify_invalid_framebuffer)(struct st_context_iface *stctxi,
- struct st_framebuffer_iface *stfbi);
-
- /**
* Flush all drawing from context to the pipe also flushes the pipe.
*/
void (*flush)(struct st_context_iface *stctxi, unsigned flags,
diff --git a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
index 741a97f897d..0bb9d852f84 100644
--- a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
+++ b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
@@ -250,21 +250,21 @@ struct GalliumDXGIAdapter
DXGI_ADAPTER_DESC1 desc;
std::vector<ComPtr<IDXGIOutput> > outputs;
int num_outputs;
- struct native_event_handler handler;
GalliumDXGIAdapter(GalliumDXGIFactory* factory, const struct native_platform* platform, void* dpy)
{
this->parent = factory;
- /* FIXME handler should be static */
- handler.invalid_surface = handle_invalid_surface;
- handler.new_drm_screen = dxgi_loader_create_drm_screen;
- handler.new_sw_screen = dxgi_loader_create_sw_screen;
- platform->set_event_handler(&handler);
-
- display = platform->create_display(dpy, FALSE, this);
+ display = platform->create_display(dpy, FALSE);
if(!display)
- display = platform->create_display(dpy, TRUE, this);
+ display = platform->create_display(dpy, TRUE);
+ if (display) {
+ display->user_data = this;
+ if (!display->init_screen(display)) {
+ display->destroy(display);
+ display = NULL;
+ }
+ }
if(!display)
throw E_FAIL;
memset(&desc, 0, sizeof(desc));
@@ -1413,6 +1413,11 @@ struct dxgi_binding
static dxgi_binding dxgi_default_binding;
static __thread dxgi_binding dxgi_thread_binding;
+static const struct native_event_handler dxgi_event_handler = {
+ GalliumDXGIAdapter::handle_invalid_surface,
+ dxgi_loader_create_drm_screen,
+ dxgi_loader_create_sw_screen
+};
void STDMETHODCALLTYPE GalliumDXGIUseNothing()
{
@@ -1427,7 +1432,7 @@ void STDMETHODCALLTYPE GalliumDXGIUseNothing()
void STDMETHODCALLTYPE GalliumDXGIUseX11Display(Display* dpy, IGalliumDXGIBackend* backend)
{
GalliumDXGIUseNothing();
- dxgi_thread_binding.platform = native_get_x11_platform();
+ dxgi_thread_binding.platform = native_get_x11_platform(&dxgi_event_handler);
dxgi_thread_binding.display = dpy;
if(backend)
@@ -1443,7 +1448,7 @@ void STDMETHODCALLTYPE GalliumDXGIUseX11Display(Display* dpy, IGalliumDXGIBacken
void STDMETHODCALLTYPE GalliumDXGIUseDRMCard(int fd)
{
GalliumDXGIUseNothing();
- dxgi_thread_binding.platform = native_get_drm_platform();
+ dxgi_thread_binding.platform = native_get_drm_platform(&dxgi_event_handler);
dxgi_thread_binding.display = (void*)fd;
dxgi_thread_binding.backend = 0;
}
@@ -1453,7 +1458,7 @@ void STDMETHODCALLTYPE GalliumDXGIUseDRMCard(int fd)
void STDMETHODCALLTYPE GalliumDXGIUseFBDev(int fd)
{
GalliumDXGIUseNothing();
- dxgi_thread_binding.platform = native_get_fbdev_platform();
+ dxgi_thread_binding.platform = native_get_fbdev_platform(&dxgi_event_handler);
dxgi_thread_binding.display = (void*)fd;
dxgi_thread_binding.backend = 0;
}
@@ -1463,7 +1468,7 @@ void STDMETHODCALLTYPE GalliumDXGIUseFBDev(int fd)
void STDMETHODCALLTYPE GalliumDXGIUseHDC(HDC hdc, PFNHWNDRESOLVER resolver, void* resolver_cookie)
{
GalliumDXGIUseNothing();
- dxgi_thread_binding.platform = native_get_gdi_platform();
+ dxgi_thread_binding.platform = native_get_gdi_platform(&dxgi_event_handler);
dxgi_thread_binding.display = (void*)hdc;
dxgi_thread_binding.backend = 0;
}
@@ -1493,7 +1498,7 @@ void STDMETHODCALLTYPE GalliumDXGIMakeDefault()
else if(dxgi_default_binding.platform)
factory = new GalliumDXGIFactory(dxgi_default_binding.platform, dxgi_default_binding.display, dxgi_default_binding.backend);
else
- factory = new GalliumDXGIFactory(native_get_x11_platform(), NULL, NULL);
+ factory = new GalliumDXGIFactory(native_get_x11_platform(&dxgi_event_handler), NULL, NULL);
HRESULT hres = factory->QueryInterface(riid, out_factory);
factory->Release();
return hres;
diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c
index e23c1bcafaf..08bbdf96e34 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.c
+++ b/src/gallium/state_trackers/dri/common/dri_context.c
@@ -151,8 +151,6 @@ dri_unbind_context(__DRIcontext * cPriv)
if (ctx->st == ctx->stapi->get_current(ctx->stapi)) {
ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL);
stapi->make_current(stapi, NULL, NULL, NULL);
- draw->context = NULL;
- read->context = NULL;
}
}
@@ -180,12 +178,10 @@ dri_make_current(__DRIcontext * cPriv,
else if (!driDrawPriv || !driReadPriv)
return GL_FALSE;
- draw->context = ctx;
if (ctx->dPriv != driDrawPriv) {
ctx->dPriv = driDrawPriv;
draw->texture_stamp = driDrawPriv->lastStamp - 1;
}
- read->context = ctx;
if (ctx->rPriv != driReadPriv) {
ctx->rPriv = driReadPriv;
read->texture_stamp = driReadPriv->lastStamp - 1;
diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c
index 28a33ac7d07..7b8de3174be 100644
--- a/src/gallium/state_trackers/dri/common/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/common/dri_drawable.c
@@ -136,6 +136,7 @@ dri_create_buffer(__DRIscreen * sPriv,
drawable->sPriv = sPriv;
drawable->dPriv = dPriv;
dPriv->driverPrivate = (void *)drawable;
+ p_atomic_set(&drawable->base.stamp, 1);
return GL_TRUE;
fail:
diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h
index 7f1aa512ca1..fd3460dd30b 100644
--- a/src/gallium/state_trackers/dri/common/dri_drawable.h
+++ b/src/gallium/state_trackers/dri/common/dri_drawable.h
@@ -42,7 +42,6 @@ struct dri_drawable
struct st_visual stvis;
struct dri_screen *screen;
- struct dri_context *context;
/* dri */
__DRIdrawable *dPriv;
diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript
index b188f76f910..c63918a0e18 100644
--- a/src/gallium/state_trackers/dri/drm/SConscript
+++ b/src/gallium/state_trackers/dri/drm/SConscript
@@ -5,7 +5,7 @@ Import('*')
env = env.Clone()
-env.ParseConfig('pkg-config --cflags --libs libdrm')
+env.PkgUseModules(['DRM'])
env.Append(CPPPATH = [
'#/src/mapi',
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index e471e8e5be2..fe4ddb312be 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -52,13 +52,11 @@ static void
dri2_invalidate_drawable(__DRIdrawable *dPriv)
{
struct dri_drawable *drawable = dri_drawable(dPriv);
- struct dri_context *ctx = drawable->context;
dri2InvalidateDrawable(dPriv);
drawable->dPriv->lastStamp = *drawable->dPriv->pStamp;
- if (ctx)
- ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
+ p_atomic_inc(&drawable->base.stamp);
}
static const __DRI2flushExtension dri2FlushExtension = {
@@ -564,6 +562,24 @@ dri2_query_image(__DRIimage *image, int attrib, int *value)
}
}
+static __DRIimage *
+dri2_dup_image(__DRIimage *image, void *loaderPrivate)
+{
+ __DRIimage *img;
+
+ img = CALLOC_STRUCT(__DRIimageRec);
+ if (!img)
+ return NULL;
+
+ img->texture = NULL;
+ pipe_resource_reference(&img->texture, image->texture);
+ img->level = image->level;
+ img->layer = image->layer;
+ img->loader_private = loaderPrivate;
+
+ return img;
+}
+
static void
dri2_destroy_image(__DRIimage *img)
{
@@ -578,6 +594,7 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
dri2_destroy_image,
dri2_create_image,
dri2_query_image,
+ dri2_dup_image,
};
/*
diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c
index ac11f7c47f6..a1879a8f46a 100644
--- a/src/gallium/state_trackers/dri/sw/drisw.c
+++ b/src/gallium/state_trackers/dri/sw/drisw.c
@@ -103,14 +103,11 @@ drisw_present_texture(__DRIdrawable *dPriv,
static INLINE void
drisw_invalidate_drawable(__DRIdrawable *dPriv)
{
- struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
struct dri_drawable *drawable = dri_drawable(dPriv);
drawable->texture_stamp = dPriv->lastStamp - 1;
- /* check if swapping currently bound buffer */
- if (ctx && ctx->dPriv == dPriv)
- ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
+ p_atomic_inc(&drawable->base.stamp);
}
static INLINE void
diff --git a/src/gallium/state_trackers/egl/Makefile b/src/gallium/state_trackers/egl/Makefile
index 763e7b58a49..1c970222c1f 100644
--- a/src/gallium/state_trackers/egl/Makefile
+++ b/src/gallium/state_trackers/egl/Makefile
@@ -33,7 +33,8 @@ wayland_INCLUDES = \
wayland_SOURCES = $(wildcard wayland/*.c)
wayland_OBJECTS = $(wayland_SOURCES:.c=.o)
-drm_INCLUDES = -I$(TOP)/src/gallium/winsys $(shell pkg-config --cflags-only-I libdrm)
+drm_INCLUDES = -I$(TOP)/src/gallium/winsys $(shell pkg-config --cflags-only-I libdrm) \
+ -I$(TOP)/src/gbm/main -I$(TOP)/src/gallium/state_trackers/gbm
drm_SOURCES = $(wildcard drm/*.c)
drm_OBJECTS = $(drm_SOURCES:.c=.o)
diff --git a/src/gallium/state_trackers/egl/SConscript b/src/gallium/state_trackers/egl/SConscript
index 9ade76ecbb2..c04fec637c1 100644
--- a/src/gallium/state_trackers/egl/SConscript
+++ b/src/gallium/state_trackers/egl/SConscript
@@ -40,7 +40,12 @@ else:
env.Append(CPPDEFINES = ['GLX_DIRECT_RENDERING'])
sources.append(['#/src/glx/dri2.c'])
if env['drm']:
+ env.PkgUseModules('DRM')
env.Append(CPPDEFINES = ['HAVE_DRM_BACKEND'])
+ env.Append(CPPPATH = [
+ '#/src/gbm/main',
+ '#/src/gallium/state_trackers/gbm',
+ ])
sources.append(['drm/native_drm.c', 'drm/modeset.c'])
st_egl = env.ConvenienceLibrary(
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 29dbbefbf48..6649f02b244 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -31,6 +31,7 @@
#include "util/u_memory.h"
#include "util/u_format.h"
#include "util/u_string.h"
+#include "util/u_atomic.h"
#include "egl_g3d.h"
#include "egl_g3d_api.h"
@@ -45,15 +46,9 @@ egl_g3d_invalid_surface(struct native_display *ndpy,
{
/* XXX not thread safe? */
struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data);
- struct egl_g3d_context *gctx;
-
- /*
- * Some functions such as egl_g3d_copy_buffers create a temporary native
- * surface. There is no gsurf associated with it.
- */
- gctx = (gsurf) ? egl_g3d_context(gsurf->base.CurrentContext) : NULL;
- if (gctx)
- gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi);
+
+ if (gsurf && gsurf->stfbi)
+ p_atomic_inc(&gsurf->stfbi->stamp);
}
static struct pipe_screen *
@@ -72,10 +67,26 @@ egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws)
return gdpy->loader->create_sw_screen(ws);
}
-static struct native_event_handler egl_g3d_native_event_handler = {
+static struct pipe_resource *
+egl_g3d_lookup_egl_image(struct native_display *ndpy, void *egl_image)
+{
+ _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ struct st_egl_image img;
+ struct pipe_resource *resource = NULL;
+
+ memset(&img, 0, sizeof(img));
+ if (gdpy->smapi->get_egl_image(gdpy->smapi, egl_image, &img))
+ resource = img.texture;
+
+ return resource;
+}
+
+static const struct native_event_handler egl_g3d_native_event_handler = {
egl_g3d_invalid_surface,
egl_g3d_new_drm_screen,
- egl_g3d_new_sw_screen
+ egl_g3d_new_sw_screen,
+ egl_g3d_lookup_egl_image
};
/**
@@ -94,40 +105,38 @@ egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat)
case _EGL_PLATFORM_WINDOWS:
plat_name = "Windows";
#ifdef HAVE_GDI_BACKEND
- nplat = native_get_gdi_platform();
+ nplat = native_get_gdi_platform(&egl_g3d_native_event_handler);
#endif
break;
case _EGL_PLATFORM_X11:
plat_name = "X11";
#ifdef HAVE_X11_BACKEND
- nplat = native_get_x11_platform();
+ nplat = native_get_x11_platform(&egl_g3d_native_event_handler);
#endif
break;
case _EGL_PLATFORM_WAYLAND:
plat_name = "wayland";
#ifdef HAVE_WAYLAND_BACKEND
- nplat = native_get_wayland_platform();
+ nplat = native_get_wayland_platform(&egl_g3d_native_event_handler);
#endif
break;
case _EGL_PLATFORM_DRM:
plat_name = "DRM";
#ifdef HAVE_DRM_BACKEND
- nplat = native_get_drm_platform();
+ nplat = native_get_drm_platform(&egl_g3d_native_event_handler);
#endif
break;
case _EGL_PLATFORM_FBDEV:
plat_name = "FBDEV";
#ifdef HAVE_FBDEV_BACKEND
- nplat = native_get_fbdev_platform();
+ nplat = native_get_fbdev_platform(&egl_g3d_native_event_handler);
#endif
break;
default:
break;
}
- if (nplat)
- nplat->set_event_handler(&egl_g3d_native_event_handler);
- else
+ if (!nplat)
_eglLog(_EGL_WARNING, "unsupported platform %s", plat_name);
gdrv->platforms[plat] = nplat;
@@ -504,13 +513,20 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
gdpy->loader = gdrv->loader;
dpy->DriverData = gdpy;
- _eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay);
- gdpy->native = nplat->create_display(dpy->PlatformDisplay,
- dpy->Options.UseFallback, (void *) dpy);
+ _eglLog(_EGL_INFO, "use %s for display %p",
+ nplat->name, dpy->PlatformDisplay);
+ gdpy->native =
+ nplat->create_display(dpy->PlatformDisplay, dpy->Options.UseFallback);
if (!gdpy->native) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
goto fail;
}
+ gdpy->native->user_data = (void *) dpy;
+ if (!gdpy->native->init_screen(gdpy->native)) {
+ _eglError(EGL_NOT_INITIALIZED,
+ "eglInitialize(failed to initialize screen)");
+ goto fail;
+ }
if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK)
dpy->ClientAPIs |= EGL_OPENGL_BIT;
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h
index 301db3128ff..5989a023573 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.h
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.h
@@ -126,4 +126,12 @@ _EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj)
#endif /* EGL_MESA_screen_surface */
+static INLINE struct st_api *
+egl_g3d_get_st_api(_EGLDriver *drv, enum st_api_type api)
+{
+ struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+
+ return gdrv->loader->get_st_api(api);
+}
+
#endif /* _EGL_G3D_H_ */
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
index 8b1821e0055..f897054a540 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
@@ -37,7 +37,6 @@
#include "egl_g3d_image.h"
#include "egl_g3d_sync.h"
#include "egl_g3d_st.h"
-#include "egl_g3d_loader.h"
#include "native.h"
/**
@@ -47,7 +46,6 @@ static struct st_api *
egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx,
enum st_profile_type *profile)
{
- struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
struct st_api *stapi;
EGLint api = -1;
@@ -81,96 +79,66 @@ egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx,
break;
}
- switch (api) {
- case ST_API_OPENGL:
- stapi = gdrv->loader->guess_gl_api(*profile);
- break;
- case ST_API_OPENVG:
- stapi = gdrv->loader->get_st_api(api);
- break;
- default:
- stapi = NULL;
- break;
- }
+ stapi = egl_g3d_get_st_api(drv, api);
if (stapi && !(stapi->profile_mask & (1 << *profile)))
stapi = NULL;
return stapi;
}
+struct egl_g3d_choose_config_data {
+ _EGLConfig criteria;
+ enum pipe_format format;
+};
+
static int
egl_g3d_compare_config(const _EGLConfig *conf1, const _EGLConfig *conf2,
void *priv_data)
{
- const _EGLConfig *criteria = (const _EGLConfig *) priv_data;
+ struct egl_g3d_choose_config_data *data =
+ (struct egl_g3d_choose_config_data *) priv_data;
+ const _EGLConfig *criteria = &data->criteria;;
/* EGL_NATIVE_VISUAL_TYPE ignored? */
return _eglCompareConfigs(conf1, conf2, criteria, EGL_TRUE);
}
static EGLBoolean
-egl_g3d_match_config(const _EGLConfig *conf, const _EGLConfig *criteria)
+egl_g3d_match_config(const _EGLConfig *conf, void *priv_data)
{
- if (!_eglMatchConfig(conf, criteria))
- return EGL_FALSE;
-
- if (criteria->MatchNativePixmap != EGL_NONE &&
- criteria->MatchNativePixmap != EGL_DONT_CARE) {
- struct egl_g3d_display *gdpy = egl_g3d_display(conf->Display);
- struct egl_g3d_config *gconf = egl_g3d_config(conf);
- EGLNativePixmapType pix =
- (EGLNativePixmapType) criteria->MatchNativePixmap;
+ struct egl_g3d_choose_config_data *data =
+ (struct egl_g3d_choose_config_data *) priv_data;
+ struct egl_g3d_config *gconf = egl_g3d_config(conf);
- if (!gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native))
- return EGL_FALSE;
- }
+ if (data->format != PIPE_FORMAT_NONE &&
+ data->format != gconf->native->color_format)
+ return EGL_FALSE;
- return EGL_TRUE;
+ return _eglMatchConfig(conf, &data->criteria);
}
static EGLBoolean
egl_g3d_choose_config(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attribs,
EGLConfig *configs, EGLint size, EGLint *num_configs)
{
- _EGLConfig **tmp_configs, criteria;
- EGLint tmp_size, i;
-
- if (!num_configs)
- return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs");
+ struct egl_g3d_choose_config_data data;
- if (!_eglParseConfigAttribList(&criteria, dpy, attribs))
+ if (!_eglParseConfigAttribList(&data.criteria, dpy, attribs))
return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
- /* get the number of matched configs */
- tmp_size = _eglFilterArray(dpy->Configs, NULL, 0,
- (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria);
- if (!tmp_size) {
- *num_configs = tmp_size;
- return EGL_TRUE;
- }
-
- tmp_configs = MALLOC(sizeof(tmp_configs[0]) * tmp_size);
- if (!tmp_configs)
- return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
+ data.format = PIPE_FORMAT_NONE;
+ if (data.criteria.MatchNativePixmap != EGL_NONE &&
+ data.criteria.MatchNativePixmap != EGL_DONT_CARE) {
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
- /* get the matched configs */
- _eglFilterArray(dpy->Configs, (void **) tmp_configs, tmp_size,
- (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria);
-
- /* perform sorting of configs */
- if (configs && tmp_size) {
- _eglSortConfigs((const _EGLConfig **) tmp_configs, tmp_size,
- egl_g3d_compare_config, (void *) &criteria);
- tmp_size = MIN2(tmp_size, size);
- for (i = 0; i < tmp_size; i++)
- configs[i] = _eglGetConfigHandle(tmp_configs[i]);
+ if (!gdpy->native->get_pixmap_format(gdpy->native,
+ (EGLNativePixmapType) data.criteria.MatchNativePixmap,
+ &data.format))
+ return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglChooseConfig");
}
- FREE(tmp_configs);
-
- *num_configs = tmp_size;
-
- return EGL_TRUE;
+ return _eglFilterConfigArray(dpy->Configs, configs, size, num_configs,
+ egl_g3d_match_config, egl_g3d_compare_config, &data);
}
static _EGLContext *
@@ -536,19 +504,12 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
(gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL);
if (ok) {
if (gdraw) {
- gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi,
- gdraw->stfbi);
-
if (gdraw->base.Type == EGL_WINDOW_BIT) {
gctx->base.WindowRenderBuffer =
(gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ?
EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
}
}
- if (gread && gread != gdraw) {
- gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi,
- gread->stfbi);
- }
}
}
else if (old_gctx) {
@@ -614,21 +575,6 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
gsurf->base.SwapInterval);
}
-/**
- * Get the pipe surface of the given attachment of the native surface.
- */
-static struct pipe_resource *
-get_pipe_resource(struct native_display *ndpy, struct native_surface *nsurf,
- enum native_attachment natt)
-{
- struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
-
- textures[natt] = NULL;
- nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL);
-
- return textures[natt];
-}
-
static EGLBoolean
egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
EGLNativePixmapType target)
@@ -636,43 +582,18 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
_EGLContext *ctx = _eglGetCurrentContext();
- struct native_surface *nsurf;
- struct pipe_resource *ptex;
- struct pipe_context *pipe;
if (!gsurf->render_texture)
return EGL_TRUE;
- nsurf = gdpy->native->create_pixmap_surface(gdpy->native, target, NULL);
- if (!nsurf)
- return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
-
/* flush if the surface is current */
if (ctx && ctx->DrawSurface == &gsurf->base) {
struct egl_g3d_context *gctx = egl_g3d_context(ctx);
gctx->stctxi->flush(gctx->stctxi, ST_FLUSH_FRONT, NULL);
}
- pipe = ndpy_get_copy_context(gdpy->native);
- if (!pipe)
- return EGL_FALSE;
-
- ptex = get_pipe_resource(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
- if (ptex) {
- struct pipe_box src_box;
-
- u_box_origin_2d(ptex->width0, ptex->height0, &src_box);
- pipe->resource_copy_region(pipe, ptex, 0, 0, 0, 0,
- gsurf->render_texture, 0, &src_box);
- pipe->flush(pipe, NULL);
- nsurf->present(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
-
- pipe_resource_reference(&ptex, NULL);
- }
-
- nsurf->destroy(nsurf);
-
- return EGL_TRUE;
+ return gdpy->native->copy_to_pixmap(gdpy->native,
+ target, gsurf->render_texture);
}
static EGLBoolean
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
index ce72e27c3d5..7e9a29b0284 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_image.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
@@ -37,9 +37,6 @@
#include "egl_g3d.h"
#include "egl_g3d_image.h"
-/* for struct winsys_handle */
-#include "state_tracker/drm_driver.h"
-
/**
* Reference and return the front left buffer of the native pixmap.
*/
@@ -137,10 +134,9 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
_EGLImage *img, const EGLint *attribs)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
- struct pipe_resource templ;
- struct winsys_handle wsh;
_EGLImageAttribs attrs;
EGLint format;
+ struct native_buffer nbuf;
if (!dpy->Extensions.MESA_drm_image)
return NULL;
@@ -166,21 +162,21 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name,
break;
}
- memset(&templ, 0, sizeof(templ));
- templ.target = PIPE_TEXTURE_2D;
- templ.format = format;
- templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
- templ.width0 = attrs.Width;
- templ.height0 = attrs.Height;
- templ.depth0 = 1;
- templ.array_size = 1;
-
- memset(&wsh, 0, sizeof(wsh));
- wsh.handle = (unsigned) name;
- wsh.stride =
- attrs.DRMBufferStrideMESA * util_format_get_blocksize(templ.format);
-
- return gdpy->native->buffer->import_buffer(gdpy->native, &templ, &wsh);
+ memset(&nbuf, 0, sizeof(nbuf));
+ nbuf.type = NATIVE_BUFFER_DRM;
+ nbuf.u.drm.templ.target = PIPE_TEXTURE_2D;
+ nbuf.u.drm.templ.format = format;
+ nbuf.u.drm.templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+ nbuf.u.drm.templ.width0 = attrs.Width;
+ nbuf.u.drm.templ.height0 = attrs.Height;
+ nbuf.u.drm.templ.depth0 = 1;
+ nbuf.u.drm.templ.array_size = 1;
+
+ nbuf.u.drm.name = name;
+ nbuf.u.drm.stride =
+ attrs.DRMBufferStrideMESA * util_format_get_blocksize(format);
+
+ return gdpy->native->buffer->import_buffer(gdpy->native, &nbuf);
}
#endif /* EGL_MESA_drm_image */
@@ -327,35 +323,26 @@ egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img,
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_image *gimg = egl_g3d_image(img);
- struct winsys_handle wsh;
+ struct native_buffer nbuf;
if (!dpy->Extensions.MESA_drm_image)
return EGL_FALSE;
- /* get shared handle */
- if (name) {
- memset(&handle, 0, sizeof(handle));
- wsh.type = DRM_API_HANDLE_TYPE_SHARED;
- if (!gdpy->native->buffer->export_buffer(gdpy->native,
- gimg->texture, &wsh))
- return EGL_FALSE;
+ memset(&nbuf, 0, sizeof(nbuf));
+ nbuf.type = NATIVE_BUFFER_DRM;
+ if (name)
+ nbuf.u.drm.templ.bind |= PIPE_BIND_SHARED;
- *name = wsh.handle;
- }
+ if (!gdpy->native->buffer->export_buffer(gdpy->native,
+ gimg->texture, &nbuf))
+ return EGL_FALSE;
- /* get KMS handle */
- if (handle || stride) {
- memset(&wsh, 0, sizeof(wsh));
- wsh.type = DRM_API_HANDLE_TYPE_KMS;
- if (!gdpy->native->buffer->export_buffer(gdpy->native,
- gimg->texture, &wsh))
- return EGL_FALSE;
-
- if (handle)
- *handle = wsh.handle;
- if (stride)
- *stride = wsh.stride;
- }
+ if (name)
+ *name = nbuf.u.drm.name;
+ if (handle)
+ *handle = nbuf.u.drm.handle;
+ if (stride)
+ *stride = nbuf.u.drm.stride;
return EGL_TRUE;
}
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
index 78bfe2131ef..e9403fa293b 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
@@ -39,7 +39,6 @@ struct sw_winsys;
struct egl_g3d_loader {
uint profile_masks[ST_API_COUNT];
struct st_api *(*get_st_api)(enum st_api_type api);
- struct st_api *(*guess_gl_api)(enum st_profile_type profile);
struct pipe_screen *(*create_drm_screen)(const char *name, int fd);
struct pipe_screen *(*create_sw_screen)(struct sw_winsys *ws);
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
index 2b944b521a4..60c3e332ac9 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_st.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
@@ -292,6 +292,8 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf)
return NULL;
stfbi->visual = &gsurf->stvis;
+ p_atomic_set(&stfbi->stamp, 1);
+
if (gsurf->base.Type != EGL_PBUFFER_BIT) {
stfbi->flush_front = egl_g3d_st_framebuffer_flush_front;
stfbi->validate = egl_g3d_st_framebuffer_validate;
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index 8646e52ed7c..fc50ee485fe 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -152,6 +152,11 @@ struct native_display {
*/
void *user_data;
+ /**
+ * Initialize and create the pipe screen.
+ */
+ boolean (*init_screen)(struct native_display *ndpy);
+
void (*destroy)(struct native_display *ndpy);
/**
@@ -170,16 +175,21 @@ struct native_display {
int *num_configs);
/**
- * Test if a pixmap is supported by the given config. Required unless no
- * config has pixmap_bit set.
- *
- * This function is usually called to find a config that supports a given
- * pixmap. Thus, it is usually called with the same pixmap in a row.
+ * Get the color format of the pixmap. Required unless no config has
+ * pixmap_bit set.
*/
- boolean (*is_pixmap_supported)(struct native_display *ndpy,
- EGLNativePixmapType pix,
- const struct native_config *nconf);
+ boolean (*get_pixmap_format)(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ enum pipe_format *format);
+ /**
+ * Copy the contents of the resource to the pixmap's front-left attachment.
+ * This is used to implement eglCopyBuffers. Required unless no config has
+ * pixmap_bit set.
+ */
+ boolean (*copy_to_pixmap)(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src);
/**
* Create a window surface. Required unless no config has window_bit set.
@@ -219,6 +229,9 @@ struct native_event_handler {
const char *name, int fd);
struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy,
struct sw_winsys *ws);
+
+ struct pipe_resource *(*lookup_egl_image)(struct native_display *ndpy,
+ void *egl_image);
};
/**
@@ -256,26 +269,29 @@ ndpy_uninit(struct native_display *ndpy)
struct native_platform {
const char *name;
- void (*set_event_handler)(struct native_event_handler *handler);
- struct native_display *(*create_display)(void *dpy,
- boolean use_sw,
- void *user_data);
+ /**
+ * Create the native display and usually establish a connection to the
+ * display server.
+ *
+ * No event should be generated at this stage.
+ */
+ struct native_display *(*create_display)(void *dpy, boolean use_sw);
};
const struct native_platform *
-native_get_gdi_platform(void);
+native_get_gdi_platform(const struct native_event_handler *event_handler);
const struct native_platform *
-native_get_x11_platform(void);
+native_get_x11_platform(const struct native_event_handler *event_handler);
const struct native_platform *
-native_get_wayland_platform(void);
+native_get_wayland_platform(const struct native_event_handler *event_handler);
const struct native_platform *
-native_get_drm_platform(void);
+native_get_drm_platform(const struct native_event_handler *event_handler);
const struct native_platform *
-native_get_fbdev_platform(void);
+native_get_fbdev_platform(const struct native_event_handler *event_handler);
#ifdef __cplusplus
}
diff --git a/src/gallium/state_trackers/egl/common/native_buffer.h b/src/gallium/state_trackers/egl/common/native_buffer.h
index 5c29ab97411..b8a66d17e12 100644
--- a/src/gallium/state_trackers/egl/common/native_buffer.h
+++ b/src/gallium/state_trackers/egl/common/native_buffer.h
@@ -30,30 +30,43 @@
#define _NATIVE_BUFFER_H_
#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
struct native_display;
-struct pipe_resource;
+
+enum native_buffer_type {
+ NATIVE_BUFFER_DRM,
+
+ NUM_NATIVE_BUFFERS
+};
+
+struct native_buffer {
+ enum native_buffer_type type;
+
+ union {
+ struct {
+ struct pipe_resource templ;
+ unsigned name; /**< the name of the GEM object */
+ unsigned handle; /**< the handle of the GEM object */
+ unsigned stride;
+ } drm;
+ } u;
+};
/**
* Buffer interface of the native display. It allows native buffers to be
* imported and exported.
- *
- * Just like a native window or a native pixmap, a native buffer is another
- * native type. Its definition depends on the native display.
- *
- * For DRM platform, the type of a native buffer is struct winsys_handle.
*/
struct native_display_buffer {
struct pipe_resource *(*import_buffer)(struct native_display *ndpy,
- const struct pipe_resource *templ,
- void *buf);
+ struct native_buffer *buf);
/**
* The resource must be creatred with PIPE_BIND_SHARED.
*/
boolean (*export_buffer)(struct native_display *ndpy,
struct pipe_resource *res,
- void *buf);
+ struct native_buffer *nbuf);
};
#endif /* _NATIVE_BUFFER_H_ */
diff --git a/src/gallium/state_trackers/egl/common/native_helper.c b/src/gallium/state_trackers/egl/common/native_helper.c
index ee18cb2025b..cca1e1c6295 100644
--- a/src/gallium/state_trackers/egl/common/native_helper.c
+++ b/src/gallium/state_trackers/egl/common/native_helper.c
@@ -282,9 +282,9 @@ resource_surface_copy_swap(struct resource_surface *rsurf,
btex, 0, &src_box);
ret = TRUE;
- out_no_ftex:
- pipe_resource_reference(&btex, NULL);
out_no_btex:
+ pipe_resource_reference(&btex, NULL);
+ out_no_ftex:
pipe_resource_reference(&ftex, NULL);
return ret;
@@ -367,3 +367,116 @@ resource_surface_wait(struct resource_surface *rsurf)
{
while (resource_surface_throttle(rsurf));
}
+
+boolean
+native_display_copy_to_pixmap(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src)
+{
+ struct pipe_context *pipe;
+ struct native_surface *nsurf;
+ struct pipe_resource *dst;
+ struct pipe_resource *tmp[NUM_NATIVE_ATTACHMENTS];
+ const enum native_attachment natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+ pipe = ndpy_get_copy_context(ndpy);
+ if (!pipe)
+ return FALSE;
+
+ nsurf = ndpy->create_pixmap_surface(ndpy, pix, NULL);
+ if (!nsurf)
+ return FALSE;
+
+ /* get the texutre */
+ tmp[natt] = NULL;
+ nsurf->validate(nsurf, 1 << natt, NULL, tmp, NULL, NULL);
+ dst = tmp[natt];
+
+ if (dst && dst->format == src->format) {
+ struct pipe_box src_box;
+
+ u_box_origin_2d(src->width0, src->height0, &src_box);
+ pipe->resource_copy_region(pipe, dst, 0, 0, 0, 0, src, 0, &src_box);
+ pipe->flush(pipe, NULL);
+ nsurf->present(nsurf, natt, FALSE, 0);
+ }
+
+ if (dst)
+ pipe_resource_reference(&dst, NULL);
+
+ nsurf->destroy(nsurf);
+
+ return TRUE;
+}
+
+#include "state_tracker/drm_driver.h"
+struct pipe_resource *
+drm_display_import_native_buffer(struct native_display *ndpy,
+ struct native_buffer *nbuf)
+{
+ struct pipe_screen *screen = ndpy->screen;
+ struct pipe_resource *res = NULL;
+
+ switch (nbuf->type) {
+ case NATIVE_BUFFER_DRM:
+ {
+ struct winsys_handle wsh;
+
+ memset(&wsh, 0, sizeof(wsh));
+ wsh.handle = nbuf->u.drm.name;
+ wsh.stride = nbuf->u.drm.stride;
+
+ res = screen->resource_from_handle(screen, &nbuf->u.drm.templ, &wsh);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return res;
+}
+
+boolean
+drm_display_export_native_buffer(struct native_display *ndpy,
+ struct pipe_resource *res,
+ struct native_buffer *nbuf)
+{
+ struct pipe_screen *screen = ndpy->screen;
+ boolean ret = FALSE;
+
+ switch (nbuf->type) {
+ case NATIVE_BUFFER_DRM:
+ {
+ struct winsys_handle wsh;
+
+ if ((nbuf->u.drm.templ.bind & res->bind) != nbuf->u.drm.templ.bind)
+ break;
+
+ memset(&wsh, 0, sizeof(wsh));
+ wsh.type = DRM_API_HANDLE_TYPE_KMS;
+ if (!screen->resource_get_handle(screen, res, &wsh))
+ break;
+
+ nbuf->u.drm.handle = wsh.handle;
+ nbuf->u.drm.stride = wsh.stride;
+
+ /* get the name of the GEM object */
+ if (nbuf->u.drm.templ.bind & PIPE_BIND_SHARED) {
+ memset(&wsh, 0, sizeof(wsh));
+ wsh.type = DRM_API_HANDLE_TYPE_SHARED;
+ if (!screen->resource_get_handle(screen, res, &wsh))
+ break;
+
+ nbuf->u.drm.name = wsh.handle;
+ }
+
+ nbuf->u.drm.templ = *res;
+ ret = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
diff --git a/src/gallium/state_trackers/egl/common/native_helper.h b/src/gallium/state_trackers/egl/common/native_helper.h
index 39564a04365..e8d91ccb02a 100644
--- a/src/gallium/state_trackers/egl/common/native_helper.h
+++ b/src/gallium/state_trackers/egl/common/native_helper.h
@@ -105,3 +105,17 @@ resource_surface_flush(struct resource_surface *rsurf,
*/
void
resource_surface_wait(struct resource_surface *rsurf);
+
+boolean
+native_display_copy_to_pixmap(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src);
+
+struct pipe_resource *
+drm_display_import_native_buffer(struct native_display *ndpy,
+ struct native_buffer *nbuf);
+
+boolean
+drm_display_export_native_buffer(struct native_display *ndpy,
+ struct pipe_resource *res,
+ struct native_buffer *nbuf);
diff --git a/src/gallium/state_trackers/egl/drm/modeset.c b/src/gallium/state_trackers/egl/drm/modeset.c
index 3fff9540905..73968d1343b 100644
--- a/src/gallium/state_trackers/egl/drm/modeset.c
+++ b/src/gallium/state_trackers/egl/drm/modeset.c
@@ -290,6 +290,42 @@ drm_display_create_surface(struct native_display *ndpy,
return drmsurf;
}
+struct native_surface *
+drm_display_create_surface_from_resource(struct native_display *ndpy,
+ struct pipe_resource *resource)
+{
+ struct drm_display *drmdpy = drm_display(ndpy);
+ struct drm_surface *drmsurf;
+ enum native_attachment natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+ drmsurf = CALLOC_STRUCT(drm_surface);
+ if (!drmsurf)
+ return NULL;
+
+ drmsurf->drmdpy = drmdpy;
+ drmsurf->color_format = resource->format;
+ drmsurf->width = resource->width0;
+ drmsurf->height = resource->height0;
+ drmsurf->have_pageflip = FALSE;
+
+ drmsurf->rsurf = resource_surface_create(drmdpy->base.screen,
+ drmsurf->color_format,
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_SAMPLER_VIEW |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT);
+
+ resource_surface_import_resource(drmsurf->rsurf, natt, resource);
+
+ drmsurf->base.destroy = drm_surface_destroy;
+ drmsurf->base.present = drm_surface_present;
+ drmsurf->base.validate = drm_surface_validate;
+ drmsurf->base.wait = drm_surface_wait;
+
+ return &drmsurf->base;
+}
+
+
/**
* Choose a CRTC that supports all given connectors.
*/
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c
index 725fe28e4e2..47910de8d3c 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.c
+++ b/src/gallium/state_trackers/egl/drm/native_drm.c
@@ -33,6 +33,8 @@
#include "native_drm.h"
+#include "gbm_gallium_drmint.h"
+
#ifdef HAVE_LIBUDEV
#include <libudev.h>
#endif
@@ -125,6 +127,8 @@ drm_display_destroy(struct native_display *ndpy)
drm_display_fini_modeset(&drmdpy->base);
+ /* gbm owns screen */
+ ndpy->screen = NULL;
ndpy_uninit(ndpy);
if (drmdpy->device_name)
@@ -136,54 +140,10 @@ drm_display_destroy(struct native_display *ndpy)
FREE(drmdpy);
}
-/**
- * Initialize KMS and pipe screen.
- */
-static boolean
-drm_display_init_screen(struct native_display *ndpy)
-{
- struct drm_display *drmdpy = drm_display(ndpy);
- drmVersionPtr version;
-
- version = drmGetVersion(drmdpy->fd);
- if (!version) {
- _eglLog(_EGL_WARNING, "invalid fd %d", drmdpy->fd);
- return FALSE;
- }
-
- drmdpy->base.screen =
- drmdpy->event_handler->new_drm_screen(&drmdpy->base, NULL, drmdpy->fd);
- drmFreeVersion(version);
-
- if (!drmdpy->base.screen) {
- _eglLog(_EGL_DEBUG, "failed to create DRM screen");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static struct pipe_resource *
-drm_display_import_buffer(struct native_display *ndpy,
- const struct pipe_resource *templ,
- void *buf)
-{
- return ndpy->screen->resource_from_handle(ndpy->screen,
- templ, (struct winsys_handle *) buf);
-}
-
-static boolean
-drm_display_export_buffer(struct native_display *ndpy,
- struct pipe_resource *res,
- void *buf)
-{
- return ndpy->screen->resource_get_handle(ndpy->screen,
- res, (struct winsys_handle *) buf);
-}
-
static struct native_display_buffer drm_display_buffer = {
- drm_display_import_buffer,
- drm_display_export_buffer
+ /* use the helpers */
+ drm_display_import_native_buffer,
+ drm_display_export_native_buffer
};
static int
@@ -281,9 +241,25 @@ static struct native_display_wayland_bufmgr drm_display_wayland_bufmgr = {
#endif /* HAVE_WAYLAND_BACKEND */
+static struct native_surface *
+drm_create_pixmap_surface(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ const struct native_config *nconf)
+{
+ struct gbm_gallium_drm_bo *bo = (void *) pix;
+
+ return drm_display_create_surface_from_resource(ndpy, bo->resource);
+}
+
+static boolean
+drm_display_init_screen(struct native_display *ndpy)
+{
+ return TRUE;
+}
+
static struct native_display *
-drm_create_display(int fd, struct native_event_handler *event_handler,
- void *user_data)
+drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
+ const struct native_event_handler *event_handler)
{
struct drm_display *drmdpy;
@@ -291,20 +267,24 @@ drm_create_display(int fd, struct native_event_handler *event_handler,
if (!drmdpy)
return NULL;
- drmdpy->fd = fd;
- drmdpy->device_name = drm_get_device_name(fd);
+ drmdpy->fd = gbmdrm->base.base.fd;
+ drmdpy->device_name = drm_get_device_name(drmdpy->fd);
+
+ gbmdrm->lookup_egl_image = (struct pipe_resource *(*)(void *, void *))
+ event_handler->lookup_egl_image;
+ gbmdrm->lookup_egl_image_data = &drmdpy->base;
+
drmdpy->event_handler = event_handler;
- drmdpy->base.user_data = user_data;
- if (!drm_display_init_screen(&drmdpy->base)) {
- drm_display_destroy(&drmdpy->base);
- return NULL;
- }
+ drmdpy->base.screen = gbmdrm->screen;
+ drmdpy->base.init_screen = drm_display_init_screen;
drmdpy->base.destroy = drm_display_destroy;
drmdpy->base.get_param = drm_display_get_param;
drmdpy->base.get_configs = drm_display_get_configs;
+ drmdpy->base.create_pixmap_surface = drm_create_pixmap_surface;
+
drmdpy->base.buffer = &drm_display_buffer;
#ifdef HAVE_WAYLAND_BACKEND
if (drmdpy->device_name)
@@ -315,39 +295,39 @@ drm_create_display(int fd, struct native_event_handler *event_handler,
return &drmdpy->base;
}
-static struct native_event_handler *drm_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
- drm_event_handler = event_handler;
-}
+static const struct native_event_handler *drm_event_handler;
static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
{
+ struct gbm_gallium_drm_device *gbm;
int fd;
- if (dpy) {
- fd = dup((int) pointer_to_intptr(dpy));
- }
- else {
+ gbm = dpy;
+
+ if (gbm == NULL) {
fd = open("/dev/dri/card0", O_RDWR);
+ gbm = gbm_gallium_drm_device(gbm_create_device(fd));
}
- if (fd < 0)
+
+ if (gbm == NULL)
+ return NULL;
+
+ if (strcmp(gbm_device_get_backend_name(&gbm->base.base), "drm") != 0 ||
+ gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM)
return NULL;
- return drm_create_display(fd, drm_event_handler, user_data);
+ return drm_create_display(gbm, drm_event_handler);
}
static const struct native_platform drm_platform = {
"DRM", /* name */
- native_set_event_handler,
native_create_display
};
const struct native_platform *
-native_get_drm_platform(void)
+native_get_drm_platform(const struct native_event_handler *event_handler)
{
+ drm_event_handler = event_handler;
return &drm_platform;
}
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h
index 41cdc4f9d04..675a58a1922 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.h
+++ b/src/gallium/state_trackers/egl/drm/native_drm.h
@@ -50,7 +50,7 @@ struct drm_surface;
struct drm_display {
struct native_display base;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
int fd;
char *device_name;
@@ -154,4 +154,8 @@ drm_display_init_modeset(struct native_display *ndpy);
void
drm_display_fini_modeset(struct native_display *ndpy);
+struct native_surface *
+drm_display_create_surface_from_resource(struct native_display *ndpy,
+ struct pipe_resource *resource);
+
#endif /* _NATIVE_DRM_H_ */
diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
index e2fde00e975..6772d379f73 100644
--- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
+++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
@@ -26,6 +26,21 @@
* Chia-I Wu <[email protected]>
*/
+/**
+ * Considering fbdev as an in-kernel window system,
+ *
+ * - opening a device opens a connection
+ * - there is only one window: the framebuffer
+ * - fb_var_screeninfo decides window position, size, and even color format
+ * - there is no pixmap
+ *
+ * Now EGL is built on top of this window system. So we should have
+ *
+ * - the fd as the handle of the native display
+ * - reject all but one native window: NULL
+ * - no pixmap support
+ */
+
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -45,16 +60,13 @@ struct fbdev_display {
struct native_display base;
int fd;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct fb_fix_screeninfo finfo;
- struct fb_var_screeninfo vinfo;
-
+ struct fb_var_screeninfo config_vinfo;
struct native_config config;
- struct native_connector connector;
- struct native_mode mode;
- struct fbdev_surface *current_surface;
+ boolean assume_fixed_vinfo;
};
struct fbdev_surface {
@@ -66,7 +78,7 @@ struct fbdev_surface {
unsigned int sequence_number;
- boolean is_current;
+ struct fbdev_sw_drawable drawable;
};
static INLINE struct fbdev_display *
@@ -103,38 +115,70 @@ fbdev_surface_validate(struct native_surface *nsurf, uint attachment_mask,
return TRUE;
}
-static boolean
-fbdev_surface_flush_frontbuffer(struct native_surface *nsurf)
+static enum pipe_format
+vinfo_to_format(const struct fb_var_screeninfo *vinfo)
{
- struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
+ enum pipe_format format = PIPE_FORMAT_NONE;
- if (!fbsurf->is_current)
- return TRUE;
+ /* should also check channel offsets... */
+ switch (vinfo->bits_per_pixel) {
+ case 32:
+ if (vinfo->red.length == 8 &&
+ vinfo->green.length == 8 &&
+ vinfo->blue.length == 8) {
+ format = (vinfo->transp.length == 8) ?
+ PIPE_FORMAT_B8G8R8A8_UNORM : PIPE_FORMAT_B8G8R8X8_UNORM;
+ }
+ break;
+ case 16:
+ if (vinfo->red.length == 5 &&
+ vinfo->green.length == 6 &&
+ vinfo->blue.length == 5 &&
+ vinfo->transp.length == 0)
+ format = PIPE_FORMAT_B5G6R5_UNORM;
+ break;
+ default:
+ break;
+ }
- return resource_surface_present(fbsurf->rsurf,
- NATIVE_ATTACHMENT_FRONT_LEFT, NULL);
+ return format;
}
static boolean
-fbdev_surface_swap_buffers(struct native_surface *nsurf)
+fbdev_surface_update_drawable(struct native_surface *nsurf,
+ const struct fb_var_screeninfo *vinfo)
{
struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
- struct fbdev_display *fbdpy = fbsurf->fbdpy;
- boolean ret = TRUE;
-
- if (fbsurf->is_current) {
- ret = resource_surface_present(fbsurf->rsurf,
- NATIVE_ATTACHMENT_BACK_LEFT, NULL);
+ unsigned x, y, width, height;
+
+ x = vinfo->xoffset;
+ y = vinfo->yoffset;
+ width = MIN2(vinfo->xres, fbsurf->width);
+ height = MIN2(vinfo->yres, fbsurf->height);
+
+ /* sanitize the values */
+ if (x + width > vinfo->xres_virtual) {
+ if (x > vinfo->xres_virtual)
+ width = 0;
+ else
+ width = vinfo->xres_virtual - x;
+ }
+ if (y + height > vinfo->yres_virtual) {
+ if (y > vinfo->yres_virtual)
+ height = 0;
+ else
+ height = vinfo->yres_virtual - y;
}
- resource_surface_swap_buffers(fbsurf->rsurf,
- NATIVE_ATTACHMENT_FRONT_LEFT, NATIVE_ATTACHMENT_BACK_LEFT, TRUE);
- /* the front/back textures are swapped */
- fbsurf->sequence_number++;
- fbdpy->event_handler->invalid_surface(&fbdpy->base,
- &fbsurf->base, fbsurf->sequence_number);
+ fbsurf->drawable.format = vinfo_to_format(vinfo);
+ fbsurf->drawable.x = vinfo->xoffset;
+ fbsurf->drawable.y = vinfo->yoffset;
+ fbsurf->drawable.width = vinfo->xres;
+ fbsurf->drawable.height = vinfo->yres;
- return ret;
+ return (fbsurf->drawable.format != PIPE_FORMAT_NONE &&
+ fbsurf->drawable.width &&
+ fbsurf->drawable.height);
}
static boolean
@@ -143,21 +187,43 @@ fbdev_surface_present(struct native_surface *nsurf,
boolean preserve,
uint swap_interval)
{
- boolean ret;
+ struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
+ struct fbdev_display *fbdpy = fbsurf->fbdpy;
+ boolean ret = FALSE;
- if (preserve || swap_interval)
+ if (swap_interval)
+ return FALSE;
+ if (natt != NATIVE_ATTACHMENT_BACK_LEFT)
return FALSE;
- switch (natt) {
- case NATIVE_ATTACHMENT_FRONT_LEFT:
- ret = fbdev_surface_flush_frontbuffer(nsurf);
- break;
- case NATIVE_ATTACHMENT_BACK_LEFT:
- ret = fbdev_surface_swap_buffers(nsurf);
- break;
- default:
- ret = FALSE;
- break;
+ if (!fbdpy->assume_fixed_vinfo) {
+ struct fb_var_screeninfo vinfo;
+
+ memset(&vinfo, 0, sizeof(vinfo));
+ if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &vinfo))
+ return FALSE;
+
+ /* present the surface */
+ if (fbdev_surface_update_drawable(&fbsurf->base, &vinfo)) {
+ ret = resource_surface_present(fbsurf->rsurf,
+ natt, (void *) &fbsurf->drawable);
+ }
+
+ fbsurf->width = vinfo.xres;
+ fbsurf->height = vinfo.yres;
+
+ if (resource_surface_set_size(fbsurf->rsurf,
+ fbsurf->width, fbsurf->height)) {
+ /* surface resized */
+ fbsurf->sequence_number++;
+ fbdpy->event_handler->invalid_surface(&fbdpy->base,
+ &fbsurf->base, fbsurf->sequence_number);
+ }
+ }
+ else {
+ /* the drawable never changes */
+ ret = resource_surface_present(fbsurf->rsurf,
+ natt, (void *) &fbsurf->drawable);
}
return ret;
@@ -179,26 +245,48 @@ fbdev_surface_destroy(struct native_surface *nsurf)
}
static struct native_surface *
-fbdev_display_create_scanout_surface(struct native_display *ndpy,
- const struct native_config *nconf,
- uint width, uint height)
+fbdev_display_create_window_surface(struct native_display *ndpy,
+ EGLNativeWindowType win,
+ const struct native_config *nconf)
{
struct fbdev_display *fbdpy = fbdev_display(ndpy);
struct fbdev_surface *fbsurf;
+ struct fb_var_screeninfo vinfo;
+
+ /* there is only one native window: NULL */
+ if (win)
+ return NULL;
fbsurf = CALLOC_STRUCT(fbdev_surface);
if (!fbsurf)
return NULL;
fbsurf->fbdpy = fbdpy;
- fbsurf->width = width;
- fbsurf->height = height;
+
+ /* get current vinfo */
+ if (fbdpy->assume_fixed_vinfo) {
+ vinfo = fbdpy->config_vinfo;
+ }
+ else {
+ memset(&vinfo, 0, sizeof(vinfo));
+ if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &vinfo)) {
+ FREE(fbsurf);
+ return NULL;
+ }
+ }
+
+ fbsurf->width = vinfo.xres;
+ fbsurf->height = vinfo.yres;
+
+ if (!fbdev_surface_update_drawable(&fbsurf->base, &vinfo)) {
+ FREE(fbsurf);
+ return NULL;
+ }
fbsurf->rsurf = resource_surface_create(fbdpy->base.screen,
nconf->color_format,
PIPE_BIND_RENDER_TARGET |
- PIPE_BIND_DISPLAY_TARGET |
- PIPE_BIND_SCANOUT);
+ PIPE_BIND_DISPLAY_TARGET);
if (!fbsurf->rsurf) {
FREE(fbsurf);
return NULL;
@@ -214,42 +302,43 @@ fbdev_display_create_scanout_surface(struct native_display *ndpy,
return &fbsurf->base;
}
+static struct native_surface *
+fbdev_display_create_scanout_surface(struct native_display *ndpy,
+ const struct native_config *nconf,
+ uint width, uint height)
+{
+ return fbdev_display_create_window_surface(ndpy,
+ (EGLNativeWindowType) NULL, nconf);
+}
+
static boolean
fbdev_display_program(struct native_display *ndpy, int crtc_idx,
struct native_surface *nsurf, uint x, uint y,
const struct native_connector **nconns, int num_nconns,
const struct native_mode *nmode)
{
- struct fbdev_display *fbdpy = fbdev_display(ndpy);
- struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
-
- if (x || y)
- return FALSE;
-
- if (fbdpy->current_surface) {
- if (fbdpy->current_surface == fbsurf)
- return TRUE;
- fbdpy->current_surface->is_current = FALSE;
- }
-
- if (fbsurf)
- fbsurf->is_current = TRUE;
- fbdpy->current_surface = fbsurf;
-
return TRUE;
}
static const struct native_mode **
fbdev_display_get_modes(struct native_display *ndpy,
- const struct native_connector *nconn,
- int *num_modes)
+ const struct native_connector *nconn,
+ int *num_modes)
{
- struct fbdev_display *fbdpy = fbdev_display(ndpy);
+ static struct native_mode mode;
const struct native_mode **modes;
+ if (!mode.desc) {
+ struct fbdev_display *fbdpy = fbdev_display(ndpy);
+ mode.desc = "Current Mode";
+ mode.width = fbdpy->config_vinfo.xres;
+ mode.height = fbdpy->config_vinfo.yres;
+ mode.refresh_rate = 60 * 1000; /* dummy */
+ }
+
modes = MALLOC(sizeof(*modes));
if (modes) {
- modes[0] = &fbdpy->mode;
+ modes[0] = &mode;
if (num_modes)
*num_modes = 1;
}
@@ -261,12 +350,12 @@ static const struct native_connector **
fbdev_display_get_connectors(struct native_display *ndpy, int *num_connectors,
int *num_crtc)
{
- struct fbdev_display *fbdpy = fbdev_display(ndpy);
+ static struct native_connector connector;
const struct native_connector **connectors;
connectors = MALLOC(sizeof(*connectors));
if (connectors) {
- connectors[0] = &fbdpy->connector;
+ connectors[0] = &connector;
if (num_connectors)
*num_connectors = 1;
}
@@ -274,7 +363,8 @@ fbdev_display_get_connectors(struct native_display *ndpy, int *num_connectors,
return connectors;
}
-static struct native_display_modeset fbdev_display_modeset = {
+/* remove modeset support one day! */
+static const struct native_display_modeset fbdev_display_modeset = {
.get_connectors = fbdev_display_get_connectors,
.get_modes = fbdev_display_get_modes,
.create_scanout_surface = fbdev_display_create_scanout_surface,
@@ -304,8 +394,10 @@ fbdev_display_get_param(struct native_display *ndpy,
int val;
switch (param) {
- case NATIVE_PARAM_USE_NATIVE_BUFFER:
case NATIVE_PARAM_PRESERVE_BUFFER:
+ val = 1;
+ break;
+ case NATIVE_PARAM_USE_NATIVE_BUFFER:
case NATIVE_PARAM_MAX_SWAP_INTERVAL:
default:
val = 0;
@@ -326,114 +418,55 @@ fbdev_display_destroy(struct native_display *ndpy)
}
static boolean
-fbdev_display_init_modes(struct native_display *ndpy)
+fbdev_display_init_screen(struct native_display *ndpy)
{
struct fbdev_display *fbdpy = fbdev_display(ndpy);
- struct native_mode *nmode = &fbdpy->mode;
-
- nmode->desc = "Current Mode";
- nmode->width = fbdpy->vinfo.xres;
- nmode->height = fbdpy->vinfo.yres;
- nmode->refresh_rate = 60 * 1000; /* dummy */
-
- return TRUE;
-}
-
-static boolean
-fbdev_display_init_connectors(struct native_display *ndpy)
-{
- return TRUE;
-}
+ struct sw_winsys *ws;
-static enum pipe_format
-vinfo_to_format(const struct fb_var_screeninfo *vinfo)
-{
- enum pipe_format format = PIPE_FORMAT_NONE;
+ ws = fbdev_create_sw_winsys(fbdpy->fd);
+ if (!ws)
+ return FALSE;
- switch (vinfo->bits_per_pixel) {
- case 32:
- if (vinfo->red.length == 8 &&
- vinfo->green.length == 8 &&
- vinfo->blue.length == 8) {
- format = (vinfo->transp.length == 8) ?
- PIPE_FORMAT_B8G8R8A8_UNORM : PIPE_FORMAT_B8G8R8X8_UNORM;
- }
- break;
- case 16:
- if (vinfo->red.length == 5 &&
- vinfo->green.length == 6 &&
- vinfo->blue.length == 5 &&
- vinfo->transp.length == 0)
- format = PIPE_FORMAT_B5G6R5_UNORM;
- break;
- default:
- break;
+ fbdpy->base.screen = fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws);
+ if (!fbdpy->base.screen) {
+ if (ws->destroy)
+ ws->destroy(ws);
+ return FALSE;
}
- return format;
-}
-
-static boolean
-fbdev_display_init_configs(struct native_display *ndpy)
-{
- struct fbdev_display *fbdpy = fbdev_display(ndpy);
- struct native_config *nconf = &fbdpy->config;
-
- nconf->color_format = vinfo_to_format(&fbdpy->vinfo);
- if (nconf->color_format == PIPE_FORMAT_NONE)
+ if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen,
+ fbdpy->config.color_format, PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET)) {
+ fbdpy->base.screen->destroy(fbdpy->base.screen);
+ fbdpy->base.screen = NULL;
return FALSE;
-
- nconf->buffer_mask =
- (1 << NATIVE_ATTACHMENT_FRONT_LEFT) |
- (1 << NATIVE_ATTACHMENT_BACK_LEFT);
-
- nconf->scanout_bit = TRUE;
+ }
return TRUE;
}
static boolean
-fbdev_display_init(struct native_display *ndpy)
+fbdev_display_init_config(struct native_display *ndpy)
{
struct fbdev_display *fbdpy = fbdev_display(ndpy);
- struct sw_winsys *ws;
-
- if (ioctl(fbdpy->fd, FBIOGET_FSCREENINFO, &fbdpy->finfo))
- return FALSE;
+ struct native_config *nconf = &fbdpy->config;
- if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &fbdpy->vinfo))
+ if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &fbdpy->config_vinfo))
return FALSE;
- if (fbdpy->finfo.visual != FB_VISUAL_TRUECOLOR ||
- fbdpy->finfo.type != FB_TYPE_PACKED_PIXELS)
+ nconf->color_format = vinfo_to_format(&fbdpy->config_vinfo);
+ if (nconf->color_format == PIPE_FORMAT_NONE)
return FALSE;
- if (!fbdev_display_init_configs(&fbdpy->base) ||
- !fbdev_display_init_connectors(&fbdpy->base) ||
- !fbdev_display_init_modes(&fbdpy->base))
- return FALSE;
+ nconf->buffer_mask = (1 << NATIVE_ATTACHMENT_BACK_LEFT);
- ws = fbdev_create_sw_winsys(fbdpy->fd, fbdpy->config.color_format);
- if (ws) {
- fbdpy->base.screen =
- fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws);
- }
+ nconf->window_bit = TRUE;
- if (fbdpy->base.screen) {
- if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen,
- fbdpy->config.color_format, PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET)) {
- fbdpy->base.screen->destroy(fbdpy->base.screen);
- fbdpy->base.screen = NULL;
- }
- }
-
- return (fbdpy->base.screen != NULL);
+ return TRUE;
}
static struct native_display *
-fbdev_display_create(int fd, struct native_event_handler *event_handler,
- void *user_data)
+fbdev_display_create(int fd, const struct native_event_handler *event_handler)
{
struct fbdev_display *fbdpy;
@@ -443,32 +476,41 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler,
fbdpy->fd = fd;
fbdpy->event_handler = event_handler;
- fbdpy->base.user_data = user_data;
- if (!fbdev_display_init(&fbdpy->base)) {
- FREE(fbdpy);
- return NULL;
- }
+ if (ioctl(fbdpy->fd, FBIOGET_FSCREENINFO, &fbdpy->finfo))
+ goto fail;
+
+ if (fbdpy->finfo.visual != FB_VISUAL_TRUECOLOR ||
+ fbdpy->finfo.type != FB_TYPE_PACKED_PIXELS)
+ goto fail;
+
+ if (!fbdev_display_init_config(&fbdpy->base))
+ goto fail;
+ fbdpy->assume_fixed_vinfo = TRUE;
+
+ fbdpy->base.init_screen = fbdev_display_init_screen;
fbdpy->base.destroy = fbdev_display_destroy;
fbdpy->base.get_param = fbdev_display_get_param;
fbdpy->base.get_configs = fbdev_display_get_configs;
+ fbdpy->base.create_window_surface = fbdev_display_create_window_surface;
+
+ /* we'd like to remove modeset support one day */
+ fbdpy->config.scanout_bit = TRUE;
fbdpy->base.modeset = &fbdev_display_modeset;
return &fbdpy->base;
-}
-static struct native_event_handler *fbdev_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
- fbdev_event_handler = event_handler;
+fail:
+ FREE(fbdpy);
+ return NULL;
}
+static const struct native_event_handler *fbdev_event_handler;
+
static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
{
struct native_display *ndpy;
int fd;
@@ -483,7 +525,7 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
if (fd < 0)
return NULL;
- ndpy = fbdev_display_create(fd, fbdev_event_handler, user_data);
+ ndpy = fbdev_display_create(fd, fbdev_event_handler);
if (!ndpy)
close(fd);
@@ -492,12 +534,12 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
static const struct native_platform fbdev_platform = {
"FBDEV", /* name */
- native_set_event_handler,
native_create_display
};
const struct native_platform *
-native_get_fbdev_platform(void)
+native_get_fbdev_platform(const struct native_event_handler *event_handler)
{
+ fbdev_event_handler = event_handler;
return &fbdev_platform;
}
diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c
index 5d0045f92ee..6bf0d4e4668 100644
--- a/src/gallium/state_trackers/egl/gdi/native_gdi.c
+++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c
@@ -41,7 +41,7 @@ struct gdi_display {
struct native_display base;
HDC hDC;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct native_config *configs;
int num_configs;
@@ -368,35 +368,39 @@ gdi_display_destroy(struct native_display *ndpy)
FREE(gdpy);
}
-static struct native_display *
-gdi_create_display(HDC hDC, struct native_event_handler *event_handler,
- void *user_data)
+static boolean
+gdi_display_init_screen(struct native_display *ndpy)
{
- struct gdi_display *gdpy;
+ struct gdi_display *gdpy = gdi_display(ndpy);
struct sw_winsys *winsys;
- gdpy = CALLOC_STRUCT(gdi_display);
- if (!gdpy)
- return NULL;
-
- gdpy->hDC = hDC;
- gdpy->event_handler = event_handler;
- gdpy->base.user_data = user_data;
-
winsys = gdi_create_sw_winsys();
- if (!winsys) {
- FREE(gdpy);
- return NULL;
- }
+ if (!winsys)
+ return FALSE;
gdpy->base.screen = gdpy->event_handler->new_sw_screen(&gdpy->base, winsys);
if (!gdpy->base.screen) {
if (winsys->destroy)
winsys->destroy(winsys);
- FREE(gdpy);
- return NULL;
+ return FALSE;
}
+ return TRUE;
+}
+
+static struct native_display *
+gdi_create_display(HDC hDC, const struct native_event_handler *event_handler)
+{
+ struct gdi_display *gdpy;
+
+ gdpy = CALLOC_STRUCT(gdi_display);
+ if (!gdpy)
+ return NULL;
+
+ gdpy->hDC = hDC;
+ gdpy->event_handler = event_handler;
+
+ gdpy->base.init_screen = gdi_display_init_screen;
gdpy->base.destroy = gdi_display_destroy;
gdpy->base.get_param = gdi_display_get_param;
@@ -406,28 +410,22 @@ gdi_create_display(HDC hDC, struct native_event_handler *event_handler,
return &gdpy->base;
}
-static struct native_event_handler *gdi_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
- gdi_event_handler = event_handler;
-}
+static const struct native_event_handler *gdi_event_handler;
static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
{
- return gdi_create_display((HDC) dpy, gdi_event_handler, user_data);
+ return gdi_create_display((HDC) dpy, gdi_event_handler);
}
static const struct native_platform gdi_platform = {
"GDI", /* name */
- native_set_event_handler,
native_create_display
};
const struct native_platform *
-native_get_gdi_platform(void)
+native_get_gdi_platform(const struct native_event_handler *event_handler)
{
+ gdi_event_handler = event_handler;
return &gdi_platform;
}
diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
index a9fd30319eb..e34b24b58b1 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -51,7 +51,7 @@
struct wayland_drm_display {
struct wayland_display base;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct wl_drm *wl_drm;
struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
@@ -212,27 +212,10 @@ wayland_drm_display_init_screen(struct native_display *ndpy)
return TRUE;
}
-static struct pipe_resource *
-wayland_drm_display_import_buffer(struct native_display *ndpy,
- const struct pipe_resource *templ,
- void *buf)
-{
- return ndpy->screen->resource_from_handle(ndpy->screen,
- templ, (struct winsys_handle *) buf);
-}
-
-static boolean
-wayland_drm_display_export_buffer(struct native_display *ndpy,
- struct pipe_resource *res,
- void *buf)
-{
- return ndpy->screen->resource_get_handle(ndpy->screen,
- res, (struct winsys_handle *) buf);
-}
-
static struct native_display_buffer wayland_drm_display_buffer = {
- wayland_drm_display_import_buffer,
- wayland_drm_display_export_buffer
+ /* use the helpers */
+ drm_display_import_native_buffer,
+ drm_display_export_native_buffer
};
static int
@@ -302,8 +285,7 @@ static struct native_display_wayland_bufmgr wayland_drm_display_wayland_bufmgr =
struct wayland_display *
wayland_create_drm_display(struct wl_display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
struct wayland_drm_display *drmdpy;
@@ -312,7 +294,6 @@ wayland_create_drm_display(struct wl_display *dpy,
return NULL;
drmdpy->event_handler = event_handler;
- drmdpy->base.base.user_data = user_data;
drmdpy->base.dpy = dpy;
if (!drmdpy->base.dpy) {
@@ -320,10 +301,7 @@ wayland_create_drm_display(struct wl_display *dpy,
return NULL;
}
- if (!wayland_drm_display_init_screen(&drmdpy->base.base)) {
- wayland_drm_display_destroy(&drmdpy->base.base);
- return NULL;
- }
+ drmdpy->base.base.init_screen = wayland_drm_display_init_screen;
drmdpy->base.base.destroy = wayland_drm_display_destroy;
drmdpy->base.base.buffer = &wayland_drm_display_buffer;
drmdpy->base.base.wayland_bufmgr = &wayland_drm_display_wayland_bufmgr;
diff --git a/src/gallium/state_trackers/egl/wayland/native_shm.c b/src/gallium/state_trackers/egl/wayland/native_shm.c
index 8614a761abf..1c0799528fe 100644
--- a/src/gallium/state_trackers/egl/wayland/native_shm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_shm.c
@@ -47,7 +47,7 @@
struct wayland_shm_display {
struct wayland_display base;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct wl_shm *wl_shm;
};
@@ -144,8 +144,7 @@ wayland_shm_display_init_screen(struct native_display *ndpy)
struct wayland_display *
wayland_create_shm_display(struct wl_display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
struct wayland_shm_display *shmdpy;
@@ -154,7 +153,6 @@ wayland_create_shm_display(struct wl_display *dpy,
return NULL;
shmdpy->event_handler = event_handler;
- shmdpy->base.base.user_data = user_data;
shmdpy->base.dpy = dpy;
if (!shmdpy->base.dpy) {
@@ -162,11 +160,7 @@ wayland_create_shm_display(struct wl_display *dpy,
return NULL;
}
- if (!wayland_shm_display_init_screen(&shmdpy->base.base)) {
- wayland_shm_display_destroy(&shmdpy->base.base);
- return NULL;
- }
-
+ shmdpy->base.base.init_screen = wayland_shm_display_init_screen;
shmdpy->base.base.destroy = wayland_shm_display_destroy;
shmdpy->base.create_buffer = wayland_create_shm_buffer;
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c
index 3d1bb6ff8b1..544d4be215a 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.c
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c
@@ -35,7 +35,7 @@
#include "native_wayland.h"
-static struct native_event_handler *wayland_event_handler;
+static const struct native_event_handler *wayland_event_handler;
static void
sync_callback(void *data)
@@ -114,11 +114,12 @@ wayland_display_get_param(struct native_display *ndpy,
}
static boolean
-wayland_display_is_pixmap_supported(struct native_display *ndpy,
- EGLNativePixmapType pix,
- const struct native_config *nconf)
+wayland_display_get_pixmap_format(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ enum pipe_format *format)
{
/* all wl_egl_pixmaps are supported */
+ *format = PIPE_FORMAT_NONE;
return TRUE;
}
@@ -195,13 +196,11 @@ wayland_window_surface_handle_resize(struct wayland_surface *surface)
wl_buffer_destroy(surface->buffer[i]);
surface->buffer[i] = NULL;
}
+
+ surface->dx = surface->win->dx;
+ surface->dy = surface->win->dy;
}
pipe_resource_reference(&front_resource, NULL);
-
- surface->dx = surface->win->dx;
- surface->dy = surface->win->dy;
- surface->win->dx = 0;
- surface->win->dy = 0;
}
static boolean
@@ -449,14 +448,8 @@ wayland_create_window_surface(struct native_display *ndpy,
return &surface->base;
}
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
- wayland_event_handler = event_handler;
-}
-
static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
{
struct wayland_display *display = NULL;
boolean own_dpy = FALSE;
@@ -473,12 +466,10 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
if (use_sw) {
_eglLog(_EGL_INFO, "use software fallback");
display = wayland_create_shm_display((struct wl_display *) dpy,
- wayland_event_handler,
- user_data);
+ wayland_event_handler);
} else {
display = wayland_create_drm_display((struct wl_display *) dpy,
- wayland_event_handler,
- user_data);
+ wayland_event_handler);
}
if (!display)
@@ -486,7 +477,8 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
display->base.get_param = wayland_display_get_param;
display->base.get_configs = wayland_display_get_configs;
- display->base.is_pixmap_supported = wayland_display_is_pixmap_supported;
+ display->base.get_pixmap_format = wayland_display_get_pixmap_format;
+ display->base.copy_to_pixmap = native_display_copy_to_pixmap;
display->base.create_window_surface = wayland_create_window_surface;
display->base.create_pixmap_surface = wayland_create_pixmap_surface;
@@ -497,13 +489,13 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
static const struct native_platform wayland_platform = {
"wayland", /* name */
- native_set_event_handler,
native_create_display
};
const struct native_platform *
-native_get_wayland_platform(void)
+native_get_wayland_platform(const struct native_event_handler *event_handler)
{
+ wayland_event_handler = event_handler;
return &wayland_platform;
}
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.h b/src/gallium/state_trackers/egl/wayland/native_wayland.h
index 81c7a8b4840..5390f2f08c9 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.h
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.h
@@ -103,11 +103,10 @@ wayland_config(const struct native_config *nconf)
struct wayland_display *
wayland_create_shm_display(struct wl_display *display,
- struct native_event_handler *event_handler,
- void *user_data);
+ const struct native_event_handler *event_handler);
+
struct wayland_display *
wayland_create_drm_display(struct wl_display *display,
- struct native_event_handler *event_handler,
- void *user_data);
+ const struct native_event_handler *event_handler);
#endif /* _NATIVE_WAYLAND_H_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index a56d43428fc..4b8be7bc759 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -38,6 +38,7 @@
#include "native_x11.h"
#include "x11_screen.h"
+#include "common/native_helper.h"
#ifdef HAVE_WAYLAND_BACKEND
#include "common/native_wayland_drm_bufmgr_helper.h"
#endif
@@ -49,7 +50,7 @@ struct dri2_display {
Display *dpy;
boolean own_dpy;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct x11_screen *xscr;
int xscr_number;
@@ -682,18 +683,30 @@ dri2_display_get_configs(struct native_display *ndpy, int *num_configs)
}
static boolean
-dri2_display_is_pixmap_supported(struct native_display *ndpy,
- EGLNativePixmapType pix,
- const struct native_config *nconf)
+dri2_display_get_pixmap_format(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ enum pipe_format *format)
{
struct dri2_display *dri2dpy = dri2_display(ndpy);
- uint depth, nconf_depth;
+ boolean ret = EGL_TRUE;
+ uint depth;
depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix);
- nconf_depth = util_format_get_blocksizebits(nconf->color_format);
+ switch (depth) {
+ case 32:
+ case 24:
+ *format = PIPE_FORMAT_B8G8R8A8_UNORM;
+ break;
+ case 16:
+ *format = PIPE_FORMAT_B5G6R5_UNORM;
+ break;
+ default:
+ *format = PIPE_FORMAT_NONE;
+ ret = EGL_FALSE;
+ break;
+ }
- /* simple depth match for now */
- return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth));
+ return ret;
}
static int
@@ -870,8 +883,7 @@ static struct native_display_wayland_bufmgr dri2_display_wayland_bufmgr = {
struct native_display *
x11_create_dri2_display(Display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
struct dri2_display *dri2dpy;
@@ -880,7 +892,6 @@ x11_create_dri2_display(Display *dpy,
return NULL;
dri2dpy->event_handler = event_handler;
- dri2dpy->base.user_data = user_data;
dri2dpy->dpy = dpy;
if (!dri2dpy->dpy) {
@@ -899,11 +910,6 @@ x11_create_dri2_display(Display *dpy,
return NULL;
}
- if (!dri2_display_init_screen(&dri2dpy->base)) {
- dri2_display_destroy(&dri2dpy->base);
- return NULL;
- }
-
dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash,
dri2_display_hash_table_compare);
if (!dri2dpy->surfaces) {
@@ -911,10 +917,12 @@ x11_create_dri2_display(Display *dpy,
return NULL;
}
+ dri2dpy->base.init_screen = dri2_display_init_screen;
dri2dpy->base.destroy = dri2_display_destroy;
dri2dpy->base.get_param = dri2_display_get_param;
dri2dpy->base.get_configs = dri2_display_get_configs;
- dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
+ dri2dpy->base.get_pixmap_format = dri2_display_get_pixmap_format;
+ dri2dpy->base.copy_to_pixmap = native_display_copy_to_pixmap;
dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
#ifdef HAVE_WAYLAND_BACKEND
@@ -928,8 +936,7 @@ x11_create_dri2_display(Display *dpy,
struct native_display *
x11_create_dri2_display(Display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
return NULL;
}
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c
index a0bcad4c734..ef038b52152 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.c
+++ b/src/gallium/state_trackers/egl/x11/native_x11.c
@@ -30,16 +30,10 @@
#include "native_x11.h"
-static struct native_event_handler *x11_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
- x11_event_handler = event_handler;
-}
+static const struct native_event_handler *x11_event_handler;
static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
{
struct native_display *ndpy = NULL;
boolean force_sw;
@@ -48,12 +42,10 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
if (force_sw || use_sw) {
_eglLog(_EGL_INFO, "use software fallback");
- ndpy = x11_create_ximage_display((Display *) dpy,
- x11_event_handler, user_data);
+ ndpy = x11_create_ximage_display((Display *) dpy, x11_event_handler);
}
else {
- ndpy = x11_create_dri2_display((Display *) dpy,
- x11_event_handler, user_data);
+ ndpy = x11_create_dri2_display((Display *) dpy, x11_event_handler);
}
return ndpy;
@@ -61,12 +53,12 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
static const struct native_platform x11_platform = {
"X11", /* name */
- native_set_event_handler,
native_create_display
};
const struct native_platform *
-native_get_x11_platform(void)
+native_get_x11_platform(const struct native_event_handler *event_handler)
{
+ x11_event_handler = event_handler;
return &x11_platform;
}
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h
index 8945117276e..d3c9270a667 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.h
+++ b/src/gallium/state_trackers/egl/x11/native_x11.h
@@ -31,12 +31,10 @@
struct native_display *
x11_create_ximage_display(Display *dpy,
- struct native_event_handler *event_handler,
- void *user_data);
+ const struct native_event_handler *event_handler);
struct native_display *
x11_create_dri2_display(Display *dpy,
- struct native_event_handler *event_handler,
- void *user_data);
+ const struct native_event_handler *event_handler);
#endif /* _NATIVE_X11_H_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
index 8e32c6ff0c4..e7794f0d3d7 100644
--- a/src/gallium/state_trackers/egl/x11/native_ximage.c
+++ b/src/gallium/state_trackers/egl/x11/native_ximage.c
@@ -43,7 +43,7 @@ struct ximage_display {
Display *dpy;
boolean own_dpy;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct x11_screen *xscr;
int xscr_number;
@@ -437,14 +437,54 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
}
static boolean
-ximage_display_is_pixmap_supported(struct native_display *ndpy,
- EGLNativePixmapType pix,
- const struct native_config *nconf)
+ximage_display_get_pixmap_format(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ enum pipe_format *format)
{
struct ximage_display *xdpy = ximage_display(ndpy);
- enum pipe_format fmt = get_pixmap_format(&xdpy->base, pix);
- return (fmt == nconf->color_format);
+ *format = get_pixmap_format(&xdpy->base, pix);
+
+ return (*format != PIPE_FORMAT_NONE);
+}
+
+static boolean
+ximage_display_copy_to_pixmap(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src)
+{
+ /* fast path to avoid unnecessary allocation and resource_copy_region */
+ if (src->bind & PIPE_BIND_DISPLAY_TARGET) {
+ struct ximage_display *xdpy = ximage_display(ndpy);
+ enum pipe_format fmt = get_pixmap_format(&xdpy->base, pix);
+ const struct ximage_config *xconf;
+ struct xlib_drawable xdraw;
+ int i;
+
+ if (fmt == PIPE_FORMAT_NONE || src->format != fmt)
+ return FALSE;
+
+ for (i = 0; i < xdpy->num_configs; i++) {
+ if (xdpy->configs[i].base.color_format == fmt) {
+ xconf = &xdpy->configs[i];
+ break;
+ }
+ }
+ if (!xconf)
+ return FALSE;
+
+ memset(&xdraw, 0, sizeof(xdraw));
+ xdraw.visual = xconf->visual->visual;
+ xdraw.depth = xconf->visual->depth;
+ xdraw.drawable = (Drawable) pix;
+
+ xdpy->base.screen->flush_frontbuffer(xdpy->base.screen,
+ src, 0, 0, &xdraw);
+
+ return TRUE;
+ }
+
+ return native_display_copy_to_pixmap(ndpy, pix, src);
}
static int
@@ -484,13 +524,32 @@ ximage_display_destroy(struct native_display *ndpy)
FREE(xdpy);
}
+static boolean
+ximage_display_init_screen(struct native_display *ndpy)
+{
+ struct ximage_display *xdpy = ximage_display(ndpy);
+ struct sw_winsys *winsys;
+
+ winsys = xlib_create_sw_winsys(xdpy->dpy);
+ if (!winsys)
+ return FALSE;
+
+ xdpy->base.screen =
+ xdpy->event_handler->new_sw_screen(&xdpy->base, winsys);
+ if (!xdpy->base.screen) {
+ if (winsys->destroy)
+ winsys->destroy(winsys);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
struct native_display *
x11_create_ximage_display(Display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
struct ximage_display *xdpy;
- struct sw_winsys *winsys = NULL;
xdpy = CALLOC_STRUCT(ximage_display);
if (!xdpy)
@@ -507,39 +566,25 @@ x11_create_ximage_display(Display *dpy,
}
xdpy->event_handler = event_handler;
- xdpy->base.user_data = user_data;
xdpy->xscr_number = DefaultScreen(xdpy->dpy);
xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
- if (!xdpy->xscr)
- goto fail;
-
- winsys = xlib_create_sw_winsys(xdpy->dpy);
- if (!winsys)
- goto fail;
-
- xdpy->base.screen =
- xdpy->event_handler->new_sw_screen(&xdpy->base, winsys);
- if (!xdpy->base.screen)
- goto fail;
+ if (!xdpy->xscr) {
+ if (xdpy->own_dpy)
+ XCloseDisplay(xdpy->dpy);
+ FREE(xdpy);
+ return NULL;
+ }
+ xdpy->base.init_screen = ximage_display_init_screen;
xdpy->base.destroy = ximage_display_destroy;
xdpy->base.get_param = ximage_display_get_param;
xdpy->base.get_configs = ximage_display_get_configs;
- xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported;
+ xdpy->base.get_pixmap_format = ximage_display_get_pixmap_format;
+ xdpy->base.copy_to_pixmap = ximage_display_copy_to_pixmap;
xdpy->base.create_window_surface = ximage_display_create_window_surface;
xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface;
return &xdpy->base;
-
-fail:
- if (winsys && winsys->destroy)
- winsys->destroy(winsys);
- if (xdpy->xscr)
- x11_screen_destroy(xdpy->xscr);
- if (xdpy->dpy && xdpy->own_dpy)
- XCloseDisplay(xdpy->dpy);
- FREE(xdpy);
- return NULL;
}
diff --git a/src/gallium/state_trackers/gbm/Makefile b/src/gallium/state_trackers/gbm/Makefile
new file mode 100644
index 00000000000..1d96eb2032d
--- /dev/null
+++ b/src/gallium/state_trackers/gbm/Makefile
@@ -0,0 +1,46 @@
+TOP = ../../../..
+include $(TOP)/configs/current
+
+gbm_INCLUDES = \
+ -I. \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gbm/main \
+ -I$(TOP)/include
+
+gbm_SOURCES = $(wildcard *.c)
+gbm_OBJECTS = $(gbm_SOURCES:.c=.o)
+
+ALL_INCLUDES = $(gbm_INCLUDES)
+ALL_SOURCES = $(gbm_SOURCES)
+
+GBM_OBJECTS = $(gbm_OBJECTS)
+GBM_CPPFLAGS = $(gbm_INCLUDES)
+
+##### TARGETS #####
+
+default: depend libgbm.a
+
+libgbm.a: $(GBM_OBJECTS) Makefile
+ $(MKLIB) -o gbm -static $(GBM_OBJECTS)
+
+depend:
+ rm -f depend
+ touch depend
+ $(MKDEP) $(MKDEP_OPTIONS) $(ALL_INCLUDES) $(ALL_SOURCES) 2> /dev/null
+
+clean:
+ rm -f libgbm.a
+ rm -f $(GBM_OBJECTS)
+ rm -f depend depend.bak
+
+# Dummy target
+install:
+ @echo -n ""
+
+##### RULES #####
+
+$(gbm_OBJECTS): %.o: %.c
+ $(CC) -c $(GBM_CPPFLAGS) $(DEFINES) $(CFLAGS) $< -o $@
+
+sinclude depend
diff --git a/src/gallium/state_trackers/gbm/gbm_drm.c b/src/gallium/state_trackers/gbm/gbm_drm.c
new file mode 100644
index 00000000000..d4baf87096a
--- /dev/null
+++ b/src/gallium/state_trackers/gbm/gbm_drm.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright © 2011 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:
+ * Benjamin Franzke <[email protected]>
+ */
+
+#include "util/u_memory.h"
+#include "util/u_inlines.h"
+
+#include "state_tracker/drm_driver.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "gbm_gallium_drmint.h"
+
+static INLINE enum pipe_format
+gbm_format_to_gallium(enum gbm_bo_format format)
+{
+ switch (format) {
+ case GBM_BO_FORMAT_XRGB8888:
+ return PIPE_FORMAT_B8G8R8X8_UNORM;
+ case GBM_BO_FORMAT_ARGB8888:
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ default:
+ return PIPE_FORMAT_NONE;
+ }
+
+ return PIPE_FORMAT_NONE;
+}
+
+static INLINE uint
+gbm_usage_to_gallium(uint usage)
+{
+ uint resource_usage = 0;
+
+ if (usage & GBM_BO_USE_SCANOUT)
+ resource_usage |= PIPE_BIND_SCANOUT;
+
+ if (usage & GBM_BO_USE_RENDERING)
+ resource_usage |= PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
+ if (usage & GBM_BO_USE_CURSOR_64X64)
+ resource_usage |= PIPE_BIND_CURSOR;
+
+ return resource_usage;
+}
+
+static int
+gbm_gallium_drm_is_format_supported(struct gbm_device *gbm,
+ enum gbm_bo_format format,
+ uint32_t usage)
+{
+ struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm);
+ enum pipe_format pf;
+
+ pf = gbm_format_to_gallium(format);
+ if (pf == PIPE_FORMAT_NONE)
+ return 0;
+
+ if (!gdrm->screen->is_format_supported(gdrm->screen, PIPE_TEXTURE_2D, pf, 0,
+ gbm_usage_to_gallium(usage)))
+ return 0;
+
+ if (usage & GBM_BO_USE_SCANOUT && format != GBM_BO_FORMAT_XRGB8888)
+ return 0;
+
+ return 1;
+}
+
+static void
+gbm_gallium_drm_bo_destroy(struct gbm_bo *_bo)
+{
+ struct gbm_gallium_drm_bo *bo = gbm_gallium_drm_bo(_bo);
+
+ pipe_resource_reference(&bo->resource, NULL);
+ free(bo);
+}
+
+static struct gbm_bo *
+gbm_gallium_drm_bo_create_from_egl_image(struct gbm_device *gbm,
+ void *egl_dpy, void *egl_image,
+ uint32_t width, uint32_t height,
+ uint32_t usage)
+{
+ struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm);
+ struct gbm_gallium_drm_bo *bo;
+ struct winsys_handle whandle;
+
+ if (!gdrm->lookup_egl_image)
+ return NULL;
+
+ bo = CALLOC_STRUCT(gbm_gallium_drm_bo);
+ if (bo == NULL)
+ return NULL;
+
+ bo->resource = gdrm->lookup_egl_image(gdrm->lookup_egl_image_data,
+ egl_image);
+ if (bo->resource == NULL) {
+ FREE(bo);
+ return NULL;
+ }
+
+ bo->base.base.gbm = gbm;
+ bo->base.base.width = width;
+ bo->base.base.height = height;
+
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.type = DRM_API_HANDLE_TYPE_KMS;
+ gdrm->screen->resource_get_handle(gdrm->screen, bo->resource, &whandle);
+
+ bo->base.base.handle.u32 = whandle.handle;
+ bo->base.base.pitch = whandle.stride;
+
+ return &bo->base.base;
+}
+
+static struct gbm_bo *
+gbm_gallium_drm_bo_create(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ enum gbm_bo_format format, uint32_t usage)
+{
+ struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm);
+ struct gbm_gallium_drm_bo *bo;
+ struct pipe_resource templ;
+ struct winsys_handle whandle;
+ enum pipe_format pf;
+
+ bo = CALLOC_STRUCT(gbm_gallium_drm_bo);
+ if (bo == NULL)
+ return NULL;
+
+ bo->base.base.gbm = gbm;
+ bo->base.base.width = width;
+ bo->base.base.height = height;
+
+ pf = gbm_format_to_gallium(format);
+ if (pf == PIPE_FORMAT_NONE)
+ return NULL;
+
+ memset(&templ, 0, sizeof(templ));
+ templ.bind = gbm_usage_to_gallium(usage);
+ templ.format = pf;
+ templ.target = PIPE_TEXTURE_2D;
+ templ.last_level = 0;
+ templ.width0 = width;
+ templ.height0 = height;
+ templ.depth0 = 1;
+ templ.array_size = 1;
+
+ bo->resource = gdrm->screen->resource_create(gdrm->screen, &templ);
+ if (bo->resource == NULL) {
+ FREE(bo);
+ return NULL;
+ }
+
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.type = DRM_API_HANDLE_TYPE_KMS;
+ gdrm->screen->resource_get_handle(gdrm->screen, bo->resource, &whandle);
+
+ bo->base.base.handle.u32 = whandle.handle;
+ bo->base.base.pitch = whandle.stride;
+
+ return &bo->base.base;
+}
+
+static void
+gbm_gallium_drm_destroy(struct gbm_device *gbm)
+{
+ struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm);
+
+ gdrm->screen->destroy(gdrm->screen);
+
+ FREE(gdrm->base.driver_name);
+
+ FREE(gdrm);
+}
+
+struct gbm_device *
+gbm_gallium_drm_device_create(int fd)
+{
+ struct gbm_gallium_drm_device *gdrm;
+ int ret;
+
+ gdrm = calloc(1, sizeof *gdrm);
+
+ gdrm->base.base.fd = fd;
+ gdrm->base.base.bo_create = gbm_gallium_drm_bo_create;
+ gdrm->base.base.bo_create_from_egl_image =
+ gbm_gallium_drm_bo_create_from_egl_image;
+ gdrm->base.base.bo_destroy = gbm_gallium_drm_bo_destroy;
+ gdrm->base.base.is_format_supported = gbm_gallium_drm_is_format_supported;
+ gdrm->base.base.destroy = gbm_gallium_drm_destroy;
+
+ gdrm->base.type = GBM_DRM_DRIVER_TYPE_GALLIUM;
+ gdrm->base.base.name = "drm";
+
+ ret = gallium_screen_create(gdrm);
+ if (ret) {
+ free(gdrm);
+ return NULL;
+ }
+
+ return &gdrm->base.base;
+}
diff --git a/src/gallium/state_trackers/gbm/gbm_gallium_drmint.h b/src/gallium/state_trackers/gbm/gbm_gallium_drmint.h
new file mode 100644
index 00000000000..6277b8dba2e
--- /dev/null
+++ b/src/gallium/state_trackers/gbm/gbm_gallium_drmint.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2011 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:
+ * Benjamin Franzke <[email protected]>
+ */
+
+#ifndef _GBM_GALLIUM_DRMINT_H_
+#define _GBM_GALLIUM_DRMINT_H_
+
+#include "pipe/p_state.h"
+
+#include "gbmint.h"
+
+#include "common.h"
+#include "common_drm.h"
+
+struct gbm_gallium_drm_device {
+ struct gbm_drm_device base;
+
+ struct pipe_screen *screen;
+ void *driver;
+
+ struct pipe_resource *(*lookup_egl_image)(void *data,
+ void *egl_image);
+ void *lookup_egl_image_data;
+
+};
+
+struct gbm_gallium_drm_bo {
+ struct gbm_drm_bo base;
+
+ struct pipe_resource *resource;
+};
+
+static inline struct gbm_gallium_drm_device *
+gbm_gallium_drm_device(struct gbm_device *gbm)
+{
+ return (struct gbm_gallium_drm_device *) gbm;
+}
+
+static inline struct gbm_gallium_drm_bo *
+gbm_gallium_drm_bo(struct gbm_bo *bo)
+{
+ return (struct gbm_gallium_drm_bo *) bo;
+}
+
+struct gbm_device *
+gbm_gallium_drm_device_create(int fd);
+
+int
+gallium_screen_create(struct gbm_gallium_drm_device *gdrm);
+
+#endif
diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c
index ab4f6753e11..8f6406ddaee 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.c
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.c
@@ -59,6 +59,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
+#include "util/u_atomic.h"
#include "xm_public.h"
#include <GL/glx.h>
@@ -1113,10 +1114,7 @@ XMesaDestroyBuffer(XMesaBuffer b)
void
xmesa_notify_invalid_buffer(XMesaBuffer b)
{
- XMesaContext xmctx = XMesaGetCurrentContext();
-
- if (xmctx && xmctx->xm_buffer == b)
- xmctx->st->notify_invalid_framebuffer(xmctx->st, b->stfb);
+ p_atomic_inc(&b->stfb->stamp);
}
@@ -1126,11 +1124,18 @@ xmesa_notify_invalid_buffer(XMesaBuffer b)
void
xmesa_check_buffer_size(XMesaBuffer b)
{
+ GLuint old_width, old_height;
+
if (b->type == PBUFFER)
return;
+ old_width = b->width;
+ old_height = b->height;
+
xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height);
- xmesa_notify_invalid_buffer(b);
+
+ if (b->width != old_width || b->height != old_height)
+ xmesa_notify_invalid_buffer(b);
}
diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c
index 6bfe8b0788c..ec3f531f7df 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_st.c
+++ b/src/gallium/state_trackers/glx/xlib/xm_st.c
@@ -30,6 +30,7 @@
#include "xm_st.h"
#include "util/u_inlines.h"
+#include "util/u_atomic.h"
struct xmesa_st_framebuffer {
XMesaDisplay display;
@@ -302,6 +303,7 @@ xmesa_create_st_framebuffer(XMesaDisplay xmdpy, XMesaBuffer b)
stfbi->visual = &xstfb->stvis;
stfbi->flush_front = xmesa_st_framebuffer_flush_front;
stfbi->validate = xmesa_st_framebuffer_validate;
+ p_atomic_set(&stfbi->stamp, 1);
stfbi->st_manager_private = (void *) xstfb;
return stfbi;
diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h
index 71491a5aa22..d91ee9797f1 100644
--- a/src/gallium/state_trackers/vega/vg_context.h
+++ b/src/gallium/state_trackers/vega/vg_context.h
@@ -65,6 +65,8 @@ struct st_framebuffer {
enum st_attachment_type strb_att;
void *privateData;
+ int32_t stamp;
+ int32_t iface_stamp;
};
enum vg_object_type {
@@ -105,7 +107,6 @@ struct vg_context
VGErrorCode _error;
struct st_framebuffer *draw_buffer;
- int32_t draw_buffer_invalid;
struct cso_hash *owned_objects[VG_OBJECT_LAST];
@@ -129,6 +130,8 @@ struct vg_context
struct vg_paint *default_paint;
struct blit_state *blit;
+
+ int32_t draw_stamp;
};
diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c
index eeea68677de..dec1581fb84 100644
--- a/src/gallium/state_trackers/vega/vg_manager.c
+++ b/src/gallium/state_trackers/vega/vg_manager.c
@@ -106,35 +106,38 @@ vg_manager_validate_framebuffer(struct vg_context *ctx)
{
struct st_framebuffer *stfb = ctx->draw_buffer;
struct pipe_resource *pt;
+ int32_t new_stamp;
/* no binding surface */
if (!stfb)
return;
- if (!p_atomic_read(&ctx->draw_buffer_invalid))
- return;
+ new_stamp = p_atomic_read(&stfb->iface->stamp);
+ if (stfb->iface_stamp != new_stamp) {
+ do {
+ /* validate the fb */
+ if (!stfb->iface->validate(stfb->iface, &stfb->strb_att,
+ 1, &pt) || !pt)
+ return;
- /* validate the fb */
- if (!stfb->iface->validate(stfb->iface, &stfb->strb_att, 1, &pt) || !pt)
- return;
+ stfb->iface_stamp = new_stamp;
+ new_stamp = p_atomic_read(&stfb->iface->stamp);
- p_atomic_set(&ctx->draw_buffer_invalid, FALSE);
+ } while (stfb->iface_stamp != new_stamp);
- if (vg_context_update_color_rb(ctx, pt) ||
- stfb->width != pt->width0 ||
- stfb->height != pt->height0)
- ctx->state.dirty |= FRAMEBUFFER_DIRTY;
+ if (vg_context_update_color_rb(ctx, pt) ||
+ stfb->width != pt->width0 ||
+ stfb->height != pt->height0)
+ ++stfb->stamp;
- stfb->width = pt->width0;
- stfb->height = pt->height0;
-}
+ stfb->width = pt->width0;
+ stfb->height = pt->height0;
+ }
-static void
-vg_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
- struct st_framebuffer_iface *stfbi)
-{
- struct vg_context *ctx = (struct vg_context *) stctxi;
- p_atomic_set(&ctx->draw_buffer_invalid, TRUE);
+ if (ctx->draw_stamp != stfb->stamp) {
+ ctx->state.dirty |= FRAMEBUFFER_DIRTY;
+ ctx->draw_stamp = stfb->stamp;
+ }
}
static void
@@ -187,8 +190,6 @@ vg_api_create_context(struct st_api *stapi, struct st_manager *smapi,
ctx->iface.destroy = vg_context_destroy;
- ctx->iface.notify_invalid_framebuffer =
- vg_context_notify_invalid_framebuffer;
ctx->iface.flush = vg_context_flush;
ctx->iface.teximage = NULL;
@@ -266,8 +267,6 @@ vg_context_bind_framebuffers(struct st_context_iface *stctxi,
if (stdrawi != streadi)
return FALSE;
- p_atomic_set(&ctx->draw_buffer_invalid, TRUE);
-
strb_att = (stdrawi) ? choose_attachment(stdrawi) : ST_ATTACHMENT_INVALID;
if (ctx->draw_buffer) {
@@ -313,11 +312,14 @@ vg_context_bind_framebuffers(struct st_context_iface *stctxi,
stfb->width = 0;
stfb->height = 0;
stfb->strb_att = strb_att;
+ stfb->stamp = 1;
+ stfb->iface_stamp = p_atomic_read(&stdrawi->stamp) - 1;
ctx->draw_buffer = stfb;
}
ctx->draw_buffer->iface = stdrawi;
+ ctx->draw_stamp = ctx->draw_buffer->stamp - 1;
return TRUE;
}
diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c
index 5608d4f4ce7..c2839fe815f 100644
--- a/src/gallium/state_trackers/wgl/stw_context.c
+++ b/src/gallium/state_trackers/wgl/stw_context.c
@@ -31,6 +31,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "util/u_memory.h"
+#include "util/u_atomic.h"
#include "state_tracker/st_api.h"
#include "stw_icd.h"
@@ -361,10 +362,7 @@ stw_flush_current_locked( struct stw_framebuffer *fb )
void
stw_notify_current_locked( struct stw_framebuffer *fb )
{
- struct stw_context *ctx = stw_current_context();
-
- if (ctx && ctx->current_framebuffer == fb)
- ctx->st->notify_invalid_framebuffer(ctx->st, fb->stfb);
+ p_atomic_inc(&fb->stfb->stamp);
}
/**
diff --git a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
index 424d8daccb3..c7273f26545 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
@@ -268,7 +268,7 @@ wglQueryPbufferARB(HPBUFFERARB hPbuffer,
*piValue = fb->width;
return TRUE;
case WGL_PBUFFER_HEIGHT_ARB:
- *piValue = fb->width;
+ *piValue = fb->height;
return TRUE;
case WGL_PBUFFER_LOST_ARB:
/* We assume that no content is ever lost due to display mode change */
diff --git a/src/gallium/state_trackers/wgl/stw_st.c b/src/gallium/state_trackers/wgl/stw_st.c
index 9174533fc06..28c93f4fb57 100644
--- a/src/gallium/state_trackers/wgl/stw_st.c
+++ b/src/gallium/state_trackers/wgl/stw_st.c
@@ -27,6 +27,7 @@
#include "util/u_memory.h"
#include "util/u_inlines.h"
+#include "util/u_atomic.h"
#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */
#include "stw_st.h"
@@ -196,6 +197,7 @@ stw_st_create_framebuffer(struct stw_framebuffer *fb)
stwfb->stvis = fb->pfi->stvis;
stwfb->base.visual = &stwfb->stvis;
+ p_atomic_set(&stwfb->base.stamp, 1);
stwfb->base.flush_front = stw_st_framebuffer_flush_front;
stwfb->base.validate = stw_st_framebuffer_validate;
diff --git a/src/gallium/state_trackers/xorg/SConscript b/src/gallium/state_trackers/xorg/SConscript
index 19315694b7c..4ea4ec4ee8b 100644
--- a/src/gallium/state_trackers/xorg/SConscript
+++ b/src/gallium/state_trackers/xorg/SConscript
@@ -9,10 +9,11 @@ env.Append(CPPPATH = [
'#/src/mesa',
])
-env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server')
+env.PkgUseModules(['DRM', 'XORG'])
-if env['kms']:
+if env['HAVE_KMS']:
env.Append(CPPDEFINES = ['HAVE_LIBKMS'])
+ env.PkgUseModules(['KMS'])
conf = env.Configure()
diff --git a/src/gallium/state_trackers/xorg/xorg_composite.c b/src/gallium/state_trackers/xorg/xorg_composite.c
index d4dc84a122b..f696b72e1e3 100644
--- a/src/gallium/state_trackers/xorg/xorg_composite.c
+++ b/src/gallium/state_trackers/xorg/xorg_composite.c
@@ -237,7 +237,7 @@ picture_format_fixups(struct exa_pixmap_priv *pSrc, PicturePtr pSrcPicture, bool
boolean swizzle = FALSE;
unsigned ret = 0;
- if (pSrc->picture_format == pSrcPicture->format) {
+ if (pSrc && pSrc->picture_format == pSrcPicture->format) {
if (pSrc->picture_format == PICT_a8) {
if (mask)
return FS_MASK_LUMINANCE;
@@ -252,7 +252,7 @@ picture_format_fixups(struct exa_pixmap_priv *pSrc, PicturePtr pSrcPicture, bool
return 0;
}
- if (pSrc->picture_format != PICT_a8r8g8b8) {
+ if (pSrc && pSrc->picture_format != PICT_a8r8g8b8) {
assert(!"can not handle formats");
return 0;
}
@@ -355,7 +355,7 @@ bind_samplers(struct exa_context *exa, int op,
struct exa_pixmap_priv *pMask,
struct exa_pixmap_priv *pDst)
{
- struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
+ struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS] = {0};
struct pipe_sampler_state src_sampler, mask_sampler;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *src_view;
diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c
index 0499ed1ea0b..22e61cf7081 100644
--- a/src/gallium/state_trackers/xorg/xorg_crtc.c
+++ b/src/gallium/state_trackers/xorg/xorg_crtc.c
@@ -122,6 +122,7 @@ crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
drm_mode.hskew = mode->HSkew;
drm_mode.vscan = mode->VScan;
drm_mode.vrefresh = mode->VRefresh;
+ drm_mode.type = 0;
if (!mode->name)
xf86SetModeDefaultName(mode);
strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN - 1);
diff --git a/src/gallium/targets/Makefile.xorg b/src/gallium/targets/Makefile.xorg
index 47040bb14c8..6fad7109f29 100644
--- a/src/gallium/targets/Makefile.xorg
+++ b/src/gallium/targets/Makefile.xorg
@@ -41,7 +41,7 @@ endif
default: depend $(TOP)/$(LIB_DIR)/gallium $(LIBNAME) $(LIBNAME_STAGING)
-$(LIBNAME): $(OBJECTS) Makefile ../Makefile.xorg $(LIBS) $(DRIVER_PIPES)
+$(LIBNAME): $(OBJECTS) Makefile ../Makefile.xorg $(LIBS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES)
$(MKLIB) -linker '$(CC)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS)
depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES)
diff --git a/src/gallium/targets/SConscript.dri b/src/gallium/targets/SConscript.dri
index 101863a6848..5ad17f8b3ae 100644
--- a/src/gallium/targets/SConscript.dri
+++ b/src/gallium/targets/SConscript.dri
@@ -29,7 +29,7 @@ drienv.Replace(CPPPATH = [
'#src/egl/drivers/dri',
])
-drienv.ParseConfig('pkg-config --cflags --libs libdrm')
+drienv.PkgUseModules('DRM')
dri_common_utils = drienv.SharedObject(
target = 'utils.o',
diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript
index ab60013830e..b3bd3dd5826 100644
--- a/src/gallium/targets/dri-i915/SConscript
+++ b/src/gallium/targets/dri-i915/SConscript
@@ -2,7 +2,7 @@ Import('*')
env = drienv.Clone()
-env.ParseConfig('pkg-config --cflags --libs libdrm_intel')
+env.PkgUseModules('DRM_INTEL')
env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE', 'GALLIUM_GALAHAD'])
@@ -26,4 +26,4 @@ module = env.LoadableModule(
SHLIBPREFIX = '',
)
-env.Alias('dri-i915', module) \ No newline at end of file
+env.Alias('dri-i915', module)
diff --git a/src/gallium/targets/dri-i965/SConscript b/src/gallium/targets/dri-i965/SConscript
index 669f70d6b8d..01a458db228 100644
--- a/src/gallium/targets/dri-i965/SConscript
+++ b/src/gallium/targets/dri-i965/SConscript
@@ -2,7 +2,7 @@ Import('*')
env = drienv.Clone()
-env.ParseConfig('pkg-config --cflags --libs libdrm_intel')
+env.PkgUseModules('DRM_INTEL')
env.Append(CPPDEFINES = [
'GALLIUM_SOFTPIPE',
@@ -29,4 +29,4 @@ module = env.LoadableModule(
SHLIBPREFIX = '',
)
-env.Alias('dri-i965', module) \ No newline at end of file
+env.Alias('dri-i965', module)
diff --git a/src/gallium/targets/dri-swrast/SConscript b/src/gallium/targets/dri-swrast/SConscript
index b67483800e4..33acc614e76 100644
--- a/src/gallium/targets/dri-swrast/SConscript
+++ b/src/gallium/targets/dri-swrast/SConscript
@@ -39,4 +39,6 @@ module = env.LoadableModule(
SHLIBPREFIX = '',
)
+module = env.InstallSharedLibrary(module)
+
env.Alias('dri-swrast', module)
diff --git a/src/gallium/targets/egl-static/Makefile b/src/gallium/targets/egl-static/Makefile
new file mode 100644
index 00000000000..832d7ba438f
--- /dev/null
+++ b/src/gallium/targets/egl-static/Makefile
@@ -0,0 +1,201 @@
+# src/gallium/targets/egl-static/Makefile
+#
+# This is Makefile for egl_gallium.so. It is static in that all state trackers
+# and pipe drivers are linked statically when possible.
+#
+# The following variables are examined
+#
+# EGL_PLATFORMS - platforms to support
+# EGL_CLIENT_APIS - state trackers to support
+# GALLIUM_WINSYS_DIRS - pipe drivers to support
+# SHARED_GLAPI - st/mesa can be statically linked or not
+#
+
+TOP = ../../../..
+include $(TOP)/configs/current
+
+OUTPUTS := egl_gallium
+
+egl_CPPFLAGS := \
+ -I$(TOP)/include \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gallium/drivers \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/winsys
+egl_LIBS := \
+ $(TOP)/src/gallium/drivers/identity/libidentity.a \
+ $(TOP)/src/gallium/drivers/trace/libtrace.a \
+ $(TOP)/src/gallium/drivers/rbug/librbug.a \
+ $(GALLIUM_AUXILIARIES)
+egl_SYS :=
+
+egl_SOURCES := \
+ egl.c \
+ egl_pipe.c \
+ egl_st.c
+
+egl_OBJECTS := $(egl_SOURCES:%.c=%.o)
+
+# st/egl
+egl_CPPFLAGS += \
+ -I$(TOP)/src/gallium/state_trackers/egl \
+ -I$(TOP)/src/egl/main \
+ -D_EGL_MAIN=_eglMain
+egl_LIBS += $(TOP)/src/gallium/state_trackers/egl/libegl.a
+egl_SYS += $(LIBUDEV_LIBS) $(DLOPEN_LIBS) -lEGL -lm
+
+# EGL platforms
+ifneq ($(findstring x11, $(EGL_PLATFORMS)),)
+egl_CPPFLAGS += $(LIBDRM_CFLAGS)
+egl_LIBS += $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a
+egl_SYS += -lX11 -lXext -lXfixes $(LIBDRM_LIB)
+endif
+ifneq ($(findstring wayland, $(EGL_PLATFORMS)),)
+egl_CPPFLAGS += $(LIBDRM_CFLAGS)
+egl_LIBS += $(TOP)/src/gallium/winsys/sw/wayland/libws_wayland.a
+egl_LIBS += $(TOP)/src/egl/wayland/wayland-drm/libwayland-drm.a
+egl_SYS += $(LIBDRM_LIB) $(WAYLAND_LIBS)
+endif
+ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
+egl_CPPFLAGS += $(LIBDRM_CFLAGS)
+egl_SYS += $(LIBDRM_LIB) -lgbm
+endif
+ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
+egl_LIBS += $(TOP)/src/gallium/winsys/sw/fbdev/libfbdev.a
+endif
+
+# st/mesa
+ifneq ($(filter $(GL_LIB), $(EGL_CLIENT_APIS)),)
+egl_CPPFLAGS += -I$(TOP)/src/mesa $(API_DEFINES)
+# make st/mesa built-in when there is a single glapi provider
+ifeq ($(SHARED_GLAPI),1)
+egl_LIBS += $(TOP)/src/mesa/libmesagallium.a
+egl_SYS += -lm -lpthread $(DLOPEN_LIBS) -l$(GLAPI_LIB)
+else
+egl_CPPFLAGS += -D_EGL_EXTERNAL_GL=1
+OUTPUTS += st_GL
+endif # SHARED_GLAPI
+endif
+
+# st/vega
+ifneq ($(filter $(VG_LIB), $(EGL_CLIENT_APIS)),)
+egl_CPPFLAGS += -I$(TOP)/src/gallium/state_trackers/vega -DFEATURE_VG=1
+egl_LIBS += $(TOP)/src/gallium/state_trackers/vega/libvega.a
+egl_SYS += -lm -l$(VG_LIB)
+endif
+
+# i915
+ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_I915=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \
+ $(TOP)/src/gallium/drivers/i915/libi915.a
+egl_SYS += -ldrm_intel
+endif
+
+# i965
+ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_I995=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \
+ $(TOP)/src/gallium/drivers/i965/libi965.a \
+ $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a
+egl_SYS += -ldrm_intel
+endif
+
+# nouveau
+ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_NOUVEAU=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \
+ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \
+ $(TOP)/src/gallium/drivers/nv50/libnv50.a \
+ $(TOP)/src/gallium/drivers/nvc0/libnvc0.a \
+ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a
+egl_SYS += -ldrm_nouveau
+endif
+
+# r300
+ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_R300=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
+ $(TOP)/src/gallium/drivers/r300/libr300.a
+egl_SYS += -ldrm_radeon
+endif
+
+# r600
+ifneq ($(findstring r600/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_R600=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/r600/drm/libr600winsys.a \
+ $(TOP)/src/gallium/drivers/r600/libr600.a
+egl_SYS += -ldrm_radeon
+endif
+
+# vmwgfx
+ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),)
+egl_CPPFLAGS += -D_EGL_PIPE_VMWGFX=1
+egl_LIBS += \
+ $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \
+ $(TOP)/src/gallium/drivers/svga/libsvga.a
+endif
+
+# swrast
+egl_CPPFLAGS += -DGALLIUM_SOFTPIPE -DGALLIUM_RBUG -DGALLIUM_TRACE
+egl_LIBS += $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a
+egl_SYS += -lm
+
+# sort to remove duplicates
+egl_CPPFLAGS := $(sort $(egl_CPPFLAGS))
+egl_LIBS := $(sort $(egl_LIBS))
+egl_SYS := $(sort $(egl_SYS))
+
+# st_GL, built only when shared glapi is not enabled
+st_GL_CPPFLAGS := -I $(TOP)/src/mesa -I$(TOP)/src/gallium/include
+st_GL_LIBS := $(TOP)/src/mesa/libmesagallium.a $(GALLIUM_AUXILIARIES)
+st_GL_SYS := -lm -lpthread $(DLOPEN_LIBS)
+
+# LLVM
+ifeq ($(MESA_LLVM),1)
+egl_CPPFLAGS += -DGALLIUM_LLVMPIPE
+egl_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
+egl_SYS += $(LLVM_LIBS)
+LDFLAGS += $(LLVM_LDFLAGS)
+
+st_GL_SYS += $(LLVM_LIBS)
+endif
+
+OUTPUT_PATH := $(TOP)/$(LIB_DIR)/egl
+OUTPUTS := $(addprefix $(OUTPUT_PATH)/, $(addsuffix .so, $(OUTPUTS)))
+
+default: $(OUTPUTS)
+
+$(OUTPUT_PATH)/egl_gallium.so: $(egl_OBJECTS) $(egl_LIBS)
+ $(MKLIB) -o $(notdir $@) -noprefix -linker '$(CXX)' \
+ -ldflags '-L$(TOP)/$(LIB_DIR) -Wl,--no-undefined $(LDFLAGS)' \
+ -cplusplus -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) \
+ $(egl_OBJECTS) -Wl,--start-group $(egl_LIBS) -Wl,--end-group \
+ $(egl_SYS)
+
+$(OUTPUT_PATH)/st_GL.so: st_GL.o $(st_GL_LIBS)
+ $(MKLIB) -o $(notdir $@) -noprefix -linker '$(CXX)' \
+ -ldflags '-L$(TOP)/$(LIB_DIR) $(LDFLAGS)' \
+ -cplusplus -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) \
+ $< -Wl,--start-group $(st_GL_LIBS) -Wl,--end-group \
+ $(st_GL_SYS)
+
+$(egl_OBJECTS): %.o: %.c
+ $(CC) -c -o $@ $< $(egl_CPPFLAGS) $(DEFINES) $(CFLAGS)
+
+st_GL.o: st_GL.c
+ $(CC) -c -o $@ $< $(st_GL_CPPFLAGS) $(DEFINES) $(CFLAGS)
+
+install: $(OUTPUTS)
+ $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR)
+ for out in $(OUTPUTS); do \
+ $(MINSTALL) -m 755 "$$out" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \
+ done
+
+clean:
+ rm -f *.o
diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript
index cbd98cc416a..dfd05437231 100644
--- a/src/gallium/targets/egl-static/SConscript
+++ b/src/gallium/targets/egl-static/SConscript
@@ -79,21 +79,17 @@ if True:
openvg_name = 'OpenVG' if env['platform'] != 'windows' else 'libOpenVG'
env.Prepend(LIBS = [openvg_name, st_vega])
-if env['x11']:
+if env['HAVE_X11']:
env.Prepend(LIBS = [
ws_xlib,
- env['X11_LIBS'],
])
-
-if env['dri']:
- env.ParseConfig('pkg-config --cflags --libs xfixes')
+ env.PkgUseModules('X11')
# pipe drivers
-if env['drm']:
- env.ParseConfig('pkg-config --cflags --libs libdrm')
+if env['HAVE_DRM']:
+ env.PkgUseModules('DRM')
- if env['drm_intel']:
- env.ParseConfig('pkg-config --cflags --libs libdrm_intel')
+ if env['HAVE_DRM_INTEL']:
env.Append(CPPDEFINES = ['_EGL_PIPE_I915', '_EGL_PIPE_I965'])
env.Prepend(LIBS = [
i915drm,
@@ -103,7 +99,7 @@ if env['drm']:
ws_wrapper,
])
- if env['drm_radeon']:
+ if env['HAVE_DRM_RADEON']:
env.Append(CPPDEFINES = ['_EGL_PIPE_R300', '_EGL_PIPE_R600'])
env.Prepend(LIBS = [
radeonwinsys,
diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c
index e617ff50208..568f5498dd4 100644
--- a/src/gallium/targets/egl-static/egl.c
+++ b/src/gallium/targets/egl-static/egl.c
@@ -28,6 +28,15 @@
#include "common/egl_g3d_loader.h"
#include "egldriver.h"
+#include "egllog.h"
+
+#ifdef HAVE_LIBUDEV
+#include <stdio.h> /* for sscanf */
+#include <libudev.h>
+#endif
+
+#define DRIVER_MAP_GALLIUM_ONLY
+#include "pci_ids/pci_id_driver_map.h"
#include "egl_pipe.h"
#include "egl_st.h"
@@ -52,15 +61,108 @@ get_st_api(enum st_api_type api)
return stmod->stapi;
}
-static struct st_api *
-guess_gl_api(enum st_profile_type profile)
+#ifdef HAVE_LIBUDEV
+
+static boolean
+drm_fd_get_pci_id(int fd, int *vendor_id, int *chip_id)
{
- return get_st_api(ST_API_OPENGL);
+ struct udev *udev = NULL;
+ struct udev_device *device = NULL, *parent;
+ struct stat buf;
+ const char *pci_id;
+
+ *chip_id = -1;
+
+ udev = udev_new();
+ if (fstat(fd, &buf) < 0) {
+ _eglLog(_EGL_WARNING, "failed to stat fd %d", fd);
+ goto out;
+ }
+
+ device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
+ if (device == NULL) {
+ _eglLog(_EGL_WARNING,
+ "could not create udev device for fd %d", fd);
+ goto out;
+ }
+
+ parent = udev_device_get_parent(device);
+ if (parent == NULL) {
+ _eglLog(_EGL_WARNING, "could not get parent device");
+ goto out;
+ }
+
+ pci_id = udev_device_get_property_value(parent, "PCI_ID");
+ if (pci_id == NULL ||
+ sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) {
+ _eglLog(_EGL_WARNING, "malformed or no PCI ID");
+ *chip_id = -1;
+ goto out;
+ }
+
+out:
+ if (device)
+ udev_device_unref(device);
+ if (udev)
+ udev_unref(udev);
+
+ return (*chip_id >= 0);
+}
+
+#else
+
+static boolean
+drm_fd_get_pci_id(int fd, int *vendor_id, int *chip_id)
+{
+ return FALSE;
+}
+
+#endif /* HAVE_LIBUDEV */
+
+static const char *
+drm_fd_get_screen_name(int fd)
+{
+ int vendor_id, chip_id;
+ int idx, i;
+
+ if (!drm_fd_get_pci_id(fd, &vendor_id, &chip_id)) {
+ _eglLog(_EGL_WARNING, "failed to get driver name for fd %d", fd);
+ return NULL;
+ }
+
+ for (idx = 0; driver_map[idx].driver; idx++) {
+ if (vendor_id != driver_map[idx].vendor_id)
+ continue;
+
+ /* done if no chip id */
+ if (driver_map[idx].num_chips_ids == -1)
+ break;
+
+ for (i = 0; i < driver_map[idx].num_chips_ids; i++) {
+ if (driver_map[idx].chip_ids[i] == chip_id)
+ break;
+ }
+ /* matched! */
+ if (i < driver_map[idx].num_chips_ids)
+ break;
+ }
+
+ _eglLog((driver_map[idx].driver) ? _EGL_INFO : _EGL_WARNING,
+ "pci id for fd %d: %04x:%04x, driver %s",
+ fd, vendor_id, chip_id, driver_map[idx].driver);
+
+ return driver_map[idx].driver;
}
static struct pipe_screen *
create_drm_screen(const char *name, int fd)
{
+ if (!name) {
+ name = drm_fd_get_screen_name(fd);
+ if (!name)
+ return NULL;
+ }
+
return egl_pipe_create_drm_screen(name, fd);
}
@@ -79,7 +181,6 @@ loader_init(void)
egl_g3d_loader.profile_masks[i] = egl_st_get_profile_mask(i);
egl_g3d_loader.get_st_api = get_st_api;
- egl_g3d_loader.guess_gl_api = guess_gl_api;
egl_g3d_loader.create_drm_screen = create_drm_screen;
egl_g3d_loader.create_sw_screen = create_sw_screen;
@@ -95,7 +196,7 @@ loader_fini(void)
struct st_module *stmod = &st_modules[i];
if (stmod->stapi) {
- stmod->stapi->destroy(stmod->stapi);
+ egl_st_destroy_api(stmod->stapi);
stmod->stapi = NULL;
}
stmod->initialized = FALSE;
diff --git a/src/gallium/targets/egl-static/egl_st.c b/src/gallium/targets/egl-static/egl_st.c
index 3db52621def..81d7bb47568 100644
--- a/src/gallium/targets/egl-static/egl_st.c
+++ b/src/gallium/targets/egl-static/egl_st.c
@@ -29,52 +29,143 @@
#include "state_tracker/st_api.h"
#include "egl_st.h"
-/* for st/mesa */
+#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
#include "state_tracker/st_gl_api.h"
-/* for st/vega */
+#endif
+
+#if FEATURE_VG
#include "vg_api.h"
+#endif
+
+#if _EGL_EXTERNAL_GL
+
+#include "util/u_string.h"
+#include "util/u_dl.h"
+#include "egldriver.h"
+#include "egllog.h"
+
+static struct util_dl_library *egl_st_gl_lib;
+
+static EGLBoolean
+dlopen_gl_lib_cb(const char *dir, size_t len, void *callback_data)
+{
+ const char *name = (const char *) callback_data;
+ char path[1024];
+ int ret;
+
+ if (len) {
+ ret = util_snprintf(path, sizeof(path), "%.*s/%s" UTIL_DL_EXT,
+ len, dir, name);
+ }
+ else {
+ ret = util_snprintf(path, sizeof(path), "%s" UTIL_DL_EXT, name);
+ }
+
+ if (ret > 0 && ret < sizeof(path)) {
+ egl_st_gl_lib = util_dl_open(path);
+ if (egl_st_gl_lib)
+ _eglLog(_EGL_DEBUG, "loaded %s", path);
+ }
+
+ return !egl_st_gl_lib;
+}
static struct st_api *
-st_GL_create_api(void)
+load_gl(const char *name, const char *procname)
{
-#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
- return st_gl_api_create();
-#else
- return NULL;
-#endif
+ struct st_api *(*create_api)(void);
+ struct st_api *stapi = NULL;
+
+ _eglSearchPathForEach(dlopen_gl_lib_cb, (void *) name);
+ if (!egl_st_gl_lib)
+ return NULL;
+
+ create_api = (struct st_api *(*)(void))
+ util_dl_get_proc_address(egl_st_gl_lib, procname);
+ if (create_api)
+ stapi = create_api();
+
+ if (!stapi) {
+ util_dl_close(egl_st_gl_lib);
+ egl_st_gl_lib = NULL;
+ }
+
+ return stapi;
}
static struct st_api *
-st_OpenVG_create_api(void)
+egl_st_load_gl(void)
{
-#if FEATURE_VG
- return (struct st_api *) vg_api_get();
-#else
- return NULL;
-#endif
+ const char module[] = "st_GL";
+ const char symbol[] = "st_api_create_OpenGL";
+ struct st_api *stapi;
+
+ stapi = load_gl(module, symbol);
+
+ /* try again with libglapi.so loaded */
+ if (!stapi) {
+ struct util_dl_library *glapi = util_dl_open("libglapi" UTIL_DL_EXT);
+
+ if (glapi) {
+ _eglLog(_EGL_DEBUG, "retry with libglapi" UTIL_DL_EXT " loaded");
+
+ stapi = load_gl(module, symbol);
+ util_dl_close(glapi);
+ }
+ }
+ if (!stapi)
+ _eglLog(_EGL_WARNING, "unable to load %s" UTIL_DL_EXT, module);
+
+ return stapi;
}
+#endif /* _EGL_EXTERNAL_GL */
+
struct st_api *
egl_st_create_api(enum st_api_type api)
{
- struct st_api *stapi;
+ struct st_api *stapi = NULL;
switch (api) {
case ST_API_OPENGL:
- stapi = st_GL_create_api();
+#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
+#if _EGL_EXTERNAL_GL
+ stapi = egl_st_load_gl();
+#else
+ stapi = st_gl_api_create();
+#endif
+#endif
break;
case ST_API_OPENVG:
- stapi = st_OpenVG_create_api();
+#if FEATURE_VG
+ stapi = (struct st_api *) vg_api_get();
+#endif
break;
default:
assert(!"Unknown API Type\n");
- stapi = NULL;
break;
}
return stapi;
}
+void
+egl_st_destroy_api(struct st_api *stapi)
+{
+#if _EGL_EXTERNAL_GL
+ boolean is_gl = (stapi->api == ST_API_OPENGL);
+
+ stapi->destroy(stapi);
+
+ if (is_gl) {
+ util_dl_close(egl_st_gl_lib);
+ egl_st_gl_lib = NULL;
+ }
+#else
+ stapi->destroy(stapi);
+#endif
+}
+
uint
egl_st_get_profile_mask(enum st_api_type api)
{
diff --git a/src/gallium/targets/egl-static/egl_st.h b/src/gallium/targets/egl-static/egl_st.h
index ba82faf0b0e..7a3773c6ba2 100644
--- a/src/gallium/targets/egl-static/egl_st.h
+++ b/src/gallium/targets/egl-static/egl_st.h
@@ -34,6 +34,9 @@
struct st_api *
egl_st_create_api(enum st_api_type api);
+void
+egl_st_destroy_api(struct st_api *stapi);
+
uint
egl_st_get_profile_mask(enum st_api_type api);
diff --git a/src/gallium/targets/egl/egl.h b/src/gallium/targets/egl-static/st_GL.c
index 5fd06785407..3f4b7a09fa4 100644
--- a/src/gallium/targets/egl/egl.h
+++ b/src/gallium/targets/egl-static/st_GL.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 7.9
+ * Version: 7.10
*
- * Copyright (C) 2010 LunarG Inc.
+ * Copyright (C) 2011 LunarG Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -25,20 +25,14 @@
* Authors:
* Chia-I Wu <[email protected]>
*/
-
-#ifndef _EGL_H_
-#define _EGL_H_
-
+#include "state_tracker/st_gl_api.h"
#include "pipe/p_compiler.h"
-#include "state_tracker/st_api.h"
-
-#define ST_CREATE_OPENGL_SYMBOL "st_api_create_OpenGL"
-#define ST_CREATE_OPENVG_SYMBOL "st_api_create_OpenVG"
PUBLIC struct st_api *
st_api_create_OpenGL(void);
-PUBLIC struct st_api *
-st_api_create_OpenVG(void);
-
-#endif /* _EGL_H_ */
+struct st_api *
+st_api_create_OpenGL(void)
+{
+ return st_gl_api_create();
+}
diff --git a/src/gallium/targets/egl/Makefile b/src/gallium/targets/egl/Makefile
deleted file mode 100644
index dd566bd9a06..00000000000
--- a/src/gallium/targets/egl/Makefile
+++ /dev/null
@@ -1,242 +0,0 @@
-# src/gallium/targets/egl/Makefile
-#
-# This is the Makefile for EGL Gallium driver package. The package consists of
-#
-# egl_gallium.so - EGL driver
-# pipe_<HW>.so - pipe drivers
-# st_<API>.so - client API state trackers
-#
-# The following variables are examined
-#
-# EGL_PLATFORMS - platforms to support
-# GALLIUM_WINSYS_DIRS - pipe drivers to support
-# EGL_CLIENT_APIS - state trackers to support
-#
-
-TOP = ../../../..
-include $(TOP)/configs/current
-
-ST_PREFIX := st_
-PIPE_PREFIX := pipe_
-
-common_CPPFLAGS := \
- -I$(TOP)/include \
- -I$(TOP)/src/gallium/auxiliary \
- -I$(TOP)/src/gallium/drivers \
- -I$(TOP)/src/gallium/include \
- -I$(TOP)/src/gallium/winsys \
- $(LIBDRM_CFLAGS)
-
-common_SYS :=
-common_LIBS := \
- $(TOP)/src/gallium/drivers/identity/libidentity.a \
- $(TOP)/src/gallium/drivers/trace/libtrace.a \
- $(TOP)/src/gallium/drivers/rbug/librbug.a \
- $(GALLIUM_AUXILIARIES)
-
-# EGL driver
-egl_CPPFLAGS := \
- -I$(TOP)/src/gallium/state_trackers/egl \
- -I$(TOP)/src/egl/main \
- -DPIPE_PREFIX=\"$(PIPE_PREFIX)\" -DST_PREFIX=\"$(ST_PREFIX)\"
-egl_SYS := -lm $(DLOPEN_LIBS) -lEGL
-egl_LIBS := $(TOP)/src/gallium/state_trackers/egl/libegl.a
-
-ifneq ($(findstring x11, $(EGL_PLATFORMS)),)
-egl_SYS += -lX11 -lXext -lXfixes $(LIBDRM_LIB)
-egl_LIBS += $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a
-endif
-ifneq ($(findstring wayland, $(EGL_PLATFORMS)),)
-egl_SYS += $(WAYLAND_LIBS) $(LIBDRM_LIB)
-egl_LIBS += $(TOP)/src/gallium/winsys/sw/wayland/libws_wayland.a
-egl_LIBS += $(TOP)/src/egl/wayland/wayland-drm/libwayland-drm.a
-endif
-ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
-egl_SYS += $(LIBUDEV_LIBS) $(LIBDRM_LIB)
-endif
-ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
-egl_LIBS += $(TOP)/src/gallium/winsys/sw/fbdev/libfbdev.a
-endif
-
-# EGL_RENDERABLE_TYPE is a compile time attribute
-ifneq ($(filter $(GL_LIB), $(EGL_CLIENT_APIS)),)
-egl_CPPFLAGS += $(API_DEFINES)
-endif
-ifneq ($(filter $(VG_LIB), $(EGL_CLIENT_APIS)),)
-egl_CPPFLAGS += -DFEATURE_VG=1
-endif
-egl_CPPFLAGS := $(sort $(egl_CPPFLAGS))
-
-# i915 pipe driver
-i915_CPPFLAGS :=
-i915_SYS := -ldrm_intel
-i915_LIBS := \
- $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \
- $(TOP)/src/gallium/drivers/i915/libi915.a
-
-# i965 pipe driver
-i965_CPPFLAGS :=
-i965_SYS := -ldrm_intel
-i965_LIBS := \
- $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \
- $(TOP)/src/gallium/drivers/i965/libi965.a \
- $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a
-
-# nouveau pipe driver
-nouveau_CPPFLAGS :=
-nouveau_SYS := -ldrm_nouveau
-nouveau_LIBS := \
- $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \
- $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \
- $(TOP)/src/gallium/drivers/nv50/libnv50.a \
- $(TOP)/src/gallium/drivers/nvc0/libnvc0.a \
- $(TOP)/src/gallium/drivers/nouveau/libnouveau.a
-
-# r300 pipe driver
-r300_CPPFLAGS :=
-r300_SYS := -ldrm
-r300_LIBS := \
- $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
- $(TOP)/src/gallium/drivers/r300/libr300.a
-
-# r600 pipe driver
-r600_CPPFLAGS :=
-r600_SYS := -ldrm -ldrm_radeon
-r600_LIBS := \
- $(TOP)/src/gallium/winsys/r600/drm/libr600winsys.a \
- $(TOP)/src/gallium/drivers/r600/libr600.a
-
-# vmwgfx pipe driver
-vmwgfx_CPPFLAGS :=
-vmwgfx_SYS :=
-vmwgfx_LIBS := \
- $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \
- $(TOP)/src/gallium/drivers/svga/libsvga.a
-
-# swrast (pseudo) pipe driver
-swrast_CPPFLAGS := -DGALLIUM_SOFTPIPE -DGALLIUM_RBUG -DGALLIUM_TRACE
-swrast_SYS := -lm
-swrast_LIBS := $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a
-
-# LLVM
-ifeq ($(MESA_LLVM),1)
-common_SYS += $(LLVM_LIBS)
-swrast_CPPFLAGS += -DGALLIUM_LLVMPIPE
-swrast_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
-LDFLAGS += $(LLVM_LDFLAGS)
-endif
-
-# OpenGL state tracker
-GL_CPPFLAGS := -I$(TOP)/src/mesa $(API_DEFINES)
-ifeq ($(SHARED_GLAPI),1)
-GL_SYS := $(DRI_LIB_DEPS) -l$(GLAPI_LIB)
-else
-# cannot link to $(GL_LIB) as the app might want GL or GLES
-GL_SYS := $(DRI_LIB_DEPS)
-endif
-GL_LIBS := $(TOP)/src/mesa/libmesagallium.a
-
-# OpenVG state tracker
-OpenVG_CPPFLAGS := -I$(TOP)/src/gallium/state_trackers/vega
-OpenVG_SYS := -lm -l$(VG_LIB)
-OpenVG_LIBS := $(TOP)/src/gallium/state_trackers/vega/libvega.a
-
-
-OUTPUT_PATH := $(TOP)/$(LIB_DIR)/egl
-
-# determine the outputs
-ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += i915
-endif
-ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += i965
-endif
-ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += nouveau
-endif
-ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += r300
-endif
-ifneq ($(findstring r600/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += r600
-endif
-ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),)
-OUTPUTS += vmwgfx
-endif
-OUTPUTS += swrast
-OUTPUTS := $(addprefix $(PIPE_PREFIX), $(OUTPUTS))
-
-# EGL driver and state trackers
-OUTPUTS += egl_gallium $(addprefix $(ST_PREFIX), $(EGL_CLIENT_APIS))
-
-OUTPUTS := $(addsuffix .so, $(OUTPUTS))
-OUTPUTS := $(addprefix $(OUTPUT_PATH)/, $(OUTPUTS))
-
-default: $(OUTPUTS)
-
-define mklib
-$(MKLIB) -o $(notdir $@) -noprefix -linker '$(CC)' \
- -L$(TOP)/$(LIB_DIR) -ldflags '$(LDFLAGS)' \
- -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) $< \
- -Wl,--start-group $(common_LIBS) $($(1)_LIBS) -Wl,--end-group \
- $(common_SYS) $($(1)_SYS)
-endef
-
-define mklib-cxx
-$(MKLIB) -o $(notdir $@) -noprefix -linker '$(CXX)' \
- -L$(TOP)/$(LIB_DIR) -ldflags '$(LDFLAGS)' \
- -cplusplus -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) $< \
- -Wl,--start-group $(common_LIBS) $($(1)_LIBS) -Wl,--end-group \
- $(common_SYS) $($(1)_SYS)
-endef
-
-# EGL driver
-$(OUTPUT_PATH)/egl_gallium.so: egl.o $(egl_LIBS)
- $(call mklib,egl)
-
-# pipe drivers
-$(OUTPUT_PATH)/$(PIPE_PREFIX)i915.so: pipe_i915.o $(i915_LIBS)
- $(call mklib,i915)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)i965.so: pipe_i965.o $(i965_LIBS)
- $(call mklib,i965)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)nouveau.so: pipe_nouveau.o $(nouveau_LIBS)
- $(call mklib,nouveau)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)r300.so: pipe_r300.o $(r300_LIBS)
- $(call mklib,r300)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)r600.so: pipe_r600.o $(r600_LIBS)
- $(call mklib,r600)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)vmwgfx.so: pipe_vmwgfx.o $(vmwgfx_LIBS)
- $(call mklib,vmwgfx)
-
-$(OUTPUT_PATH)/$(PIPE_PREFIX)swrast.so: pipe_swrast.o $(swrast_LIBS)
- $(call mklib,swrast)
-
-# state trackers
-$(OUTPUT_PATH)/$(ST_PREFIX)$(GL_LIB).so: st_GL.o $(GL_LIBS)
- $(call mklib-cxx,GL)
-
-$(OUTPUT_PATH)/$(ST_PREFIX)$(VG_LIB).so: st_OpenVG.o $(OpenVG_LIBS)
- $(call mklib,OpenVG)
-
-egl.o: egl.c
- $(CC) -c -o $@ $< $(common_CPPFLAGS) $(egl_CPPFLAGS) $(DEFINES) $(CFLAGS)
-
-pipe_%.o: pipe_%.c
- $(CC) -c -o $@ $< $(common_CPPFLAGS) $($*_CPPFLAGS) $(DEFINES) $(CFLAGS)
-
-st_%.o: st_%.c
- $(CC) -c -o $@ $< $(common_CPPFLAGS) $($*_CPPFLAGS) $(DEFINES) $(CFLAGS)
-
-install: $(OUTPUTS)
- $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR)
- for out in $(OUTPUTS); do \
- $(MINSTALL) -m 755 "$$out" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \
- done
-
-clean:
- rm -f *.o
diff --git a/src/gallium/targets/egl/egl.c b/src/gallium/targets/egl/egl.c
deleted file mode 100644
index 3467aea9991..00000000000
--- a/src/gallium/targets/egl/egl.c
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.9
- *
- * Copyright (C) 2010 LunarG Inc.
- *
- * 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 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:
- * Chia-I Wu <[email protected]>
- */
-
-#include "util/u_debug.h"
-#include "util/u_string.h"
-#include "util/u_memory.h"
-#include "util/u_dl.h"
-#include "egldriver.h"
-#include "egllog.h"
-
-#include "state_tracker/st_api.h"
-#include "state_tracker/drm_driver.h"
-#include "common/egl_g3d_loader.h"
-
-#ifdef HAVE_LIBUDEV
-#include <libudev.h>
-#define DRIVER_MAP_GALLIUM_ONLY
-#include "pci_ids/pci_id_driver_map.h"
-#endif
-
-#include "egl.h"
-
-struct egl_g3d_loader egl_g3d_loader;
-
-static struct st_module {
- boolean initialized;
- char *name;
- struct util_dl_library *lib;
- struct st_api *stapi;
-} st_modules[ST_API_COUNT];
-
-static struct pipe_module {
- boolean initialized;
- char *name;
- struct util_dl_library *lib;
- const struct drm_driver_descriptor *drmdd;
- struct pipe_screen *(*swrast_create_screen)(struct sw_winsys *);
-} pipe_modules[16];
-
-static char *
-loader_strdup(const char *s)
-{
- size_t len = (s) ? strlen(s) : 0;
- char *t = MALLOC(len + 1);
- if (t) {
- memcpy(t, s, len);
- t[len] = '\0';
- }
- return t;
-}
-
-static EGLBoolean
-dlopen_st_module_cb(const char *dir, size_t len, void *callback_data)
-{
- struct st_module *stmod =
- (struct st_module *) callback_data;
- char path[1024];
- int ret;
-
- if (len) {
- ret = util_snprintf(path, sizeof(path),
- "%.*s/" ST_PREFIX "%s" UTIL_DL_EXT, len, dir, stmod->name);
- }
- else {
- ret = util_snprintf(path, sizeof(path),
- ST_PREFIX "%s" UTIL_DL_EXT, stmod->name);
- }
-
- if (ret > 0 && ret < sizeof(path)) {
- stmod->lib = util_dl_open(path);
- if (stmod->lib)
- _eglLog(_EGL_DEBUG, "loaded %s", path);
- }
-
- return !(stmod->lib);
-}
-
-static boolean
-load_st_module(struct st_module *stmod,
- const char *name, const char *procname)
-{
- struct st_api *(*create_api)(void);
-
- if (name) {
- _eglLog(_EGL_DEBUG, "searching for st module %s", name);
- stmod->name = loader_strdup(name);
- }
- else {
- stmod->name = NULL;
- }
-
- if (stmod->name)
- _eglSearchPathForEach(dlopen_st_module_cb, (void *) stmod);
- else
- stmod->lib = util_dl_open(NULL);
-
- if (stmod->lib) {
- create_api = (struct st_api *(*)(void))
- util_dl_get_proc_address(stmod->lib, procname);
- if (create_api)
- stmod->stapi = create_api();
-
- if (!stmod->stapi) {
- util_dl_close(stmod->lib);
- stmod->lib = NULL;
- }
- }
-
- if (!stmod->stapi) {
- FREE(stmod->name);
- stmod->name = NULL;
- }
-
- return (stmod->stapi != NULL);
-}
-
-static EGLBoolean
-dlopen_pipe_module_cb(const char *dir, size_t len, void *callback_data)
-{
- struct pipe_module *pmod = (struct pipe_module *) callback_data;
- char path[1024];
- int ret;
-
- if (len) {
- ret = util_snprintf(path, sizeof(path),
- "%.*s/" PIPE_PREFIX "%s" UTIL_DL_EXT, len, dir, pmod->name);
- }
- else {
- ret = util_snprintf(path, sizeof(path),
- PIPE_PREFIX "%s" UTIL_DL_EXT, pmod->name);
- }
- if (ret > 0 && ret < sizeof(path)) {
- pmod->lib = util_dl_open(path);
- if (pmod->lib)
- _eglLog(_EGL_DEBUG, "loaded %s", path);
- }
-
- return !(pmod->lib);
-}
-
-static boolean
-load_pipe_module(struct pipe_module *pmod, const char *name)
-{
- pmod->name = loader_strdup(name);
- if (!pmod->name)
- return FALSE;
-
- _eglLog(_EGL_DEBUG, "searching for pipe module %s", pmod->name);
- _eglSearchPathForEach(dlopen_pipe_module_cb, (void *) pmod);
- if (pmod->lib) {
- pmod->drmdd = (const struct drm_driver_descriptor *)
- util_dl_get_proc_address(pmod->lib, "driver_descriptor");
-
- /* sanity check on the name */
- if (pmod->drmdd && strcmp(pmod->drmdd->name, pmod->name) != 0)
- pmod->drmdd = NULL;
-
- /* swrast */
- if (pmod->drmdd && !pmod->drmdd->driver_name) {
- pmod->swrast_create_screen =
- (struct pipe_screen *(*)(struct sw_winsys *))
- util_dl_get_proc_address(pmod->lib, "swrast_create_screen");
- if (!pmod->swrast_create_screen)
- pmod->drmdd = NULL;
- }
-
- if (!pmod->drmdd) {
- util_dl_close(pmod->lib);
- pmod->lib = NULL;
- }
- }
-
- return (pmod->drmdd != NULL);
-}
-
-static struct st_api *
-get_st_api_full(enum st_api_type api, enum st_profile_type profile)
-{
- struct st_module *stmod = &st_modules[api];
- const char *names[8], *symbol;
- int i, count = 0;
-
- if (stmod->initialized)
- return stmod->stapi;
-
- switch (api) {
- case ST_API_OPENGL:
- symbol = ST_CREATE_OPENGL_SYMBOL;
- names[count++] = "GL";
- break;
- case ST_API_OPENVG:
- symbol = ST_CREATE_OPENVG_SYMBOL;
- names[count++] = "OpenVG";
- break;
- default:
- symbol = NULL;
- assert(!"Unknown API Type\n");
- break;
- }
-
- /* NULL means the process itself */
- names[count++] = NULL;
-
- for (i = 0; i < count; i++) {
- if (load_st_module(stmod, names[i], symbol))
- break;
- }
-
- /* try again with libGL.so loaded */
- if (!stmod->stapi && api == ST_API_OPENGL) {
- struct util_dl_library *glapi = util_dl_open("libGL" UTIL_DL_EXT);
-
- if (glapi) {
- _eglLog(_EGL_DEBUG, "retry with libGL" UTIL_DL_EXT " loaded");
- /* skip the last name (which is NULL) */
- for (i = 0; i < count - 1; i++) {
- if (load_st_module(stmod, names[i], symbol))
- break;
- }
- util_dl_close(glapi);
- }
- }
-
- if (!stmod->stapi) {
- EGLint level = (egl_g3d_loader.profile_masks[api]) ?
- _EGL_WARNING : _EGL_DEBUG;
- _eglLog(level, "unable to load " ST_PREFIX "%s" UTIL_DL_EXT, names[0]);
- }
-
- stmod->initialized = TRUE;
-
- return stmod->stapi;
-}
-
-static struct st_api *
-get_st_api(enum st_api_type api)
-{
- enum st_profile_type profile = ST_PROFILE_DEFAULT;
-
- /* determine the profile from the linked libraries */
- if (api == ST_API_OPENGL) {
- struct util_dl_library *self;
-
- self = util_dl_open(NULL);
- if (self) {
- if (util_dl_get_proc_address(self, "glColor4x"))
- profile = ST_PROFILE_OPENGL_ES1;
- else if (util_dl_get_proc_address(self, "glShaderBinary"))
- profile = ST_PROFILE_OPENGL_ES2;
- util_dl_close(self);
- }
- }
-
- return get_st_api_full(api, profile);
-}
-
-static struct st_api *
-guess_gl_api(enum st_profile_type profile)
-{
- return get_st_api_full(ST_API_OPENGL, profile);
-}
-
-static struct pipe_module *
-get_pipe_module(const char *name)
-{
- struct pipe_module *pmod = NULL;
- int i;
-
- if (!name)
- return NULL;
-
- for (i = 0; i < Elements(pipe_modules); i++) {
- if (!pipe_modules[i].initialized ||
- strcmp(pipe_modules[i].name, name) == 0) {
- pmod = &pipe_modules[i];
- break;
- }
- }
- if (!pmod)
- return NULL;
-
- if (!pmod->initialized) {
- load_pipe_module(pmod, name);
- pmod->initialized = TRUE;
- }
-
- return pmod;
-}
-
-static char *
-drm_fd_get_screen_name(int fd)
-{
- char *driver = NULL;
-#ifdef HAVE_LIBUDEV
- struct udev *udev;
- struct udev_device *device, *parent;
- struct stat buf;
- const char *pci_id;
- int vendor_id, chip_id, i, j;
-
- udev = udev_new();
- if (fstat(fd, &buf) < 0) {
- _eglLog(_EGL_WARNING, "failed to stat fd %d", fd);
- return NULL;
- }
-
- device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
- if (device == NULL) {
- _eglLog(_EGL_WARNING,
- "could not create udev device for fd %d", fd);
- return NULL;
- }
-
- parent = udev_device_get_parent(device);
- if (parent == NULL) {
- _eglLog(_EGL_WARNING, "could not get parent device");
- goto out;
- }
-
- pci_id = udev_device_get_property_value(parent, "PCI_ID");
- if (pci_id == NULL ||
- sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
- _eglLog(_EGL_WARNING, "malformed or no PCI ID");
- goto out;
- }
-
- for (i = 0; driver_map[i].driver; i++) {
- if (vendor_id != driver_map[i].vendor_id)
- continue;
- if (driver_map[i].num_chips_ids == -1) {
- driver = strdup(driver_map[i].driver);
- _eglLog(_EGL_WARNING,
- "pci id for %d: %04x:%04x, driver %s",
- fd, vendor_id, chip_id, driver);
- goto out;
- }
-
- for (j = 0; j < driver_map[i].num_chips_ids; j++)
- if (driver_map[i].chip_ids[j] == chip_id) {
- driver = strdup(driver_map[i].driver);
- _eglLog(_EGL_WARNING,
- "pci id for %d: %04x:%04x, driver %s",
- fd, vendor_id, chip_id, driver);
- goto out;
- }
- }
-
-out:
- udev_device_unref(device);
- udev_unref(udev);
-
-#endif
- return driver;
-}
-
-static struct pipe_screen *
-create_drm_screen(const char *name, int fd)
-{
- struct pipe_module *pmod;
- const char *screen_name = name;
-
- if (screen_name == NULL)
- if ((screen_name = drm_fd_get_screen_name(fd)) == NULL)
- return NULL;
- pmod = get_pipe_module(screen_name);
-
- return (pmod && pmod->drmdd && pmod->drmdd->create_screen) ?
- pmod->drmdd->create_screen(fd) : NULL;
-}
-
-static struct pipe_screen *
-create_sw_screen(struct sw_winsys *ws)
-{
- struct pipe_module *pmod = get_pipe_module("swrast");
- return (pmod && pmod->swrast_create_screen) ?
- pmod->swrast_create_screen(ws) : NULL;
-}
-
-static const struct egl_g3d_loader *
-loader_init(void)
-{
- /* TODO detect at runtime? */
-#if FEATURE_GL
- egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK;
-#endif
-#if FEATURE_ES1
- egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK;
-#endif
-#if FEATURE_ES2
- egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK;
-#endif
-#if FEATURE_VG
- egl_g3d_loader.profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK;
-#endif
-
- egl_g3d_loader.get_st_api = get_st_api;
- egl_g3d_loader.guess_gl_api = guess_gl_api;
- egl_g3d_loader.create_drm_screen = create_drm_screen;
- egl_g3d_loader.create_sw_screen = create_sw_screen;
-
- return &egl_g3d_loader;
-}
-
-static void
-loader_fini(void)
-{
- int i;
-
- for (i = 0; i < ST_API_COUNT; i++) {
- struct st_module *stmod = &st_modules[i];
-
- if (stmod->stapi) {
- stmod->stapi->destroy(stmod->stapi);
- stmod->stapi = NULL;
- }
- if (stmod->lib) {
- util_dl_close(stmod->lib);
- stmod->lib = NULL;
- }
- if (stmod->name) {
- FREE(stmod->name);
- stmod->name = NULL;
- }
- stmod->initialized = FALSE;
- }
- for (i = 0; i < Elements(pipe_modules); i++) {
- struct pipe_module *pmod = &pipe_modules[i];
-
- if (!pmod->initialized)
- break;
-
- pmod->drmdd = NULL;
- pmod->swrast_create_screen = NULL;
- if (pmod->lib) {
- util_dl_close(pmod->lib);
- pmod->lib = NULL;
- }
- if (pmod->name) {
- FREE(pmod->name);
- pmod->name = NULL;
- }
- pmod->initialized = FALSE;
- }
-}
-
-static void
-egl_g3d_unload(_EGLDriver *drv)
-{
- egl_g3d_destroy_driver(drv);
- loader_fini();
-}
-
-_EGLDriver *
-_eglMain(const char *args)
-{
- const struct egl_g3d_loader *loader;
- _EGLDriver *drv;
-
- loader = loader_init();
- drv = egl_g3d_create_driver(loader);
- if (!drv) {
- loader_fini();
- return NULL;
- }
-
- drv->Name = "Gallium";
- drv->Unload = egl_g3d_unload;
-
- return drv;
-}
diff --git a/src/gallium/targets/egl/st_GL.c b/src/gallium/targets/egl/st_GL.c
deleted file mode 100644
index c1df844aa43..00000000000
--- a/src/gallium/targets/egl/st_GL.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "state_tracker/st_gl_api.h"
-#include "egl.h"
-
-PUBLIC struct st_api *
-st_api_create_OpenGL(void)
-{
- return st_gl_api_create();
-}
diff --git a/src/gallium/targets/egl/st_OpenVG.c b/src/gallium/targets/egl/st_OpenVG.c
deleted file mode 100644
index d0bf4dbae91..00000000000
--- a/src/gallium/targets/egl/st_OpenVG.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "vg_api.h"
-#include "egl.h"
-
-PUBLIC struct st_api *
-st_api_create_OpenVG(void)
-{
- return (struct st_api *) vg_api_get();
-}
diff --git a/src/gallium/targets/gbm/Makefile b/src/gallium/targets/gbm/Makefile
new file mode 100644
index 00000000000..53104253d4f
--- /dev/null
+++ b/src/gallium/targets/gbm/Makefile
@@ -0,0 +1,169 @@
+# src/gallium/targets/gbm/Makefile
+
+TOP = ../../../..
+include $(TOP)/configs/current
+
+PIPE_PREFIX := pipe_
+
+GBM_BACKEND = gbm_gallium_drm
+GBM_SOURCES = gbm.c pipe_loader.c
+
+GBM_INCLUDES = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/gallium/state_trackers/gbm \
+ -I$(TOP)/src/gbm/main \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gallium/include \
+
+GBM_LIBS = $(LIBUDEV_LIBS) $(LIBDRM_LIB) \
+ $(TOP)/src/gallium/state_trackers/gbm/libgbm.a \
+ $(TOP)/src/gallium/drivers/identity/libidentity.a \
+ $(TOP)/src/gallium/drivers/galahad/libgalahad.a \
+ $(TOP)/src/gallium/drivers/trace/libtrace.a \
+ $(TOP)/src/gallium/drivers/rbug/librbug.a \
+ $(GALLIUM_AUXILIARIES)
+
+
+GBM_CFLAGS = \
+ -DGBM_BACKEND_SEARCH_DIR=\"$(GBM_BACKEND_INSTALL_DIR)\" \
+ -DPIPE_PREFIX=\"$(PIPE_PREFIX)\" \
+ $(LIBUDEV_CFLAGS) \
+ $(LIBDRM_CFLAGS)
+
+
+pipe_INCLUDES = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gallium/drivers \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/winsys
+
+pipe_LIBS = \
+ $(TOP)/src/gallium/drivers/identity/libidentity.a \
+ $(TOP)/src/gallium/drivers/trace/libtrace.a \
+ $(TOP)/src/gallium/drivers/rbug/librbug.a \
+ $(GALLIUM_AUXILIARIES)
+
+# as if we are DRI modules
+pipe_SYS = $(DRI_LIB_DEPS)
+
+pipe_CLFLAGS = \
+ -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD \
+ $(LIBDRM_CFLAGS)
+
+pipe_LDFLAGS = -Wl,--no-undefined
+
+# i915 pipe driver
+i915_LIBS = \
+ $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \
+ $(TOP)/src/gallium/drivers/i915/libi915.a
+i915_SYS = -ldrm_intel
+
+# i965 pipe driver
+i965_LIBS = \
+ $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \
+ $(TOP)/src/gallium/drivers/i965/libi965.a \
+ $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a
+i965_SYS = -ldrm_intel
+
+# nouveau pipe driver
+nouveau_LIBS = \
+ $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \
+ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \
+ $(TOP)/src/gallium/drivers/nv50/libnv50.a \
+ $(TOP)/src/gallium/drivers/nvc0/libnvc0.a \
+ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a
+nouveau_SYS = -ldrm_nouveau
+
+# r300 pipe driver
+r300_LIBS = \
+ $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
+ $(TOP)/src/gallium/drivers/r300/libr300.a
+r300_SYS = -ldrm_radeon
+
+# r600 pipe driver
+r600_LIBS = \
+ $(TOP)/src/gallium/winsys/r600/drm/libr600winsys.a \
+ $(TOP)/src/gallium/drivers/r600/libr600.a
+r600_SYS = -ldrm_radeon
+
+# vmwgfx pipe driver
+vmwgfx_LIBS = \
+ $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \
+ $(TOP)/src/gallium/drivers/svga/libsvga.a
+
+# LLVM
+ifeq ($(MESA_LLVM),1)
+pipe_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
+pipe_SYS += $(LLVM_LIBS)
+pipe_LDFLAGS += $(LLVM_LDFLAGS)
+endif
+
+# determine the targets/sources
+pipe_TARGETS =
+pipe_SOURCES =
+
+ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)i915.so
+pipe_SOURCES += pipe_i915.c
+endif
+
+ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)i965.so
+pipe_SOURCES += pipe_i965.c
+endif
+
+ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)nouveau.so
+pipe_SOURCES += pipe_nouveau.c
+endif
+
+ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)r300.so
+pipe_SOURCES += pipe_r300.c
+endif
+
+ifneq ($(findstring r600/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)r600.so
+pipe_SOURCES += pipe_r600.c
+endif
+
+ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),)
+pipe_TARGETS += $(PIPE_PREFIX)vmwgfx.so
+pipe_SOURCES += pipe_vmwgfx.c
+endif
+
+pipe_OBJECTS = $(pipe_SOURCES:.c=.o)
+
+
+GBM_EXTRA_TARGETS = $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS))
+GBM_EXTRA_INSTALL = install-pipes
+GBM_EXTRA_CLEAN = clean-pipes
+GBM_EXTRA_SOURCES = $(pipe_SOURCES)
+
+include $(TOP)/src/gbm/backends/Makefile.template
+
+
+$(GBM_EXTRA_TARGETS): $(TOP)/$(LIB_DIR)/gbm/%: %
+ @$(INSTALL) -d $(dir $@)
+ $(INSTALL) $< $(dir $@)
+
+$(pipe_TARGETS): $(PIPE_PREFIX)%.so: pipe_%.o
+ $(MKLIB) -o $@ -noprefix -linker '$(CC)' \
+ -ldflags '-L$(TOP)/$(LIB_DIR) $(pipe_LDFLAGS) $(LDFLAGS)' \
+ $(MKLIB_OPTIONS) $< \
+ -Wl,--start-group $(pipe_LIBS) $($*_LIBS) -Wl,--end-group \
+ $(pipe_SYS) $($*_SYS)
+
+$(pipe_OBJECTS): %.o: %.c
+ $(CC) -c -o $@ $< $(pipe_INCLUDES) $(pipe_CFLAGS) $(CFLAGS)
+
+install-pipes: $(GBM_EXTRA_TARGETS)
+ $(INSTALL) -d $(DESTDIR)$(GBM_BACKEND_INSTALL_DIR)
+ for tgt in $(GBM_EXTRA_TARGETS); do \
+ $(MINSTALL) "$$tgt" $(DESTDIR)$(GBM_BACKEND_INSTALL_DIR); \
+ done
+
+clean-pipes:
+ rm -f $(pipe_TARGETS)
+ rm -f $(pipe_OBJECTS)
diff --git a/src/gallium/targets/gbm/gbm.c b/src/gallium/targets/gbm/gbm.c
new file mode 100644
index 00000000000..e840fc5fa1a
--- /dev/null
+++ b/src/gallium/targets/gbm/gbm.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2011 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:
+ * Benjamin Franzke <[email protected]>
+ */
+
+#include "util/u_inlines.h"
+
+#include "gbm_gallium_drmint.h"
+#include "pipe_loader.h"
+
+static struct pipe_screen *
+create_drm_screen(const char *name, int fd)
+{
+ struct pipe_module *pmod = get_pipe_module(name);
+
+ return (pmod && pmod->drmdd && pmod->drmdd->create_screen) ?
+ pmod->drmdd->create_screen(fd) : NULL;
+}
+
+int
+gallium_screen_create(struct gbm_gallium_drm_device *gdrm)
+{
+ gdrm->base.driver_name = drm_fd_get_screen_name(gdrm->base.base.fd);
+ if (gdrm->base.driver_name == NULL)
+ return -1;
+
+ gdrm->screen = create_drm_screen(gdrm->base.driver_name, gdrm->base.base.fd);
+ if (gdrm->screen == NULL) {
+ debug_printf("failed to load driver: %s\n", gdrm->base.driver_name);
+ return -1;
+ };
+
+ return 0;
+}
+
+GBM_EXPORT struct gbm_backend gbm_backend = {
+ .backend_name = "gallium_drm",
+ .create_device = gbm_gallium_drm_device_create,
+};
diff --git a/src/gallium/targets/egl/pipe_i915.c b/src/gallium/targets/gbm/pipe_i915.c
index cd74044d8c1..cd74044d8c1 100644
--- a/src/gallium/targets/egl/pipe_i915.c
+++ b/src/gallium/targets/gbm/pipe_i915.c
diff --git a/src/gallium/targets/egl/pipe_i965.c b/src/gallium/targets/gbm/pipe_i965.c
index f810ecffb0a..f810ecffb0a 100644
--- a/src/gallium/targets/egl/pipe_i965.c
+++ b/src/gallium/targets/gbm/pipe_i965.c
diff --git a/src/gallium/targets/gbm/pipe_loader.c b/src/gallium/targets/gbm/pipe_loader.c
new file mode 100644
index 00000000000..6200541dbf0
--- /dev/null
+++ b/src/gallium/targets/gbm/pipe_loader.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright © 2011 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 <[email protected]>
+ * Benjamin Franzke <[email protected]>
+ */
+
+#include <stdio.h>
+#include "util/u_string.h"
+#include "util/u_memory.h"
+
+#include <libudev.h>
+
+#include "gbm_gallium_drmint.h"
+#include "pipe_loader.h"
+#define DRIVER_MAP_GALLIUM_ONLY
+#include "pci_ids/pci_id_driver_map.h"
+
+static struct pipe_module pipe_modules[16];
+
+static INLINE char *
+loader_strdup(const char *str)
+{
+ return mem_dup(str, strlen(str) + 1);
+}
+
+char *
+drm_fd_get_screen_name(int fd)
+{
+ struct udev *udev;
+ struct udev_device *device, *parent;
+ const char *pci_id;
+ char *driver = NULL;
+ int vendor_id, chip_id, i, j;
+
+ udev = udev_new();
+ device = _gbm_udev_device_new_from_fd(udev, fd);
+ if (device == NULL)
+ return NULL;
+
+ parent = udev_device_get_parent(device);
+ if (parent == NULL) {
+ fprintf(stderr, "gbm: could not get parent device");
+ goto out;
+ }
+
+ pci_id = udev_device_get_property_value(parent, "PCI_ID");
+ if (pci_id == NULL ||
+ sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
+ fprintf(stderr, "gbm: malformed or no PCI ID");
+ goto out;
+ }
+
+ for (i = 0; driver_map[i].driver; i++) {
+ if (vendor_id != driver_map[i].vendor_id)
+ continue;
+ if (driver_map[i].num_chips_ids == -1) {
+ driver = loader_strdup(driver_map[i].driver);
+ _gbm_log("pci id for %d: %04x:%04x, driver %s",
+ fd, vendor_id, chip_id, driver);
+ goto out;
+ }
+
+ for (j = 0; j < driver_map[i].num_chips_ids; j++)
+ if (driver_map[i].chip_ids[j] == chip_id) {
+ driver = loader_strdup(driver_map[i].driver);
+ _gbm_log("pci id for %d: %04x:%04x, driver %s",
+ fd, vendor_id, chip_id, driver);
+ goto out;
+ }
+ }
+
+out:
+ udev_device_unref(device);
+ udev_unref(udev);
+
+ return driver;
+}
+
+static void
+find_pipe_module(struct pipe_module *pmod, const char *name)
+{
+ char *search_paths, *end, *next, *p;
+ char path[PATH_MAX];
+ int ret;
+
+ search_paths = NULL;
+ if (geteuid() == getuid()) {
+ /* don't allow setuid apps to use GBM_BACKENDS_PATH */
+ search_paths = getenv("GBM_BACKENDS_PATH");
+ }
+ if (search_paths == NULL)
+ search_paths = GBM_BACKEND_SEARCH_DIR;
+
+ end = search_paths + strlen(search_paths);
+ for (p = search_paths; p < end && pmod->lib == NULL; p = next + 1) {
+ int len;
+ next = strchr(p, ':');
+ if (next == NULL)
+ next = end;
+
+ len = next - p;
+
+ if (len) {
+ ret = util_snprintf(path, sizeof(path),
+ "%.*s/" PIPE_PREFIX "%s" UTIL_DL_EXT, len, p, pmod->name);
+ }
+ else {
+ ret = util_snprintf(path, sizeof(path),
+ PIPE_PREFIX "%s" UTIL_DL_EXT, pmod->name);
+ }
+ if (ret > 0 && ret < sizeof(path)) {
+ pmod->lib = util_dl_open(path);
+ debug_printf("loaded %s\n", path);
+ }
+
+ }
+}
+
+static boolean
+load_pipe_module(struct pipe_module *pmod, const char *name)
+{
+ pmod->name = loader_strdup(name);
+ if (!pmod->name)
+ return FALSE;
+
+ find_pipe_module(pmod, name);
+
+ if (pmod->lib) {
+ pmod->drmdd = (const struct drm_driver_descriptor *)
+ util_dl_get_proc_address(pmod->lib, "driver_descriptor");
+
+ /* sanity check on the name */
+ if (pmod->drmdd && strcmp(pmod->drmdd->name, pmod->name) != 0)
+ pmod->drmdd = NULL;
+
+ if (!pmod->drmdd) {
+ util_dl_close(pmod->lib);
+ pmod->lib = NULL;
+ }
+ }
+
+ return (pmod->drmdd != NULL);
+}
+
+struct pipe_module *
+get_pipe_module(const char *name)
+{
+ struct pipe_module *pmod = NULL;
+ int i;
+
+ if (!name)
+ return NULL;
+
+ for (i = 0; i < Elements(pipe_modules); i++) {
+ if (!pipe_modules[i].initialized ||
+ strcmp(pipe_modules[i].name, name) == 0) {
+ pmod = &pipe_modules[i];
+ break;
+ }
+ }
+ if (!pmod)
+ return NULL;
+
+ if (!pmod->initialized) {
+ load_pipe_module(pmod, name);
+ pmod->initialized = TRUE;
+ }
+
+ return pmod;
+}
diff --git a/src/gallium/targets/gbm/pipe_loader.h b/src/gallium/targets/gbm/pipe_loader.h
new file mode 100644
index 00000000000..2e4cd9906b7
--- /dev/null
+++ b/src/gallium/targets/gbm/pipe_loader.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2011 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:
+ * Benjamin Franzke <[email protected]>
+ */
+
+#ifndef _PIPE_LOADER_H_
+#define _PIPE_LOADER_H_
+
+#include "pipe/p_compiler.h"
+#include "util/u_dl.h"
+#include "state_tracker/drm_driver.h"
+
+struct pipe_module {
+ boolean initialized;
+ char *name;
+ struct util_dl_library *lib;
+ const struct drm_driver_descriptor *drmdd;
+};
+
+struct pipe_module *
+get_pipe_module(const char *name);
+
+char *
+drm_fd_get_screen_name(int fd);
+
+#endif
diff --git a/src/gallium/targets/egl/pipe_nouveau.c b/src/gallium/targets/gbm/pipe_nouveau.c
index 0c9081bc713..0c9081bc713 100644
--- a/src/gallium/targets/egl/pipe_nouveau.c
+++ b/src/gallium/targets/gbm/pipe_nouveau.c
diff --git a/src/gallium/targets/egl/pipe_r300.c b/src/gallium/targets/gbm/pipe_r300.c
index 09940f0a194..09940f0a194 100644
--- a/src/gallium/targets/egl/pipe_r300.c
+++ b/src/gallium/targets/gbm/pipe_r300.c
diff --git a/src/gallium/targets/egl/pipe_r600.c b/src/gallium/targets/gbm/pipe_r600.c
index 486a6592585..486a6592585 100644
--- a/src/gallium/targets/egl/pipe_r600.c
+++ b/src/gallium/targets/gbm/pipe_r600.c
diff --git a/src/gallium/targets/egl/pipe_swrast.c b/src/gallium/targets/gbm/pipe_swrast.c
index b2e3289c5d3..b2e3289c5d3 100644
--- a/src/gallium/targets/egl/pipe_swrast.c
+++ b/src/gallium/targets/gbm/pipe_swrast.c
diff --git a/src/gallium/targets/egl/pipe_vmwgfx.c b/src/gallium/targets/gbm/pipe_vmwgfx.c
index 22a28fa858a..22a28fa858a 100644
--- a/src/gallium/targets/egl/pipe_vmwgfx.c
+++ b/src/gallium/targets/gbm/pipe_vmwgfx.c
diff --git a/src/gallium/targets/libgl-xlib/SConscript b/src/gallium/targets/libgl-xlib/SConscript
index ca15372f1d9..7d5d9bc47a9 100644
--- a/src/gallium/targets/libgl-xlib/SConscript
+++ b/src/gallium/targets/libgl-xlib/SConscript
@@ -54,7 +54,7 @@ libgl = env.SharedLibrary(
source = sources,
)
-if True:
+if False:
# XXX: Only install this libGL.so if DRI not enabled
libgl = env.InstallSharedLibrary(libgl, version=(1, 5))
diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile
index 5a2cdb1b0ef..755969cae27 100644
--- a/src/gallium/targets/xorg-nouveau/Makefile
+++ b/src/gallium/targets/xorg-nouveau/Makefile
@@ -1,7 +1,7 @@
TOP = ../../../..
include $(TOP)/configs/current
-LIBNAME = modesetting_drv.so
+LIBNAME = nouveau2_drv.so
C_SOURCES = \
nouveau_target.c \
@@ -23,4 +23,7 @@ DRIVER_PIPES = \
DRIVER_LINKS = \
$(shell pkg-config --libs libdrm libdrm_nouveau)
+DRIVER_INCLUDES = \
+ $(shell pkg-config --cflags-only-I libdrm libdrm_nouveau xf86driproto)
+
include ../Makefile.xorg
diff --git a/src/gallium/targets/xorg-nouveau/nouveau_xorg.c b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c
index f0d64925c73..43470a1656b 100644
--- a/src/gallium/targets/xorg-nouveau/nouveau_xorg.c
+++ b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c
@@ -29,6 +29,9 @@
*/
#include "../../state_trackers/xorg/xorg_winsys.h"
+#include <nouveau_drmif.h>
+#include <xorg/dri.h>
+#include <xf86drmMode.h>
static void nouveau_xorg_identify(int flags);
static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num,
@@ -38,23 +41,16 @@ static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num,
static const struct pci_id_match nouveau_xorg_device_match[] = {
{ 0x10de, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
0x00030000, 0x00ffffff, 0 },
- { 0x12d2, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
- 0x00030000, 0x00ffffff, 0 },
{0, 0, 0},
};
-static SymTabRec nouveau_xorg_chipsets[] = {
- {PCI_MATCH_ANY, "NVIDIA Graphics Device"},
- {-1, NULL}
-};
-
static PciChipsets nouveau_xorg_pci_devices[] = {
{PCI_MATCH_ANY, PCI_MATCH_ANY, NULL},
{-1, -1, NULL}
};
static XF86ModuleVersionInfo nouveau_xorg_version = {
- "modesetting",
+ "nouveau2",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
@@ -70,9 +66,9 @@ static XF86ModuleVersionInfo nouveau_xorg_version = {
* Xorg driver exported structures
*/
-_X_EXPORT DriverRec modesetting = {
+_X_EXPORT DriverRec nouveau2 = {
1,
- "modesetting",
+ "nouveau2",
nouveau_xorg_identify,
NULL,
xorg_tracker_available_options,
@@ -85,7 +81,7 @@ _X_EXPORT DriverRec modesetting = {
static MODULESETUPPROTO(nouveau_xorg_setup);
-_X_EXPORT XF86ModuleData modesettingModuleData = {
+_X_EXPORT XF86ModuleData nouveau2ModuleData = {
&nouveau_xorg_version,
nouveau_xorg_setup,
NULL
@@ -104,7 +100,7 @@ nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin)
*/
if (!setupDone) {
setupDone = 1;
- xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+ xf86AddDriver(&nouveau2, module, HaveDriverFuncs);
/*
* The return value must be non-NULL on success even though there
@@ -121,8 +117,7 @@ nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin)
static void
nouveau_xorg_identify(int flags)
{
- xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
- nouveau_xorg_chipsets);
+ xf86DrvMsg(0, X_INFO, "nouveau2: Gallium3D based 2D driver for NV30+ NVIDIA chipsets\n");
}
static Bool
@@ -131,13 +126,63 @@ nouveau_xorg_pci_probe(DriverPtr driver,
{
ScrnInfoPtr scrn = NULL;
EntityInfoPtr entity;
+ struct nouveau_device *dev = NULL;
+ char *busid;
+ int chipset, ret;
+
+ if (device->vendor_id != 0x10DE)
+ return FALSE;
+
+ if (!xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
+ xf86DrvMsg(-1, X_ERROR, "[drm] No DRICreatePCIBusID symbol\n");
+ return FALSE;
+ }
+ busid = DRICreatePCIBusID(device);
+
+ ret = nouveau_device_open(&dev, busid);
+ if (ret) {
+ xf86DrvMsg(-1, X_ERROR, "[drm] failed to open device\n");
+ free(busid);
+ return FALSE;
+ }
+
+ chipset = dev->chipset;
+ nouveau_device_close(&dev);
+
+ ret = drmCheckModesettingSupported(busid);
+ free(busid);
+ if (ret) {
+ xf86DrvMsg(-1, X_ERROR, "[drm] KMS not enabled\n");
+ return FALSE;
+ }
+
+ switch (chipset & 0xf0) {
+ case 0x00:
+ case 0x10:
+ case 0x20:
+ xf86DrvMsg(-1, X_NOTICE, "Too old chipset: NV%02x\n", chipset);
+ return FALSE;
+ case 0x30:
+ case 0x40:
+ case 0x60:
+ case 0x50:
+ case 0x80:
+ case 0x90:
+ case 0xa0:
+ case 0xc0:
+ xf86DrvMsg(-1, X_INFO, "Detected chipset: NV%02x\n", chipset);
+ break;
+ default:
+ xf86DrvMsg(-1, X_ERROR, "Unknown chipset: NV%02x\n", chipset);
+ return FALSE;
+ }
scrn = xf86ConfigPciEntity(scrn, 0, entity_num, nouveau_xorg_pci_devices,
NULL, NULL, NULL, NULL, NULL);
if (scrn != NULL) {
scrn->driverVersion = 1;
scrn->driverName = "nouveau";
- scrn->name = "modesetting";
+ scrn->name = "nouveau2";
scrn->Probe = NULL;
entity = xf86GetEntityInfo(entity_num);
diff --git a/src/gallium/targets/xorg-vmwgfx/SConscript b/src/gallium/targets/xorg-vmwgfx/SConscript
index 099d49cf1b7..41f4326ee86 100644
--- a/src/gallium/targets/xorg-vmwgfx/SConscript
+++ b/src/gallium/targets/xorg-vmwgfx/SConscript
@@ -4,10 +4,10 @@ Import('*')
env = env.Clone()
-env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server')
+env.PkgUseModules(['DRM', 'XORG'])
if env['kms']:
- env.ParseConfig('pkg-config --cflags --libs libkms')
+ env.PkgUseModules(['KMS'])
env.Prepend(CPPPATH = [
'#/include',
diff --git a/src/gallium/tests/trivial/Makefile b/src/gallium/tests/trivial/Makefile
index 2ed63419c7e..4ddbb0b73dc 100644
--- a/src/gallium/tests/trivial/Makefile
+++ b/src/gallium/tests/trivial/Makefile
@@ -1,4 +1,4 @@
-# progs/gallium/simple/Makefile
+# src/gallium/tests/trivial/Makefile
TOP = ../../../..
include $(TOP)/configs/current
@@ -11,7 +11,12 @@ INCLUDES = \
-I$(TOP)/src/gallium/winsys \
$(PROG_INCLUDES)
-LINKS = \
+ifeq ($(MESA_LLVM),1)
+LINKS = $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
+LDFLAGS += $(LLVM_LDFLAGS)
+endif
+
+LINKS += \
$(TOP)/src/gallium/drivers/rbug/librbug.a \
$(TOP)/src/gallium/drivers/trace/libtrace.a \
$(TOP)/src/gallium/drivers/galahad/libgalahad.a \
@@ -46,4 +51,4 @@ $(OBJECTS): %.o: %.c
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@
$(PROGS): %: %.o $(LINKS)
- $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@
+ $(CXX) $(LDFLAGS) $< $(LINKS) $(LLVM_LIBS) -lm -lpthread -ldl -o $@
diff --git a/src/gallium/tests/trivial/quad-tex.c b/src/gallium/tests/trivial/quad-tex.c
index 3a64b1c8d96..6c38b1096c1 100644
--- a/src/gallium/tests/trivial/quad-tex.c
+++ b/src/gallium/tests/trivial/quad-tex.c
@@ -212,7 +212,7 @@ static void init_prog(struct program *p)
p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
p->sampler.normalized_coords = 1;
- surf_tmpl.format = templat.format;
+ surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
@@ -329,7 +329,7 @@ static void draw(struct program *p)
/* vertex element data */
cso_set_vertex_elements(p->cso, 2, p->velem);
- util_draw_vertex_buffer(p->pipe,
+ util_draw_vertex_buffer(p->pipe, p->cso,
p->vbuf, 0,
PIPE_PRIM_QUADS,
4, /* verts */
diff --git a/src/gallium/tests/trivial/tri.c b/src/gallium/tests/trivial/tri.c
index bfd2f3ca9a3..656e92ee886 100644
--- a/src/gallium/tests/trivial/tri.c
+++ b/src/gallium/tests/trivial/tri.c
@@ -153,7 +153,7 @@ static void init_prog(struct program *p)
p->rasterizer.cull_face = PIPE_FACE_NONE;
p->rasterizer.gl_rasterization_rules = 1;
- surf_tmpl.format = templat.format;
+ surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM;
surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
@@ -258,7 +258,7 @@ static void draw(struct program *p)
/* vertex element data */
cso_set_vertex_elements(p->cso, 2, p->velem);
- util_draw_vertex_buffer(p->pipe,
+ util_draw_vertex_buffer(p->pipe, p->cso,
p->vbuf, 0,
PIPE_PRIM_TRIANGLES,
3, /* verts */
diff --git a/src/gallium/winsys/i915/drm/SConscript b/src/gallium/winsys/i915/drm/SConscript
index d8f5885b62c..15c97998fd8 100644
--- a/src/gallium/winsys/i915/drm/SConscript
+++ b/src/gallium/winsys/i915/drm/SConscript
@@ -2,7 +2,7 @@ Import('*')
env = env.Clone()
-env.ParseConfig('pkg-config --cflags libdrm')
+env.PkgUseModules('DRM')
i915drm_sources = [
'i915_drm_batchbuffer.c',
diff --git a/src/gallium/winsys/i965/drm/SConscript b/src/gallium/winsys/i965/drm/SConscript
index 785be449f70..a0f32ded402 100644
--- a/src/gallium/winsys/i965/drm/SConscript
+++ b/src/gallium/winsys/i965/drm/SConscript
@@ -2,7 +2,7 @@ Import('*')
env = env.Clone()
-env.ParseConfig('pkg-config --cflags libdrm')
+env.PkgUseModules('DRM')
i965drm_sources = [
'i965_drm_buffer.c',
diff --git a/src/gallium/winsys/r600/drm/SConscript b/src/gallium/winsys/r600/drm/SConscript
index cc9a06a2393..f55bb265226 100644
--- a/src/gallium/winsys/r600/drm/SConscript
+++ b/src/gallium/winsys/r600/drm/SConscript
@@ -13,11 +13,7 @@ r600_sources = [
'r600_bomgr.c',
]
-try:
- env.ParseConfig('pkg-config --cflags libdrm_radeon')
-except OSError:
- print 'warning: not building r600g'
- Return()
+env.PkgUseModules('DRM_RADEON')
env.Append(CPPPATH = '#/src/gallium/drivers/r600')
diff --git a/src/gallium/winsys/r600/drm/r600_drm.c b/src/gallium/winsys/r600/drm/r600_drm.c
index 03fe385334c..4602f7f2a4b 100644
--- a/src/gallium/winsys/r600/drm/r600_drm.c
+++ b/src/gallium/winsys/r600/drm/r600_drm.c
@@ -156,7 +156,20 @@ static int eg_interpret_tiling(struct radeon *radeon, uint32_t tiling_config)
return -EINVAL;
}
- radeon->tiling_info.num_banks = (tiling_config & 0xf0) >> 4;
+ switch ((tiling_config & 0xf0) >> 4) {
+ case 0:
+ radeon->tiling_info.num_banks = 4;
+ break;
+ case 1:
+ radeon->tiling_info.num_banks = 8;
+ break;
+ case 2:
+ radeon->tiling_info.num_banks = 16;
+ break;
+ default:
+ return -EINVAL;
+
+ }
switch ((tiling_config & 0xf00) >> 8) {
case 0:
diff --git a/src/gallium/winsys/r600/drm/r600_hw_context.c b/src/gallium/winsys/r600/drm/r600_hw_context.c
index f89f24c4d18..19dc729d00a 100644
--- a/src/gallium/winsys/r600/drm/r600_hw_context.c
+++ b/src/gallium/winsys/r600/drm/r600_hw_context.c
@@ -62,6 +62,8 @@ void r600_init_cs(struct r600_context *ctx)
ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_CONTEXT_CONTROL, 1, 0);
ctx->pm4[ctx->pm4_cdwords++] = 0x80000000;
ctx->pm4[ctx->pm4_cdwords++] = 0x80000000;
+
+ ctx->init_dwords = ctx->pm4_cdwords;
}
static void INLINE r600_context_update_fenced_list(struct r600_context *ctx)
@@ -1496,7 +1498,7 @@ void r600_context_flush(struct r600_context *ctx)
int r;
struct r600_block *enable_block = NULL;
- if (!ctx->pm4_cdwords)
+ if (ctx->pm4_cdwords == ctx->init_dwords)
return;
/* suspend queries */
diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript
index 39a8c711b84..2edb1e94645 100644
--- a/src/gallium/winsys/radeon/drm/SConscript
+++ b/src/gallium/winsys/radeon/drm/SConscript
@@ -8,11 +8,7 @@ radeon_sources = [
'radeon_drm_winsys.c',
]
-try:
- env.ParseConfig('pkg-config --cflags libdrm')
-except:
- print 'warning: not building Gallium Radeon'
- Return()
+env.PkgUseModules('DRM')
radeonwinsys = env.ConvenienceLibrary(
target ='radeonwinsys',
diff --git a/src/gallium/winsys/svga/drm/SConscript b/src/gallium/winsys/svga/drm/SConscript
index b049ea60aa8..3e25c8aa748 100644
--- a/src/gallium/winsys/svga/drm/SConscript
+++ b/src/gallium/winsys/svga/drm/SConscript
@@ -2,7 +2,7 @@ Import('*')
env = env.Clone()
-env.ParseConfig('pkg-config --cflags libdrm')
+env.PkgUseModules('DRM')
if env['gcc']:
env.Append(CCFLAGS = ['-fvisibility=hidden'])
diff --git a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c
index f4f4cd7969b..38d88f63aa2 100644
--- a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c
+++ b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c
@@ -54,10 +54,8 @@ struct fbdev_sw_winsys
struct sw_winsys base;
int fd;
- enum pipe_format format;
struct fb_fix_screeninfo finfo;
- void *fbmem;
unsigned rows;
unsigned stride;
};
@@ -77,22 +75,53 @@ fbdev_sw_winsys(struct sw_winsys *ws)
static void
fbdev_displaytarget_display(struct sw_winsys *ws,
struct sw_displaytarget *dt,
- void *context_private)
+ void *winsys_private)
{
struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws);
- struct fbdev_sw_displaytarget *fbdt = fbdev_sw_displaytarget(dt);
- unsigned rows, len, i;
+ struct fbdev_sw_displaytarget *src = fbdev_sw_displaytarget(dt);
+ const struct fbdev_sw_drawable *dst =
+ (const struct fbdev_sw_drawable *) winsys_private;
+ unsigned height, row_offset, row_len, i;
+ void *fbmem;
+
+ /* FIXME format conversion */
+ if (dst->format != src->format) {
+ assert(0);
+ return;
+ }
- rows = MIN2(fbdt->height, fbdev->rows);
- len = util_format_get_stride(fbdt->format, fbdt->width);
- len = MIN2(len, fbdev->stride);
+ height = dst->height;
+ if (dst->y + dst->height > fbdev->rows) {
+ /* nothing to copy */
+ if (dst->y >= fbdev->rows)
+ return;
- for (i = 0; i < rows; i++) {
- void *dst = fbdev->fbmem + fbdev->stride * i;
- void *src = fbdt->data + fbdt->stride * i;
+ height = fbdev->rows - dst->y;
+ }
+
+ row_offset = util_format_get_stride(dst->format, dst->x);
+ row_len = util_format_get_stride(dst->format, dst->width);
+ if (row_offset + row_len > fbdev->stride) {
+ /* nothing to copy */
+ if (row_offset >= fbdev->stride)
+ return;
- memcpy(dst, src, len);
+ row_len = fbdev->stride - row_offset;
}
+
+ fbmem = mmap(0, fbdev->finfo.smem_len,
+ PROT_WRITE, MAP_SHARED, fbdev->fd, 0);
+ if (fbmem == MAP_FAILED)
+ return;
+
+ for (i = 0; i < height; i++) {
+ char *from = (char *) src->data + src->stride * i;
+ char *to = (char *) fbmem + fbdev->stride * (dst->y + i) + row_offset;
+
+ memcpy(to, from, row_len);
+ }
+
+ munmap(fbmem, fbdev->finfo.smem_len);
}
static void
@@ -133,13 +162,9 @@ fbdev_displaytarget_create(struct sw_winsys *ws,
unsigned alignment,
unsigned *stride)
{
- struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws);
struct fbdev_sw_displaytarget *fbdt;
unsigned nblocksy, size, format_stride;
- if (fbdev->format != format)
- return NULL;
-
fbdt = CALLOC_STRUCT(fbdev_sw_displaytarget);
if (!fbdt)
return NULL;
@@ -170,8 +195,7 @@ fbdev_is_displaytarget_format_supported(struct sw_winsys *ws,
unsigned tex_usage,
enum pipe_format format)
{
- struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws);
- return (fbdev->format == format);
+ return TRUE;
}
static void
@@ -179,12 +203,11 @@ fbdev_destroy(struct sw_winsys *ws)
{
struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws);
- munmap(fbdev->fbmem, fbdev->finfo.smem_len);
FREE(fbdev);
}
struct sw_winsys *
-fbdev_create_sw_winsys(int fd, enum pipe_format format)
+fbdev_create_sw_winsys(int fd)
{
struct fbdev_sw_winsys *fbdev;
@@ -193,19 +216,11 @@ fbdev_create_sw_winsys(int fd, enum pipe_format format)
return NULL;
fbdev->fd = fd;
- fbdev->format = format;
if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->finfo)) {
FREE(fbdev);
return NULL;
}
- fbdev->fbmem = mmap(0, fbdev->finfo.smem_len,
- PROT_WRITE, MAP_SHARED, fbdev->fd, 0);
- if (fbdev->fbmem == MAP_FAILED) {
- FREE(fbdev);
- return NULL;
- }
-
fbdev->rows = fbdev->finfo.smem_len / fbdev->finfo.line_length;
fbdev->stride = fbdev->finfo.line_length;
diff --git a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h
index d958ab9db3e..59d8a8f5cfe 100644
--- a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h
+++ b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h
@@ -32,7 +32,14 @@
struct sw_winsys;
enum pipe_format;
+/* for pipe_screen::flush_frontbuffer */
+struct fbdev_sw_drawable {
+ enum pipe_format format;
+ unsigned x, y;
+ unsigned width, height;
+};
+
struct sw_winsys *
-fbdev_create_sw_winsys(int fd, enum pipe_format format);
+fbdev_create_sw_winsys(int fd);
#endif /* FBDEV_SW_WINSYS */
diff --git a/src/gallium/winsys/sw/wayland/wayland_sw_winsys.h b/src/gallium/winsys/sw/wayland/wayland_sw_winsys.h
index 5e3cfd0bf23..bedd2408f05 100644
--- a/src/gallium/winsys/sw/wayland/wayland_sw_winsys.h
+++ b/src/gallium/winsys/sw/wayland/wayland_sw_winsys.h
@@ -27,6 +27,7 @@
#define WAYLAND_SW_WINSYS
struct sw_winsys;
+struct wl_display;
struct winsys_handle {
int fd;