From 9009a854d1e0a8682af50b34650e0de62f5fe3a3 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sat, 6 Mar 2010 06:33:20 +0200 Subject: config: drop WINDOW_SYSTEM var --- configure.ac | 3 --- 1 file changed, 3 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 8ca274932cc..70e158f5d7a 100644 --- a/configure.ac +++ b/configure.ac @@ -457,7 +457,6 @@ CORE_DIRS="glsl mesa" SRC_DIRS="glew" GLU_DIRS="sgi" -WINDOW_SYSTEM="" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_WINSYS_DIRS="" GALLIUM_WINSYS_DRM_DIRS="" @@ -472,7 +471,6 @@ xlib) dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - WINDOW_SYSTEM="dri" GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm" ;; osmesa) @@ -482,7 +480,6 @@ esac AC_SUBST([SRC_DIRS]) AC_SUBST([GLU_DIRS]) AC_SUBST([DRIVER_DIRS]) -AC_SUBST([WINDOW_SYSTEM]) AC_SUBST([GALLIUM_DIRS]) AC_SUBST([GALLIUM_WINSYS_DIRS]) AC_SUBST([GALLIUM_WINSYS_DRM_DIRS]) -- cgit v1.2.3 From 683a099954bf03b7a8c28183b39ef26563a57bcc Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 11 Mar 2010 19:23:15 +0000 Subject: st/xorg: Fixup configure Make sure we always test for XEXT version. Make sure that the user has a recent version of libkms and libdrm installed. Note that the st/xorg code requires so new versions to work but these are needed to make a proper vmwgfx_drv.so driver which is the only real user. Cherry picked from 46cf606cd35d6740b28fd26bd32dbdfdde2c7833 Conflicts: configure.ac --- configure.ac | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 8ca274932cc..61487c3905e 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,8 @@ LIBDRM_REQUIRED=2.4.15 LIBDRM_RADEON_REQUIRED=2.4.17 DRI2PROTO_REQUIRED=2.1 GLPROTO_REQUIRED=1.4.11 +LIBDRM_XORG_REQUIRED=2.4.17 +LIBKMS_XORG_REQUIRED=1.0.0 dnl Check for progs AC_PROG_CPP @@ -1203,7 +1205,7 @@ yes) GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" fi # Have only tested st/xorg on 1.6.0 servers - PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0], + PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED], HAVE_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg", HAVE_XORG="no") ;; @@ -1223,9 +1225,9 @@ yes) fi ;; xorg) - PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1], - HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71", - HAVE_XEXTPROTO_71="no") + PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED]) + PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED]) + HAVE_XORG="yes" ;; es) # mesa/es is required to build es state tracker @@ -1237,6 +1239,12 @@ yes) ;; esac +if test "x$HAVE_XORG" = xyes; then + PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1], + HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71", + HAVE_XEXTPROTO_71="no") +fi + AC_ARG_WITH([egl-displays], [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@], [comma delimited native displays libEGL supports, e.g. -- cgit v1.2.3 From 51bff09f72632fbe431175bc81b49da7b2cc731c Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 11 Mar 2010 14:43:00 +0000 Subject: mesa: fix linux-dri and autogen builds since sw-api-2 merge --- configs/default | 2 +- configs/linux-dri | 2 +- configure.ac | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'configure.ac') diff --git a/configs/default b/configs/default index a6a92efe8fb..8fbf8dd219a 100644 --- a/configs/default +++ b/configs/default @@ -100,7 +100,7 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = drm null xlib +GALLIUM_WINSYS_DIRS = null xlib drm GALLIUM_TARGET_DIRS = libgl-xlib GALLIUM_WINSYS_DRM_DIRS = swrast GALLIUM_STATE_TRACKERS_DIRS = glx vega diff --git a/configs/linux-dri b/configs/linux-dri index 04bcfd859d1..d362fd8b377 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -58,7 +58,7 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS) EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri -GALLIUM_WINSYS_DIRS = drm +GALLIUM_WINSYS_DIRS = null xlib drm GALLIUM_TARGET_DIRS = GALLIUM_WINSYS_DRM_DIRS = vmware intel i965 GALLIUM_STATE_TRACKERS_DIRS = egl diff --git a/configure.ac b/configure.ac index 70e158f5d7a..049c9e5e8ec 100644 --- a/configure.ac +++ b/configure.ac @@ -458,6 +458,7 @@ CORE_DIRS="glsl mesa" SRC_DIRS="glew" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" +GALLIUM_TARGET_DIRS="" GALLIUM_WINSYS_DIRS="" GALLIUM_WINSYS_DRM_DIRS="" GALLIUM_DRIVERS_DIRS="softpipe failover trace identity" @@ -467,11 +468,12 @@ case "$mesa_driver" in xlib) DRIVER_DIRS="x11" GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib" ;; dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm" ;; osmesa) DRIVER_DIRS="osmesa" @@ -481,6 +483,7 @@ AC_SUBST([SRC_DIRS]) AC_SUBST([GLU_DIRS]) AC_SUBST([DRIVER_DIRS]) AC_SUBST([GALLIUM_DIRS]) +AC_SUBST([GALLIUM_TARGET_DIRS]) AC_SUBST([GALLIUM_WINSYS_DIRS]) AC_SUBST([GALLIUM_WINSYS_DRM_DIRS]) AC_SUBST([GALLIUM_DRIVERS_DIRS]) @@ -1415,6 +1418,7 @@ echo "" if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then echo " Gallium: yes" echo " Gallium dirs: $GALLIUM_DIRS" + echo " Target dirs: $GALLIUM_TARGET_DIRS" echo " Winsys dirs: $GALLIUM_WINSYS_DIRS" echo " Winsys drm dirs:$GALLIUM_WINSYS_DRM_DIRS" echo " Driver dirs: $GALLIUM_DRIVERS_DIRS" -- cgit v1.2.3 From 8d86d395dcf6a5f192b6987485bb7aef49f1fefc Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Fri, 12 Mar 2010 18:55:09 -0600 Subject: Use X_LIBS from pkg-config, instead of libdir, for locating libX11 Signed-off-by: Jeff Smith Signed-off-by: Dan Nicholson --- configs/autoconf.in | 2 ++ configure.ac | 4 +++- progs/egl/Makefile | 6 +++--- progs/xdemos/Makefile | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'configure.ac') diff --git a/configs/autoconf.in b/configs/autoconf.in index bf34f3bffad..f50fb7dd093 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -24,6 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@ RADEON_LDFLAGS = @RADEON_LDFLAGS@ INTEL_LIBS = @INTEL_LIBS@ INTEL_CFLAGS = @INTEL_CFLAGS@ +X_LIBS = @X_LIBS@ +X_CFLAGS = @X_CFLAGS@ # Assembler MESA_ASM_SOURCES = @MESA_ASM_SOURCES@ diff --git a/configure.ac b/configure.ac index ed47f428c9e..35fbcd9d85b 100644 --- a/configure.ac +++ b/configure.ac @@ -547,7 +547,9 @@ else x11_pkgconfig=no fi dnl Use the autoconf macro if no pkg-config files -if test "$x11_pkgconfig" = no; then +if test "$x11_pkgconfig" = yes; then + PKG_CHECK_MODULES([X], [x11]) +else AC_PATH_XTRA fi diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 25de6e1f703..5f51104fed6 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) clean: -rm -f *.o *~ diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index e87d55d011e..f81aafe00f6 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -9,9 +9,9 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) # Add X11 and pthread libs to satisfy GNU gold. -APP_LIB_DEPS += -lX11 -lpthread +APP_LIB_DEPS += $(X_LIBS) -lpthread -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS) PROGS = \ corender \ -- cgit v1.2.3 From 6321a183319fdcb2ebee757b7f0922efe3f919db Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sat, 20 Feb 2010 19:52:22 +0100 Subject: nvfx: add nvfx directory to build system Will be used to hold source files unified between nv30 and nv40. Eventually all nv30 and nv40 code will be moved there and the nv30 and nv40 directories will be removed. --- configure.ac | 2 +- src/gallium/drivers/nvfx/Makefile | 11 +++++++++++ src/gallium/winsys/drm/nouveau/dri/Makefile | 7 +++++++ src/gallium/winsys/drm/nouveau/egl/Makefile | 7 +++++++ src/gallium/winsys/drm/nouveau/xorg/Makefile | 7 +++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/gallium/drivers/nvfx/Makefile (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 35fbcd9d85b..eb271e9d515 100644 --- a/configure.ac +++ b/configure.ac @@ -1360,7 +1360,7 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau" - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv30 nv40 nv50" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv30 nv40 nv50" fi dnl diff --git a/src/gallium/drivers/nvfx/Makefile b/src/gallium/drivers/nvfx/Makefile new file mode 100644 index 00000000000..05cdda0cc02 --- /dev/null +++ b/src/gallium/drivers/nvfx/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nvfx + +nvfx_dummy.c: + touch nvfx_dummy.c + +C_SOURCES = nvfx_dummy.c + +include ../../Makefile.template diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile index 7e95f79d03c..0cc60395ffe 100644 --- a/src/gallium/winsys/drm/nouveau/dri/Makefile +++ b/src/gallium/winsys/drm/nouveau/dri/Makefile @@ -3,11 +3,18 @@ include $(TOP)/configs/current LIBNAME = nouveau_dri.so +# hideous hack +-Wl,--start-group: +-Wl,--end-group: + PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + -Wl,--start-group \ $(TOP)/src/gallium/drivers/nv30/libnv30.a \ $(TOP)/src/gallium/drivers/nv40/libnv40.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + -Wl,--end-group \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile index 2c352603320..0f5e6d64aa4 100644 --- a/src/gallium/winsys/drm/nouveau/egl/Makefile +++ b/src/gallium/winsys/drm/nouveau/egl/Makefile @@ -5,10 +5,17 @@ EGL_DRIVER_NAME = nouveau EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_nouveau +# hideous hack +-Wl,--start-group: +-Wl,--end-group: + EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + -Wl,--start-group \ $(TOP)/src/gallium/drivers/nv30/libnv30.a \ $(TOP)/src/gallium/drivers/nv40/libnv40.a \ + $(TOP)/src/gallium/drivers/nv40/libnvfx.a \ + -Wl,--end-group \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a diff --git a/src/gallium/winsys/drm/nouveau/xorg/Makefile b/src/gallium/winsys/drm/nouveau/xorg/Makefile index 179b50230b5..0607d82a6e4 100644 --- a/src/gallium/winsys/drm/nouveau/xorg/Makefile +++ b/src/gallium/winsys/drm/nouveau/xorg/Makefile @@ -15,11 +15,18 @@ INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/egl/main +# hideous hack +-Wl,--start-group: +-Wl,--end-group: + LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + --Wl,--start-group \ $(TOP)/src/gallium/drivers/nv30/libnv30.a \ $(TOP)/src/gallium/drivers/nv40/libnv40.a \ + $(TOP)/src/gallium/drivers/nv40/libnvfx.a \ + --Wl,--end-group \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ $(GALLIUM_AUXILIARIES) -- cgit v1.2.3 From f9d09a2e7859a2cf025d71b7c3cb189edb6688c4 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sun, 21 Feb 2010 15:13:12 +0100 Subject: nv30, nv40: move last files to nvfx/ and rm -rf nv30 nv40 This is the last nvfx unification patch. nv[34]0_fragtex.c are moved to the common directory nv[34]0_shader.h are renamed to nv[34]0_vertprog.h and moved to the common directory The separate nv30 and nv40 directories are removed from the build system --- configure.ac | 2 +- src/gallium/drivers/nv30/Makefile | 11 -- src/gallium/drivers/nv30/nv30_fragtex.c | 148 ---------------------- src/gallium/drivers/nv30/nv30_shader.h | 169 ------------------------- src/gallium/drivers/nv40/Makefile | 11 -- src/gallium/drivers/nv40/nv40_fragtex.c | 174 -------------------------- src/gallium/drivers/nv40/nv40_shader.h | 178 --------------------------- src/gallium/drivers/nvfx/Makefile | 2 + src/gallium/drivers/nvfx/nv30_fragtex.c | 147 ++++++++++++++++++++++ src/gallium/drivers/nvfx/nv30_vertprog.h | 169 +++++++++++++++++++++++++ src/gallium/drivers/nvfx/nv40_fragtex.c | 174 ++++++++++++++++++++++++++ src/gallium/drivers/nvfx/nv40_vertprog.h | 177 ++++++++++++++++++++++++++ src/gallium/drivers/nvfx/nvfx_draw.c | 4 +- src/gallium/drivers/nvfx/nvfx_vertprog.c | 4 +- src/gallium/winsys/drm/nouveau/dri/Makefile | 8 -- src/gallium/winsys/drm/nouveau/egl/Makefile | 10 +- src/gallium/winsys/drm/nouveau/xorg/Makefile | 10 +- 17 files changed, 676 insertions(+), 722 deletions(-) delete mode 100644 src/gallium/drivers/nv30/Makefile delete mode 100644 src/gallium/drivers/nv30/nv30_fragtex.c delete mode 100644 src/gallium/drivers/nv30/nv30_shader.h delete mode 100644 src/gallium/drivers/nv40/Makefile delete mode 100644 src/gallium/drivers/nv40/nv40_fragtex.c delete mode 100644 src/gallium/drivers/nv40/nv40_shader.h create mode 100644 src/gallium/drivers/nvfx/nv30_fragtex.c create mode 100644 src/gallium/drivers/nvfx/nv30_vertprog.h create mode 100644 src/gallium/drivers/nvfx/nv40_fragtex.c create mode 100644 src/gallium/drivers/nvfx/nv40_vertprog.h (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index eb271e9d515..0f51097ef62 100644 --- a/configure.ac +++ b/configure.ac @@ -1360,7 +1360,7 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau" - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv30 nv40 nv50" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi dnl diff --git a/src/gallium/drivers/nv30/Makefile b/src/gallium/drivers/nv30/Makefile deleted file mode 100644 index 70741101d65..00000000000 --- a/src/gallium/drivers/nv30/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = nv30 - -C_SOURCES = \ - nv30_fragtex.c - -LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/nvfx - -include ../../Makefile.template diff --git a/src/gallium/drivers/nv30/nv30_fragtex.c b/src/gallium/drivers/nv30/nv30_fragtex.c deleted file mode 100644 index 081362d1509..00000000000 --- a/src/gallium/drivers/nv30/nv30_fragtex.c +++ /dev/null @@ -1,148 +0,0 @@ -#include "util/u_format.h" - -#include "nvfx_context.h" -#include "nouveau/nouveau_util.h" -#include "nvfx_tex.h" - -void -nv30_sampler_state_init(struct pipe_context *pipe, - struct nvfx_sampler_state *ps, - const struct pipe_sampler_state *cso) -{ - if (cso->max_anisotropy >= 8) { - ps->en |= NV34TCL_TX_ENABLE_ANISO_8X; - } else - if (cso->max_anisotropy >= 4) { - ps->en |= NV34TCL_TX_ENABLE_ANISO_4X; - } else - if (cso->max_anisotropy >= 2) { - ps->en |= NV34TCL_TX_ENABLE_ANISO_2X; - } - - { - float limit; - - limit = CLAMP(cso->lod_bias, -16.0, 15.0); - ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; - - limit = CLAMP(cso->max_lod, 0.0, 15.0); - ps->en |= (int)(limit) << 14 /*NV34TCL_TX_ENABLE_MIPMAP_MAX_LOD_SHIFT*/; - - limit = CLAMP(cso->min_lod, 0.0, 15.0); - ps->en |= (int)(limit) << 26 /*NV34TCL_TX_ENABLE_MIPMAP_MIN_LOD_SHIFT*/; - } -} - -#define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w) \ -{ \ - TRUE, \ - PIPE_FORMAT_##m, \ - NV34TCL_TX_FORMAT_FORMAT_##tf, \ - (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y | \ - NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w | \ - NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y | \ - NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w) \ -} - -struct nv30_texture_format { - boolean defined; - uint pipe; - int format; - int swizzle; -}; - -static struct nv30_texture_format -nv30_texture_formats[] = { - _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W), - _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), - _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), - _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), - _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), - _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X), - _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X), - _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X), - _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y), - _(Z16_UNORM , R5G6B5 , S1, S1, S1, ONE, X, X, X, X), - _(S8Z24_UNORM , A8R8G8B8, S1, S1, S1, ONE, X, X, X, X), - _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W), - _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W), - _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W), - _(DXT5_RGBA , DXT5 , S1, S1, S1, S1, X, Y, Z, W), - {}, -}; - -static struct nv30_texture_format * -nv30_fragtex_format(uint pipe_format) -{ - struct nv30_texture_format *tf = nv30_texture_formats; - - while (tf->defined) { - if (tf->pipe == pipe_format) - return tf; - tf++; - } - - NOUVEAU_ERR("unknown texture format %s\n", util_format_name(pipe_format)); - return NULL; -} - - -struct nouveau_stateobj * -nv30_fragtex_build(struct nvfx_context *nvfx, int unit) -{ - struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; - struct nvfx_miptree *nv30mt = nvfx->tex_miptree[unit]; - struct pipe_texture *pt = &nv30mt->base; - struct nouveau_bo *bo = nouveau_bo(nv30mt->buffer); - struct nv30_texture_format *tf; - struct nouveau_stateobj *so; - uint32_t txf, txs; - unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; - - tf = nv30_fragtex_format(pt->format); - if (!tf) - return NULL; - - txf = tf->format; - txf |= ((pt->last_level>0) ? NV34TCL_TX_FORMAT_MIPMAP : 0); - txf |= log2i(pt->width0) << NV34TCL_TX_FORMAT_BASE_SIZE_U_SHIFT; - txf |= log2i(pt->height0) << NV34TCL_TX_FORMAT_BASE_SIZE_V_SHIFT; - txf |= log2i(pt->depth0) << NV34TCL_TX_FORMAT_BASE_SIZE_W_SHIFT; - txf |= NV34TCL_TX_FORMAT_NO_BORDER | 0x10000; - - switch (pt->target) { - case PIPE_TEXTURE_CUBE: - txf |= NV34TCL_TX_FORMAT_CUBIC; - /* fall-through */ - case PIPE_TEXTURE_2D: - txf |= NV34TCL_TX_FORMAT_DIMS_2D; - break; - case PIPE_TEXTURE_3D: - txf |= NV34TCL_TX_FORMAT_DIMS_3D; - break; - case PIPE_TEXTURE_1D: - txf |= NV34TCL_TX_FORMAT_DIMS_1D; - break; - default: - NOUVEAU_ERR("Unknown target %d\n", pt->target); - return NULL; - } - - txs = tf->swizzle; - - so = so_new(1, 8, 2); - so_method(so, nvfx->screen->eng3d, NV34TCL_TX_OFFSET(unit), 8); - so_reloc (so, bo, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0); - so_reloc (so, bo, txf, tex_flags | NOUVEAU_BO_OR, - NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1); - so_data (so, ps->wrap); - so_data (so, NV34TCL_TX_ENABLE_ENABLE | ps->en); - so_data (so, txs); - so_data (so, ps->filt | 0x2000 /*voodoo*/); - so_data (so, (pt->width0 << NV34TCL_TX_NPOT_SIZE_W_SHIFT) | - pt->height0); - so_data (so, ps->bcol); - - return so; -} - diff --git a/src/gallium/drivers/nv30/nv30_shader.h b/src/gallium/drivers/nv30/nv30_shader.h deleted file mode 100644 index f19efb5aa4d..00000000000 --- a/src/gallium/drivers/nv30/nv30_shader.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef __NV30_SHADER_H__ -#define __NV30_SHADER_H__ - -/* Vertex programs instruction set - * - * 128bit opcodes, split into 4 32-bit ones for ease of use. - * - * Non-native instructions - * ABS - MOV + NV40_VP_INST0_DEST_ABS - * POW - EX2 + MUL + LG2 - * SUB - ADD, second source negated - * SWZ - MOV - * XPD - - * - * Register access - * - Only one INPUT can be accessed per-instruction (move extras into TEMPs) - * - Only one CONST can be accessed per-instruction (move extras into TEMPs) - * - * Relative Addressing - * According to the value returned for - * MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB - * - * there are only two address registers available. The destination in the - * ARL instruction is set to TEMP (The temp isn't actually written). - * - * When using vanilla ARB_v_p, the proprietary driver will squish both the - * available ADDRESS regs into the first hardware reg in the X and Y - * components. - * - * To use an address reg as an index into consts, the CONST_SRC is set to - * (const_base + offset) and INDEX_CONST is set. - * - * To access the second address reg use ADDR_REG_SELECT_1. A particular - * component of the address regs is selected with ADDR_SWZ. - * - * Only one address register can be accessed per instruction. - * - * Conditional execution (see NV_vertex_program{2,3} for details) Conditional - * execution of an instruction is enabled by setting COND_TEST_ENABLE, and - * selecting the condition which will allow the test to pass with - * COND_{FL,LT,...}. It is possible to swizzle the values in the condition - * register, which allows for testing against an individual component. - * - * Branching: - * - * The BRA/CAL instructions seem to follow a slightly different opcode - * layout. The destination instruction ID (IADDR) overlaps a source field. - * Instruction ID's seem to be numbered based on the UPLOAD_FROM_ID FIFO - * command, and is incremented automatically on each UPLOAD_INST FIFO - * command. - * - * Conditional branching is achieved by using the condition tests described - * above. There doesn't appear to be dedicated looping instructions, but - * this can be done using a temp reg + conditional branching. - * - * Subroutines may be uploaded before the main program itself, but the first - * executed instruction is determined by the PROGRAM_START_ID FIFO command. - * - */ - -/* DWORD 0 */ - -#define NV30_VP_INST_ADDR_REG_SELECT_1 (1 << 24) -#define NV30_VP_INST_SRC2_ABS (1 << 23) /* guess */ -#define NV30_VP_INST_SRC1_ABS (1 << 22) /* guess */ -#define NV30_VP_INST_SRC0_ABS (1 << 21) /* guess */ -#define NV30_VP_INST_VEC_RESULT (1 << 20) -#define NV30_VP_INST_DEST_TEMP_ID_SHIFT 16 -#define NV30_VP_INST_DEST_TEMP_ID_MASK (0x0F << 16) -#define NV30_VP_INST_COND_UPDATE_ENABLE (1<<15) -#define NV30_VP_INST_VEC_DEST_TEMP_MASK (0xF << 16) -#define NV30_VP_INST_COND_TEST_ENABLE (1<<14) -#define NV30_VP_INST_COND_SHIFT 11 -#define NV30_VP_INST_COND_MASK (0x07 << 11) -#define NV30_VP_INST_COND_SWZ_X_SHIFT 9 -#define NV30_VP_INST_COND_SWZ_X_MASK (0x03 << 9) -#define NV30_VP_INST_COND_SWZ_Y_SHIFT 7 -#define NV30_VP_INST_COND_SWZ_Y_MASK (0x03 << 7) -#define NV30_VP_INST_COND_SWZ_Z_SHIFT 5 -#define NV30_VP_INST_COND_SWZ_Z_MASK (0x03 << 5) -#define NV30_VP_INST_COND_SWZ_W_SHIFT 3 -#define NV30_VP_INST_COND_SWZ_W_MASK (0x03 << 3) -#define NV30_VP_INST_COND_SWZ_ALL_SHIFT 3 -#define NV30_VP_INST_COND_SWZ_ALL_MASK (0xFF << 3) -#define NV30_VP_INST_ADDR_SWZ_SHIFT 1 -#define NV30_VP_INST_ADDR_SWZ_MASK (0x03 << 1) -#define NV30_VP_INST_SCA_OPCODEH_SHIFT 0 -#define NV30_VP_INST_SCA_OPCODEH_MASK (0x01 << 0) - -/* DWORD 1 */ -#define NV30_VP_INST_SCA_OPCODEL_SHIFT 28 -#define NV30_VP_INST_SCA_OPCODEL_MASK (0x0F << 28) -#define NV30_VP_INST_VEC_OPCODE_SHIFT 23 -#define NV30_VP_INST_VEC_OPCODE_MASK (0x1F << 23) -#define NV30_VP_INST_CONST_SRC_SHIFT 14 -#define NV30_VP_INST_CONST_SRC_MASK (0xFF << 14) -#define NV30_VP_INST_INPUT_SRC_SHIFT 9 /*NV20*/ -#define NV30_VP_INST_INPUT_SRC_MASK (0x0F << 9) /*NV20*/ -#define NV30_VP_INST_SRC0H_SHIFT 0 /*NV20*/ -#define NV30_VP_INST_SRC0H_MASK (0x1FF << 0) /*NV20*/ - -/* Please note: the IADDR fields overlap other fields because they are used - * only for branch instructions. See Branching: label above - * - * DWORD 2 - */ -#define NV30_VP_INST_SRC0L_SHIFT 26 /*NV20*/ -#define NV30_VP_INST_SRC0L_MASK (0x3F <<26) /* NV30_VP_SRC0_LOW_MASK << 26 */ -#define NV30_VP_INST_SRC1_SHIFT 11 /*NV20*/ -#define NV30_VP_INST_SRC1_MASK (0x7FFF<<11) /*NV20*/ -#define NV30_VP_INST_SRC2H_SHIFT 0 /*NV20*/ -#define NV30_VP_INST_SRC2H_MASK (0x7FF << 0) /* NV30_VP_SRC2_HIGH_MASK >> 4*/ -#define NV30_VP_INST_IADDR_SHIFT 2 -#define NV30_VP_INST_IADDR_MASK (0xF << 28) /* NV30_VP_SRC2_LOW_MASK << 28 */ - -/* DWORD 3 */ -#define NV30_VP_INST_SRC2L_SHIFT 28 /*NV20*/ -#define NV30_VP_INST_SRC2L_MASK (0x0F <<28) /*NV20*/ -#define NV30_VP_INST_STEMP_WRITEMASK_SHIFT 24 -#define NV30_VP_INST_STEMP_WRITEMASK_MASK (0x0F << 24) -#define NV30_VP_INST_VTEMP_WRITEMASK_SHIFT 20 -#define NV30_VP_INST_VTEMP_WRITEMASK_MASK (0x0F << 20) -#define NV30_VP_INST_SDEST_WRITEMASK_SHIFT 16 -#define NV30_VP_INST_SDEST_WRITEMASK_MASK (0x0F << 16) -#define NV30_VP_INST_VDEST_WRITEMASK_SHIFT 12 /*NV20*/ -#define NV30_VP_INST_VDEST_WRITEMASK_MASK (0x0F << 12) /*NV20*/ -#define NV30_VP_INST_DEST_SHIFT 2 -#define NV30_VP_INST_DEST_MASK (0x0F << 2) -# define NV30_VP_INST_DEST_POS 0 -# define NV30_VP_INST_DEST_BFC0 1 -# define NV30_VP_INST_DEST_BFC1 2 -# define NV30_VP_INST_DEST_COL0 3 -# define NV30_VP_INST_DEST_COL1 4 -# define NV30_VP_INST_DEST_FOGC 5 -# define NV30_VP_INST_DEST_PSZ 6 -# define NV30_VP_INST_DEST_TC(n) (8+n) - -/* Useful to split the source selection regs into their pieces */ -#define NV30_VP_SRC0_HIGH_SHIFT 6 -#define NV30_VP_SRC0_HIGH_MASK 0x00007FC0 -#define NV30_VP_SRC0_LOW_MASK 0x0000003F -#define NV30_VP_SRC2_HIGH_SHIFT 4 -#define NV30_VP_SRC2_HIGH_MASK 0x00007FF0 -#define NV30_VP_SRC2_LOW_MASK 0x0000000F - - -/* Source-register definition - matches NV20 exactly */ -#define NV30_VP_SRC_NEGATE (1<<14) -#define NV30_VP_SRC_SWZ_X_SHIFT 12 -#define NV30_VP_SRC_REG_SWZ_X_MASK (0x03 <<12) -#define NV30_VP_SRC_SWZ_Y_SHIFT 10 -#define NV30_VP_SRC_REG_SWZ_Y_MASK (0x03 <<10) -#define NV30_VP_SRC_SWZ_Z_SHIFT 8 -#define NV30_VP_SRC_REG_SWZ_Z_MASK (0x03 << 8) -#define NV30_VP_SRC_SWZ_W_SHIFT 6 -#define NV30_VP_SRC_REG_SWZ_W_MASK (0x03 << 6) -#define NV30_VP_SRC_REG_SWZ_ALL_SHIFT 6 -#define NV30_VP_SRC_REG_SWZ_ALL_MASK (0xFF << 6) -#define NV30_VP_SRC_TEMP_SRC_SHIFT 2 -#define NV30_VP_SRC_REG_TEMP_ID_MASK (0x0F << 0) -#define NV30_VP_SRC_REG_TYPE_SHIFT 0 -#define NV30_VP_SRC_REG_TYPE_MASK (0x03 << 0) -#define NV30_VP_SRC_REG_TYPE_TEMP 1 -#define NV30_VP_SRC_REG_TYPE_INPUT 2 -#define NV30_VP_SRC_REG_TYPE_CONST 3 /* guess */ - -#include "nvfx_shader.h" - -#endif diff --git a/src/gallium/drivers/nv40/Makefile b/src/gallium/drivers/nv40/Makefile deleted file mode 100644 index 8b69f9432d1..00000000000 --- a/src/gallium/drivers/nv40/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = nv40 - -C_SOURCES = \ - nv40_fragtex.c - -LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/nvfx - -include ../../Makefile.template diff --git a/src/gallium/drivers/nv40/nv40_fragtex.c b/src/gallium/drivers/nv40/nv40_fragtex.c deleted file mode 100644 index 5889b5e40d5..00000000000 --- a/src/gallium/drivers/nv40/nv40_fragtex.c +++ /dev/null @@ -1,174 +0,0 @@ -#include "util/u_format.h" -#include "nvfx_context.h" -#include "nvfx_tex.h" - -void -nv40_sampler_state_init(struct pipe_context *pipe, - struct nvfx_sampler_state *ps, - const struct pipe_sampler_state *cso) -{ - if (cso->max_anisotropy >= 2) { - /* no idea, binary driver sets it, works without it.. meh.. */ - ps->wrap |= (1 << 5); - - if (cso->max_anisotropy >= 16) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_16X; - } else - if (cso->max_anisotropy >= 12) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_12X; - } else - if (cso->max_anisotropy >= 10) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_10X; - } else - if (cso->max_anisotropy >= 8) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_8X; - } else - if (cso->max_anisotropy >= 6) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_6X; - } else - if (cso->max_anisotropy >= 4) { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_4X; - } else { - ps->en |= NV40TCL_TEX_ENABLE_ANISO_2X; - } - } - - { - float limit; - - limit = CLAMP(cso->lod_bias, -16.0, 15.0); - ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; - - limit = CLAMP(cso->max_lod, 0.0, 15.0); - ps->en |= (int)(limit * 256.0) << 7; - - limit = CLAMP(cso->min_lod, 0.0, 15.0); - ps->en |= (int)(limit * 256.0) << 19; - } -} - -#define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w,sx,sy,sz,sw) \ -{ \ - TRUE, \ - PIPE_FORMAT_##m, \ - NV40TCL_TEX_FORMAT_FORMAT_##tf, \ - (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y | \ - NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w | \ - NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y | \ - NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w), \ - ((NV34TCL_TX_FILTER_SIGNED_RED*sx) | (NV34TCL_TX_FILTER_SIGNED_GREEN*sy) | \ - (NV34TCL_TX_FILTER_SIGNED_BLUE*sz) | (NV34TCL_TX_FILTER_SIGNED_ALPHA*sw)) \ -} - -struct nv40_texture_format { - boolean defined; - uint pipe; - int format; - int swizzle; - int sign; -}; - -static struct nv40_texture_format -nv40_texture_formats[] = { - _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), - _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), - _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), - _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X, 0, 0, 0, 0), - _(R16_SNORM , A16 , ZERO, ZERO, S1, ONE, X, X, X, Y, 1, 1, 1, 1), - _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X, 0, 0, 0, 0), - _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y, 0, 0, 0, 0), - _(Z16_UNORM , Z16 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), - _(S8Z24_UNORM , Z24 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), - _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), - _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(DXT5_RGBA , DXT5 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - {}, -}; - -static struct nv40_texture_format * -nv40_fragtex_format(uint pipe_format) -{ - struct nv40_texture_format *tf = nv40_texture_formats; - - while (tf->defined) { - if (tf->pipe == pipe_format) - return tf; - tf++; - } - - NOUVEAU_ERR("unknown texture format %s\n", util_format_name(pipe_format)); - return NULL; -} - - -struct nouveau_stateobj * -nv40_fragtex_build(struct nvfx_context *nvfx, int unit) -{ - struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; - struct nvfx_miptree *nv40mt = nvfx->tex_miptree[unit]; - struct nouveau_bo *bo = nouveau_bo(nv40mt->buffer); - struct pipe_texture *pt = &nv40mt->base; - struct nv40_texture_format *tf; - struct nouveau_stateobj *so; - uint32_t txf, txs, txp; - unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; - - tf = nv40_fragtex_format(pt->format); - if (!tf) - assert(0); - - txf = ps->fmt; - txf |= tf->format | 0x8000; - txf |= ((pt->last_level + 1) << NV40TCL_TEX_FORMAT_MIPMAP_COUNT_SHIFT); - - if (1) /* XXX */ - txf |= NV34TCL_TX_FORMAT_NO_BORDER; - - switch (pt->target) { - case PIPE_TEXTURE_CUBE: - txf |= NV34TCL_TX_FORMAT_CUBIC; - /* fall-through */ - case PIPE_TEXTURE_2D: - txf |= NV34TCL_TX_FORMAT_DIMS_2D; - break; - case PIPE_TEXTURE_3D: - txf |= NV34TCL_TX_FORMAT_DIMS_3D; - break; - case PIPE_TEXTURE_1D: - txf |= NV34TCL_TX_FORMAT_DIMS_1D; - break; - default: - NOUVEAU_ERR("Unknown target %d\n", pt->target); - return NULL; - } - - if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) { - txp = 0; - } else { - txp = nv40mt->level[0].pitch; - txf |= NV40TCL_TEX_FORMAT_LINEAR; - } - - txs = tf->swizzle; - - so = so_new(2, 9, 2); - so_method(so, nvfx->screen->eng3d, NV34TCL_TX_OFFSET(unit), 8); - so_reloc (so, bo, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0); - so_reloc (so, bo, txf, tex_flags | NOUVEAU_BO_OR, - NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1); - so_data (so, ps->wrap); - so_data (so, NV40TCL_TEX_ENABLE_ENABLE | ps->en); - so_data (so, txs); - so_data (so, ps->filt | tf->sign | 0x2000 /*voodoo*/); - so_data (so, (pt->width0 << NV34TCL_TX_NPOT_SIZE_W_SHIFT) | - pt->height0); - so_data (so, ps->bcol); - so_method(so, nvfx->screen->eng3d, NV40TCL_TEX_SIZE1(unit), 1); - so_data (so, (pt->depth0 << NV40TCL_TEX_SIZE1_DEPTH_SHIFT) | txp); - - return so; -} diff --git a/src/gallium/drivers/nv40/nv40_shader.h b/src/gallium/drivers/nv40/nv40_shader.h deleted file mode 100644 index 8d28137e9de..00000000000 --- a/src/gallium/drivers/nv40/nv40_shader.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef __NV40_SHADER_H__ -#define __NV40_SHADER_H__ - -/* Vertex programs instruction set - * - * The NV40 instruction set is very similar to NV30. Most fields are in - * a slightly different position in the instruction however. - * - * Merged instructions - * In some cases it is possible to put two instructions into one opcode - * slot. The rules for when this is OK is not entirely clear to me yet. - * - * There are separate writemasks and dest temp register fields for each - * grouping of instructions. There is however only one field with the - * ID of a result register. Writing to temp/result regs is selected by - * setting VEC_RESULT/SCA_RESULT. - * - * Temporary registers - * The source/dest temp register fields have been extended by 1 bit, to - * give a total of 32 temporary registers. - * - * Relative Addressing - * NV40 can use an address register to index into vertex attribute regs. - * This is done by putting the offset value into INPUT_SRC and setting - * the INDEX_INPUT flag. - * - * Conditional execution (see NV_vertex_program{2,3} for details) - * There is a second condition code register on NV40, it's use is enabled - * by setting the COND_REG_SELECT_1 flag. - * - * Texture lookup - * TODO - */ - -/* ---- OPCODE BITS 127:96 / data DWORD 0 --- */ -#define NV40_VP_INST_VEC_RESULT (1 << 30) -/* uncertain.. */ -#define NV40_VP_INST_COND_UPDATE_ENABLE ((1 << 14)|1<<29) -/* use address reg as index into attribs */ -#define NV40_VP_INST_INDEX_INPUT (1 << 27) -#define NV40_VP_INST_COND_REG_SELECT_1 (1 << 25) -#define NV40_VP_INST_ADDR_REG_SELECT_1 (1 << 24) -#define NV40_VP_INST_SRC2_ABS (1 << 23) -#define NV40_VP_INST_SRC1_ABS (1 << 22) -#define NV40_VP_INST_SRC0_ABS (1 << 21) -#define NV40_VP_INST_VEC_DEST_TEMP_SHIFT 15 -#define NV40_VP_INST_VEC_DEST_TEMP_MASK (0x1F << 15) -#define NV40_VP_INST_COND_TEST_ENABLE (1 << 13) -#define NV40_VP_INST_COND_SHIFT 10 -#define NV40_VP_INST_COND_MASK (0x7 << 10) -#define NV40_VP_INST_COND_SWZ_X_SHIFT 8 -#define NV40_VP_INST_COND_SWZ_X_MASK (3 << 8) -#define NV40_VP_INST_COND_SWZ_Y_SHIFT 6 -#define NV40_VP_INST_COND_SWZ_Y_MASK (3 << 6) -#define NV40_VP_INST_COND_SWZ_Z_SHIFT 4 -#define NV40_VP_INST_COND_SWZ_Z_MASK (3 << 4) -#define NV40_VP_INST_COND_SWZ_W_SHIFT 2 -#define NV40_VP_INST_COND_SWZ_W_MASK (3 << 2) -#define NV40_VP_INST_COND_SWZ_ALL_SHIFT 2 -#define NV40_VP_INST_COND_SWZ_ALL_MASK (0xFF << 2) -#define NV40_VP_INST_ADDR_SWZ_SHIFT 0 -#define NV40_VP_INST_ADDR_SWZ_MASK (0x03 << 0) -#define NV40_VP_INST0_KNOWN ( \ - NV40_VP_INST_INDEX_INPUT | \ - NV40_VP_INST_COND_REG_SELECT_1 | \ - NV40_VP_INST_ADDR_REG_SELECT_1 | \ - NV40_VP_INST_SRC2_ABS | \ - NV40_VP_INST_SRC1_ABS | \ - NV40_VP_INST_SRC0_ABS | \ - NV40_VP_INST_VEC_DEST_TEMP_MASK | \ - NV40_VP_INST_COND_TEST_ENABLE | \ - NV40_VP_INST_COND_MASK | \ - NV40_VP_INST_COND_SWZ_ALL_MASK | \ - NV40_VP_INST_ADDR_SWZ_MASK) - -/* ---- OPCODE BITS 95:64 / data DWORD 1 --- */ -#define NV40_VP_INST_VEC_OPCODE_SHIFT 22 -#define NV40_VP_INST_VEC_OPCODE_MASK (0x1F << 22) -#define NV40_VP_INST_SCA_OPCODE_SHIFT 27 -#define NV40_VP_INST_SCA_OPCODE_MASK (0x1F << 27) -#define NV40_VP_INST_CONST_SRC_SHIFT 12 -#define NV40_VP_INST_CONST_SRC_MASK (0xFF << 12) -#define NV40_VP_INST_INPUT_SRC_SHIFT 8 -#define NV40_VP_INST_INPUT_SRC_MASK (0x0F << 8) -#define NV40_VP_INST_SRC0H_SHIFT 0 -#define NV40_VP_INST_SRC0H_MASK (0xFF << 0) -#define NV40_VP_INST1_KNOWN ( \ - NV40_VP_INST_VEC_OPCODE_MASK | \ - NV40_VP_INST_SCA_OPCODE_MASK | \ - NV40_VP_INST_CONST_SRC_MASK | \ - NV40_VP_INST_INPUT_SRC_MASK | \ - NV40_VP_INST_SRC0H_MASK \ - ) - -/* ---- OPCODE BITS 63:32 / data DWORD 2 --- */ -#define NV40_VP_INST_SRC0L_SHIFT 23 -#define NV40_VP_INST_SRC0L_MASK (0x1FF << 23) -#define NV40_VP_INST_SRC1_SHIFT 6 -#define NV40_VP_INST_SRC1_MASK (0x1FFFF << 6) -#define NV40_VP_INST_SRC2H_SHIFT 0 -#define NV40_VP_INST_SRC2H_MASK (0x3F << 0) -#define NV40_VP_INST_IADDRH_SHIFT 0 -#define NV40_VP_INST_IADDRH_MASK (0x1F << 0) - -/* ---- OPCODE BITS 31:0 / data DWORD 3 --- */ -#define NV40_VP_INST_IADDRL_SHIFT 29 -#define NV40_VP_INST_IADDRL_MASK (7 << 29) -#define NV40_VP_INST_SRC2L_SHIFT 21 -#define NV40_VP_INST_SRC2L_MASK (0x7FF << 21) -#define NV40_VP_INST_SCA_WRITEMASK_SHIFT 17 -#define NV40_VP_INST_SCA_WRITEMASK_MASK (0xF << 17) -# define NV40_VP_INST_SCA_WRITEMASK_X (1 << 20) -# define NV40_VP_INST_SCA_WRITEMASK_Y (1 << 19) -# define NV40_VP_INST_SCA_WRITEMASK_Z (1 << 18) -# define NV40_VP_INST_SCA_WRITEMASK_W (1 << 17) -#define NV40_VP_INST_VEC_WRITEMASK_SHIFT 13 -#define NV40_VP_INST_VEC_WRITEMASK_MASK (0xF << 13) -# define NV40_VP_INST_VEC_WRITEMASK_X (1 << 16) -# define NV40_VP_INST_VEC_WRITEMASK_Y (1 << 15) -# define NV40_VP_INST_VEC_WRITEMASK_Z (1 << 14) -# define NV40_VP_INST_VEC_WRITEMASK_W (1 << 13) -#define NV40_VP_INST_SCA_RESULT (1 << 12) -#define NV40_VP_INST_SCA_DEST_TEMP_SHIFT 7 -#define NV40_VP_INST_SCA_DEST_TEMP_MASK (0x1F << 7) -#define NV40_VP_INST_DEST_SHIFT 2 -#define NV40_VP_INST_DEST_MASK (31 << 2) -# define NV40_VP_INST_DEST_POS 0 -# define NV40_VP_INST_DEST_COL0 1 -# define NV40_VP_INST_DEST_COL1 2 -# define NV40_VP_INST_DEST_BFC0 3 -# define NV40_VP_INST_DEST_BFC1 4 -# define NV40_VP_INST_DEST_FOGC 5 -# define NV40_VP_INST_DEST_PSZ 6 -# define NV40_VP_INST_DEST_TC0 7 -# define NV40_VP_INST_DEST_TC(n) (7+n) -# define NV40_VP_INST_DEST_TEMP 0x1F -#define NV40_VP_INST_INDEX_CONST (1 << 1) -#define NV40_VP_INST3_KNOWN ( \ - NV40_VP_INST_SRC2L_MASK |\ - NV40_VP_INST_SCA_WRITEMASK_MASK |\ - NV40_VP_INST_VEC_WRITEMASK_MASK |\ - NV40_VP_INST_SCA_DEST_TEMP_MASK |\ - NV40_VP_INST_DEST_MASK |\ - NV40_VP_INST_INDEX_CONST) - -/* Useful to split the source selection regs into their pieces */ -#define NV40_VP_SRC0_HIGH_SHIFT 9 -#define NV40_VP_SRC0_HIGH_MASK 0x0001FE00 -#define NV40_VP_SRC0_LOW_MASK 0x000001FF -#define NV40_VP_SRC2_HIGH_SHIFT 11 -#define NV40_VP_SRC2_HIGH_MASK 0x0001F800 -#define NV40_VP_SRC2_LOW_MASK 0x000007FF - -/* Source selection - these are the bits you fill NV40_VP_INST_SRCn with */ -#define NV40_VP_SRC_NEGATE (1 << 16) -#define NV40_VP_SRC_SWZ_X_SHIFT 14 -#define NV40_VP_SRC_SWZ_X_MASK (3 << 14) -#define NV40_VP_SRC_SWZ_Y_SHIFT 12 -#define NV40_VP_SRC_SWZ_Y_MASK (3 << 12) -#define NV40_VP_SRC_SWZ_Z_SHIFT 10 -#define NV40_VP_SRC_SWZ_Z_MASK (3 << 10) -#define NV40_VP_SRC_SWZ_W_SHIFT 8 -#define NV40_VP_SRC_SWZ_W_MASK (3 << 8) -#define NV40_VP_SRC_SWZ_ALL_SHIFT 8 -#define NV40_VP_SRC_SWZ_ALL_MASK (0xFF << 8) -#define NV40_VP_SRC_TEMP_SRC_SHIFT 2 -#define NV40_VP_SRC_TEMP_SRC_MASK (0x1F << 2) -#define NV40_VP_SRC_REG_TYPE_SHIFT 0 -#define NV40_VP_SRC_REG_TYPE_MASK (3 << 0) -# define NV40_VP_SRC_REG_TYPE_UNK0 0 -# define NV40_VP_SRC_REG_TYPE_TEMP 1 -# define NV40_VP_SRC_REG_TYPE_INPUT 2 -# define NV40_VP_SRC_REG_TYPE_CONST 3 - -#include "nvfx_shader.h" - -#endif - diff --git a/src/gallium/drivers/nvfx/Makefile b/src/gallium/drivers/nvfx/Makefile index 51fa34cfad2..e912177b211 100644 --- a/src/gallium/drivers/nvfx/Makefile +++ b/src/gallium/drivers/nvfx/Makefile @@ -9,6 +9,8 @@ C_SOURCES = \ nvfx_draw.c \ nvfx_fragprog.c \ nvfx_fragtex.c \ + nv30_fragtex.c \ + nv40_fragtex.c \ nvfx_miptree.c \ nvfx_query.c \ nvfx_screen.c \ diff --git a/src/gallium/drivers/nvfx/nv30_fragtex.c b/src/gallium/drivers/nvfx/nv30_fragtex.c new file mode 100644 index 00000000000..2b56f454921 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv30_fragtex.c @@ -0,0 +1,147 @@ +#include "util/u_format.h" + +#include "nvfx_context.h" +#include "nouveau/nouveau_util.h" +#include "nvfx_tex.h" + +void +nv30_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso) +{ + if (cso->max_anisotropy >= 8) { + ps->en |= NV34TCL_TX_ENABLE_ANISO_8X; + } else + if (cso->max_anisotropy >= 4) { + ps->en |= NV34TCL_TX_ENABLE_ANISO_4X; + } else + if (cso->max_anisotropy >= 2) { + ps->en |= NV34TCL_TX_ENABLE_ANISO_2X; + } + + { + float limit; + + limit = CLAMP(cso->lod_bias, -16.0, 15.0); + ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; + + limit = CLAMP(cso->max_lod, 0.0, 15.0); + ps->en |= (int)(limit) << 14 /*NV34TCL_TX_ENABLE_MIPMAP_MAX_LOD_SHIFT*/; + + limit = CLAMP(cso->min_lod, 0.0, 15.0); + ps->en |= (int)(limit) << 26 /*NV34TCL_TX_ENABLE_MIPMAP_MIN_LOD_SHIFT*/; + } +} + +#define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w) \ +{ \ + TRUE, \ + PIPE_FORMAT_##m, \ + NV34TCL_TX_FORMAT_FORMAT_##tf, \ + (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y | \ + NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w | \ + NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y | \ + NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w) \ +} + +struct nv30_texture_format { + boolean defined; + uint pipe; + int format; + int swizzle; +}; + +static struct nv30_texture_format +nv30_texture_formats[] = { + _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W), + _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), + _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), + _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), + _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), + _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X), + _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X), + _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X), + _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y), + _(Z16_UNORM , R5G6B5 , S1, S1, S1, ONE, X, X, X, X), + _(S8Z24_UNORM , A8R8G8B8, S1, S1, S1, ONE, X, X, X, X), + _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W), + _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W), + _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W), + _(DXT5_RGBA , DXT5 , S1, S1, S1, S1, X, Y, Z, W), + {}, +}; + +static struct nv30_texture_format * +nv30_fragtex_format(uint pipe_format) +{ + struct nv30_texture_format *tf = nv30_texture_formats; + + while (tf->defined) { + if (tf->pipe == pipe_format) + return tf; + tf++; + } + + NOUVEAU_ERR("unknown texture format %s\n", util_format_name(pipe_format)); + return NULL; +} + + +struct nouveau_stateobj * +nv30_fragtex_build(struct nvfx_context *nvfx, int unit) +{ + struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; + struct nvfx_miptree *nv30mt = nvfx->tex_miptree[unit]; + struct pipe_texture *pt = &nv30mt->base; + struct nouveau_bo *bo = nouveau_bo(nv30mt->buffer); + struct nv30_texture_format *tf; + struct nouveau_stateobj *so; + uint32_t txf, txs; + unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + + tf = nv30_fragtex_format(pt->format); + if (!tf) + return NULL; + + txf = tf->format; + txf |= ((pt->last_level>0) ? NV34TCL_TX_FORMAT_MIPMAP : 0); + txf |= log2i(pt->width0) << NV34TCL_TX_FORMAT_BASE_SIZE_U_SHIFT; + txf |= log2i(pt->height0) << NV34TCL_TX_FORMAT_BASE_SIZE_V_SHIFT; + txf |= log2i(pt->depth0) << NV34TCL_TX_FORMAT_BASE_SIZE_W_SHIFT; + txf |= NV34TCL_TX_FORMAT_NO_BORDER | 0x10000; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE: + txf |= NV34TCL_TX_FORMAT_CUBIC; + /* fall-through */ + case PIPE_TEXTURE_2D: + txf |= NV34TCL_TX_FORMAT_DIMS_2D; + break; + case PIPE_TEXTURE_3D: + txf |= NV34TCL_TX_FORMAT_DIMS_3D; + break; + case PIPE_TEXTURE_1D: + txf |= NV34TCL_TX_FORMAT_DIMS_1D; + break; + default: + NOUVEAU_ERR("Unknown target %d\n", pt->target); + return NULL; + } + + txs = tf->swizzle; + + so = so_new(1, 8, 2); + so_method(so, nvfx->screen->eng3d, NV34TCL_TX_OFFSET(unit), 8); + so_reloc (so, bo, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0); + so_reloc (so, bo, txf, tex_flags | NOUVEAU_BO_OR, + NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1); + so_data (so, ps->wrap); + so_data (so, NV34TCL_TX_ENABLE_ENABLE | ps->en); + so_data (so, txs); + so_data (so, ps->filt | 0x2000 /*voodoo*/); + so_data (so, (pt->width0 << NV34TCL_TX_NPOT_SIZE_W_SHIFT) | + pt->height0); + so_data (so, ps->bcol); + + return so; +} diff --git a/src/gallium/drivers/nvfx/nv30_vertprog.h b/src/gallium/drivers/nvfx/nv30_vertprog.h new file mode 100644 index 00000000000..ec0444c07f8 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv30_vertprog.h @@ -0,0 +1,169 @@ +#ifndef __NV30_SHADER_H__ +#define __NV30_SHADER_H__ + +/* Vertex programs instruction set + * + * 128bit opcodes, split into 4 32-bit ones for ease of use. + * + * Non-native instructions + * ABS - MOV + NV40_VP_INST0_DEST_ABS + * POW - EX2 + MUL + LG2 + * SUB - ADD, second source negated + * SWZ - MOV + * XPD - + * + * Register access + * - Only one INPUT can be accessed per-instruction (move extras into TEMPs) + * - Only one CONST can be accessed per-instruction (move extras into TEMPs) + * + * Relative Addressing + * According to the value returned for + * MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB + * + * there are only two address registers available. The destination in the + * ARL instruction is set to TEMP (The temp isn't actually written). + * + * When using vanilla ARB_v_p, the proprietary driver will squish both the + * available ADDRESS regs into the first hardware reg in the X and Y + * components. + * + * To use an address reg as an index into consts, the CONST_SRC is set to + * (const_base + offset) and INDEX_CONST is set. + * + * To access the second address reg use ADDR_REG_SELECT_1. A particular + * component of the address regs is selected with ADDR_SWZ. + * + * Only one address register can be accessed per instruction. + * + * Conditional execution (see NV_vertex_program{2,3} for details) Conditional + * execution of an instruction is enabled by setting COND_TEST_ENABLE, and + * selecting the condition which will allow the test to pass with + * COND_{FL,LT,...}. It is possible to swizzle the values in the condition + * register, which allows for testing against an individual component. + * + * Branching: + * + * The BRA/CAL instructions seem to follow a slightly different opcode + * layout. The destination instruction ID (IADDR) overlaps a source field. + * Instruction ID's seem to be numbered based on the UPLOAD_FROM_ID FIFO + * command, and is incremented automatically on each UPLOAD_INST FIFO + * command. + * + * Conditional branching is achieved by using the condition tests described + * above. There doesn't appear to be dedicated looping instructions, but + * this can be done using a temp reg + conditional branching. + * + * Subroutines may be uploaded before the main program itself, but the first + * executed instruction is determined by the PROGRAM_START_ID FIFO command. + * + */ + +/* DWORD 0 */ + +#define NV30_VP_INST_ADDR_REG_SELECT_1 (1 << 24) +#define NV30_VP_INST_SRC2_ABS (1 << 23) /* guess */ +#define NV30_VP_INST_SRC1_ABS (1 << 22) /* guess */ +#define NV30_VP_INST_SRC0_ABS (1 << 21) /* guess */ +#define NV30_VP_INST_VEC_RESULT (1 << 20) +#define NV30_VP_INST_DEST_TEMP_ID_SHIFT 16 +#define NV30_VP_INST_DEST_TEMP_ID_MASK (0x0F << 16) +#define NV30_VP_INST_COND_UPDATE_ENABLE (1<<15) +#define NV30_VP_INST_VEC_DEST_TEMP_MASK (0xF << 16) +#define NV30_VP_INST_COND_TEST_ENABLE (1<<14) +#define NV30_VP_INST_COND_SHIFT 11 +#define NV30_VP_INST_COND_MASK (0x07 << 11) +#define NV30_VP_INST_COND_SWZ_X_SHIFT 9 +#define NV30_VP_INST_COND_SWZ_X_MASK (0x03 << 9) +#define NV30_VP_INST_COND_SWZ_Y_SHIFT 7 +#define NV30_VP_INST_COND_SWZ_Y_MASK (0x03 << 7) +#define NV30_VP_INST_COND_SWZ_Z_SHIFT 5 +#define NV30_VP_INST_COND_SWZ_Z_MASK (0x03 << 5) +#define NV30_VP_INST_COND_SWZ_W_SHIFT 3 +#define NV30_VP_INST_COND_SWZ_W_MASK (0x03 << 3) +#define NV30_VP_INST_COND_SWZ_ALL_SHIFT 3 +#define NV30_VP_INST_COND_SWZ_ALL_MASK (0xFF << 3) +#define NV30_VP_INST_ADDR_SWZ_SHIFT 1 +#define NV30_VP_INST_ADDR_SWZ_MASK (0x03 << 1) +#define NV30_VP_INST_SCA_OPCODEH_SHIFT 0 +#define NV30_VP_INST_SCA_OPCODEH_MASK (0x01 << 0) + +/* DWORD 1 */ +#define NV30_VP_INST_SCA_OPCODEL_SHIFT 28 +#define NV30_VP_INST_SCA_OPCODEL_MASK (0x0F << 28) +#define NV30_VP_INST_VEC_OPCODE_SHIFT 23 +#define NV30_VP_INST_VEC_OPCODE_MASK (0x1F << 23) +#define NV30_VP_INST_CONST_SRC_SHIFT 14 +#define NV30_VP_INST_CONST_SRC_MASK (0xFF << 14) +#define NV30_VP_INST_INPUT_SRC_SHIFT 9 /*NV20*/ +#define NV30_VP_INST_INPUT_SRC_MASK (0x0F << 9) /*NV20*/ +#define NV30_VP_INST_SRC0H_SHIFT 0 /*NV20*/ +#define NV30_VP_INST_SRC0H_MASK (0x1FF << 0) /*NV20*/ + +/* Please note: the IADDR fields overlap other fields because they are used + * only for branch instructions. See Branching: label above + * + * DWORD 2 + */ +#define NV30_VP_INST_SRC0L_SHIFT 26 /*NV20*/ +#define NV30_VP_INST_SRC0L_MASK (0x3F <<26) /* NV30_VP_SRC0_LOW_MASK << 26 */ +#define NV30_VP_INST_SRC1_SHIFT 11 /*NV20*/ +#define NV30_VP_INST_SRC1_MASK (0x7FFF<<11) /*NV20*/ +#define NV30_VP_INST_SRC2H_SHIFT 0 /*NV20*/ +#define NV30_VP_INST_SRC2H_MASK (0x7FF << 0) /* NV30_VP_SRC2_HIGH_MASK >> 4*/ +#define NV30_VP_INST_IADDR_SHIFT 2 +#define NV30_VP_INST_IADDR_MASK (0xF << 28) /* NV30_VP_SRC2_LOW_MASK << 28 */ + +/* DWORD 3 */ +#define NV30_VP_INST_SRC2L_SHIFT 28 /*NV20*/ +#define NV30_VP_INST_SRC2L_MASK (0x0F <<28) /*NV20*/ +#define NV30_VP_INST_STEMP_WRITEMASK_SHIFT 24 +#define NV30_VP_INST_STEMP_WRITEMASK_MASK (0x0F << 24) +#define NV30_VP_INST_VTEMP_WRITEMASK_SHIFT 20 +#define NV30_VP_INST_VTEMP_WRITEMASK_MASK (0x0F << 20) +#define NV30_VP_INST_SDEST_WRITEMASK_SHIFT 16 +#define NV30_VP_INST_SDEST_WRITEMASK_MASK (0x0F << 16) +#define NV30_VP_INST_VDEST_WRITEMASK_SHIFT 12 /*NV20*/ +#define NV30_VP_INST_VDEST_WRITEMASK_MASK (0x0F << 12) /*NV20*/ +#define NV30_VP_INST_DEST_SHIFT 2 +#define NV30_VP_INST_DEST_MASK (0x0F << 2) +# define NV30_VP_INST_DEST_POS 0 +# define NV30_VP_INST_DEST_BFC0 1 +# define NV30_VP_INST_DEST_BFC1 2 +# define NV30_VP_INST_DEST_COL0 3 +# define NV30_VP_INST_DEST_COL1 4 +# define NV30_VP_INST_DEST_FOGC 5 +# define NV30_VP_INST_DEST_PSZ 6 +# define NV30_VP_INST_DEST_TC(n) (8+n) + +/* Useful to split the source selection regs into their pieces */ +#define NV30_VP_SRC0_HIGH_SHIFT 6 +#define NV30_VP_SRC0_HIGH_MASK 0x00007FC0 +#define NV30_VP_SRC0_LOW_MASK 0x0000003F +#define NV30_VP_SRC2_HIGH_SHIFT 4 +#define NV30_VP_SRC2_HIGH_MASK 0x00007FF0 +#define NV30_VP_SRC2_LOW_MASK 0x0000000F + + +/* Source-register definition - matches NV20 exactly */ +#define NV30_VP_SRC_NEGATE (1<<14) +#define NV30_VP_SRC_SWZ_X_SHIFT 12 +#define NV30_VP_SRC_REG_SWZ_X_MASK (0x03 <<12) +#define NV30_VP_SRC_SWZ_Y_SHIFT 10 +#define NV30_VP_SRC_REG_SWZ_Y_MASK (0x03 <<10) +#define NV30_VP_SRC_SWZ_Z_SHIFT 8 +#define NV30_VP_SRC_REG_SWZ_Z_MASK (0x03 << 8) +#define NV30_VP_SRC_SWZ_W_SHIFT 6 +#define NV30_VP_SRC_REG_SWZ_W_MASK (0x03 << 6) +#define NV30_VP_SRC_REG_SWZ_ALL_SHIFT 6 +#define NV30_VP_SRC_REG_SWZ_ALL_MASK (0xFF << 6) +#define NV30_VP_SRC_TEMP_SRC_SHIFT 2 +#define NV30_VP_SRC_REG_TEMP_ID_MASK (0x0F << 0) +#define NV30_VP_SRC_REG_TYPE_SHIFT 0 +#define NV30_VP_SRC_REG_TYPE_MASK (0x03 << 0) +#define NV30_VP_SRC_REG_TYPE_TEMP 1 +#define NV30_VP_SRC_REG_TYPE_INPUT 2 +#define NV30_VP_SRC_REG_TYPE_CONST 3 /* guess */ + +#include "nvfx_shader.h" + +#endif diff --git a/src/gallium/drivers/nvfx/nv40_fragtex.c b/src/gallium/drivers/nvfx/nv40_fragtex.c new file mode 100644 index 00000000000..5889b5e40d5 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv40_fragtex.c @@ -0,0 +1,174 @@ +#include "util/u_format.h" +#include "nvfx_context.h" +#include "nvfx_tex.h" + +void +nv40_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso) +{ + if (cso->max_anisotropy >= 2) { + /* no idea, binary driver sets it, works without it.. meh.. */ + ps->wrap |= (1 << 5); + + if (cso->max_anisotropy >= 16) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_16X; + } else + if (cso->max_anisotropy >= 12) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_12X; + } else + if (cso->max_anisotropy >= 10) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_10X; + } else + if (cso->max_anisotropy >= 8) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_8X; + } else + if (cso->max_anisotropy >= 6) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_6X; + } else + if (cso->max_anisotropy >= 4) { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_4X; + } else { + ps->en |= NV40TCL_TEX_ENABLE_ANISO_2X; + } + } + + { + float limit; + + limit = CLAMP(cso->lod_bias, -16.0, 15.0); + ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; + + limit = CLAMP(cso->max_lod, 0.0, 15.0); + ps->en |= (int)(limit * 256.0) << 7; + + limit = CLAMP(cso->min_lod, 0.0, 15.0); + ps->en |= (int)(limit * 256.0) << 19; + } +} + +#define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w,sx,sy,sz,sw) \ +{ \ + TRUE, \ + PIPE_FORMAT_##m, \ + NV40TCL_TEX_FORMAT_FORMAT_##tf, \ + (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y | \ + NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w | \ + NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y | \ + NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w), \ + ((NV34TCL_TX_FILTER_SIGNED_RED*sx) | (NV34TCL_TX_FILTER_SIGNED_GREEN*sy) | \ + (NV34TCL_TX_FILTER_SIGNED_BLUE*sz) | (NV34TCL_TX_FILTER_SIGNED_ALPHA*sw)) \ +} + +struct nv40_texture_format { + boolean defined; + uint pipe; + int format; + int swizzle; + int sign; +}; + +static struct nv40_texture_format +nv40_texture_formats[] = { + _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), + _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), + _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), + _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X, 0, 0, 0, 0), + _(R16_SNORM , A16 , ZERO, ZERO, S1, ONE, X, X, X, Y, 1, 1, 1, 1), + _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X, 0, 0, 0, 0), + _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y, 0, 0, 0, 0), + _(Z16_UNORM , Z16 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), + _(S8Z24_UNORM , Z24 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), + _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), + _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(DXT5_RGBA , DXT5 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + {}, +}; + +static struct nv40_texture_format * +nv40_fragtex_format(uint pipe_format) +{ + struct nv40_texture_format *tf = nv40_texture_formats; + + while (tf->defined) { + if (tf->pipe == pipe_format) + return tf; + tf++; + } + + NOUVEAU_ERR("unknown texture format %s\n", util_format_name(pipe_format)); + return NULL; +} + + +struct nouveau_stateobj * +nv40_fragtex_build(struct nvfx_context *nvfx, int unit) +{ + struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; + struct nvfx_miptree *nv40mt = nvfx->tex_miptree[unit]; + struct nouveau_bo *bo = nouveau_bo(nv40mt->buffer); + struct pipe_texture *pt = &nv40mt->base; + struct nv40_texture_format *tf; + struct nouveau_stateobj *so; + uint32_t txf, txs, txp; + unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + + tf = nv40_fragtex_format(pt->format); + if (!tf) + assert(0); + + txf = ps->fmt; + txf |= tf->format | 0x8000; + txf |= ((pt->last_level + 1) << NV40TCL_TEX_FORMAT_MIPMAP_COUNT_SHIFT); + + if (1) /* XXX */ + txf |= NV34TCL_TX_FORMAT_NO_BORDER; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE: + txf |= NV34TCL_TX_FORMAT_CUBIC; + /* fall-through */ + case PIPE_TEXTURE_2D: + txf |= NV34TCL_TX_FORMAT_DIMS_2D; + break; + case PIPE_TEXTURE_3D: + txf |= NV34TCL_TX_FORMAT_DIMS_3D; + break; + case PIPE_TEXTURE_1D: + txf |= NV34TCL_TX_FORMAT_DIMS_1D; + break; + default: + NOUVEAU_ERR("Unknown target %d\n", pt->target); + return NULL; + } + + if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) { + txp = 0; + } else { + txp = nv40mt->level[0].pitch; + txf |= NV40TCL_TEX_FORMAT_LINEAR; + } + + txs = tf->swizzle; + + so = so_new(2, 9, 2); + so_method(so, nvfx->screen->eng3d, NV34TCL_TX_OFFSET(unit), 8); + so_reloc (so, bo, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0); + so_reloc (so, bo, txf, tex_flags | NOUVEAU_BO_OR, + NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1); + so_data (so, ps->wrap); + so_data (so, NV40TCL_TEX_ENABLE_ENABLE | ps->en); + so_data (so, txs); + so_data (so, ps->filt | tf->sign | 0x2000 /*voodoo*/); + so_data (so, (pt->width0 << NV34TCL_TX_NPOT_SIZE_W_SHIFT) | + pt->height0); + so_data (so, ps->bcol); + so_method(so, nvfx->screen->eng3d, NV40TCL_TEX_SIZE1(unit), 1); + so_data (so, (pt->depth0 << NV40TCL_TEX_SIZE1_DEPTH_SHIFT) | txp); + + return so; +} diff --git a/src/gallium/drivers/nvfx/nv40_vertprog.h b/src/gallium/drivers/nvfx/nv40_vertprog.h new file mode 100644 index 00000000000..7337293babc --- /dev/null +++ b/src/gallium/drivers/nvfx/nv40_vertprog.h @@ -0,0 +1,177 @@ +#ifndef __NV40_SHADER_H__ +#define __NV40_SHADER_H__ + +/* Vertex programs instruction set + * + * The NV40 instruction set is very similar to NV30. Most fields are in + * a slightly different position in the instruction however. + * + * Merged instructions + * In some cases it is possible to put two instructions into one opcode + * slot. The rules for when this is OK is not entirely clear to me yet. + * + * There are separate writemasks and dest temp register fields for each + * grouping of instructions. There is however only one field with the + * ID of a result register. Writing to temp/result regs is selected by + * setting VEC_RESULT/SCA_RESULT. + * + * Temporary registers + * The source/dest temp register fields have been extended by 1 bit, to + * give a total of 32 temporary registers. + * + * Relative Addressing + * NV40 can use an address register to index into vertex attribute regs. + * This is done by putting the offset value into INPUT_SRC and setting + * the INDEX_INPUT flag. + * + * Conditional execution (see NV_vertex_program{2,3} for details) + * There is a second condition code register on NV40, it's use is enabled + * by setting the COND_REG_SELECT_1 flag. + * + * Texture lookup + * TODO + */ + +/* ---- OPCODE BITS 127:96 / data DWORD 0 --- */ +#define NV40_VP_INST_VEC_RESULT (1 << 30) +/* uncertain.. */ +#define NV40_VP_INST_COND_UPDATE_ENABLE ((1 << 14)|1<<29) +/* use address reg as index into attribs */ +#define NV40_VP_INST_INDEX_INPUT (1 << 27) +#define NV40_VP_INST_COND_REG_SELECT_1 (1 << 25) +#define NV40_VP_INST_ADDR_REG_SELECT_1 (1 << 24) +#define NV40_VP_INST_SRC2_ABS (1 << 23) +#define NV40_VP_INST_SRC1_ABS (1 << 22) +#define NV40_VP_INST_SRC0_ABS (1 << 21) +#define NV40_VP_INST_VEC_DEST_TEMP_SHIFT 15 +#define NV40_VP_INST_VEC_DEST_TEMP_MASK (0x1F << 15) +#define NV40_VP_INST_COND_TEST_ENABLE (1 << 13) +#define NV40_VP_INST_COND_SHIFT 10 +#define NV40_VP_INST_COND_MASK (0x7 << 10) +#define NV40_VP_INST_COND_SWZ_X_SHIFT 8 +#define NV40_VP_INST_COND_SWZ_X_MASK (3 << 8) +#define NV40_VP_INST_COND_SWZ_Y_SHIFT 6 +#define NV40_VP_INST_COND_SWZ_Y_MASK (3 << 6) +#define NV40_VP_INST_COND_SWZ_Z_SHIFT 4 +#define NV40_VP_INST_COND_SWZ_Z_MASK (3 << 4) +#define NV40_VP_INST_COND_SWZ_W_SHIFT 2 +#define NV40_VP_INST_COND_SWZ_W_MASK (3 << 2) +#define NV40_VP_INST_COND_SWZ_ALL_SHIFT 2 +#define NV40_VP_INST_COND_SWZ_ALL_MASK (0xFF << 2) +#define NV40_VP_INST_ADDR_SWZ_SHIFT 0 +#define NV40_VP_INST_ADDR_SWZ_MASK (0x03 << 0) +#define NV40_VP_INST0_KNOWN ( \ + NV40_VP_INST_INDEX_INPUT | \ + NV40_VP_INST_COND_REG_SELECT_1 | \ + NV40_VP_INST_ADDR_REG_SELECT_1 | \ + NV40_VP_INST_SRC2_ABS | \ + NV40_VP_INST_SRC1_ABS | \ + NV40_VP_INST_SRC0_ABS | \ + NV40_VP_INST_VEC_DEST_TEMP_MASK | \ + NV40_VP_INST_COND_TEST_ENABLE | \ + NV40_VP_INST_COND_MASK | \ + NV40_VP_INST_COND_SWZ_ALL_MASK | \ + NV40_VP_INST_ADDR_SWZ_MASK) + +/* ---- OPCODE BITS 95:64 / data DWORD 1 --- */ +#define NV40_VP_INST_VEC_OPCODE_SHIFT 22 +#define NV40_VP_INST_VEC_OPCODE_MASK (0x1F << 22) +#define NV40_VP_INST_SCA_OPCODE_SHIFT 27 +#define NV40_VP_INST_SCA_OPCODE_MASK (0x1F << 27) +#define NV40_VP_INST_CONST_SRC_SHIFT 12 +#define NV40_VP_INST_CONST_SRC_MASK (0xFF << 12) +#define NV40_VP_INST_INPUT_SRC_SHIFT 8 +#define NV40_VP_INST_INPUT_SRC_MASK (0x0F << 8) +#define NV40_VP_INST_SRC0H_SHIFT 0 +#define NV40_VP_INST_SRC0H_MASK (0xFF << 0) +#define NV40_VP_INST1_KNOWN ( \ + NV40_VP_INST_VEC_OPCODE_MASK | \ + NV40_VP_INST_SCA_OPCODE_MASK | \ + NV40_VP_INST_CONST_SRC_MASK | \ + NV40_VP_INST_INPUT_SRC_MASK | \ + NV40_VP_INST_SRC0H_MASK \ + ) + +/* ---- OPCODE BITS 63:32 / data DWORD 2 --- */ +#define NV40_VP_INST_SRC0L_SHIFT 23 +#define NV40_VP_INST_SRC0L_MASK (0x1FF << 23) +#define NV40_VP_INST_SRC1_SHIFT 6 +#define NV40_VP_INST_SRC1_MASK (0x1FFFF << 6) +#define NV40_VP_INST_SRC2H_SHIFT 0 +#define NV40_VP_INST_SRC2H_MASK (0x3F << 0) +#define NV40_VP_INST_IADDRH_SHIFT 0 +#define NV40_VP_INST_IADDRH_MASK (0x1F << 0) + +/* ---- OPCODE BITS 31:0 / data DWORD 3 --- */ +#define NV40_VP_INST_IADDRL_SHIFT 29 +#define NV40_VP_INST_IADDRL_MASK (7 << 29) +#define NV40_VP_INST_SRC2L_SHIFT 21 +#define NV40_VP_INST_SRC2L_MASK (0x7FF << 21) +#define NV40_VP_INST_SCA_WRITEMASK_SHIFT 17 +#define NV40_VP_INST_SCA_WRITEMASK_MASK (0xF << 17) +# define NV40_VP_INST_SCA_WRITEMASK_X (1 << 20) +# define NV40_VP_INST_SCA_WRITEMASK_Y (1 << 19) +# define NV40_VP_INST_SCA_WRITEMASK_Z (1 << 18) +# define NV40_VP_INST_SCA_WRITEMASK_W (1 << 17) +#define NV40_VP_INST_VEC_WRITEMASK_SHIFT 13 +#define NV40_VP_INST_VEC_WRITEMASK_MASK (0xF << 13) +# define NV40_VP_INST_VEC_WRITEMASK_X (1 << 16) +# define NV40_VP_INST_VEC_WRITEMASK_Y (1 << 15) +# define NV40_VP_INST_VEC_WRITEMASK_Z (1 << 14) +# define NV40_VP_INST_VEC_WRITEMASK_W (1 << 13) +#define NV40_VP_INST_SCA_RESULT (1 << 12) +#define NV40_VP_INST_SCA_DEST_TEMP_SHIFT 7 +#define NV40_VP_INST_SCA_DEST_TEMP_MASK (0x1F << 7) +#define NV40_VP_INST_DEST_SHIFT 2 +#define NV40_VP_INST_DEST_MASK (31 << 2) +# define NV40_VP_INST_DEST_POS 0 +# define NV40_VP_INST_DEST_COL0 1 +# define NV40_VP_INST_DEST_COL1 2 +# define NV40_VP_INST_DEST_BFC0 3 +# define NV40_VP_INST_DEST_BFC1 4 +# define NV40_VP_INST_DEST_FOGC 5 +# define NV40_VP_INST_DEST_PSZ 6 +# define NV40_VP_INST_DEST_TC0 7 +# define NV40_VP_INST_DEST_TC(n) (7+n) +# define NV40_VP_INST_DEST_TEMP 0x1F +#define NV40_VP_INST_INDEX_CONST (1 << 1) +#define NV40_VP_INST3_KNOWN ( \ + NV40_VP_INST_SRC2L_MASK |\ + NV40_VP_INST_SCA_WRITEMASK_MASK |\ + NV40_VP_INST_VEC_WRITEMASK_MASK |\ + NV40_VP_INST_SCA_DEST_TEMP_MASK |\ + NV40_VP_INST_DEST_MASK |\ + NV40_VP_INST_INDEX_CONST) + +/* Useful to split the source selection regs into their pieces */ +#define NV40_VP_SRC0_HIGH_SHIFT 9 +#define NV40_VP_SRC0_HIGH_MASK 0x0001FE00 +#define NV40_VP_SRC0_LOW_MASK 0x000001FF +#define NV40_VP_SRC2_HIGH_SHIFT 11 +#define NV40_VP_SRC2_HIGH_MASK 0x0001F800 +#define NV40_VP_SRC2_LOW_MASK 0x000007FF + +/* Source selection - these are the bits you fill NV40_VP_INST_SRCn with */ +#define NV40_VP_SRC_NEGATE (1 << 16) +#define NV40_VP_SRC_SWZ_X_SHIFT 14 +#define NV40_VP_SRC_SWZ_X_MASK (3 << 14) +#define NV40_VP_SRC_SWZ_Y_SHIFT 12 +#define NV40_VP_SRC_SWZ_Y_MASK (3 << 12) +#define NV40_VP_SRC_SWZ_Z_SHIFT 10 +#define NV40_VP_SRC_SWZ_Z_MASK (3 << 10) +#define NV40_VP_SRC_SWZ_W_SHIFT 8 +#define NV40_VP_SRC_SWZ_W_MASK (3 << 8) +#define NV40_VP_SRC_SWZ_ALL_SHIFT 8 +#define NV40_VP_SRC_SWZ_ALL_MASK (0xFF << 8) +#define NV40_VP_SRC_TEMP_SRC_SHIFT 2 +#define NV40_VP_SRC_TEMP_SRC_MASK (0x1F << 2) +#define NV40_VP_SRC_REG_TYPE_SHIFT 0 +#define NV40_VP_SRC_REG_TYPE_MASK (3 << 0) +# define NV40_VP_SRC_REG_TYPE_UNK0 0 +# define NV40_VP_SRC_REG_TYPE_TEMP 1 +# define NV40_VP_SRC_REG_TYPE_INPUT 2 +# define NV40_VP_SRC_REG_TYPE_CONST 3 + +#include "nvfx_shader.h" + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_draw.c b/src/gallium/drivers/nvfx/nvfx_draw.c index 8700e143297..7308f0667c7 100644 --- a/src/gallium/drivers/nvfx/nvfx_draw.c +++ b/src/gallium/drivers/nvfx/nvfx_draw.c @@ -9,8 +9,8 @@ #include "nvfx_context.h" #define NVFX_SHADER_NO_FUCKEDNESS -#include "nv30/nv30_shader.h" -#include "nv40/nv40_shader.h" +#include "nv30_vertprog.h" +#include "nv40_vertprog.h" /* Simple, but crappy, swtnl path, hopefully we wont need to hit this very * often at all. Uses "quadro style" vertex submission + a fixed vertex diff --git a/src/gallium/drivers/nvfx/nvfx_vertprog.c b/src/gallium/drivers/nvfx/nvfx_vertprog.c index 730361a9827..3d0e8c23a15 100644 --- a/src/gallium/drivers/nvfx/nvfx_vertprog.c +++ b/src/gallium/drivers/nvfx/nvfx_vertprog.c @@ -33,8 +33,8 @@ #define MASK_ALL (MASK_X|MASK_Y|MASK_Z|MASK_W) #define DEF_SCALE 0 #define DEF_CTEST 0 -#include "nv30/nv30_shader.h" -#include "nv40/nv40_shader.h" +#include "nv30_vertprog.h" +#include "nv40_vertprog.h" #define swz(s,x,y,z,w) nvfx_sr_swz((s), SWZ_##x, SWZ_##y, SWZ_##z, SWZ_##w) #define neg(s) nvfx_sr_neg((s)) diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile index 0cc60395ffe..50ac3f203e5 100644 --- a/src/gallium/winsys/drm/nouveau/dri/Makefile +++ b/src/gallium/winsys/drm/nouveau/dri/Makefile @@ -3,18 +3,10 @@ include $(TOP)/configs/current LIBNAME = nouveau_dri.so -# hideous hack --Wl,--start-group: --Wl,--end-group: - PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - -Wl,--start-group \ - $(TOP)/src/gallium/drivers/nv30/libnv30.a \ - $(TOP)/src/gallium/drivers/nv40/libnv40.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - -Wl,--end-group \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile index 0f5e6d64aa4..47d11276155 100644 --- a/src/gallium/winsys/drm/nouveau/egl/Makefile +++ b/src/gallium/winsys/drm/nouveau/egl/Makefile @@ -5,17 +5,9 @@ EGL_DRIVER_NAME = nouveau EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_nouveau -# hideous hack --Wl,--start-group: --Wl,--end-group: - EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - -Wl,--start-group \ - $(TOP)/src/gallium/drivers/nv30/libnv30.a \ - $(TOP)/src/gallium/drivers/nv40/libnv40.a \ - $(TOP)/src/gallium/drivers/nv40/libnvfx.a \ - -Wl,--end-group \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a diff --git a/src/gallium/winsys/drm/nouveau/xorg/Makefile b/src/gallium/winsys/drm/nouveau/xorg/Makefile index 0607d82a6e4..f7f6fe17dd6 100644 --- a/src/gallium/winsys/drm/nouveau/xorg/Makefile +++ b/src/gallium/winsys/drm/nouveau/xorg/Makefile @@ -15,18 +15,10 @@ INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/egl/main -# hideous hack --Wl,--start-group: --Wl,--end-group: - LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - --Wl,--start-group \ - $(TOP)/src/gallium/drivers/nv30/libnv30.a \ - $(TOP)/src/gallium/drivers/nv40/libnv40.a \ - $(TOP)/src/gallium/drivers/nv40/libnvfx.a \ - --Wl,--end-group \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ $(GALLIUM_AUXILIARIES) -- cgit v1.2.3 From e725ef171b5a4d5425461f237d9ccab223806913 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Mon, 15 Mar 2010 20:53:56 -0700 Subject: Change libX11 variables to not conflict with AC_PATH_XTRA The variable X_LIBS from AC_PATH_XTRA contains only the -L searchdir parameter and not the -lX11 to link to Xlib. Use X11 prefixed build vars for linking with Xlib to avoid the conflict. Signed-off-by: Dan Nicholson --- configs/autoconf.in | 4 ++-- configure.ac | 6 +++++- progs/egl/Makefile | 6 +++--- progs/xdemos/Makefile | 2 +- src/gallium/state_trackers/glx/xlib/Makefile | 2 +- src/gallium/winsys/xlib/Makefile | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) (limited to 'configure.ac') diff --git a/configs/autoconf.in b/configs/autoconf.in index f50fb7dd093..66c1ee48e87 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -24,8 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@ RADEON_LDFLAGS = @RADEON_LDFLAGS@ INTEL_LIBS = @INTEL_LIBS@ INTEL_CFLAGS = @INTEL_CFLAGS@ -X_LIBS = @X_LIBS@ -X_CFLAGS = @X_CFLAGS@ +X11_LIBS = @X11_LIBS@ +X11_CFLAGS = @X11_CFLAGS@ # Assembler MESA_ASM_SOURCES = @MESA_ASM_SOURCES@ diff --git a/configure.ac b/configure.ac index 0f51097ef62..26960e85ea4 100644 --- a/configure.ac +++ b/configure.ac @@ -548,9 +548,13 @@ else fi dnl Use the autoconf macro if no pkg-config files if test "$x11_pkgconfig" = yes; then - PKG_CHECK_MODULES([X], [x11]) + PKG_CHECK_MODULES([X11], [x11]) else AC_PATH_XTRA + test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS" + test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11" + AC_SUBST([X11_CFLAGS]) + AC_SUBST([X11_LIBS]) fi dnl Try to tell the user that the --x-* options are only used when diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 5f51104fed6..8dfcb4eabcb 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) clean: -rm -f *.o *~ diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index f81aafe00f6..660c540657a 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -9,7 +9,7 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) # Add X11 and pthread libs to satisfy GNU gold. -APP_LIB_DEPS += $(X_LIBS) -lpthread +APP_LIB_DEPS += $(X11_LIBS) -lpthread LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS) diff --git a/src/gallium/state_trackers/glx/xlib/Makefile b/src/gallium/state_trackers/glx/xlib/Makefile index 582e72bb463..35509fd708b 100644 --- a/src/gallium/state_trackers/glx/xlib/Makefile +++ b/src/gallium/state_trackers/glx/xlib/Makefile @@ -6,7 +6,7 @@ LIBNAME = xlib LIBRARY_INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/mesa \ - $(X_CFLAGS) + $(X11_CFLAGS) C_SOURCES = \ glx_api.c \ diff --git a/src/gallium/winsys/xlib/Makefile b/src/gallium/winsys/xlib/Makefile index 18357a41127..83d53c59542 100644 --- a/src/gallium/winsys/xlib/Makefile +++ b/src/gallium/winsys/xlib/Makefile @@ -7,7 +7,7 @@ LIBRARY_INCLUDES = \ -I$(TOP)/src/gallium/include \ -I$(TOP)/src/gallium/drivers \ -I$(TOP)/src/gallium/auxiliary \ - $(X_CFLAGS) + $(X11_CFLAGS) C_SOURCES = \ xlib_sw_winsys.c -- cgit v1.2.3 From 41d2ebf2020311eb032882d9b0bd1efe916f1feb Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 13:44:32 +0000 Subject: gallium: Remove GALLIUM_WINSYS_DRM_DIRS --- configs/autoconf.in | 1 - configs/default | 3 +-- configs/linux-dri | 3 +-- configs/linux-opengl-es | 3 +-- configure.ac | 25 +++++++++++++++---------- src/gallium/winsys/drm/Makefile | 12 ------------ 6 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 src/gallium/winsys/drm/Makefile (limited to 'configure.ac') diff --git a/configs/autoconf.in b/configs/autoconf.in index 66c1ee48e87..b6cc9b3b73e 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -76,7 +76,6 @@ GALLIUM_DIRS = @GALLIUM_DIRS@ GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@ GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@ GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_DIRS@ -GALLIUM_WINSYS_DRM_DIRS = @GALLIUM_WINSYS_DRM_DIRS@ GALLIUM_STATE_TRACKERS_DIRS = @GALLIUM_STATE_TRACKERS_DIRS@ GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) diff --git a/configs/default b/configs/default index 8fbf8dd219a..03feed973a2 100644 --- a/configs/default +++ b/configs/default @@ -100,9 +100,8 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib drm +GALLIUM_WINSYS_DIRS = null xlib drm/swrast GALLIUM_TARGET_DIRS = libgl-xlib -GALLIUM_WINSYS_DRM_DIRS = swrast GALLIUM_STATE_TRACKERS_DIRS = glx vega # native displays EGL should support diff --git a/configs/linux-dri b/configs/linux-dri index d362fd8b377..e10021d7994 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -58,9 +58,8 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS) EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri -GALLIUM_WINSYS_DIRS = null xlib drm +GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 GALLIUM_TARGET_DIRS = -GALLIUM_WINSYS_DRM_DIRS = vmware intel i965 GALLIUM_STATE_TRACKERS_DIRS = egl DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \ diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es index 76054aad14e..ddcb717f836 100644 --- a/configs/linux-opengl-es +++ b/configs/linux-opengl-es @@ -24,5 +24,4 @@ GALLIUM_STATE_TRACKERS_DIRS = es # build egl_x11_{swrast,i915}.so GALLIUM_DRIVERS_DIRS += trace i915 GALLIUM_STATE_TRACKERS_DIRS += egl -GALLIUM_WINSYS_DIRS += drm -GALLIUM_WINSYS_DRM_DIRS += intel swrast +GALLIUM_WINSYS_DIRS += drm/intel drm/swrast diff --git a/configure.ac b/configure.ac index 26960e85ea4..aab16b6ea8a 100644 --- a/configure.ac +++ b/configure.ac @@ -461,8 +461,7 @@ SRC_DIRS="glew" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" -GALLIUM_WINSYS_DIRS="" -GALLIUM_WINSYS_DRM_DIRS="" +GALLIUM_WINSYS_DIRS="null" GALLIUM_DRIVERS_DIRS="softpipe failover trace identity" GALLIUM_STATE_TRACKERS_DIRS="" @@ -475,7 +474,7 @@ xlib) dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm/sw" ;; osmesa) DRIVER_DIRS="osmesa" @@ -487,7 +486,6 @@ AC_SUBST([DRIVER_DIRS]) AC_SUBST([GALLIUM_DIRS]) AC_SUBST([GALLIUM_TARGET_DIRS]) AC_SUBST([GALLIUM_WINSYS_DIRS]) -AC_SUBST([GALLIUM_WINSYS_DRM_DIRS]) AC_SUBST([GALLIUM_DRIVERS_DIRS]) AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS]) @@ -1318,7 +1316,9 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga="$enableval"], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS vmware" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1333,7 +1333,9 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel="$enableval"], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS intel i965" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1348,7 +1350,9 @@ AC_ARG_ENABLE([gallium-radeon], [enable_gallium_radeon="$enableval"], [enable_gallium_radeon=auto]) if test "x$enable_gallium_radeon" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS radeon" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1363,7 +1367,9 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau="$enableval"], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi @@ -1376,7 +1382,7 @@ AC_ARG_ENABLE([gallium-swrast], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/swrast" fi dnl prepend CORE_DIRS to SRC_DIRS @@ -1434,7 +1440,6 @@ if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then echo " Gallium dirs: $GALLIUM_DIRS" echo " Target dirs: $GALLIUM_TARGET_DIRS" echo " Winsys dirs: $GALLIUM_WINSYS_DIRS" - echo " Winsys drm dirs:$GALLIUM_WINSYS_DRM_DIRS" echo " Driver dirs: $GALLIUM_DRIVERS_DIRS" echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS" else diff --git a/src/gallium/winsys/drm/Makefile b/src/gallium/winsys/drm/Makefile deleted file mode 100644 index a998aff931d..00000000000 --- a/src/gallium/winsys/drm/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/Makefile -TOP = ../../../.. -include $(TOP)/configs/current - -SUBDIRS = sw $(GALLIUM_WINSYS_DRM_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done -- cgit v1.2.3 From be38b32531cc974ff8a33e4504d4169150be4d55 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 23 Mar 2010 13:23:26 +0000 Subject: gallium: Move dri drivers to targets Attached output from git commit: rename src/gallium/{winsys/drm/Makefile.template => targets/Makefile.dri} (100%) rename src/gallium/{winsys/drm/intel/dri => targets/dri-i915}/Makefile (75%) rename src/gallium/{winsys/drm/intel/dri => targets/dri-i915}/SConscript (100%) rename src/gallium/{winsys/drm/i965/dri => targets/dri-i965}/Makefile (76%) rename src/gallium/{winsys/drm/i965/dri => targets/dri-i965}/SConscript (100%) rename src/gallium/{winsys/drm/nouveau/dri => targets/dri-nouveau}/Makefile (86%) rename src/gallium/{winsys/drm/radeon/dri => targets/dri-radeong}/Makefile (85%) rename src/gallium/{winsys/drm/radeon/dri => targets/dri-radeong}/SConscript (100%) rename src/gallium/{winsys/drm/vmware/dri => targets/dri-vmwgfx}/Makefile (85%) rename src/gallium/{winsys/drm/vmware/dri => targets/dri-vmwgfx}/SConscript (100%) --- configure.ac | 6 +- src/gallium/targets/Makefile.dri | 105 +++++++++++++++++++++++++++ src/gallium/targets/dri-i915/Makefile | 22 ++++++ src/gallium/targets/dri-i915/SConscript | 21 ++++++ src/gallium/targets/dri-i965/Makefile | 23 ++++++ src/gallium/targets/dri-i965/SConscript | 19 +++++ src/gallium/targets/dri-nouveau/Makefile | 21 ++++++ src/gallium/targets/dri-radeong/Makefile | 21 ++++++ src/gallium/targets/dri-radeong/SConscript | 17 +++++ src/gallium/targets/dri-vmwgfx/Makefile | 17 +++++ src/gallium/targets/dri-vmwgfx/SConscript | 63 ++++++++++++++++ src/gallium/winsys/drm/Makefile.template | 105 --------------------------- src/gallium/winsys/drm/i965/SConscript | 4 - src/gallium/winsys/drm/i965/dri/Makefile | 27 ------- src/gallium/winsys/drm/i965/dri/SConscript | 19 ----- src/gallium/winsys/drm/intel/SConscript | 4 - src/gallium/winsys/drm/intel/dri/Makefile | 26 ------- src/gallium/winsys/drm/intel/dri/SConscript | 21 ------ src/gallium/winsys/drm/nouveau/dri/Makefile | 23 ------ src/gallium/winsys/drm/radeon/SConscript | 4 - src/gallium/winsys/drm/radeon/dri/Makefile | 24 ------ src/gallium/winsys/drm/radeon/dri/SConscript | 17 ----- src/gallium/winsys/drm/vmware/SConscript | 4 - src/gallium/winsys/drm/vmware/dri/Makefile | 18 ----- src/gallium/winsys/drm/vmware/dri/SConscript | 63 ---------------- 25 files changed, 334 insertions(+), 360 deletions(-) create mode 100644 src/gallium/targets/Makefile.dri create mode 100644 src/gallium/targets/dri-i915/Makefile create mode 100644 src/gallium/targets/dri-i915/SConscript create mode 100644 src/gallium/targets/dri-i965/Makefile create mode 100644 src/gallium/targets/dri-i965/SConscript create mode 100644 src/gallium/targets/dri-nouveau/Makefile create mode 100644 src/gallium/targets/dri-radeong/Makefile create mode 100644 src/gallium/targets/dri-radeong/SConscript create mode 100644 src/gallium/targets/dri-vmwgfx/Makefile create mode 100644 src/gallium/targets/dri-vmwgfx/SConscript delete mode 100644 src/gallium/winsys/drm/Makefile.template delete mode 100644 src/gallium/winsys/drm/i965/dri/Makefile delete mode 100644 src/gallium/winsys/drm/i965/dri/SConscript delete mode 100644 src/gallium/winsys/drm/intel/dri/Makefile delete mode 100644 src/gallium/winsys/drm/intel/dri/SConscript delete mode 100644 src/gallium/winsys/drm/nouveau/dri/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/dri/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/dri/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/dri/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/dri/SConscript (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index aab16b6ea8a..51b480ff972 100644 --- a/configure.ac +++ b/configure.ac @@ -1180,7 +1180,7 @@ AC_ARG_ENABLE([gallium], [enable_gallium="$enableval"], [enable_gallium=yes]) if test "x$enable_gallium" = xyes; then - SRC_DIRS="$SRC_DIRS gallium gallium/winsys" + SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets" fi dnl @@ -1318,6 +1318,7 @@ AC_ARG_ENABLE([gallium-svga], if test "x$enable_gallium_svga" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then @@ -1335,6 +1336,7 @@ AC_ARG_ENABLE([gallium-intel], if test "x$enable_gallium_intel" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then @@ -1352,6 +1354,7 @@ AC_ARG_ENABLE([gallium-radeon], if test "x$enable_gallium_radeon" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then @@ -1369,6 +1372,7 @@ AC_ARG_ENABLE([gallium-nouveau], if test "x$enable_gallium_nouveau" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri new file mode 100644 index 00000000000..6d9b81aa249 --- /dev/null +++ b/src/gallium/targets/Makefile.dri @@ -0,0 +1,105 @@ +# -*-makefile-*- + +MESA_MODULES = \ + $(TOP)/src/mesa/libmesagallium.a \ + $(GALLIUM_AUXILIARIES) + +COMMON_GALLIUM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/vblank.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c + +COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ + $(TOP)/src/mesa/drivers/common/driverfuncs.c \ + $(TOP)/src/mesa/drivers/dri/common/texmem.c \ + $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c + +COMMON_BM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/dri_bufmgr.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_drmpool.c + +INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) + +OBJECTS = \ + $(C_SOURCES:.c=.o) \ + $(ASM_SOURCES:.S=.o) + + +### Include directories +SHARED_INCLUDES = \ + -I. \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -Iserver \ + -I$(TOP)/include \ + -I$(TOP)/include/GL/internal \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys/common \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/mesa/glapi \ + -I$(TOP)/src/mesa/math \ + -I$(TOP)/src/mesa/transform \ + -I$(TOP)/src/mesa/shader \ + -I$(TOP)/src/mesa/swrast \ + -I$(TOP)/src/mesa/swrast_setup \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/egl/drivers/dri \ + $(LIBDRM_CFLAGS) + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) + +$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o + $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(OBJECTS) $(PIPE_DRIVERS) \ + -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ + $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) + @rm -f $@.test + mv -f $@.tmp $@ + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium + +depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ + $(ASM_SOURCES) 2> /dev/null + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` + + +# Remove .o and backup files +clean: + -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) + -rm -f depend depend.bak + + +install: $(LIBNAME) + $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) + + +include depend diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile new file mode 100644 index 00000000000..33eaae624f2 --- /dev/null +++ b/src/gallium/targets/dri-i915/Makefile @@ -0,0 +1,22 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i915_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_intel + +symlinks: diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript new file mode 100644 index 00000000000..0df841d8798 --- /dev/null +++ b/src/gallium/targets/dri-i915/SConscript @@ -0,0 +1,21 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +env.Prepend(LIBS = [ + st_dri, + inteldrm, + i915, + trace, + mesa, + glsl, + gallium +]) + +env.LoadableModule( + target ='i915_dri.so', + source = COMMON_GALLIUM_SOURCES, + SHLIBPREFIX = '', +) diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile new file mode 100644 index 00000000000..e17775a842a --- /dev/null +++ b/src/gallium/targets/dri-i965/Makefile @@ -0,0 +1,23 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i965_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_intel + +symlinks: diff --git a/src/gallium/targets/dri-i965/SConscript b/src/gallium/targets/dri-i965/SConscript new file mode 100644 index 00000000000..a99533fd245 --- /dev/null +++ b/src/gallium/targets/dri-i965/SConscript @@ -0,0 +1,19 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +drivers = [ + st_dri, + i965drm, + i965, + trace, +] + +env.LoadableModule( + target ='i965_dri.so', + source = COMMON_GALLIUM_SOURCES, + LIBS = drivers + mesa + gallium + env['LIBS'], + SHLIBPREFIX = '', +) diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile new file mode 100644 index 00000000000..680bad79177 --- /dev/null +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -0,0 +1,21 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveau_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs) + +symlinks: diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile new file mode 100644 index 00000000000..c6d8c524694 --- /dev/null +++ b/src/gallium/targets/dri-radeong/Makefile @@ -0,0 +1,21 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = radeong_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_radeon + +symlinks: diff --git a/src/gallium/targets/dri-radeong/SConscript b/src/gallium/targets/dri-radeong/SConscript new file mode 100644 index 00000000000..c4989d1b595 --- /dev/null +++ b/src/gallium/targets/dri-radeong/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') + +drivers = [ + trace, + softpipe, + r300 +] + +env.SharedLibrary( + target ='radeon_dri.so', + source = COMMON_GALLIUM_SOURCES, + LIBS = st_dri + radeonwinsys + mesa + drivers + gallium + env['LIBS'], +) diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile new file mode 100644 index 00000000000..1d2ddfe548f --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -0,0 +1,17 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = vmwgfx_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) + +include ../Makefile.dri + +symlinks: diff --git a/src/gallium/targets/dri-vmwgfx/SConscript b/src/gallium/targets/dri-vmwgfx/SConscript new file mode 100644 index 00000000000..d26d0cd7483 --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -0,0 +1,63 @@ +import os +import os.path + +Import('*') + +if env['platform'] == 'linux': + + if env['dri']: + env = env.Clone() + + sources = [ + '#/src/mesa/drivers/dri/common/utils.c', + '#/src/mesa/drivers/dri/common/vblank.c', + '#/src/mesa/drivers/dri/common/dri_util.c', + '#/src/mesa/drivers/dri/common/xmlconfig.c', + ] + + + env.ParseConfig('pkg-config --cflags --libs libdrm') + + env.Prepend(CPPPATH = [ + '#/src/mesa/state_tracker', + '#/src/mesa/drivers/dri/common', + '#/src/mesa/main', + '#/src/mesa/glapi', + '#/src/mesa', + '#/include', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', + ]) + + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + ]) + + env.Append(CFLAGS = [ + '-std=gnu99', + '-D_FILE_OFFSET_BITS=64', + ]) + + env.Prepend(LIBPATH = [ + ]) + + env.Prepend(LIBS = [ + trace, + st_dri, + svgadrm, + svga, + mesa, + glsl, + gallium, + ]) + + # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions + env.LoadableModule( + target ='vmwgfx_dri.so', + source = sources, + LIBS = env['LIBS'], + SHLIBPREFIX = '', + ) + + diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template deleted file mode 100644 index 6d9b81aa249..00000000000 --- a/src/gallium/winsys/drm/Makefile.template +++ /dev/null @@ -1,105 +0,0 @@ -# -*-makefile-*- - -MESA_MODULES = \ - $(TOP)/src/mesa/libmesagallium.a \ - $(GALLIUM_AUXILIARIES) - -COMMON_GALLIUM_SOURCES = \ - $(TOP)/src/mesa/drivers/dri/common/utils.c \ - $(TOP)/src/mesa/drivers/dri/common/vblank.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ - $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c - -COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ - $(TOP)/src/mesa/drivers/common/driverfuncs.c \ - $(TOP)/src/mesa/drivers/dri/common/texmem.c \ - $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c - -COMMON_BM_SOURCES = \ - $(TOP)/src/mesa/drivers/dri/common/dri_bufmgr.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_drmpool.c - -INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) - -OBJECTS = \ - $(C_SOURCES:.c=.o) \ - $(ASM_SOURCES:.S=.o) - - -### Include directories -SHARED_INCLUDES = \ - -I. \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -Iserver \ - -I$(TOP)/include \ - -I$(TOP)/include/GL/internal \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/winsys/common \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/mesa/glapi \ - -I$(TOP)/src/mesa/math \ - -I$(TOP)/src/mesa/transform \ - -I$(TOP)/src/mesa/shader \ - -I$(TOP)/src/mesa/swrast \ - -I$(TOP)/src/mesa/swrast_setup \ - -I$(TOP)/src/egl/main \ - -I$(TOP)/src/egl/drivers/dri \ - $(LIBDRM_CFLAGS) - - -##### RULES ##### - -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ - -.S.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ - - -##### TARGETS ##### - -default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) - -$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ - $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o - $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ - $(OBJECTS) $(PIPE_DRIVERS) \ - -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ - $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) - @rm -f $@.test - mv -f $@.tmp $@ - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium - -depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) - rm -f depend - touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ - $(ASM_SOURCES) 2> /dev/null - - -# Emacs tags -tags: - etags `find . -name \*.[ch]` `find ../include` - - -# Remove .o and backup files -clean: - -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) - -rm -f depend depend.bak - - -install: $(LIBNAME) - $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) - - -include depend diff --git a/src/gallium/winsys/drm/i965/SConscript b/src/gallium/winsys/drm/i965/SConscript index 50d7b75ed68..fdf57eedb94 100644 --- a/src/gallium/winsys/drm/i965/SConscript +++ b/src/gallium/winsys/drm/i965/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['gem/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/i965/dri/Makefile b/src/gallium/winsys/drm/i965/dri/Makefile deleted file mode 100644 index 56690769fc7..00000000000 --- a/src/gallium/winsys/drm/i965/dri/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i965_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/identity/libidentity.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a - - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_intel - -symlinks: $(TOP)/$(LIB_DIR)/gallium - @rm -f $(TOP)/$(LIB_DIR)/gallium/i965_dri.so diff --git a/src/gallium/winsys/drm/i965/dri/SConscript b/src/gallium/winsys/drm/i965/dri/SConscript deleted file mode 100644 index a99533fd245..00000000000 --- a/src/gallium/winsys/drm/i965/dri/SConscript +++ /dev/null @@ -1,19 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_intel') - -drivers = [ - st_dri, - i965drm, - i965, - trace, -] - -env.LoadableModule( - target ='i965_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = drivers + mesa + gallium + env['LIBS'], - SHLIBPREFIX = '', -) diff --git a/src/gallium/winsys/drm/intel/SConscript b/src/gallium/winsys/drm/intel/SConscript index 50d7b75ed68..fdf57eedb94 100644 --- a/src/gallium/winsys/drm/intel/SConscript +++ b/src/gallium/winsys/drm/intel/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['gem/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/intel/dri/Makefile b/src/gallium/winsys/drm/intel/dri/Makefile deleted file mode 100644 index 26aae4122eb..00000000000 --- a/src/gallium/winsys/drm/intel/dri/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i915_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/identity/libidentity.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a - - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_intel - -symlinks: $(TOP)/$(LIB_DIR)/gallium - @rm -f $(TOP)/$(LIB_DIR)/gallium/i965_dri.so diff --git a/src/gallium/winsys/drm/intel/dri/SConscript b/src/gallium/winsys/drm/intel/dri/SConscript deleted file mode 100644 index 0df841d8798..00000000000 --- a/src/gallium/winsys/drm/intel/dri/SConscript +++ /dev/null @@ -1,21 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_intel') - -env.Prepend(LIBS = [ - st_dri, - inteldrm, - i915, - trace, - mesa, - glsl, - gallium -]) - -env.LoadableModule( - target ='i915_dri.so', - source = COMMON_GALLIUM_SOURCES, - SHLIBPREFIX = '', -) diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile deleted file mode 100644 index 50ac3f203e5..00000000000 --- a/src/gallium/winsys/drm/nouveau/dri/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = nouveau_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs) - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/SConscript b/src/gallium/winsys/drm/radeon/SConscript index b2dfd504d42..eff87e7d010 100644 --- a/src/gallium/winsys/drm/radeon/SConscript +++ b/src/gallium/winsys/drm/radeon/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['core/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/radeon/dri/Makefile b/src/gallium/winsys/drm/radeon/dri/Makefile deleted file mode 100644 index d75f7dd6da7..00000000000 --- a/src/gallium/winsys/drm/radeon/dri/Makefile +++ /dev/null @@ -1,24 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = radeong_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -ASM_SOURCES = - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_radeon - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/dri/SConscript b/src/gallium/winsys/drm/radeon/dri/SConscript deleted file mode 100644 index c4989d1b595..00000000000 --- a/src/gallium/winsys/drm/radeon/dri/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') - -drivers = [ - trace, - softpipe, - r300 -] - -env.SharedLibrary( - target ='radeon_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = st_dri + radeonwinsys + mesa + drivers + gallium + env['LIBS'], -) diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript index 06e6d5be9ca..e4da31a6933 100644 --- a/src/gallium/winsys/drm/vmware/SConscript +++ b/src/gallium/winsys/drm/vmware/SConscript @@ -2,10 +2,6 @@ Import('*') SConscript(['core/SConscript',]) -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) - if 'xorg' in env['statetrackers']: SConscript(['xorg/SConscript']) diff --git a/src/gallium/winsys/drm/vmware/dri/Makefile b/src/gallium/winsys/drm/vmware/dri/Makefile deleted file mode 100644 index 8a39e23da6d..00000000000 --- a/src/gallium/winsys/drm/vmware/dri/Makefile +++ /dev/null @@ -1,18 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = vmwgfx_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) - -include ../../Makefile.template - -symlinks: diff --git a/src/gallium/winsys/drm/vmware/dri/SConscript b/src/gallium/winsys/drm/vmware/dri/SConscript deleted file mode 100644 index d26d0cd7483..00000000000 --- a/src/gallium/winsys/drm/vmware/dri/SConscript +++ /dev/null @@ -1,63 +0,0 @@ -import os -import os.path - -Import('*') - -if env['platform'] == 'linux': - - if env['dri']: - env = env.Clone() - - sources = [ - '#/src/mesa/drivers/dri/common/utils.c', - '#/src/mesa/drivers/dri/common/vblank.c', - '#/src/mesa/drivers/dri/common/dri_util.c', - '#/src/mesa/drivers/dri/common/xmlconfig.c', - ] - - - env.ParseConfig('pkg-config --cflags --libs libdrm') - - env.Prepend(CPPPATH = [ - '#/src/mesa/state_tracker', - '#/src/mesa/drivers/dri/common', - '#/src/mesa/main', - '#/src/mesa/glapi', - '#/src/mesa', - '#/include', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', - ]) - - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - ]) - - env.Append(CFLAGS = [ - '-std=gnu99', - '-D_FILE_OFFSET_BITS=64', - ]) - - env.Prepend(LIBPATH = [ - ]) - - env.Prepend(LIBS = [ - trace, - st_dri, - svgadrm, - svga, - mesa, - glsl, - gallium, - ]) - - # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions - env.LoadableModule( - target ='vmwgfx_dri.so', - source = sources, - LIBS = env['LIBS'], - SHLIBPREFIX = '', - ) - - -- cgit v1.2.3 From f5ba2cdeb902993b993187a958aad89c5ac79d6b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 10:58:45 +0100 Subject: gallium: Move egl drivers to targets Atteched output from git commit: rename src/gallium/{winsys/drm => targets}/Makefile.egl (100%) rename src/gallium/{winsys/drm/intel/egl => targets/egl-i915}/Makefile (86%) rename src/gallium/{winsys/drm/i965/egl => targets/egl-i915}/dummy.c (100%) rename src/gallium/{winsys/drm/i965/egl => targets/egl-i965}/Makefile (86%) rename src/gallium/{winsys/drm/intel/egl => targets/egl-i965}/dummy.c (100%) rename src/gallium/{winsys/drm/nouveau/egl => targets/egl-nouveau}/Makefile (88%) rename src/gallium/{winsys/drm/nouveau/egl => targets/egl-nouveau}/dummy.c (100%) rename src/gallium/{winsys/drm/radeon/egl => targets/egl-radeon}/Makefile (87%) rename src/gallium/{winsys/drm/radeon/egl => targets/egl-radeon}/dummy.c (100%) create mode 100644 src/gallium/targets/egl-swrast/Makefile create mode 100644 src/gallium/targets/egl-swrast/swrast_glue.c rename src/gallium/{winsys/drm/vmware/egl => targets/egl-vmwgfx}/Makefile (86%) rename src/gallium/{winsys/drm/swrast/egl => targets/egl-vmwgfx}/dummy.c (100%) delete mode 100644 src/gallium/winsys/drm/swrast/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/swrast_drm_api.c delete mode 100644 src/gallium/winsys/drm/swrast/egl/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/egl/dummy.c --- configs/default | 2 +- configs/linux-dri | 2 +- configs/linux-opengl-es | 3 +- configure.ac | 23 +++++++- src/gallium/targets/Makefile.egl | 64 ++++++++++++++++++++++ src/gallium/targets/egl-i915/Makefile | 14 +++++ src/gallium/targets/egl-i915/dummy.c | 3 + src/gallium/targets/egl-i965/Makefile | 14 +++++ src/gallium/targets/egl-i965/dummy.c | 3 + src/gallium/targets/egl-nouveau/Makefile | 15 +++++ src/gallium/targets/egl-nouveau/dummy.c | 3 + src/gallium/targets/egl-radeon/Makefile | 14 +++++ src/gallium/targets/egl-radeon/dummy.c | 3 + src/gallium/targets/egl-swrast/Makefile | 12 ++++ src/gallium/targets/egl-swrast/swrast_glue.c | 17 ++++++ src/gallium/targets/egl-vmwgfx/Makefile | 14 +++++ src/gallium/targets/egl-vmwgfx/dummy.c | 3 + src/gallium/winsys/drm/Makefile.egl | 64 ---------------------- src/gallium/winsys/drm/i965/egl/Makefile | 14 ----- src/gallium/winsys/drm/i965/egl/dummy.c | 3 - src/gallium/winsys/drm/intel/egl/Makefile | 14 ----- src/gallium/winsys/drm/intel/egl/dummy.c | 3 - src/gallium/winsys/drm/nouveau/egl/Makefile | 15 ----- src/gallium/winsys/drm/nouveau/egl/dummy.c | 3 - src/gallium/winsys/drm/radeon/egl/Makefile | 14 ----- src/gallium/winsys/drm/radeon/egl/dummy.c | 3 - src/gallium/winsys/drm/swrast/Makefile | 12 ---- src/gallium/winsys/drm/swrast/core/Makefile | 10 ---- .../winsys/drm/swrast/core/swrast_drm_api.c | 13 ----- src/gallium/winsys/drm/swrast/egl/Makefile | 12 ---- src/gallium/winsys/drm/swrast/egl/dummy.c | 3 - src/gallium/winsys/drm/vmware/egl/Makefile | 14 ----- src/gallium/winsys/drm/vmware/egl/dummy.c | 3 - 33 files changed, 204 insertions(+), 205 deletions(-) create mode 100644 src/gallium/targets/Makefile.egl create mode 100644 src/gallium/targets/egl-i915/Makefile create mode 100644 src/gallium/targets/egl-i915/dummy.c create mode 100644 src/gallium/targets/egl-i965/Makefile create mode 100644 src/gallium/targets/egl-i965/dummy.c create mode 100644 src/gallium/targets/egl-nouveau/Makefile create mode 100644 src/gallium/targets/egl-nouveau/dummy.c create mode 100644 src/gallium/targets/egl-radeon/Makefile create mode 100644 src/gallium/targets/egl-radeon/dummy.c create mode 100644 src/gallium/targets/egl-swrast/Makefile create mode 100644 src/gallium/targets/egl-swrast/swrast_glue.c create mode 100644 src/gallium/targets/egl-vmwgfx/Makefile create mode 100644 src/gallium/targets/egl-vmwgfx/dummy.c delete mode 100644 src/gallium/winsys/drm/Makefile.egl delete mode 100644 src/gallium/winsys/drm/i965/egl/Makefile delete mode 100644 src/gallium/winsys/drm/i965/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/intel/egl/Makefile delete mode 100644 src/gallium/winsys/drm/intel/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/nouveau/egl/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/radeon/egl/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/swrast/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/swrast_drm_api.c delete mode 100644 src/gallium/winsys/drm/swrast/egl/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/vmware/egl/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/egl/dummy.c (limited to 'configure.ac') diff --git a/configs/default b/configs/default index 03feed973a2..65e9847bd20 100644 --- a/configs/default +++ b/configs/default @@ -100,7 +100,7 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib drm/swrast +GALLIUM_WINSYS_DIRS = null xlib GALLIUM_TARGET_DIRS = libgl-xlib GALLIUM_STATE_TRACKERS_DIRS = glx vega diff --git a/configs/linux-dri b/configs/linux-dri index e10021d7994..b11daeda7c2 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -59,7 +59,7 @@ EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 -GALLIUM_TARGET_DIRS = +GALLIUM_TARGET_DIRS = egl-swrast GALLIUM_STATE_TRACKERS_DIRS = egl DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \ diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es index ddcb717f836..32fe40fb848 100644 --- a/configs/linux-opengl-es +++ b/configs/linux-opengl-es @@ -24,4 +24,5 @@ GALLIUM_STATE_TRACKERS_DIRS = es # build egl_x11_{swrast,i915}.so GALLIUM_DRIVERS_DIRS += trace i915 GALLIUM_STATE_TRACKERS_DIRS += egl -GALLIUM_WINSYS_DIRS += drm/intel drm/swrast +GALLIUM_WINSYS_DIRS += drm/intel +GALLIUM_TARGET_DIRS += egl-swrast egl-i915 diff --git a/configure.ac b/configure.ac index 51b480ff972..dccff6f7cc4 100644 --- a/configure.ac +++ b/configure.ac @@ -1320,6 +1320,9 @@ if test "x$enable_gallium_svga" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-vmwgfx" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1338,6 +1341,9 @@ if test "x$enable_gallium_intel" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-i915 egl-i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1356,6 +1362,9 @@ if test "x$enable_gallium_radeon" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1374,6 +1383,9 @@ if test "x$enable_gallium_nouveau" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi @@ -1382,11 +1394,18 @@ dnl Gallium swrast configuration dnl AC_ARG_ENABLE([gallium-swrast], [AS_HELP_STRING([--enable-gallium-swrast], - [build gallium swrast @<:@default=disabled@:>@])], + [build gallium swrast @<:@default=auto@:>@])], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/swrast" + if test "x$enable_egl" != xyes; then + AC_MSG_ERROR([EGL needs to be enabled for egl-swrast target]) + fi + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" +elif test "x$enable_gallium_swrast" = xauto; then + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" + fi fi dnl prepend CORE_DIRS to SRC_DIRS diff --git a/src/gallium/targets/Makefile.egl b/src/gallium/targets/Makefile.egl new file mode 100644 index 00000000000..bc5dd3a53b8 --- /dev/null +++ b/src/gallium/targets/Makefile.egl @@ -0,0 +1,64 @@ +# src/gallium/winsys/drm/Makefile.egl + +# The driver Makefile should define +# +# EGL_DRIVER_NAME, the name of the driver +# EGL_DRIVER_SOURCES, the sources of the driver +# EGL_DRIVER_LIBS, extra libraries needed by the driver +# EGL_DRIVER_PIPES, the pipe drivers of the driver +# +# before including this file. + +EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) + +common_LIBS = -ldrm -lm -ldl + +x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ + $(TOP)/src/gallium/winsys/xlib/libws_xlib.a +x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes + +kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a +kms_LIBS = $(common_LIBS) + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + + +##### TARGETS ##### + +EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so) + +EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(TOP)/$(LIB_DIR)/$(drv)) + +default: $(EGL_DISPLAY_LIBS) + +$(EGL_DISPLAY_LIBS): $(TOP)/$(LIB_DIR)/%.so: %.so + $(INSTALL) $< $(TOP)/$(LIB_DIR) + +define mklib-egl +$(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \ + -Wl,--start-group $($(1)_ST) $(EGL_DRIVER_PIPES) \ + $(GALLIUM_AUXILIARIES) -Wl,--end-group \ + $($(1)_LIBS) $(EGL_DRIVER_LIBS) +endef + +egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile + $(call mklib-egl,x11) + +egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile + $(call mklib-egl,kms) + +clean: + -rm -f $(EGL_DRIVER_OBJECTS) + -rm -f $(EGL_DISPLAY_DRIVERS) + +install: $(EGL_DISPLAY_LIBS) + $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + for lib in $(EGL_DISPLAY_LIBS); do \ + $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \ + done + +depend: diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile new file mode 100644 index 00000000000..596dd092f75 --- /dev/null +++ b/src/gallium/targets/egl-i915/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = i915 +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_intel + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-i915/dummy.c b/src/gallium/targets/egl-i915/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-i915/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-i965/Makefile b/src/gallium/targets/egl-i965/Makefile new file mode 100644 index 00000000000..e4c1a88f4c6 --- /dev/null +++ b/src/gallium/targets/egl-i965/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = i965 +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_intel + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-i965/dummy.c b/src/gallium/targets/egl-i965/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-i965/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-nouveau/Makefile b/src/gallium/targets/egl-nouveau/Makefile new file mode 100644 index 00000000000..46fcdf5e4b0 --- /dev/null +++ b/src/gallium/targets/egl-nouveau/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = nouveau +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_nouveau + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-nouveau/dummy.c b/src/gallium/targets/egl-nouveau/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-nouveau/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-radeon/Makefile b/src/gallium/targets/egl-radeon/Makefile new file mode 100644 index 00000000000..56818365dda --- /dev/null +++ b/src/gallium/targets/egl-radeon/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = radeon +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_radeon + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-radeon/dummy.c b/src/gallium/targets/egl-radeon/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-radeon/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-swrast/Makefile b/src/gallium/targets/egl-swrast/Makefile new file mode 100644 index 00000000000..937343defe5 --- /dev/null +++ b/src/gallium/targets/egl-swrast/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +# Do propperly +CFLAGS+="-I$(TOP)/src/gallium/include" + +EGL_DRIVER_NAME = swrast +EGL_DRIVER_SOURCES = swrast_glue.c +EGL_DRIVER_LIBS = +EGL_DRIVER_PIPES = $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-swrast/swrast_glue.c b/src/gallium/targets/egl-swrast/swrast_glue.c new file mode 100644 index 00000000000..9db8089a666 --- /dev/null +++ b/src/gallium/targets/egl-swrast/swrast_glue.c @@ -0,0 +1,17 @@ +#include "state_tracker/drm_api.h" + +static struct drm_api swrast_drm_api = +{ + .name = "swrast", +}; + +struct drm_api * +drm_api_create() +{ + (void) swrast_drm_api; + return NULL; +} + +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-vmwgfx/Makefile b/src/gallium/targets/egl-vmwgfx/Makefile new file mode 100644 index 00000000000..007158a6408 --- /dev/null +++ b/src/gallium/targets/egl-vmwgfx/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = vmwgfx +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-vmwgfx/dummy.c b/src/gallium/targets/egl-vmwgfx/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-vmwgfx/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/Makefile.egl b/src/gallium/winsys/drm/Makefile.egl deleted file mode 100644 index bc5dd3a53b8..00000000000 --- a/src/gallium/winsys/drm/Makefile.egl +++ /dev/null @@ -1,64 +0,0 @@ -# src/gallium/winsys/drm/Makefile.egl - -# The driver Makefile should define -# -# EGL_DRIVER_NAME, the name of the driver -# EGL_DRIVER_SOURCES, the sources of the driver -# EGL_DRIVER_LIBS, extra libraries needed by the driver -# EGL_DRIVER_PIPES, the pipe drivers of the driver -# -# before including this file. - -EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) - -common_LIBS = -ldrm -lm -ldl - -x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ - $(TOP)/src/gallium/winsys/xlib/libws_xlib.a -x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes - -kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a -kms_LIBS = $(common_LIBS) - -##### RULES ##### - -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ - - -##### TARGETS ##### - -EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so) - -EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(TOP)/$(LIB_DIR)/$(drv)) - -default: $(EGL_DISPLAY_LIBS) - -$(EGL_DISPLAY_LIBS): $(TOP)/$(LIB_DIR)/%.so: %.so - $(INSTALL) $< $(TOP)/$(LIB_DIR) - -define mklib-egl -$(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ - $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \ - -Wl,--start-group $($(1)_ST) $(EGL_DRIVER_PIPES) \ - $(GALLIUM_AUXILIARIES) -Wl,--end-group \ - $($(1)_LIBS) $(EGL_DRIVER_LIBS) -endef - -egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile - $(call mklib-egl,x11) - -egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile - $(call mklib-egl,kms) - -clean: - -rm -f $(EGL_DRIVER_OBJECTS) - -rm -f $(EGL_DISPLAY_DRIVERS) - -install: $(EGL_DISPLAY_LIBS) - $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) - for lib in $(EGL_DISPLAY_LIBS); do \ - $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \ - done - -depend: diff --git a/src/gallium/winsys/drm/i965/egl/Makefile b/src/gallium/winsys/drm/i965/egl/Makefile deleted file mode 100644 index 1c132582005..00000000000 --- a/src/gallium/winsys/drm/i965/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = i965 -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_intel - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/i965/egl/dummy.c b/src/gallium/winsys/drm/i965/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/i965/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/intel/egl/Makefile b/src/gallium/winsys/drm/intel/egl/Makefile deleted file mode 100644 index 60d675ca73d..00000000000 --- a/src/gallium/winsys/drm/intel/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = i915 -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_intel - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/intel/egl/dummy.c b/src/gallium/winsys/drm/intel/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/intel/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile deleted file mode 100644 index 47d11276155..00000000000 --- a/src/gallium/winsys/drm/nouveau/egl/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = nouveau -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_nouveau - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/nouveau/egl/dummy.c b/src/gallium/winsys/drm/nouveau/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/nouveau/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/radeon/egl/Makefile b/src/gallium/winsys/drm/radeon/egl/Makefile deleted file mode 100644 index cd4f9b20f06..00000000000 --- a/src/gallium/winsys/drm/radeon/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = radeon -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_radeon - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/radeon/egl/dummy.c b/src/gallium/winsys/drm/radeon/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/radeon/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/swrast/Makefile b/src/gallium/winsys/drm/swrast/Makefile deleted file mode 100644 index 363b89584f2..00000000000 --- a/src/gallium/winsys/drm/swrast/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/swrast/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/swrast/core/Makefile b/src/gallium/winsys/drm/swrast/core/Makefile deleted file mode 100644 index 93931ae22b9..00000000000 --- a/src/gallium/winsys/drm/swrast/core/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# src/gallium/winsys/drm/swrast/core/Makefile - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = swrastdrm - -C_SOURCES = swrast_drm_api.c - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c b/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c deleted file mode 100644 index 8c9f80e2c15..00000000000 --- a/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "state_tracker/drm_api.h" - -static struct drm_api swrast_drm_api = -{ - .name = "swrast", -}; - -struct drm_api * -drm_api_create() -{ - (void) swrast_drm_api; - return NULL; -} diff --git a/src/gallium/winsys/drm/swrast/egl/Makefile b/src/gallium/winsys/drm/swrast/egl/Makefile deleted file mode 100644 index 26fe2d2805a..00000000000 --- a/src/gallium/winsys/drm/swrast/egl/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = swrast -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/swrast/core/libswrastdrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/swrast/egl/dummy.c b/src/gallium/winsys/drm/swrast/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/swrast/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/vmware/egl/Makefile b/src/gallium/winsys/drm/vmware/egl/Makefile deleted file mode 100644 index a3e73131c35..00000000000 --- a/src/gallium/winsys/drm/vmware/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = vmwgfx -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/vmware/egl/dummy.c b/src/gallium/winsys/drm/vmware/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/vmware/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; -- cgit v1.2.3 From 43218a45a4cdbe2bc92867dc143f4b0e5fe9ca8d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 11:45:30 +0100 Subject: gallium: Move xorg drivers to targets Attached output from git commit: rename src/gallium/{winsys/drm/intel/xorg => targets/xorg-i915}/Makefile (95%) rename src/gallium/{winsys/drm/intel/xorg => targets/xorg-i915}/intel_xorg.c (98%) rename src/gallium/{winsys/drm/i965/xorg => targets/xorg-i965}/Makefile (78%) rename src/gallium/{winsys/drm/i965/xorg => targets/xorg-i965}/intel_xorg.c (98%) rename src/gallium/{winsys/drm/nouveau/xorg => targets/xorg-nouveau}/Makefile (96%) rename src/gallium/{winsys/drm/nouveau/xorg => targets/xorg-nouveau}/nouveau_xorg.c (98%) rename src/gallium/{winsys/drm/radeon/xorg => targets/xorg-radeon}/Makefile (73%) rename src/gallium/{winsys/drm/radeon/xorg => targets/xorg-radeon}/radeon_xorg.c (98%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/Makefile (97%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/SConscript (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_driver.h (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_hook.h (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_ioctl.c (99%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_screen.c (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_video.c (99%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_xorg.c (100%) --- configure.ac | 12 + src/gallium/targets/xorg-i915/Makefile | 57 ++ src/gallium/targets/xorg-i915/intel_xorg.c | 147 +++ src/gallium/targets/xorg-i965/Makefile | 48 + src/gallium/targets/xorg-i965/intel_xorg.c | 147 +++ src/gallium/targets/xorg-nouveau/Makefile | 56 + src/gallium/targets/xorg-nouveau/nouveau_xorg.c | 149 +++ src/gallium/targets/xorg-radeon/Makefile | 48 + src/gallium/targets/xorg-radeon/radeon_xorg.c | 148 +++ src/gallium/targets/xorg-vmwgfx/Makefile | 70 ++ src/gallium/targets/xorg-vmwgfx/SConscript | 57 ++ src/gallium/targets/xorg-vmwgfx/vmw_driver.h | 103 ++ src/gallium/targets/xorg-vmwgfx/vmw_hook.h | 39 + src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c | 242 +++++ src/gallium/targets/xorg-vmwgfx/vmw_screen.c | 178 ++++ src/gallium/targets/xorg-vmwgfx/vmw_video.c | 1072 ++++++++++++++++++++ src/gallium/targets/xorg-vmwgfx/vmw_xorg.c | 191 ++++ src/gallium/winsys/drm/i965/xorg/Makefile | 54 - src/gallium/winsys/drm/i965/xorg/intel_xorg.c | 147 --- src/gallium/winsys/drm/intel/xorg/Makefile | 57 -- src/gallium/winsys/drm/intel/xorg/intel_xorg.c | 147 --- src/gallium/winsys/drm/nouveau/xorg/Makefile | 57 -- src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c | 149 --- src/gallium/winsys/drm/radeon/xorg/Makefile | 54 - src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c | 148 --- src/gallium/winsys/drm/vmware/SConscript | 4 - src/gallium/winsys/drm/vmware/xorg/Makefile | 71 -- src/gallium/winsys/drm/vmware/xorg/SConscript | 57 -- src/gallium/winsys/drm/vmware/xorg/vmw_driver.h | 103 -- src/gallium/winsys/drm/vmware/xorg/vmw_hook.h | 39 - src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c | 242 ----- src/gallium/winsys/drm/vmware/xorg/vmw_screen.c | 178 ---- src/gallium/winsys/drm/vmware/xorg/vmw_video.c | 1072 -------------------- src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c | 191 ---- 34 files changed, 2764 insertions(+), 2770 deletions(-) create mode 100644 src/gallium/targets/xorg-i915/Makefile create mode 100644 src/gallium/targets/xorg-i915/intel_xorg.c create mode 100644 src/gallium/targets/xorg-i965/Makefile create mode 100644 src/gallium/targets/xorg-i965/intel_xorg.c create mode 100644 src/gallium/targets/xorg-nouveau/Makefile create mode 100644 src/gallium/targets/xorg-nouveau/nouveau_xorg.c create mode 100644 src/gallium/targets/xorg-radeon/Makefile create mode 100644 src/gallium/targets/xorg-radeon/radeon_xorg.c create mode 100644 src/gallium/targets/xorg-vmwgfx/Makefile create mode 100644 src/gallium/targets/xorg-vmwgfx/SConscript create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_driver.h create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_hook.h create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_screen.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_video.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_xorg.c delete mode 100644 src/gallium/winsys/drm/i965/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/i965/xorg/intel_xorg.c delete mode 100644 src/gallium/winsys/drm/intel/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/intel/xorg/intel_xorg.c delete mode 100644 src/gallium/winsys/drm/nouveau/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c delete mode 100644 src/gallium/winsys/drm/radeon/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/xorg/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_driver.h delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_hook.h delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_screen.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_video.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index dccff6f7cc4..c8f78dc74e8 100644 --- a/configure.ac +++ b/configure.ac @@ -1323,6 +1323,9 @@ if test "x$enable_gallium_svga" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-vmwgfx" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-vmwgfx" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1344,6 +1347,9 @@ if test "x$enable_gallium_intel" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-i915 egl-i965" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-i915 xorg-i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1365,6 +1371,9 @@ if test "x$enable_gallium_radeon" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-radeon" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1386,6 +1395,9 @@ if test "x$enable_gallium_nouveau" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-nouveau" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile new file mode 100644 index 00000000000..4442147e83f --- /dev/null +++ b/src/gallium/targets/xorg-i915/Makefile @@ -0,0 +1,57 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = modesetting_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/winsys/drm/intel/gem \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H + + +############################################# + + + +all default: $(TARGET) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-i915/intel_xorg.c b/src/gallium/targets/xorg-i915/intel_xorg.c new file mode 100644 index 00000000000..08f3b088636 --- /dev/null +++ b/src/gallium/targets/xorg-i915/intel_xorg.c @@ -0,0 +1,147 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void intel_xorg_identify(int flags); +static Bool intel_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match intel_xorg_device_match[] = { + {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec intel_xorg_chipsets[] = { + {PCI_MATCH_ANY, "Intel Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets intel_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo intel_xorg_version = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + intel_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + intel_xorg_device_match, + intel_xorg_pci_probe +}; + +static MODULESETUPPROTO(intel_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &intel_xorg_version, + intel_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +intel_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + intel_xorg_chipsets); +} + +static Bool +intel_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i915"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-i965/Makefile b/src/gallium/targets/xorg-i965/Makefile new file mode 100644 index 00000000000..8d6a741e5d1 --- /dev/null +++ b/src/gallium/targets/xorg-i965/Makefile @@ -0,0 +1,48 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = i965g_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +CFLAGS = -DHAVE_CONFIG_H \ + -g -Wall -Wimplicit-function-declaration -fPIC \ + $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) +############################################# + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-i965/intel_xorg.c b/src/gallium/targets/xorg-i965/intel_xorg.c new file mode 100644 index 00000000000..f4608f0eb41 --- /dev/null +++ b/src/gallium/targets/xorg-i965/intel_xorg.c @@ -0,0 +1,147 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void intel_xorg_identify(int flags); +static Bool intel_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match intel_xorg_device_match[] = { + {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec intel_xorg_chipsets[] = { + {PCI_MATCH_ANY, "Intel Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets intel_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo intel_xorg_version = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + intel_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + intel_xorg_device_match, + intel_xorg_pci_probe +}; + +static MODULESETUPPROTO(intel_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &intel_xorg_version, + intel_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +intel_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + intel_xorg_chipsets); +} + +static Bool +intel_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i965"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile new file mode 100644 index 00000000000..d41de0b3110 --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/Makefile @@ -0,0 +1,56 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = modesetting_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ + $(GALLIUM_AUXILIARIES) + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H + + +############################################# + + + +all default: $(TARGET) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_nouveau + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-nouveau/nouveau_xorg.c b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c new file mode 100644 index 00000000000..699af09029f --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c @@ -0,0 +1,149 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void nouveau_xorg_identify(int flags); +static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num, + struct pci_device *device, + intptr_t match_data); + +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", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + nouveau_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + nouveau_xorg_device_match, + nouveau_xorg_pci_probe +}; + +static MODULESETUPPROTO(nouveau_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &nouveau_xorg_version, + nouveau_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +nouveau_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + nouveau_xorg_chipsets); +} + +static Bool +nouveau_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, nouveau_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i915"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-radeon/Makefile b/src/gallium/targets/xorg-radeon/Makefile new file mode 100644 index 00000000000..9618d30b4d6 --- /dev/null +++ b/src/gallium/targets/xorg-radeon/Makefile @@ -0,0 +1,48 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = radeong_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +CFLAGS = -DHAVE_CONFIG_H \ + -g -Wall -Wimplicit-function-declaration -fPIC \ + $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I${TOP}/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) +############################################# + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_radeon + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-radeon/radeon_xorg.c b/src/gallium/targets/xorg-radeon/radeon_xorg.c new file mode 100644 index 00000000000..0d6aa567229 --- /dev/null +++ b/src/gallium/targets/xorg-radeon/radeon_xorg.c @@ -0,0 +1,148 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * Author: Corbin Simpson + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void radeon_xorg_identify(int flags); +static Bool radeon_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match radeon_xorg_device_match[] = { + {0x1002, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec radeon_xorg_chipsets[] = { + {PCI_MATCH_ANY, "ATI/AMD Radeon Graphics Chipset"}, + {-1, NULL} +}; + +static PciChipsets radeon_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo radeon_xorg_version = { + "radeong", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec radeong = { + 1, + "radeong", + radeon_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + radeon_xorg_device_match, + radeon_xorg_pci_probe +}; + +static MODULESETUPPROTO(radeon_xorg_setup); + +_X_EXPORT XF86ModuleData radeongModuleData = { + &radeon_xorg_version, + radeon_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +radeon_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&radeong, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +radeon_xorg_identify(int flags) +{ + xf86PrintChipsets("radeong", "Driver for Radeon Gallium with KMS", + radeon_xorg_chipsets); +} + +static Bool +radeon_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, radeon_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "radeong"; + scrn->name = "radeong"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-vmwgfx/Makefile b/src/gallium/targets/xorg-vmwgfx/Makefile new file mode 100644 index 00000000000..3691b883588 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/Makefile @@ -0,0 +1,70 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = vmwgfx_drv.so + +CFILES = \ + vmw_xorg.c \ + vmw_video.c \ + vmw_ioctl.c \ + vmw_screen.c + +OBJECTS = $(patsubst %.c,%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a \ + $(GALLIUM_AUXILIARIES) + +LINKS = \ + $(shell pkg-config --libs --silence-errors libkms) \ + $(shell pkg-config --libs libdrm) + +DRIVER_DEFINES = \ + -std=gnu99 \ + -DHAVE_CONFIG_H + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) + +############################################# + + + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(LIBS) + $(MKLIB) -noprefix -o $@ $(OBJECTS) $(LIBS) $(LINKS) + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-vmwgfx/SConscript b/src/gallium/targets/xorg-vmwgfx/SConscript new file mode 100644 index 00000000000..1e5d8ff7fed --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/SConscript @@ -0,0 +1,57 @@ +import os.path + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') + + env.Prepend(CPPPATH = [ + '#/include', + '#/src/gallium', + '#/src/mesa', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', + ]) + + env.Append(CPPDEFINES = [ + ]) + + if env['gcc']: + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + ]) + + env.Append(CFLAGS = [ + '-std=gnu99', + '-D_FILE_OFFSET_BITS=64', + ]) + + env.Prepend(LIBPATH = [ + ]) + + env.Prepend(LIBS = [ + trace, + st_xorg, + svgadrm, + svga, + gallium, + ]) + + sources = [ + 'vmw_ioctl.c', + 'vmw_screen.c', + 'vmw_video.c', + 'vmw_xorg.c', + ] + + # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions + env.LoadableModule( + target ='vmwgfx_drv.so', + source = sources, + LIBS = env['LIBS'], + SHLIBPREFIX = '', + ) diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_driver.h b/src/gallium/targets/xorg-vmwgfx/vmw_driver.h new file mode 100644 index 00000000000..ba754b51e47 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_driver.h @@ -0,0 +1,103 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Contains the shared resources for VMware Xorg driver + * that sits ontop of the Xorg State Traker. + * + * It is initialized in vmw_screen.c. + * + * @author Jakob Bornecrantz + */ + +#ifndef VMW_DRIVER_H_ +#define VMW_DRIVER_H_ + +#include "state_trackers/xorg/xorg_tracker.h" + +struct vmw_dma_buffer; + +struct vmw_customizer +{ + CustomizerRec base; + ScrnInfoPtr pScrn; + + int fd; + + void *cursor_priv; + + /* vmw_video.c */ + void *video_priv; +}; + +static INLINE struct vmw_customizer * +vmw_customizer(CustomizerPtr cust) +{ + return cust ? (struct vmw_customizer *) cust : NULL; +} + + +/*********************************************************************** + * vmw_video.c + */ + +Bool vmw_video_init(struct vmw_customizer *vmw); + +Bool vmw_video_close(struct vmw_customizer *vmw); + +void vmw_video_stop_all(struct vmw_customizer *vmw); + + +/*********************************************************************** + * vmw_ioctl.c + */ + +int vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot); + +struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_customizer *vmw, + uint32_t size, + unsigned *handle); + +void * vmw_ioctl_buffer_map(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +void vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +void vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +int vmw_ioctl_supports_streams(struct vmw_customizer *vmw); + +int vmw_ioctl_num_streams(struct vmw_customizer *vmw, + uint32_t *ntot, uint32_t *nfree); + +int vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id); + +int vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out); + + +#endif diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_hook.h b/src/gallium/targets/xorg-vmwgfx/vmw_hook.h new file mode 100644 index 00000000000..224a2d92996 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_hook.h @@ -0,0 +1,39 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +#ifndef VMW_HOOK_H_ +#define VMW_HOOK_H_ + +#include "state_trackers/xorg/xorg_winsys.h" + + +/*********************************************************************** + * vmw_screen.c + */ + +void vmw_screen_set_functions(ScrnInfoPtr pScrn); + + +#endif diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c new file mode 100644 index 00000000000..fe9c0393e23 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c @@ -0,0 +1,242 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Contains the functions for creating dma buffers by calling + * the kernel via driver specific ioctls. + * + * @author Jakob Bornecrantz + */ + +#ifndef HAVE_STDINT_H +#define HAVE_STDINT_H 1 +#endif +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include + +#include +#include "xf86drm.h" +#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" + +#include "vmw_driver.h" +#include "util/u_debug.h" + +struct vmw_dma_buffer +{ + void *data; + unsigned handle; + uint64_t map_handle; + unsigned map_count; + uint32_t size; +}; + +static int +vmw_ioctl_get_param(struct vmw_customizer *vmw, uint32_t param, uint64_t *out) +{ + struct drm_vmw_getparam_arg gp_arg; + int ret; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = param; + ret = drmCommandWriteRead(vmw->fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + + if (ret == 0) { + *out = gp_arg.value; + } + + return ret; +} + +int +vmw_ioctl_supports_streams(struct vmw_customizer *vmw) +{ + uint64_t value; + int ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &value); + if (ret) + return ret; + + return value ? 0 : -ENOSYS; +} + +int +vmw_ioctl_num_streams(struct vmw_customizer *vmw, + uint32_t *ntot, uint32_t *nfree) +{ + uint64_t v1, v2; + int ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &v1); + if (ret) + return ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_FREE_STREAMS, &v2); + if (ret) + return ret; + + *ntot = (uint32_t)v1; + *nfree = (uint32_t)v2; + + return 0; +} + +int +vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out) +{ + struct drm_vmw_stream_arg s_arg; + int ret; + + ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, + &s_arg, sizeof(s_arg)); + + if (ret) + return -1; + + *out = s_arg.stream_id; + return 0; +} + +int +vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id) +{ + struct drm_vmw_stream_arg s_arg; + int ret; + + memset(&s_arg, 0, sizeof(s_arg)); + s_arg.stream_id = stream_id; + + ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, + &s_arg, sizeof(s_arg)); + + return 0; +} + +int +vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot) +{ + struct drm_vmw_cursor_bypass_arg arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.flags = DRM_VMW_CURSOR_BYPASS_ALL; + arg.xhot = xhot; + arg.yhot = yhot; + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CURSOR_BYPASS, + &arg, sizeof(arg)); + + return ret; +} + +struct vmw_dma_buffer * +vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle) +{ + struct vmw_dma_buffer *buf; + union drm_vmw_alloc_dmabuf_arg arg; + struct drm_vmw_alloc_dmabuf_req *req = &arg.req; + struct drm_vmw_dmabuf_rep *rep = &arg.rep; + int ret; + + buf = xcalloc(1, sizeof(*buf)); + if (!buf) + goto err; + + memset(&arg, 0, sizeof(arg)); + req->size = size; + do { + ret = drmCommandWriteRead(vmw->fd, DRM_VMW_ALLOC_DMABUF, &arg, sizeof(arg)); + } while (ret == -ERESTART); + + if (ret) { + debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); + goto err_free; + } + + + buf->data = NULL; + buf->handle = rep->handle; + buf->map_handle = rep->map_handle; + buf->map_count = 0; + buf->size = size; + + *handle = rep->handle; + + return buf; + +err_free: + xfree(buf); +err: + return NULL; +} + +void +vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + struct drm_vmw_unref_dmabuf_arg arg; + + if (buf->data) { + munmap(buf->data, buf->size); + buf->data = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = buf->handle; + drmCommandWrite(vmw->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); + + xfree(buf); +} + +void * +vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + void *map; + + if (buf->data == NULL) { + map = mmap(NULL, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, + vmw->fd, buf->map_handle); + if (map == MAP_FAILED) { + debug_printf("%s: Map failed.\n", __FUNCTION__); + return NULL; + } + + buf->data = map; + } + + ++buf->map_count; + + return buf->data; +} + +void +vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + --buf->map_count; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_screen.c b/src/gallium/targets/xorg-vmwgfx/vmw_screen.c new file mode 100644 index 00000000000..f43f91e5c0d --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_screen.c @@ -0,0 +1,178 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Contains the init code for the VMware Xorg driver. + * + * @author Jakob Bornecrantz + */ + +#include "vmw_hook.h" +#include "vmw_driver.h" + +#include "cursorstr.h" + +/* modified version of crtc functions */ +xf86CrtcFuncsRec vmw_screen_crtc_funcs; + +static void +vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) +{ + struct vmw_customizer *vmw = + vmw_customizer(xorg_customizer(crtc->scrn)); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + xf86CrtcFuncsPtr funcs = vmw->cursor_priv; + CursorPtr c = config->cursor; + + /* Run the ioctl before uploading the image */ + vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot); + + funcs->load_cursor_argb(crtc, image); +} + +static void +vmw_screen_cursor_init(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int i; + + /* XXX assume that all crtc's have the same function struct */ + + /* Save old struct need to call the old functions as well */ + vmw->cursor_priv = (void*)(config->crtc[0]->funcs); + memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec)); + vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb; + + for (i = 0; i < config->num_crtc; i++) + config->crtc[i]->funcs = &vmw_screen_crtc_funcs; +} + +static void +vmw_screen_cursor_close(struct vmw_customizer *vmw) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn); + int i; + + vmw_ioctl_cursor_bypass(vmw, 0, 0); + + for (i = 0; i < config->num_crtc; i++) + config->crtc[i]->funcs = vmw->cursor_priv; +} + +static Bool +vmw_screen_init(CustomizerPtr cust, int fd) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + vmw->fd = fd; + vmw_screen_cursor_init(vmw); + + /* if gallium is used then we don't need to do anything more. */ + if (xorg_has_gallium(vmw->pScrn)) + return TRUE; + + vmw_video_init(vmw); + + return TRUE; +} + +static Bool +vmw_screen_close(CustomizerPtr cust) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + if (!vmw) + return TRUE; + + vmw_screen_cursor_close(vmw); + + vmw_video_close(vmw); + + return TRUE; +} + +static Bool +vmw_screen_enter_vt(CustomizerPtr cust) +{ + debug_printf("%s: enter\n", __func__); + + return TRUE; +} + +static Bool +vmw_screen_leave_vt(CustomizerPtr cust) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + debug_printf("%s: enter\n", __func__); + + vmw_video_stop_all(vmw); + + return TRUE; +} + +/* + * Functions for setting up hooks into the xorg state tracker + */ + +static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL; + +static Bool +vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags) +{ + struct vmw_customizer *vmw; + CustomizerPtr cust; + + vmw = xnfcalloc(1, sizeof(*vmw)); + if (!vmw) + return FALSE; + + cust = &vmw->base; + + cust->winsys_screen_init = vmw_screen_init; + cust->winsys_screen_close = vmw_screen_close; + cust->winsys_enter_vt = vmw_screen_enter_vt; + cust->winsys_leave_vt = vmw_screen_leave_vt; + vmw->pScrn = pScrn; + + pScrn->driverPrivate = cust; + + pScrn->PreInit = vmw_screen_pre_init_saved; + if (!pScrn->PreInit(pScrn, flags)) + return FALSE; + + return TRUE; +} + +void +vmw_screen_set_functions(ScrnInfoPtr pScrn) +{ + assert(!vmw_screen_pre_init_saved); + + vmw_screen_pre_init_saved = pScrn->PreInit; + pScrn->PreInit = vmw_screen_pre_init; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_video.c b/src/gallium/targets/xorg-vmwgfx/vmw_video.c new file mode 100644 index 00000000000..7909999edfb --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_video.c @@ -0,0 +1,1072 @@ +/* + * Copyright 2007 by VMware, 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarevideo.c -- + * + * Xv extension support. + * See http://www.xfree86.org/current/DESIGN16.html + * + */ + + +#include "xf86xv.h" +#include "fourcc.h" + +#include "pipe/p_compiler.h" +/* + * We can't incude svga_types.h due to conflicting types for Bool. + */ +typedef int64_t int64; +typedef uint64_t uint64; + +typedef int32_t int32; +typedef uint32_t uint32; + +typedef int16_t int16; +typedef uint16_t uint16; + +typedef int8_t int8; +typedef uint8_t uint8; + +#include "svga/include/svga_reg.h" +#include "svga/include/svga_escape.h" +#include "svga/include/svga_overlay.h" + +#include "vmw_driver.h" + +#include + +#include "xf86drm.h" +#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" + +#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) + +/* + * Number of videos that can be played simultaneously + */ +#define VMWARE_VID_NUM_PORTS 1 + +/* + * Using a dark shade as the default colorKey + */ +#define VMWARE_VIDEO_COLORKEY 0x100701 + +/* + * Maximum dimensions + */ +#define VMWARE_VID_MAX_WIDTH 2048 +#define VMWARE_VID_MAX_HEIGHT 2048 + +#define VMWARE_VID_NUM_ENCODINGS 1 +static XF86VideoEncodingRec vmwareVideoEncodings[] = +{ + { + 0, + "XV_IMAGE", + VMWARE_VID_MAX_WIDTH, VMWARE_VID_MAX_HEIGHT, + {1, 1} + } +}; + +#define VMWARE_VID_NUM_FORMATS 2 +static XF86VideoFormatRec vmwareVideoFormats[] = +{ + { 16, TrueColor}, + { 24, TrueColor} +}; + +#define VMWARE_VID_NUM_IMAGES 3 +static XF86ImageRec vmwareVideoImages[] = +{ + XVIMAGE_YV12, + XVIMAGE_YUY2, + XVIMAGE_UYVY +}; + +#define VMWARE_VID_NUM_ATTRIBUTES 2 +static XF86AttributeRec vmwareVideoAttributes[] = +{ + { + XvGettable | XvSettable, + 0x000000, + 0xffffff, + "XV_COLORKEY" + }, + { + XvGettable | XvSettable, + 0, + 1, + "XV_AUTOPAINT_COLORKEY" + } +}; + +/* + * Video frames are stored in a circular list of buffers. + * Must be power or two, See vmw_video_port_play. + */ +#define VMWARE_VID_NUM_BUFFERS 1 + +/* + * Defines the structure used to hold and pass video data to the host + */ +struct vmw_video_buffer +{ + unsigned handle; + int size; + void *data; + void *extra_data; + struct vmw_dma_buffer *buf; +}; + + +/** + * Structure representing a single video stream, aka port. + * + * Ports maps one to one to a SVGA stream. Port is just + * what Xv calls a SVGA stream. + */ +struct vmw_video_port +{ + /* + * Function prototype same as XvPutImage. + * + * This is either set to vmw_video_port_init or vmw_video_port_play. + * At init this function is set to port_init. In port_init we set it + * to port_play and call it, after initializing the struct. + */ + int (*play)(ScrnInfoPtr, struct vmw_video_port *, + short, short, short, short, short, + short, short, short, int, unsigned char*, + short, short, RegionPtr); + + /* values to go into the SVGAOverlayUnit */ + uint32 streamId; + uint32 colorKey; + uint32 flags; + + /* round robin of buffers */ + unsigned currBuf; + struct vmw_video_buffer bufs[VMWARE_VID_NUM_BUFFERS]; + + /* properties that applies to all buffers */ + int size; + int pitches[3]; + int offsets[3]; + + /* things for X */ + RegionRec clipBoxes; + Bool isAutoPaintColorkey; +}; + + +/** + * Structure holding all the infromation for video. + */ +struct vmw_video_private +{ + int fd; + + /** ports */ + struct vmw_video_port port[VMWARE_VID_NUM_PORTS]; + + /** Used to store port pointers pointers */ + DevUnion port_ptr[VMWARE_VID_NUM_PORTS]; +}; + + +/* + * Callback functions exported to Xv, prefixed with vmw_xv_*. + */ +static int vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int image, + unsigned char *buf, short width, short height, + Bool sync, RegionPtr clipBoxes, pointer data, + DrawablePtr dst); +static void vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool Cleanup); +static int vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, + unsigned short *width, + unsigned short *height, int *pitches, + int *offsets); +static int vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 value, pointer data); +static int vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 *value, pointer data); +static void vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, + short vid_w, short vid_h, short drw_w, + short drw_h, unsigned int *p_w, + unsigned int *p_h, pointer data); + + +/* + * Local functions. + */ +static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw); + +static int vmw_video_port_init(ScrnInfoPtr pScrn, + struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes); +static int vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes); +static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port); + +static int vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, + struct vmw_video_buffer *out); +static int vmw_video_buffer_free(struct vmw_customizer *vmw, + struct vmw_video_buffer *out); + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_init -- + * + * Initializes Xv support. + * + * Results: + * TRUE on success, FALSE on error. + * + * Side effects: + * Xv support is initialized. Memory is allocated for all supported + * video streams. + * + *----------------------------------------------------------------------------- + */ + +Bool +vmw_video_init(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + ScreenPtr pScreen = pScrn->pScreen; + XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL; + XF86VideoAdaptorPtr newAdaptor = NULL; + int numAdaptors; + unsigned int ntot, nfree; + + debug_printf("%s: enter\n", __func__); + + if (vmw_ioctl_num_streams(vmw, &ntot, &nfree) != 0) { + debug_printf("No stream ioctl support\n"); + return FALSE; + } + + if (nfree == 0) { + debug_printf("No free streams\n"); + return FALSE; + } + + numAdaptors = xf86XVListGenericAdaptors(pScrn, &overlayAdaptors); + + newAdaptor = vmw_video_init_adaptor(pScrn, vmw); + if (!newAdaptor) { + debug_printf("Failed to initialize Xv extension\n"); + return FALSE; + } + + if (!numAdaptors) { + numAdaptors = 1; + overlayAdaptors = &newAdaptor; + } else { + newAdaptors = xalloc((numAdaptors + 1) * + sizeof(XF86VideoAdaptorPtr*)); + if (!newAdaptors) { + xf86XVFreeVideoAdaptorRec(newAdaptor); + return FALSE; + } + + memcpy(newAdaptors, overlayAdaptors, + numAdaptors * sizeof(XF86VideoAdaptorPtr)); + newAdaptors[numAdaptors++] = newAdaptor; + overlayAdaptors = newAdaptors; + } + + if (!xf86XVScreenInit(pScreen, overlayAdaptors, numAdaptors)) { + debug_printf("Failed to initialize Xv extension\n"); + xf86XVFreeVideoAdaptorRec(newAdaptor); + return FALSE; + } + + if (newAdaptors) { + xfree(newAdaptors); + } + + debug_printf("Initialized VMware Xv extension successfully\n"); + + return TRUE; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_close -- + * + * Unitializes video. + * + * Results: + * TRUE. + * + * Side effects: + * vmw->video_priv = NULL + * + *----------------------------------------------------------------------------- + */ + +Bool +vmw_video_close(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + struct vmw_video_private *video; + int i; + + debug_printf("%s: enter\n", __func__); + + video = vmw->video_priv; + if (!video) + return TRUE; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + /* make sure the port is stoped as well */ + vmw_xv_stop_video(pScrn, &video->port[i], TRUE); + vmw_ioctl_unref_stream(vmw, video->port[i].streamId); + } + + /* XXX: I'm sure this function is missing code for turning off Xv */ + + free(vmw->video_priv); + vmw->video_priv = NULL; + + return TRUE; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_stop_all -- + * + * Stop all video streams from playing. + * + * Results: + * None. + * + * Side effects: + * All buffers are freed. + * + *----------------------------------------------------------------------------- + */ + +void vmw_video_stop_all(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + struct vmw_video_private *video = vmw->video_priv; + int i; + + debug_printf("%s: enter\n", __func__); + + if (!video) + return; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + vmw_xv_stop_video(pScrn, &video->port[i], TRUE); + } +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_init_adaptor -- + * + * Initializes a XF86VideoAdaptor structure with the capabilities and + * functions supported by this video driver. + * + * Results: + * On success initialized XF86VideoAdaptor struct or NULL on error + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static XF86VideoAdaptorPtr +vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw) +{ + XF86VideoAdaptorPtr adaptor; + struct vmw_video_private *video; + int i; + + debug_printf("%s: enter \n", __func__); + + adaptor = xf86XVAllocateVideoAdaptorRec(pScrn); + if (!adaptor) { + debug_printf("Not enough memory\n"); + return NULL; + } + + video = xcalloc(1, sizeof(*video)); + if (!video) { + debug_printf("Not enough memory.\n"); + xf86XVFreeVideoAdaptorRec(adaptor); + return NULL; + } + + vmw->video_priv = video; + + adaptor->type = XvInputMask | XvImageMask | XvWindowMask; + adaptor->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; + adaptor->name = "VMware Video Engine"; + adaptor->nEncodings = VMWARE_VID_NUM_ENCODINGS; + adaptor->pEncodings = vmwareVideoEncodings; + adaptor->nFormats = VMWARE_VID_NUM_FORMATS; + adaptor->pFormats = vmwareVideoFormats; + adaptor->nPorts = VMWARE_VID_NUM_PORTS; + adaptor->pPortPrivates = video->port_ptr; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + vmw_ioctl_claim_stream(vmw, &video->port[i].streamId); + video->port[i].play = vmw_video_port_init; + video->port[i].flags = SVGA_VIDEO_FLAG_COLORKEY; + video->port[i].colorKey = VMWARE_VIDEO_COLORKEY; + video->port[i].isAutoPaintColorkey = TRUE; + adaptor->pPortPrivates[i].ptr = &video->port[i]; + } + + adaptor->nAttributes = VMWARE_VID_NUM_ATTRIBUTES; + adaptor->pAttributes = vmwareVideoAttributes; + + adaptor->nImages = VMWARE_VID_NUM_IMAGES; + adaptor->pImages = vmwareVideoImages; + + adaptor->PutVideo = NULL; + adaptor->PutStill = NULL; + adaptor->GetVideo = NULL; + adaptor->GetStill = NULL; + adaptor->StopVideo = vmw_xv_stop_video; + adaptor->SetPortAttribute = vmw_xv_set_port_attribute; + adaptor->GetPortAttribute = vmw_xv_get_port_attribute; + adaptor->QueryBestSize = vmw_xv_query_best_size; + adaptor->PutImage = vmw_xv_put_image; + adaptor->QueryImageAttributes = vmw_xv_query_image_attributes; + + debug_printf("%s: done %p\n", __func__, adaptor); + + return adaptor; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_init -- + * + * Initializes a video stream in response to the first PutImage() on a + * video stream. The process goes as follows: + * - Figure out characteristics according to format + * - Allocate offscreen memory + * - Pass on video to Play() functions + * + * Results: + * Success or XvBadAlloc on failure. + * + * Side effects: + * Video stream is initialized and its first frame sent to the host + * (done by VideoPlay() function called at the end) + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + unsigned short w, h; + int i, ret; + + debug_printf("\t%s: id %d, format %d\n", __func__, port->streamId, format); + + w = width; + h = height; + /* init all the format attributes, used for buffers */ + port->size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, + port->pitches, port->offsets); + + if (port->size == -1) + return XvBadAlloc; + + port->play = vmw_video_port_play; + + for (i = 0; i < VMWARE_VID_NUM_BUFFERS; ++i) { + ret = vmw_video_buffer_alloc(vmw, port->size, &port->bufs[i]); + if (ret != Success) + break; + } + + /* Free all allocated buffers on failure */ + if (ret != Success) { + for (--i; i >= 0; --i) { + vmw_video_buffer_free(vmw, &port->bufs[i]); + } + return ret; + } + + port->currBuf = 0; + + REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); + + if (port->isAutoPaintColorkey) + xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); + + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, + drw_w, drw_h, format, buf, width, height, clipBoxes); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_play -- + * + * Sends all the attributes associated with the video frame using the + * FIFO ESCAPE mechanism to the host. + * + * Results: + * Always returns Success. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct drm_vmw_control_stream_arg arg; + unsigned short w, h; + int size; + int ret; + + debug_printf("\t%s: enter\n", __func__); + + w = width; + h = height; + + /* we don't update the ports size */ + size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, + port->pitches, port->offsets); + + if (size > port->size) { + debug_printf("\t%s: Increase in size of Xv video frame streamId:%d.\n", + __func__, port->streamId); + vmw_xv_stop_video(pScrn, port, TRUE); + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, + src_h, drw_w, drw_h, format, buf, width, height, + clipBoxes); + } + + memcpy(port->bufs[port->currBuf].data, buf, port->size); + + memset(&arg, 0, sizeof(arg)); + + arg.stream_id = port->streamId; + arg.enabled = TRUE; + arg.flags = port->flags; + arg.color_key = port->colorKey; + arg.handle = port->bufs[port->currBuf].handle; + arg.format = format; + arg.size = port->size; + arg.width = w; + arg.height = h; + arg.src.x = src_x; + arg.src.y = src_y; + arg.src.w = src_w; + arg.src.h = src_h; + arg.dst.x = drw_x; + arg.dst.y = drw_y; + arg.dst.w = drw_w; + arg.dst.h = drw_h; + arg.pitch[0] = port->pitches[0]; + arg.pitch[1] = port->pitches[1]; + arg.pitch[2] = port->pitches[2]; + arg.offset = 0; + + /* + * Update the clipList and paint the colorkey, if required. + */ + if (!REGION_EQUAL(pScrn->pScreen, &port->clipBoxes, clipBoxes)) { + REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); + if (port->isAutoPaintColorkey) { + xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); + } + } + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); + if (ret) { + vmw_video_port_cleanup(pScrn, port); + return XvBadAlloc; + } + + if (++(port->currBuf) >= VMWARE_VID_NUM_BUFFERS) + port->currBuf = 0; + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_cleanup -- + * + * Frees up all resources (if any) taken by a video stream. + * + * Results: + * None. + * + * Side effects: + * Same as above. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + uint32 id, colorKey, flags; + Bool isAutoPaintColorkey; + int i; + + debug_printf("\t%s: enter\n", __func__); + + for (i = 0; i < VMWARE_VID_NUM_BUFFERS; i++) { + vmw_video_buffer_free(vmw, &port->bufs[i]); + } + + /* + * reset stream for next video + */ + id = port->streamId; + colorKey = port->colorKey; + flags = port->flags; + isAutoPaintColorkey = port->isAutoPaintColorkey; + + memset(port, 0, sizeof(*port)); + + port->streamId = id; + port->play = vmw_video_port_init; + port->colorKey = colorKey; + port->flags = flags; + port->isAutoPaintColorkey = isAutoPaintColorkey; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_buffer_alloc -- + * + * Allocates and map a kernel buffer to be used as data storage. + * + * Results: + * XvBadAlloc on failure, otherwise Success. + * + * Side effects: + * Calls into the kernel, sets members of out. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, + struct vmw_video_buffer *out) +{ + out->buf = vmw_ioctl_buffer_create(vmw, size, &out->handle); + if (!out->buf) + return XvBadAlloc; + + out->data = vmw_ioctl_buffer_map(vmw, out->buf); + if (!out->data) { + vmw_ioctl_buffer_destroy(vmw, out->buf); + + out->handle = 0; + out->buf = NULL; + + return XvBadAlloc; + } + + out->size = size; + out->extra_data = xcalloc(1, size); + + debug_printf("\t\t%s: allocated buffer %p of size %i\n", __func__, out, size); + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_buffer_free -- + * + * Frees and unmaps an allocated kernel buffer. + * + * Results: + * Success. + * + * Side effects: + * Calls into the kernel, sets members of out to 0. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_buffer_free(struct vmw_customizer *vmw, + struct vmw_video_buffer *out) +{ + if (out->size == 0) + return Success; + + xfree(out->extra_data); + vmw_ioctl_buffer_unmap(vmw, out->buf); + vmw_ioctl_buffer_destroy(vmw, out->buf); + + out->buf = NULL; + out->data = NULL; + out->handle = 0; + out->size = 0; + + debug_printf("\t\t%s: freed buffer %p\n", __func__, out); + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_put_image -- + * + * Main video playback function. It copies the passed data which is in + * the specified format (e.g. FOURCC_YV12) into the overlay. + * + * If sync is TRUE the driver should not return from this + * function until it is through reading the data from buf. + * + * Results: + * Success or XvBadAlloc on failure + * + * Side effects: + * Video port will be played(initialized if 1st frame) on success + * or will fail on error. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, short height, + Bool sync, RegionPtr clipBoxes, pointer data, + DrawablePtr dst) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct vmw_video_port *port = data; + + debug_printf("%s: enter (%u, %u) (%ux%u) (%u, %u) (%ux%u) (%ux%u)\n", __func__, + src_x, src_y, src_w, src_h, + drw_x, drw_y, drw_w, drw_h, + width, height); + + if (!vmw->video_priv) + return XvBadAlloc; + + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, + drw_w, drw_h, format, buf, width, height, clipBoxes); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_stop_video -- + * + * Called when we should stop playing video for a particular stream. If + * Cleanup is FALSE, the "stop" operation is only temporary, and thus we + * don't do anything. If Cleanup is TRUE we kill the video port by + * sending a message to the host and freeing up the stream. + * + * Results: + * None. + * + * Side effects: + * See above. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct vmw_video_port *port = data; + struct drm_vmw_control_stream_arg arg; + int ret; + + debug_printf("%s: cleanup is %s\n", __func__, cleanup ? "TRUE" : "FALSE"); + + if (!vmw->video_priv) + return; + + if (!cleanup) + return; + + + memset(&arg, 0, sizeof(arg)); + arg.stream_id = port->streamId; + arg.enabled = FALSE; + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); + assert(ret == 0); + + vmw_video_port_cleanup(pScrn, port); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_query_image_attributes -- + * + * From the spec: This function is called to let the driver specify how data + * for a particular image of size width by height should be stored. + * Sometimes only the size and corrected width and height are needed. In + * that case pitches and offsets are NULL. + * + * Results: + * The size of the memory required for the image, or -1 on error. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, + unsigned short *width, unsigned short *height, + int *pitches, int *offsets) +{ + INT32 size, tmp; + + if (*width > VMWARE_VID_MAX_WIDTH) { + *width = VMWARE_VID_MAX_WIDTH; + } + if (*height > VMWARE_VID_MAX_HEIGHT) { + *height = VMWARE_VID_MAX_HEIGHT; + } + + *width = (*width + 1) & ~1; + if (offsets != NULL) { + offsets[0] = 0; + } + + switch (format) { + case FOURCC_YV12: + *height = (*height + 1) & ~1; + size = (*width + 3) & ~3; + if (pitches) { + pitches[0] = size; + } + size *= *height; + if (offsets) { + offsets[1] = size; + } + tmp = ((*width >> 1) + 3) & ~3; + if (pitches) { + pitches[1] = pitches[2] = tmp; + } + tmp *= (*height >> 1); + size += tmp; + if (offsets) { + offsets[2] = size; + } + size += tmp; + break; + case FOURCC_UYVY: + case FOURCC_YUY2: + size = *width * 2; + if (pitches) { + pitches[0] = size; + } + size *= *height; + break; + default: + debug_printf("Query for invalid video format %d\n", format); + return -1; + } + return size; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_set_port_attribute -- + * + * From the spec: A port may have particular attributes such as colorKey, hue, + * saturation, brightness or contrast. Xv clients set these + * attribute values by sending attribute strings (Atoms) to the server. + * + * Results: + * Success if the attribute exists and XvBadAlloc otherwise. + * + * Side effects: + * The respective attribute gets the new value. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 value, pointer data) +{ + struct vmw_video_port *port = data; + Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); + Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); + + if (attribute == xvColorKey) { + debug_printf("%s: Set colorkey:0x%x\n", __func__, (unsigned)value); + port->colorKey = value; + } else if (attribute == xvAutoPaint) { + debug_printf("%s: Set autoPaint: %s\n", __func__, value? "TRUE": "FALSE"); + port->isAutoPaintColorkey = value; + } else { + return XvBadAlloc; + } + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_get_port_attribute -- + * + * From the spec: A port may have particular attributes such as hue, + * saturation, brightness or contrast. Xv clients get these + * attribute values by sending attribute strings (Atoms) to the server + * + * Results: + * Success if the attribute exists and XvBadAlloc otherwise. + * + * Side effects: + * "value" contains the requested attribute on success. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 *value, pointer data) +{ + struct vmw_video_port *port = data; + Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); + Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); + + if (attribute == xvColorKey) { + *value = port->colorKey; + } else if (attribute == xvAutoPaint) { + *value = port->isAutoPaintColorkey; + } else { + return XvBadAlloc; + } + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_query_best_size -- + * + * From the spec: QueryBestSize provides the client with a way to query what + * the destination dimensions would end up being if they were to request + * that an area vid_w by vid_h from the video stream be scaled to rectangle + * of drw_w by drw_h on the screen. Since it is not expected that all + * hardware will be able to get the target dimensions exactly, it is + * important that the driver provide this function. + * + * This function seems to never be called, but to be on the safe side + * we apply the same logic that QueryImageAttributes has for width + * and height. + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, + short vid_w, short vid_h, short drw_w, + short drw_h, unsigned int *p_w, + unsigned int *p_h, pointer data) +{ + *p_w = (drw_w + 1) & ~1; + *p_h = drw_h; + + return; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c b/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c new file mode 100644 index 00000000000..87aad25b24f --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c @@ -0,0 +1,191 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Glue file for Xorg State Tracker. + * + * @author Alan Hourihane + * @author Jakob Bornecrantz + */ + +#include "vmw_hook.h" + + +/* + * Defines and modinfo + */ + +#define VMWGFX_DRIVER_NAME "vmwgfx" + +#define VMW_STRING_INNER(s) #s +#define VMW_STRING(str) VMW_STRING_INNER(str) + +#define VMWGFX_VERSION_MAJOR 11 +#define VMWGFX_VERSION_MINOR 0 +#define VMWGFX_VERSION_PATCH 0 +#define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR) +#define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR) +#define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH) + +#define VMWGFX_DRIVER_VERSION \ + (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH) +#define VMWGFX_DRIVER_VERSION_STRING \ + VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \ + "." VMWGFX_VERSION_STRING_PATCH + +/* + * Standard four digit version string expected by VMware Tools installer. + * As the driver's version is only {major, minor, patchlevel}, simply append an + * extra zero for the fourth digit. + */ +#ifdef __GNUC__ +_X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) = + "version=" VMWGFX_DRIVER_VERSION_STRING ".0"; +#endif + +static void vmw_xorg_identify(int flags); +_X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + + +/* + * Tables + */ + +static const struct pci_id_match vmw_xorg_device_match[] = { + {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, +}; + +static SymTabRec vmw_xorg_chipsets[] = { + {PCI_MATCH_ANY, "VMware SVGA Device"}, + {-1, NULL} +}; + +static PciChipsets vmw_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo vmw_xorg_version = { + VMWGFX_DRIVER_NAME, + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec vmwgfx = { + 1, + VMWGFX_DRIVER_NAME, + vmw_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + vmw_xorg_device_match, + vmw_xorg_pci_probe +}; + +static MODULESETUPPROTO(vmw_xorg_setup); + +_X_EXPORT XF86ModuleData vmwgfxModuleData = { + &vmw_xorg_version, + vmw_xorg_setup, + NULL +}; + + +/* + * Xorg driver functions + */ + +static pointer +vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&vmwgfx, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +vmw_xorg_identify(int flags) +{ + xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device", + vmw_xorg_chipsets); +} + +_X_EXPORT Bool +vmw_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "vmwgfx"; + scrn->name = "vmwgfx"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + + vmw_screen_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/winsys/drm/i965/xorg/Makefile b/src/gallium/winsys/drm/i965/xorg/Makefile deleted file mode 100644 index c25726b0bb1..00000000000 --- a/src/gallium/winsys/drm/i965/xorg/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -TOP = ../../../../../.. - - -GALLIUMDIR = $(TOP)/src/gallium - -TARGET = i965g_drv.so - -CFILES = $(wildcard ./*.c) - -include ${TOP}/configs/current - -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) - -CFLAGS = -DHAVE_CONFIG_H \ - -g -Wall -Wimplicit-function-declaration -fPIC \ - $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ - -I${GALLIUMDIR}/include \ - -I${GALLIUMDIR}/drivers \ - -I${GALLIUMDIR}/auxiliary \ - -I${TOP}/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) -############################################# - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/i965/xorg/intel_xorg.c b/src/gallium/winsys/drm/i965/xorg/intel_xorg.c deleted file mode 100644 index ac691cb76b3..00000000000 --- a/src/gallium/winsys/drm/i965/xorg/intel_xorg.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void intel_xorg_identify(int flags); -static Bool intel_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match intel_xorg_device_match[] = { - {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec intel_xorg_chipsets[] = { - {PCI_MATCH_ANY, "Intel Graphics Device"}, - {-1, NULL} -}; - -static PciChipsets intel_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo intel_xorg_version = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - intel_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - intel_xorg_device_match, - intel_xorg_pci_probe -}; - -static MODULESETUPPROTO(intel_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &intel_xorg_version, - intel_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -intel_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - intel_xorg_chipsets); -} - -static Bool -intel_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i965"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/intel/xorg/Makefile b/src/gallium/winsys/drm/intel/xorg/Makefile deleted file mode 100644 index 14c2462524b..00000000000 --- a/src/gallium/winsys/drm/intel/xorg/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -TARGET = modesetting_drv.so -CFILES = $(wildcard ./*.c) -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) -TOP = ../../../../../.. - -include $(TOP)/configs/current - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I../gem \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -DRIVER_DEFINES = \ - -DHAVE_CONFIG_H - - -############################################# - - - -all default: $(TARGET) - -$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/intel/xorg/intel_xorg.c b/src/gallium/winsys/drm/intel/xorg/intel_xorg.c deleted file mode 100644 index 369dc356cf8..00000000000 --- a/src/gallium/winsys/drm/intel/xorg/intel_xorg.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void intel_xorg_identify(int flags); -static Bool intel_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match intel_xorg_device_match[] = { - {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec intel_xorg_chipsets[] = { - {PCI_MATCH_ANY, "Intel Graphics Device"}, - {-1, NULL} -}; - -static PciChipsets intel_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo intel_xorg_version = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - intel_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - intel_xorg_device_match, - intel_xorg_pci_probe -}; - -static MODULESETUPPROTO(intel_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &intel_xorg_version, - intel_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -intel_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - intel_xorg_chipsets); -} - -static Bool -intel_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i915"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/nouveau/xorg/Makefile b/src/gallium/winsys/drm/nouveau/xorg/Makefile deleted file mode 100644 index f7f6fe17dd6..00000000000 --- a/src/gallium/winsys/drm/nouveau/xorg/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -TARGET = modesetting_drv.so -CFILES = $(wildcard ./*.c) -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) -TOP = ../../../../../.. - -include $(TOP)/configs/current - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I../gem \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ - $(GALLIUM_AUXILIARIES) - -DRIVER_DEFINES = \ - -DHAVE_CONFIG_H - - -############################################# - - - -all default: $(TARGET) - -$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_nouveau - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c b/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c deleted file mode 100644 index a669b3080aa..00000000000 --- a/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void nouveau_xorg_identify(int flags); -static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num, - struct pci_device *device, - intptr_t match_data); - -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", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - nouveau_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - nouveau_xorg_device_match, - nouveau_xorg_pci_probe -}; - -static MODULESETUPPROTO(nouveau_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &nouveau_xorg_version, - nouveau_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -nouveau_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - nouveau_xorg_chipsets); -} - -static Bool -nouveau_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, nouveau_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i915"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/radeon/xorg/Makefile b/src/gallium/winsys/drm/radeon/xorg/Makefile deleted file mode 100644 index 0eb1b3988f3..00000000000 --- a/src/gallium/winsys/drm/radeon/xorg/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -TOP = ../../../../../.. - - -GALLIUMDIR = $(TOP)/src/gallium - -TARGET = radeong_drv.so - -CFILES = $(wildcard ./*.c) - -include ${TOP}/configs/current - -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) - -CFLAGS = -DHAVE_CONFIG_H \ - -g -Wall -Wimplicit-function-declaration -fPIC \ - $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ - -I${GALLIUMDIR}/include \ - -I${GALLIUMDIR}/drivers \ - -I${GALLIUMDIR}/auxiliary \ - -I${TOP}/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a \ - $(GALLIUMDIR)/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) -############################################# - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_radeon - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c b/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c deleted file mode 100644 index bb76cc03499..00000000000 --- a/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * Author: Corbin Simpson - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void radeon_xorg_identify(int flags); -static Bool radeon_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match radeon_xorg_device_match[] = { - {0x1002, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec radeon_xorg_chipsets[] = { - {PCI_MATCH_ANY, "ATI/AMD Radeon Graphics Chipset"}, - {-1, NULL} -}; - -static PciChipsets radeon_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo radeon_xorg_version = { - "radeong", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec radeong = { - 1, - "radeong", - radeon_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - radeon_xorg_device_match, - radeon_xorg_pci_probe -}; - -static MODULESETUPPROTO(radeon_xorg_setup); - -_X_EXPORT XF86ModuleData radeongModuleData = { - &radeon_xorg_version, - radeon_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -radeon_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&radeong, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -radeon_xorg_identify(int flags) -{ - xf86PrintChipsets("radeong", "Driver for Radeon Gallium with KMS", - radeon_xorg_chipsets); -} - -static Bool -radeon_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, radeon_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "radeong"; - scrn->name = "radeong"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript index e4da31a6933..eff87e7d010 100644 --- a/src/gallium/winsys/drm/vmware/SConscript +++ b/src/gallium/winsys/drm/vmware/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['core/SConscript',]) - -if 'xorg' in env['statetrackers']: - - SConscript(['xorg/SConscript']) diff --git a/src/gallium/winsys/drm/vmware/xorg/Makefile b/src/gallium/winsys/drm/vmware/xorg/Makefile deleted file mode 100644 index 49e28ae17f5..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -TOP = ../../../../../.. - -include $(TOP)/configs/current - -TARGET = vmwgfx_drv.so - -CFILES = \ - vmw_xorg.c \ - vmw_video.c \ - vmw_ioctl.c \ - vmw_screen.c - -OBJECTS = $(patsubst %.c,%.o,$(CFILES)) - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/gallium - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a \ - $(GALLIUM_AUXILIARIES) - -LINKS = \ - $(shell pkg-config --libs --silence-errors libkms) \ - $(shell pkg-config --libs libdrm) - -DRIVER_DEFINES = \ - -std=gnu99 \ - -DHAVE_CONFIG_H - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) - -############################################# - - - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(LIBS) - $(MKLIB) -noprefix -o $@ $(OBJECTS) $(LIBS) $(LINKS) - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/vmware/xorg/SConscript b/src/gallium/winsys/drm/vmware/xorg/SConscript deleted file mode 100644 index 1e5d8ff7fed..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/SConscript +++ /dev/null @@ -1,57 +0,0 @@ -import os.path - -Import('*') - -if env['platform'] == 'linux': - - env = env.Clone() - - env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') - - env.Prepend(CPPPATH = [ - '#/include', - '#/src/gallium', - '#/src/mesa', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', - ]) - - env.Append(CPPDEFINES = [ - ]) - - if env['gcc']: - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - ]) - - env.Append(CFLAGS = [ - '-std=gnu99', - '-D_FILE_OFFSET_BITS=64', - ]) - - env.Prepend(LIBPATH = [ - ]) - - env.Prepend(LIBS = [ - trace, - st_xorg, - svgadrm, - svga, - gallium, - ]) - - sources = [ - 'vmw_ioctl.c', - 'vmw_screen.c', - 'vmw_video.c', - 'vmw_xorg.c', - ] - - # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions - env.LoadableModule( - target ='vmwgfx_drv.so', - source = sources, - LIBS = env['LIBS'], - SHLIBPREFIX = '', - ) diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h b/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h deleted file mode 100644 index ba754b51e47..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h +++ /dev/null @@ -1,103 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Contains the shared resources for VMware Xorg driver - * that sits ontop of the Xorg State Traker. - * - * It is initialized in vmw_screen.c. - * - * @author Jakob Bornecrantz - */ - -#ifndef VMW_DRIVER_H_ -#define VMW_DRIVER_H_ - -#include "state_trackers/xorg/xorg_tracker.h" - -struct vmw_dma_buffer; - -struct vmw_customizer -{ - CustomizerRec base; - ScrnInfoPtr pScrn; - - int fd; - - void *cursor_priv; - - /* vmw_video.c */ - void *video_priv; -}; - -static INLINE struct vmw_customizer * -vmw_customizer(CustomizerPtr cust) -{ - return cust ? (struct vmw_customizer *) cust : NULL; -} - - -/*********************************************************************** - * vmw_video.c - */ - -Bool vmw_video_init(struct vmw_customizer *vmw); - -Bool vmw_video_close(struct vmw_customizer *vmw); - -void vmw_video_stop_all(struct vmw_customizer *vmw); - - -/*********************************************************************** - * vmw_ioctl.c - */ - -int vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot); - -struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_customizer *vmw, - uint32_t size, - unsigned *handle); - -void * vmw_ioctl_buffer_map(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -void vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -void vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -int vmw_ioctl_supports_streams(struct vmw_customizer *vmw); - -int vmw_ioctl_num_streams(struct vmw_customizer *vmw, - uint32_t *ntot, uint32_t *nfree); - -int vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id); - -int vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out); - - -#endif diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h b/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h deleted file mode 100644 index 224a2d92996..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -#ifndef VMW_HOOK_H_ -#define VMW_HOOK_H_ - -#include "state_trackers/xorg/xorg_winsys.h" - - -/*********************************************************************** - * vmw_screen.c - */ - -void vmw_screen_set_functions(ScrnInfoPtr pScrn); - - -#endif diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c b/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c deleted file mode 100644 index 521578ab35d..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c +++ /dev/null @@ -1,242 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Contains the functions for creating dma buffers by calling - * the kernel via driver specific ioctls. - * - * @author Jakob Bornecrantz - */ - -#ifndef HAVE_STDINT_H -#define HAVE_STDINT_H 1 -#endif -#define _FILE_OFFSET_BITS 64 - -#include -#include -#include - -#include -#include "xf86drm.h" -#include "../core/vmwgfx_drm.h" - -#include "vmw_driver.h" -#include "util/u_debug.h" - -struct vmw_dma_buffer -{ - void *data; - unsigned handle; - uint64_t map_handle; - unsigned map_count; - uint32_t size; -}; - -static int -vmw_ioctl_get_param(struct vmw_customizer *vmw, uint32_t param, uint64_t *out) -{ - struct drm_vmw_getparam_arg gp_arg; - int ret; - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = param; - ret = drmCommandWriteRead(vmw->fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - - if (ret == 0) { - *out = gp_arg.value; - } - - return ret; -} - -int -vmw_ioctl_supports_streams(struct vmw_customizer *vmw) -{ - uint64_t value; - int ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &value); - if (ret) - return ret; - - return value ? 0 : -ENOSYS; -} - -int -vmw_ioctl_num_streams(struct vmw_customizer *vmw, - uint32_t *ntot, uint32_t *nfree) -{ - uint64_t v1, v2; - int ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &v1); - if (ret) - return ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_FREE_STREAMS, &v2); - if (ret) - return ret; - - *ntot = (uint32_t)v1; - *nfree = (uint32_t)v2; - - return 0; -} - -int -vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out) -{ - struct drm_vmw_stream_arg s_arg; - int ret; - - ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, - &s_arg, sizeof(s_arg)); - - if (ret) - return -1; - - *out = s_arg.stream_id; - return 0; -} - -int -vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id) -{ - struct drm_vmw_stream_arg s_arg; - int ret; - - memset(&s_arg, 0, sizeof(s_arg)); - s_arg.stream_id = stream_id; - - ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, - &s_arg, sizeof(s_arg)); - - return 0; -} - -int -vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot) -{ - struct drm_vmw_cursor_bypass_arg arg; - int ret; - - memset(&arg, 0, sizeof(arg)); - arg.flags = DRM_VMW_CURSOR_BYPASS_ALL; - arg.xhot = xhot; - arg.yhot = yhot; - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CURSOR_BYPASS, - &arg, sizeof(arg)); - - return ret; -} - -struct vmw_dma_buffer * -vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle) -{ - struct vmw_dma_buffer *buf; - union drm_vmw_alloc_dmabuf_arg arg; - struct drm_vmw_alloc_dmabuf_req *req = &arg.req; - struct drm_vmw_dmabuf_rep *rep = &arg.rep; - int ret; - - buf = xcalloc(1, sizeof(*buf)); - if (!buf) - goto err; - - memset(&arg, 0, sizeof(arg)); - req->size = size; - do { - ret = drmCommandWriteRead(vmw->fd, DRM_VMW_ALLOC_DMABUF, &arg, sizeof(arg)); - } while (ret == -ERESTART); - - if (ret) { - debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); - goto err_free; - } - - - buf->data = NULL; - buf->handle = rep->handle; - buf->map_handle = rep->map_handle; - buf->map_count = 0; - buf->size = size; - - *handle = rep->handle; - - return buf; - -err_free: - xfree(buf); -err: - return NULL; -} - -void -vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - struct drm_vmw_unref_dmabuf_arg arg; - - if (buf->data) { - munmap(buf->data, buf->size); - buf->data = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - drmCommandWrite(vmw->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); - - xfree(buf); -} - -void * -vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - void *map; - - if (buf->data == NULL) { - map = mmap(NULL, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, - vmw->fd, buf->map_handle); - if (map == MAP_FAILED) { - debug_printf("%s: Map failed.\n", __FUNCTION__); - return NULL; - } - - buf->data = map; - } - - ++buf->map_count; - - return buf->data; -} - -void -vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - --buf->map_count; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c b/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c deleted file mode 100644 index f43f91e5c0d..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c +++ /dev/null @@ -1,178 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Contains the init code for the VMware Xorg driver. - * - * @author Jakob Bornecrantz - */ - -#include "vmw_hook.h" -#include "vmw_driver.h" - -#include "cursorstr.h" - -/* modified version of crtc functions */ -xf86CrtcFuncsRec vmw_screen_crtc_funcs; - -static void -vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) -{ - struct vmw_customizer *vmw = - vmw_customizer(xorg_customizer(crtc->scrn)); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - xf86CrtcFuncsPtr funcs = vmw->cursor_priv; - CursorPtr c = config->cursor; - - /* Run the ioctl before uploading the image */ - vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot); - - funcs->load_cursor_argb(crtc, image); -} - -static void -vmw_screen_cursor_init(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int i; - - /* XXX assume that all crtc's have the same function struct */ - - /* Save old struct need to call the old functions as well */ - vmw->cursor_priv = (void*)(config->crtc[0]->funcs); - memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec)); - vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb; - - for (i = 0; i < config->num_crtc; i++) - config->crtc[i]->funcs = &vmw_screen_crtc_funcs; -} - -static void -vmw_screen_cursor_close(struct vmw_customizer *vmw) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn); - int i; - - vmw_ioctl_cursor_bypass(vmw, 0, 0); - - for (i = 0; i < config->num_crtc; i++) - config->crtc[i]->funcs = vmw->cursor_priv; -} - -static Bool -vmw_screen_init(CustomizerPtr cust, int fd) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - vmw->fd = fd; - vmw_screen_cursor_init(vmw); - - /* if gallium is used then we don't need to do anything more. */ - if (xorg_has_gallium(vmw->pScrn)) - return TRUE; - - vmw_video_init(vmw); - - return TRUE; -} - -static Bool -vmw_screen_close(CustomizerPtr cust) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - if (!vmw) - return TRUE; - - vmw_screen_cursor_close(vmw); - - vmw_video_close(vmw); - - return TRUE; -} - -static Bool -vmw_screen_enter_vt(CustomizerPtr cust) -{ - debug_printf("%s: enter\n", __func__); - - return TRUE; -} - -static Bool -vmw_screen_leave_vt(CustomizerPtr cust) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - debug_printf("%s: enter\n", __func__); - - vmw_video_stop_all(vmw); - - return TRUE; -} - -/* - * Functions for setting up hooks into the xorg state tracker - */ - -static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL; - -static Bool -vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags) -{ - struct vmw_customizer *vmw; - CustomizerPtr cust; - - vmw = xnfcalloc(1, sizeof(*vmw)); - if (!vmw) - return FALSE; - - cust = &vmw->base; - - cust->winsys_screen_init = vmw_screen_init; - cust->winsys_screen_close = vmw_screen_close; - cust->winsys_enter_vt = vmw_screen_enter_vt; - cust->winsys_leave_vt = vmw_screen_leave_vt; - vmw->pScrn = pScrn; - - pScrn->driverPrivate = cust; - - pScrn->PreInit = vmw_screen_pre_init_saved; - if (!pScrn->PreInit(pScrn, flags)) - return FALSE; - - return TRUE; -} - -void -vmw_screen_set_functions(ScrnInfoPtr pScrn) -{ - assert(!vmw_screen_pre_init_saved); - - vmw_screen_pre_init_saved = pScrn->PreInit; - pScrn->PreInit = vmw_screen_pre_init; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c b/src/gallium/winsys/drm/vmware/xorg/vmw_video.c deleted file mode 100644 index de28f06a475..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c +++ /dev/null @@ -1,1072 +0,0 @@ -/* - * Copyright 2007 by VMware, 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - * Except as contained in this notice, the name of the copyright holder(s) - * and author(s) shall not be used in advertising or otherwise to promote - * the sale, use or other dealings in this Software without prior written - * authorization from the copyright holder(s) and author(s). - */ - -/* - * vmwarevideo.c -- - * - * Xv extension support. - * See http://www.xfree86.org/current/DESIGN16.html - * - */ - - -#include "xf86xv.h" -#include "fourcc.h" - -#include "pipe/p_compiler.h" -/* - * We can't incude svga_types.h due to conflicting types for Bool. - */ -typedef int64_t int64; -typedef uint64_t uint64; - -typedef int32_t int32; -typedef uint32_t uint32; - -typedef int16_t int16; -typedef uint16_t uint16; - -typedef int8_t int8; -typedef uint8_t uint8; - -#include "svga/include/svga_reg.h" -#include "svga/include/svga_escape.h" -#include "svga/include/svga_overlay.h" - -#include "vmw_driver.h" - -#include - -#include "xf86drm.h" -#include "../core/vmwgfx_drm.h" - -#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) - -/* - * Number of videos that can be played simultaneously - */ -#define VMWARE_VID_NUM_PORTS 1 - -/* - * Using a dark shade as the default colorKey - */ -#define VMWARE_VIDEO_COLORKEY 0x100701 - -/* - * Maximum dimensions - */ -#define VMWARE_VID_MAX_WIDTH 2048 -#define VMWARE_VID_MAX_HEIGHT 2048 - -#define VMWARE_VID_NUM_ENCODINGS 1 -static XF86VideoEncodingRec vmwareVideoEncodings[] = -{ - { - 0, - "XV_IMAGE", - VMWARE_VID_MAX_WIDTH, VMWARE_VID_MAX_HEIGHT, - {1, 1} - } -}; - -#define VMWARE_VID_NUM_FORMATS 2 -static XF86VideoFormatRec vmwareVideoFormats[] = -{ - { 16, TrueColor}, - { 24, TrueColor} -}; - -#define VMWARE_VID_NUM_IMAGES 3 -static XF86ImageRec vmwareVideoImages[] = -{ - XVIMAGE_YV12, - XVIMAGE_YUY2, - XVIMAGE_UYVY -}; - -#define VMWARE_VID_NUM_ATTRIBUTES 2 -static XF86AttributeRec vmwareVideoAttributes[] = -{ - { - XvGettable | XvSettable, - 0x000000, - 0xffffff, - "XV_COLORKEY" - }, - { - XvGettable | XvSettable, - 0, - 1, - "XV_AUTOPAINT_COLORKEY" - } -}; - -/* - * Video frames are stored in a circular list of buffers. - * Must be power or two, See vmw_video_port_play. - */ -#define VMWARE_VID_NUM_BUFFERS 1 - -/* - * Defines the structure used to hold and pass video data to the host - */ -struct vmw_video_buffer -{ - unsigned handle; - int size; - void *data; - void *extra_data; - struct vmw_dma_buffer *buf; -}; - - -/** - * Structure representing a single video stream, aka port. - * - * Ports maps one to one to a SVGA stream. Port is just - * what Xv calls a SVGA stream. - */ -struct vmw_video_port -{ - /* - * Function prototype same as XvPutImage. - * - * This is either set to vmw_video_port_init or vmw_video_port_play. - * At init this function is set to port_init. In port_init we set it - * to port_play and call it, after initializing the struct. - */ - int (*play)(ScrnInfoPtr, struct vmw_video_port *, - short, short, short, short, short, - short, short, short, int, unsigned char*, - short, short, RegionPtr); - - /* values to go into the SVGAOverlayUnit */ - uint32 streamId; - uint32 colorKey; - uint32 flags; - - /* round robin of buffers */ - unsigned currBuf; - struct vmw_video_buffer bufs[VMWARE_VID_NUM_BUFFERS]; - - /* properties that applies to all buffers */ - int size; - int pitches[3]; - int offsets[3]; - - /* things for X */ - RegionRec clipBoxes; - Bool isAutoPaintColorkey; -}; - - -/** - * Structure holding all the infromation for video. - */ -struct vmw_video_private -{ - int fd; - - /** ports */ - struct vmw_video_port port[VMWARE_VID_NUM_PORTS]; - - /** Used to store port pointers pointers */ - DevUnion port_ptr[VMWARE_VID_NUM_PORTS]; -}; - - -/* - * Callback functions exported to Xv, prefixed with vmw_xv_*. - */ -static int vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int image, - unsigned char *buf, short width, short height, - Bool sync, RegionPtr clipBoxes, pointer data, - DrawablePtr dst); -static void vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool Cleanup); -static int vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, - unsigned short *width, - unsigned short *height, int *pitches, - int *offsets); -static int vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 value, pointer data); -static int vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 *value, pointer data); -static void vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, pointer data); - - -/* - * Local functions. - */ -static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw); - -static int vmw_video_port_init(ScrnInfoPtr pScrn, - struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes); -static int vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes); -static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port); - -static int vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, - struct vmw_video_buffer *out); -static int vmw_video_buffer_free(struct vmw_customizer *vmw, - struct vmw_video_buffer *out); - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_init -- - * - * Initializes Xv support. - * - * Results: - * TRUE on success, FALSE on error. - * - * Side effects: - * Xv support is initialized. Memory is allocated for all supported - * video streams. - * - *----------------------------------------------------------------------------- - */ - -Bool -vmw_video_init(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - ScreenPtr pScreen = pScrn->pScreen; - XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL; - XF86VideoAdaptorPtr newAdaptor = NULL; - int numAdaptors; - unsigned int ntot, nfree; - - debug_printf("%s: enter\n", __func__); - - if (vmw_ioctl_num_streams(vmw, &ntot, &nfree) != 0) { - debug_printf("No stream ioctl support\n"); - return FALSE; - } - - if (nfree == 0) { - debug_printf("No free streams\n"); - return FALSE; - } - - numAdaptors = xf86XVListGenericAdaptors(pScrn, &overlayAdaptors); - - newAdaptor = vmw_video_init_adaptor(pScrn, vmw); - if (!newAdaptor) { - debug_printf("Failed to initialize Xv extension\n"); - return FALSE; - } - - if (!numAdaptors) { - numAdaptors = 1; - overlayAdaptors = &newAdaptor; - } else { - newAdaptors = xalloc((numAdaptors + 1) * - sizeof(XF86VideoAdaptorPtr*)); - if (!newAdaptors) { - xf86XVFreeVideoAdaptorRec(newAdaptor); - return FALSE; - } - - memcpy(newAdaptors, overlayAdaptors, - numAdaptors * sizeof(XF86VideoAdaptorPtr)); - newAdaptors[numAdaptors++] = newAdaptor; - overlayAdaptors = newAdaptors; - } - - if (!xf86XVScreenInit(pScreen, overlayAdaptors, numAdaptors)) { - debug_printf("Failed to initialize Xv extension\n"); - xf86XVFreeVideoAdaptorRec(newAdaptor); - return FALSE; - } - - if (newAdaptors) { - xfree(newAdaptors); - } - - debug_printf("Initialized VMware Xv extension successfully\n"); - - return TRUE; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_close -- - * - * Unitializes video. - * - * Results: - * TRUE. - * - * Side effects: - * vmw->video_priv = NULL - * - *----------------------------------------------------------------------------- - */ - -Bool -vmw_video_close(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - struct vmw_video_private *video; - int i; - - debug_printf("%s: enter\n", __func__); - - video = vmw->video_priv; - if (!video) - return TRUE; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - /* make sure the port is stoped as well */ - vmw_xv_stop_video(pScrn, &video->port[i], TRUE); - vmw_ioctl_unref_stream(vmw, video->port[i].streamId); - } - - /* XXX: I'm sure this function is missing code for turning off Xv */ - - free(vmw->video_priv); - vmw->video_priv = NULL; - - return TRUE; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_stop_all -- - * - * Stop all video streams from playing. - * - * Results: - * None. - * - * Side effects: - * All buffers are freed. - * - *----------------------------------------------------------------------------- - */ - -void vmw_video_stop_all(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - struct vmw_video_private *video = vmw->video_priv; - int i; - - debug_printf("%s: enter\n", __func__); - - if (!video) - return; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - vmw_xv_stop_video(pScrn, &video->port[i], TRUE); - } -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_init_adaptor -- - * - * Initializes a XF86VideoAdaptor structure with the capabilities and - * functions supported by this video driver. - * - * Results: - * On success initialized XF86VideoAdaptor struct or NULL on error - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static XF86VideoAdaptorPtr -vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw) -{ - XF86VideoAdaptorPtr adaptor; - struct vmw_video_private *video; - int i; - - debug_printf("%s: enter \n", __func__); - - adaptor = xf86XVAllocateVideoAdaptorRec(pScrn); - if (!adaptor) { - debug_printf("Not enough memory\n"); - return NULL; - } - - video = xcalloc(1, sizeof(*video)); - if (!video) { - debug_printf("Not enough memory.\n"); - xf86XVFreeVideoAdaptorRec(adaptor); - return NULL; - } - - vmw->video_priv = video; - - adaptor->type = XvInputMask | XvImageMask | XvWindowMask; - adaptor->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; - adaptor->name = "VMware Video Engine"; - adaptor->nEncodings = VMWARE_VID_NUM_ENCODINGS; - adaptor->pEncodings = vmwareVideoEncodings; - adaptor->nFormats = VMWARE_VID_NUM_FORMATS; - adaptor->pFormats = vmwareVideoFormats; - adaptor->nPorts = VMWARE_VID_NUM_PORTS; - adaptor->pPortPrivates = video->port_ptr; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - vmw_ioctl_claim_stream(vmw, &video->port[i].streamId); - video->port[i].play = vmw_video_port_init; - video->port[i].flags = SVGA_VIDEO_FLAG_COLORKEY; - video->port[i].colorKey = VMWARE_VIDEO_COLORKEY; - video->port[i].isAutoPaintColorkey = TRUE; - adaptor->pPortPrivates[i].ptr = &video->port[i]; - } - - adaptor->nAttributes = VMWARE_VID_NUM_ATTRIBUTES; - adaptor->pAttributes = vmwareVideoAttributes; - - adaptor->nImages = VMWARE_VID_NUM_IMAGES; - adaptor->pImages = vmwareVideoImages; - - adaptor->PutVideo = NULL; - adaptor->PutStill = NULL; - adaptor->GetVideo = NULL; - adaptor->GetStill = NULL; - adaptor->StopVideo = vmw_xv_stop_video; - adaptor->SetPortAttribute = vmw_xv_set_port_attribute; - adaptor->GetPortAttribute = vmw_xv_get_port_attribute; - adaptor->QueryBestSize = vmw_xv_query_best_size; - adaptor->PutImage = vmw_xv_put_image; - adaptor->QueryImageAttributes = vmw_xv_query_image_attributes; - - debug_printf("%s: done %p\n", __func__, adaptor); - - return adaptor; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_init -- - * - * Initializes a video stream in response to the first PutImage() on a - * video stream. The process goes as follows: - * - Figure out characteristics according to format - * - Allocate offscreen memory - * - Pass on video to Play() functions - * - * Results: - * Success or XvBadAlloc on failure. - * - * Side effects: - * Video stream is initialized and its first frame sent to the host - * (done by VideoPlay() function called at the end) - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - unsigned short w, h; - int i, ret; - - debug_printf("\t%s: id %d, format %d\n", __func__, port->streamId, format); - - w = width; - h = height; - /* init all the format attributes, used for buffers */ - port->size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, - port->pitches, port->offsets); - - if (port->size == -1) - return XvBadAlloc; - - port->play = vmw_video_port_play; - - for (i = 0; i < VMWARE_VID_NUM_BUFFERS; ++i) { - ret = vmw_video_buffer_alloc(vmw, port->size, &port->bufs[i]); - if (ret != Success) - break; - } - - /* Free all allocated buffers on failure */ - if (ret != Success) { - for (--i; i >= 0; --i) { - vmw_video_buffer_free(vmw, &port->bufs[i]); - } - return ret; - } - - port->currBuf = 0; - - REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); - - if (port->isAutoPaintColorkey) - xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); - - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, - drw_w, drw_h, format, buf, width, height, clipBoxes); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_play -- - * - * Sends all the attributes associated with the video frame using the - * FIFO ESCAPE mechanism to the host. - * - * Results: - * Always returns Success. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct drm_vmw_control_stream_arg arg; - unsigned short w, h; - int size; - int ret; - - debug_printf("\t%s: enter\n", __func__); - - w = width; - h = height; - - /* we don't update the ports size */ - size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, - port->pitches, port->offsets); - - if (size > port->size) { - debug_printf("\t%s: Increase in size of Xv video frame streamId:%d.\n", - __func__, port->streamId); - vmw_xv_stop_video(pScrn, port, TRUE); - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, - src_h, drw_w, drw_h, format, buf, width, height, - clipBoxes); - } - - memcpy(port->bufs[port->currBuf].data, buf, port->size); - - memset(&arg, 0, sizeof(arg)); - - arg.stream_id = port->streamId; - arg.enabled = TRUE; - arg.flags = port->flags; - arg.color_key = port->colorKey; - arg.handle = port->bufs[port->currBuf].handle; - arg.format = format; - arg.size = port->size; - arg.width = w; - arg.height = h; - arg.src.x = src_x; - arg.src.y = src_y; - arg.src.w = src_w; - arg.src.h = src_h; - arg.dst.x = drw_x; - arg.dst.y = drw_y; - arg.dst.w = drw_w; - arg.dst.h = drw_h; - arg.pitch[0] = port->pitches[0]; - arg.pitch[1] = port->pitches[1]; - arg.pitch[2] = port->pitches[2]; - arg.offset = 0; - - /* - * Update the clipList and paint the colorkey, if required. - */ - if (!REGION_EQUAL(pScrn->pScreen, &port->clipBoxes, clipBoxes)) { - REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); - if (port->isAutoPaintColorkey) { - xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); - } - } - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); - if (ret) { - vmw_video_port_cleanup(pScrn, port); - return XvBadAlloc; - } - - if (++(port->currBuf) >= VMWARE_VID_NUM_BUFFERS) - port->currBuf = 0; - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_cleanup -- - * - * Frees up all resources (if any) taken by a video stream. - * - * Results: - * None. - * - * Side effects: - * Same as above. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - uint32 id, colorKey, flags; - Bool isAutoPaintColorkey; - int i; - - debug_printf("\t%s: enter\n", __func__); - - for (i = 0; i < VMWARE_VID_NUM_BUFFERS; i++) { - vmw_video_buffer_free(vmw, &port->bufs[i]); - } - - /* - * reset stream for next video - */ - id = port->streamId; - colorKey = port->colorKey; - flags = port->flags; - isAutoPaintColorkey = port->isAutoPaintColorkey; - - memset(port, 0, sizeof(*port)); - - port->streamId = id; - port->play = vmw_video_port_init; - port->colorKey = colorKey; - port->flags = flags; - port->isAutoPaintColorkey = isAutoPaintColorkey; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_buffer_alloc -- - * - * Allocates and map a kernel buffer to be used as data storage. - * - * Results: - * XvBadAlloc on failure, otherwise Success. - * - * Side effects: - * Calls into the kernel, sets members of out. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, - struct vmw_video_buffer *out) -{ - out->buf = vmw_ioctl_buffer_create(vmw, size, &out->handle); - if (!out->buf) - return XvBadAlloc; - - out->data = vmw_ioctl_buffer_map(vmw, out->buf); - if (!out->data) { - vmw_ioctl_buffer_destroy(vmw, out->buf); - - out->handle = 0; - out->buf = NULL; - - return XvBadAlloc; - } - - out->size = size; - out->extra_data = xcalloc(1, size); - - debug_printf("\t\t%s: allocated buffer %p of size %i\n", __func__, out, size); - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_buffer_free -- - * - * Frees and unmaps an allocated kernel buffer. - * - * Results: - * Success. - * - * Side effects: - * Calls into the kernel, sets members of out to 0. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_buffer_free(struct vmw_customizer *vmw, - struct vmw_video_buffer *out) -{ - if (out->size == 0) - return Success; - - xfree(out->extra_data); - vmw_ioctl_buffer_unmap(vmw, out->buf); - vmw_ioctl_buffer_destroy(vmw, out->buf); - - out->buf = NULL; - out->data = NULL; - out->handle = 0; - out->size = 0; - - debug_printf("\t\t%s: freed buffer %p\n", __func__, out); - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_put_image -- - * - * Main video playback function. It copies the passed data which is in - * the specified format (e.g. FOURCC_YV12) into the overlay. - * - * If sync is TRUE the driver should not return from this - * function until it is through reading the data from buf. - * - * Results: - * Success or XvBadAlloc on failure - * - * Side effects: - * Video port will be played(initialized if 1st frame) on success - * or will fail on error. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, short height, - Bool sync, RegionPtr clipBoxes, pointer data, - DrawablePtr dst) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct vmw_video_port *port = data; - - debug_printf("%s: enter (%u, %u) (%ux%u) (%u, %u) (%ux%u) (%ux%u)\n", __func__, - src_x, src_y, src_w, src_h, - drw_x, drw_y, drw_w, drw_h, - width, height); - - if (!vmw->video_priv) - return XvBadAlloc; - - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, - drw_w, drw_h, format, buf, width, height, clipBoxes); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_stop_video -- - * - * Called when we should stop playing video for a particular stream. If - * Cleanup is FALSE, the "stop" operation is only temporary, and thus we - * don't do anything. If Cleanup is TRUE we kill the video port by - * sending a message to the host and freeing up the stream. - * - * Results: - * None. - * - * Side effects: - * See above. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct vmw_video_port *port = data; - struct drm_vmw_control_stream_arg arg; - int ret; - - debug_printf("%s: cleanup is %s\n", __func__, cleanup ? "TRUE" : "FALSE"); - - if (!vmw->video_priv) - return; - - if (!cleanup) - return; - - - memset(&arg, 0, sizeof(arg)); - arg.stream_id = port->streamId; - arg.enabled = FALSE; - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); - assert(ret == 0); - - vmw_video_port_cleanup(pScrn, port); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_query_image_attributes -- - * - * From the spec: This function is called to let the driver specify how data - * for a particular image of size width by height should be stored. - * Sometimes only the size and corrected width and height are needed. In - * that case pitches and offsets are NULL. - * - * Results: - * The size of the memory required for the image, or -1 on error. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, - unsigned short *width, unsigned short *height, - int *pitches, int *offsets) -{ - INT32 size, tmp; - - if (*width > VMWARE_VID_MAX_WIDTH) { - *width = VMWARE_VID_MAX_WIDTH; - } - if (*height > VMWARE_VID_MAX_HEIGHT) { - *height = VMWARE_VID_MAX_HEIGHT; - } - - *width = (*width + 1) & ~1; - if (offsets != NULL) { - offsets[0] = 0; - } - - switch (format) { - case FOURCC_YV12: - *height = (*height + 1) & ~1; - size = (*width + 3) & ~3; - if (pitches) { - pitches[0] = size; - } - size *= *height; - if (offsets) { - offsets[1] = size; - } - tmp = ((*width >> 1) + 3) & ~3; - if (pitches) { - pitches[1] = pitches[2] = tmp; - } - tmp *= (*height >> 1); - size += tmp; - if (offsets) { - offsets[2] = size; - } - size += tmp; - break; - case FOURCC_UYVY: - case FOURCC_YUY2: - size = *width * 2; - if (pitches) { - pitches[0] = size; - } - size *= *height; - break; - default: - debug_printf("Query for invalid video format %d\n", format); - return -1; - } - return size; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_set_port_attribute -- - * - * From the spec: A port may have particular attributes such as colorKey, hue, - * saturation, brightness or contrast. Xv clients set these - * attribute values by sending attribute strings (Atoms) to the server. - * - * Results: - * Success if the attribute exists and XvBadAlloc otherwise. - * - * Side effects: - * The respective attribute gets the new value. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 value, pointer data) -{ - struct vmw_video_port *port = data; - Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); - Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); - - if (attribute == xvColorKey) { - debug_printf("%s: Set colorkey:0x%x\n", __func__, (unsigned)value); - port->colorKey = value; - } else if (attribute == xvAutoPaint) { - debug_printf("%s: Set autoPaint: %s\n", __func__, value? "TRUE": "FALSE"); - port->isAutoPaintColorkey = value; - } else { - return XvBadAlloc; - } - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_get_port_attribute -- - * - * From the spec: A port may have particular attributes such as hue, - * saturation, brightness or contrast. Xv clients get these - * attribute values by sending attribute strings (Atoms) to the server - * - * Results: - * Success if the attribute exists and XvBadAlloc otherwise. - * - * Side effects: - * "value" contains the requested attribute on success. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 *value, pointer data) -{ - struct vmw_video_port *port = data; - Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); - Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); - - if (attribute == xvColorKey) { - *value = port->colorKey; - } else if (attribute == xvAutoPaint) { - *value = port->isAutoPaintColorkey; - } else { - return XvBadAlloc; - } - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_query_best_size -- - * - * From the spec: QueryBestSize provides the client with a way to query what - * the destination dimensions would end up being if they were to request - * that an area vid_w by vid_h from the video stream be scaled to rectangle - * of drw_w by drw_h on the screen. Since it is not expected that all - * hardware will be able to get the target dimensions exactly, it is - * important that the driver provide this function. - * - * This function seems to never be called, but to be on the safe side - * we apply the same logic that QueryImageAttributes has for width - * and height. - * - * Results: - * None. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, pointer data) -{ - *p_w = (drw_w + 1) & ~1; - *p_h = drw_h; - - return; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c b/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c deleted file mode 100644 index 87aad25b24f..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c +++ /dev/null @@ -1,191 +0,0 @@ -/********************************************************** - * Copyright 2008-2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Glue file for Xorg State Tracker. - * - * @author Alan Hourihane - * @author Jakob Bornecrantz - */ - -#include "vmw_hook.h" - - -/* - * Defines and modinfo - */ - -#define VMWGFX_DRIVER_NAME "vmwgfx" - -#define VMW_STRING_INNER(s) #s -#define VMW_STRING(str) VMW_STRING_INNER(str) - -#define VMWGFX_VERSION_MAJOR 11 -#define VMWGFX_VERSION_MINOR 0 -#define VMWGFX_VERSION_PATCH 0 -#define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR) -#define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR) -#define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH) - -#define VMWGFX_DRIVER_VERSION \ - (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH) -#define VMWGFX_DRIVER_VERSION_STRING \ - VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \ - "." VMWGFX_VERSION_STRING_PATCH - -/* - * Standard four digit version string expected by VMware Tools installer. - * As the driver's version is only {major, minor, patchlevel}, simply append an - * extra zero for the fourth digit. - */ -#ifdef __GNUC__ -_X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) = - "version=" VMWGFX_DRIVER_VERSION_STRING ".0"; -#endif - -static void vmw_xorg_identify(int flags); -_X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - - -/* - * Tables - */ - -static const struct pci_id_match vmw_xorg_device_match[] = { - {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}, -}; - -static SymTabRec vmw_xorg_chipsets[] = { - {PCI_MATCH_ANY, "VMware SVGA Device"}, - {-1, NULL} -}; - -static PciChipsets vmw_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo vmw_xorg_version = { - VMWGFX_DRIVER_NAME, - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec vmwgfx = { - 1, - VMWGFX_DRIVER_NAME, - vmw_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - vmw_xorg_device_match, - vmw_xorg_pci_probe -}; - -static MODULESETUPPROTO(vmw_xorg_setup); - -_X_EXPORT XF86ModuleData vmwgfxModuleData = { - &vmw_xorg_version, - vmw_xorg_setup, - NULL -}; - - -/* - * Xorg driver functions - */ - -static pointer -vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&vmwgfx, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -vmw_xorg_identify(int flags) -{ - xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device", - vmw_xorg_chipsets); -} - -_X_EXPORT Bool -vmw_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "vmwgfx"; - scrn->name = "vmwgfx"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - - vmw_screen_set_functions(scrn); - } - return scrn != NULL; -} -- cgit v1.2.3 From c9f98673c5b6830cd1f41c0c53a9e5e299d47464 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 13:54:18 +0000 Subject: gallium: Reorg winsys directories Attached output from commit. delete mode 100644 src/gallium/winsys/drm/SConscript delete mode 100644 src/gallium/winsys/drm/i965/SConscript delete mode 100644 src/gallium/winsys/drm/intel/Makefile delete mode 100644 src/gallium/winsys/drm/intel/SConscript delete mode 100644 src/gallium/winsys/drm/nouveau/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/SConscript rename src/gallium/winsys/{drm/intel/gem => i915/drm}/Makefile (82%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/SConscript (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_api.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_batchbuffer.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_buffer.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_fence.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_winsys.h (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/Makefile (78%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/SConscript (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_api.c (98%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_buffer.c (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_winsys.h (100%) rename src/gallium/winsys/{drm => }/i965/xlib/Makefile (97%) rename src/gallium/winsys/{drm => }/i965/xlib/xlib_i965.c (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/Makefile (79%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_dri.h (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_drm_api.c (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_drm_api.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/Makefile (79%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/SConscript (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_buffer.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm_buffer.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_r300.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_r300.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_winsys.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/Makefile (63%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/SConscript (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_buffer.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_buffer.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_context.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_context.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_fence.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_fence.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_dri.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_ioctl.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_pools.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_svga.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_surface.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_surface.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmwgfx_drm.h (100%) rename src/gallium/winsys/{drm/i965 => sw}/Makefile (61%) copy src/gallium/winsys/{drm/sw => sw/drm}/Makefile (73%) rename src/gallium/winsys/{drm/sw => sw/drm}/sw_drm_api.c (98%) rename src/gallium/winsys/{drm/sw => sw/drm}/sw_drm_api.h (100%) rename src/gallium/winsys/{ => sw}/gdi/SConscript (100%) rename src/gallium/winsys/{ => sw}/gdi/gdi_sw_winsys.c (100%) rename src/gallium/winsys/{ => sw}/gdi/gdi_sw_winsys.h (100%) rename src/gallium/winsys/{ => sw}/null/Makefile (78%) rename src/gallium/winsys/{ => sw}/null/SConscript (100%) rename src/gallium/winsys/{ => sw}/null/null_sw_winsys.c (100%) rename src/gallium/winsys/{ => sw}/null/null_sw_winsys.h (100%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/Makefile (65%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/wrapper_sw_winsys.c (100%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/wrapper_sw_winsys.h (100%) rename src/gallium/winsys/{ => sw}/xlib/Makefile (79%) rename src/gallium/winsys/{ => sw}/xlib/SConscript (100%) rename src/gallium/winsys/{ => sw}/xlib/xlib_sw_winsys.c (100%) --- configs/default | 2 +- configs/linux-dri | 2 +- configure.ac | 14 +- src/gallium/SConscript | 2 +- src/gallium/targets/Makefile.egl | 2 +- src/gallium/targets/dri-i915/Makefile | 2 +- src/gallium/targets/dri-i965/Makefile | 5 +- src/gallium/targets/dri-nouveau/Makefile | 2 +- src/gallium/targets/dri-radeong/Makefile | 2 +- src/gallium/targets/dri-vmwgfx/Makefile | 2 +- src/gallium/targets/egl-i915/Makefile | 2 +- src/gallium/targets/egl-i965/Makefile | 2 +- src/gallium/targets/egl-nouveau/Makefile | 2 +- src/gallium/targets/egl-radeon/Makefile | 2 +- src/gallium/targets/egl-vmwgfx/Makefile | 2 +- src/gallium/targets/xorg-i915/Makefile | 2 +- src/gallium/targets/xorg-i965/Makefile | 2 +- src/gallium/targets/xorg-nouveau/Makefile | 2 +- src/gallium/targets/xorg-radeon/Makefile | 2 +- src/gallium/targets/xorg-vmwgfx/Makefile | 2 +- src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c | 2 +- src/gallium/targets/xorg-vmwgfx/vmw_video.c | 2 +- src/gallium/winsys/SConscript | 9 +- src/gallium/winsys/drm/SConscript | 69 --- src/gallium/winsys/drm/i965/Makefile | 12 - src/gallium/winsys/drm/i965/SConscript | 3 - src/gallium/winsys/drm/i965/gem/Makefile | 14 - src/gallium/winsys/drm/i965/gem/SConscript | 15 - src/gallium/winsys/drm/i965/gem/i965_drm_api.c | 122 ----- src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c | 503 ------------------- src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h | 64 --- src/gallium/winsys/drm/i965/xlib/Makefile | 97 ---- src/gallium/winsys/drm/i965/xlib/xlib_i965.c | 503 ------------------- src/gallium/winsys/drm/intel/Makefile | 12 - src/gallium/winsys/drm/intel/SConscript | 3 - src/gallium/winsys/drm/intel/gem/Makefile | 16 - src/gallium/winsys/drm/intel/gem/SConscript | 17 - src/gallium/winsys/drm/intel/gem/intel_drm_api.c | 109 ----- .../winsys/drm/intel/gem/intel_drm_batchbuffer.c | 244 --------- .../winsys/drm/intel/gem/intel_drm_buffer.c | 217 -------- src/gallium/winsys/drm/intel/gem/intel_drm_fence.c | 83 ---- .../winsys/drm/intel/gem/intel_drm_winsys.h | 77 --- src/gallium/winsys/drm/nouveau/Makefile | 12 - src/gallium/winsys/drm/nouveau/drm/Makefile | 11 - src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h | 28 -- .../winsys/drm/nouveau/drm/nouveau_drm_api.c | 157 ------ .../winsys/drm/nouveau/drm/nouveau_drm_api.h | 31 -- src/gallium/winsys/drm/radeon/Makefile | 12 - src/gallium/winsys/drm/radeon/SConscript | 3 - src/gallium/winsys/drm/radeon/core/Makefile | 17 - src/gallium/winsys/drm/radeon/core/SConscript | 18 - src/gallium/winsys/drm/radeon/core/radeon_buffer.h | 86 ---- src/gallium/winsys/drm/radeon/core/radeon_drm.c | 200 -------- src/gallium/winsys/drm/radeon/core/radeon_drm.h | 66 --- .../winsys/drm/radeon/core/radeon_drm_buffer.c | 385 --------------- src/gallium/winsys/drm/radeon/core/radeon_r300.c | 348 ------------- src/gallium/winsys/drm/radeon/core/radeon_r300.h | 30 -- src/gallium/winsys/drm/radeon/core/radeon_winsys.h | 86 ---- src/gallium/winsys/drm/sw/Makefile | 14 - src/gallium/winsys/drm/sw/sw_drm_api.c | 97 ---- src/gallium/winsys/drm/sw/sw_drm_api.h | 34 -- src/gallium/winsys/drm/sw/wrapper_sw_winsys.c | 282 ----------- src/gallium/winsys/drm/sw/wrapper_sw_winsys.h | 35 -- src/gallium/winsys/drm/vmware/Makefile | 12 - src/gallium/winsys/drm/vmware/SConscript | 3 - src/gallium/winsys/drm/vmware/core/Makefile | 35 -- src/gallium/winsys/drm/vmware/core/SConscript | 39 -- src/gallium/winsys/drm/vmware/core/vmw_buffer.c | 274 ----------- src/gallium/winsys/drm/vmware/core/vmw_buffer.h | 65 --- src/gallium/winsys/drm/vmware/core/vmw_context.c | 382 --------------- src/gallium/winsys/drm/vmware/core/vmw_context.h | 56 --- src/gallium/winsys/drm/vmware/core/vmw_fence.c | 108 ---- src/gallium/winsys/drm/vmware/core/vmw_fence.h | 59 --- src/gallium/winsys/drm/vmware/core/vmw_screen.c | 77 --- src/gallium/winsys/drm/vmware/core/vmw_screen.h | 140 ------ .../winsys/drm/vmware/core/vmw_screen_dri.c | 373 -------------- .../winsys/drm/vmware/core/vmw_screen_ioctl.c | 529 -------------------- .../winsys/drm/vmware/core/vmw_screen_pools.c | 97 ---- .../winsys/drm/vmware/core/vmw_screen_svga.c | 295 ----------- src/gallium/winsys/drm/vmware/core/vmw_surface.c | 61 --- src/gallium/winsys/drm/vmware/core/vmw_surface.h | 79 --- src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h | 545 --------------------- src/gallium/winsys/gdi/SConscript | 23 - src/gallium/winsys/gdi/gdi_sw_winsys.c | 247 ---------- src/gallium/winsys/gdi/gdi_sw_winsys.h | 16 - src/gallium/winsys/i915/drm/Makefile | 16 + src/gallium/winsys/i915/drm/SConscript | 17 + src/gallium/winsys/i915/drm/intel_drm_api.c | 109 +++++ .../winsys/i915/drm/intel_drm_batchbuffer.c | 244 +++++++++ src/gallium/winsys/i915/drm/intel_drm_buffer.c | 217 ++++++++ src/gallium/winsys/i915/drm/intel_drm_fence.c | 83 ++++ src/gallium/winsys/i915/drm/intel_drm_winsys.h | 77 +++ src/gallium/winsys/i965/drm/Makefile | 14 + src/gallium/winsys/i965/drm/SConscript | 15 + src/gallium/winsys/i965/drm/i965_drm_api.c | 122 +++++ src/gallium/winsys/i965/drm/i965_drm_buffer.c | 503 +++++++++++++++++++ src/gallium/winsys/i965/drm/i965_drm_winsys.h | 64 +++ src/gallium/winsys/i965/xlib/Makefile | 97 ++++ src/gallium/winsys/i965/xlib/xlib_i965.c | 503 +++++++++++++++++++ src/gallium/winsys/nouveau/drm/Makefile | 11 + src/gallium/winsys/nouveau/drm/nouveau_dri.h | 28 ++ src/gallium/winsys/nouveau/drm/nouveau_drm_api.c | 157 ++++++ src/gallium/winsys/nouveau/drm/nouveau_drm_api.h | 31 ++ src/gallium/winsys/null/Makefile | 16 - src/gallium/winsys/null/SConscript | 21 - src/gallium/winsys/null/null_sw_winsys.c | 148 ------ src/gallium/winsys/null/null_sw_winsys.h | 40 -- src/gallium/winsys/radeon/drm/Makefile | 17 + src/gallium/winsys/radeon/drm/SConscript | 18 + src/gallium/winsys/radeon/drm/radeon_buffer.h | 86 ++++ src/gallium/winsys/radeon/drm/radeon_drm.c | 200 ++++++++ src/gallium/winsys/radeon/drm/radeon_drm.h | 66 +++ src/gallium/winsys/radeon/drm/radeon_drm_buffer.c | 385 +++++++++++++++ src/gallium/winsys/radeon/drm/radeon_r300.c | 348 +++++++++++++ src/gallium/winsys/radeon/drm/radeon_r300.h | 30 ++ src/gallium/winsys/radeon/drm/radeon_winsys.h | 86 ++++ src/gallium/winsys/svga/drm/Makefile | 27 + src/gallium/winsys/svga/drm/SConscript | 39 ++ src/gallium/winsys/svga/drm/vmw_buffer.c | 274 +++++++++++ src/gallium/winsys/svga/drm/vmw_buffer.h | 65 +++ src/gallium/winsys/svga/drm/vmw_context.c | 382 +++++++++++++++ src/gallium/winsys/svga/drm/vmw_context.h | 56 +++ src/gallium/winsys/svga/drm/vmw_fence.c | 108 ++++ src/gallium/winsys/svga/drm/vmw_fence.h | 59 +++ src/gallium/winsys/svga/drm/vmw_screen.c | 77 +++ src/gallium/winsys/svga/drm/vmw_screen.h | 140 ++++++ src/gallium/winsys/svga/drm/vmw_screen_dri.c | 373 ++++++++++++++ src/gallium/winsys/svga/drm/vmw_screen_ioctl.c | 529 ++++++++++++++++++++ src/gallium/winsys/svga/drm/vmw_screen_pools.c | 97 ++++ src/gallium/winsys/svga/drm/vmw_screen_svga.c | 295 +++++++++++ src/gallium/winsys/svga/drm/vmw_surface.c | 61 +++ src/gallium/winsys/svga/drm/vmw_surface.h | 79 +++ src/gallium/winsys/svga/drm/vmwgfx_drm.h | 545 +++++++++++++++++++++ src/gallium/winsys/sw/Makefile | 12 + src/gallium/winsys/sw/drm/Makefile | 12 + src/gallium/winsys/sw/drm/sw_drm_api.c | 97 ++++ src/gallium/winsys/sw/drm/sw_drm_api.h | 34 ++ src/gallium/winsys/sw/gdi/SConscript | 23 + src/gallium/winsys/sw/gdi/gdi_sw_winsys.c | 247 ++++++++++ src/gallium/winsys/sw/gdi/gdi_sw_winsys.h | 16 + src/gallium/winsys/sw/null/Makefile | 16 + src/gallium/winsys/sw/null/SConscript | 21 + src/gallium/winsys/sw/null/null_sw_winsys.c | 148 ++++++ src/gallium/winsys/sw/null/null_sw_winsys.h | 40 ++ src/gallium/winsys/sw/wrapper/Makefile | 12 + src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c | 282 +++++++++++ src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h | 35 ++ src/gallium/winsys/sw/xlib/Makefile | 17 + src/gallium/winsys/sw/xlib/SConscript | 23 + src/gallium/winsys/sw/xlib/xlib_sw_winsys.c | 464 ++++++++++++++++++ src/gallium/winsys/xlib/Makefile | 17 - src/gallium/winsys/xlib/SConscript | 23 - src/gallium/winsys/xlib/xlib_sw_winsys.c | 464 ------------------ 153 files changed, 8281 insertions(+), 8412 deletions(-) delete mode 100644 src/gallium/winsys/drm/SConscript delete mode 100644 src/gallium/winsys/drm/i965/Makefile delete mode 100644 src/gallium/winsys/drm/i965/SConscript delete mode 100644 src/gallium/winsys/drm/i965/gem/Makefile delete mode 100644 src/gallium/winsys/drm/i965/gem/SConscript delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_api.c delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h delete mode 100644 src/gallium/winsys/drm/i965/xlib/Makefile delete mode 100644 src/gallium/winsys/drm/i965/xlib/xlib_i965.c delete mode 100644 src/gallium/winsys/drm/intel/Makefile delete mode 100644 src/gallium/winsys/drm/intel/SConscript delete mode 100644 src/gallium/winsys/drm/intel/gem/Makefile delete mode 100644 src/gallium/winsys/drm/intel/gem/SConscript delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_api.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_fence.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h delete mode 100644 src/gallium/winsys/drm/nouveau/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/drm/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h delete mode 100644 src/gallium/winsys/drm/radeon/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/SConscript delete mode 100644 src/gallium/winsys/drm/radeon/core/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/core/SConscript delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_buffer.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_r300.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_r300.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_winsys.h delete mode 100644 src/gallium/winsys/drm/sw/Makefile delete mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.c delete mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.h delete mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.c delete mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.h delete mode 100644 src/gallium/winsys/drm/vmware/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/core/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/core/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_buffer.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_buffer.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_context.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_context.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_fence.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_fence.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_surface.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_surface.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h delete mode 100644 src/gallium/winsys/gdi/SConscript delete mode 100644 src/gallium/winsys/gdi/gdi_sw_winsys.c delete mode 100644 src/gallium/winsys/gdi/gdi_sw_winsys.h create mode 100644 src/gallium/winsys/i915/drm/Makefile create mode 100644 src/gallium/winsys/i915/drm/SConscript create mode 100644 src/gallium/winsys/i915/drm/intel_drm_api.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_buffer.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_fence.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_winsys.h create mode 100644 src/gallium/winsys/i965/drm/Makefile create mode 100644 src/gallium/winsys/i965/drm/SConscript create mode 100644 src/gallium/winsys/i965/drm/i965_drm_api.c create mode 100644 src/gallium/winsys/i965/drm/i965_drm_buffer.c create mode 100644 src/gallium/winsys/i965/drm/i965_drm_winsys.h create mode 100644 src/gallium/winsys/i965/xlib/Makefile create mode 100644 src/gallium/winsys/i965/xlib/xlib_i965.c create mode 100644 src/gallium/winsys/nouveau/drm/Makefile create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_dri.h create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_drm_api.c create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_drm_api.h delete mode 100644 src/gallium/winsys/null/Makefile delete mode 100644 src/gallium/winsys/null/SConscript delete mode 100644 src/gallium/winsys/null/null_sw_winsys.c delete mode 100644 src/gallium/winsys/null/null_sw_winsys.h create mode 100644 src/gallium/winsys/radeon/drm/Makefile create mode 100644 src/gallium/winsys/radeon/drm/SConscript create mode 100644 src/gallium/winsys/radeon/drm/radeon_buffer.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm_buffer.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_r300.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_r300.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_winsys.h create mode 100644 src/gallium/winsys/svga/drm/Makefile create mode 100644 src/gallium/winsys/svga/drm/SConscript create mode 100644 src/gallium/winsys/svga/drm/vmw_buffer.c create mode 100644 src/gallium/winsys/svga/drm/vmw_buffer.h create mode 100644 src/gallium/winsys/svga/drm/vmw_context.c create mode 100644 src/gallium/winsys/svga/drm/vmw_context.h create mode 100644 src/gallium/winsys/svga/drm/vmw_fence.c create mode 100644 src/gallium/winsys/svga/drm/vmw_fence.h create mode 100644 src/gallium/winsys/svga/drm/vmw_screen.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen.h create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_dri.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_ioctl.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_pools.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_svga.c create mode 100644 src/gallium/winsys/svga/drm/vmw_surface.c create mode 100644 src/gallium/winsys/svga/drm/vmw_surface.h create mode 100644 src/gallium/winsys/svga/drm/vmwgfx_drm.h create mode 100644 src/gallium/winsys/sw/Makefile create mode 100644 src/gallium/winsys/sw/drm/Makefile create mode 100644 src/gallium/winsys/sw/drm/sw_drm_api.c create mode 100644 src/gallium/winsys/sw/drm/sw_drm_api.h create mode 100644 src/gallium/winsys/sw/gdi/SConscript create mode 100644 src/gallium/winsys/sw/gdi/gdi_sw_winsys.c create mode 100644 src/gallium/winsys/sw/gdi/gdi_sw_winsys.h create mode 100644 src/gallium/winsys/sw/null/Makefile create mode 100644 src/gallium/winsys/sw/null/SConscript create mode 100644 src/gallium/winsys/sw/null/null_sw_winsys.c create mode 100644 src/gallium/winsys/sw/null/null_sw_winsys.h create mode 100644 src/gallium/winsys/sw/wrapper/Makefile create mode 100644 src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c create mode 100644 src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h create mode 100644 src/gallium/winsys/sw/xlib/Makefile create mode 100644 src/gallium/winsys/sw/xlib/SConscript create mode 100644 src/gallium/winsys/sw/xlib/xlib_sw_winsys.c delete mode 100644 src/gallium/winsys/xlib/Makefile delete mode 100644 src/gallium/winsys/xlib/SConscript delete mode 100644 src/gallium/winsys/xlib/xlib_sw_winsys.c (limited to 'configure.ac') diff --git a/configs/default b/configs/default index 65e9847bd20..77a9898775c 100644 --- a/configs/default +++ b/configs/default @@ -100,7 +100,7 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib +GALLIUM_WINSYS_DIRS = sw sw/xlib GALLIUM_TARGET_DIRS = libgl-xlib GALLIUM_STATE_TRACKERS_DIRS = glx vega diff --git a/configs/linux-dri b/configs/linux-dri index b11daeda7c2..e21a3e95943 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -58,7 +58,7 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS) EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri -GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 +GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965 GALLIUM_TARGET_DIRS = egl-swrast GALLIUM_STATE_TRACKERS_DIRS = egl diff --git a/configure.ac b/configure.ac index c8f78dc74e8..edf2363a717 100644 --- a/configure.ac +++ b/configure.ac @@ -461,20 +461,20 @@ SRC_DIRS="glew" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" -GALLIUM_WINSYS_DIRS="null" +GALLIUM_WINSYS_DIRS="sw" GALLIUM_DRIVERS_DIRS="softpipe failover trace identity" GALLIUM_STATE_TRACKERS_DIRS="" case "$mesa_driver" in xlib) DRIVER_DIRS="x11" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib" ;; dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm/sw" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/drm" ;; osmesa) DRIVER_DIRS="osmesa" @@ -1317,7 +1317,7 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS svga/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi if test "x$enable_egl" = xyes; then @@ -1341,7 +1341,7 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/drm i965/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi if test "x$enable_egl" = xyes; then @@ -1365,7 +1365,7 @@ AC_ARG_ENABLE([gallium-radeon], [enable_gallium_radeon=auto]) if test "x$enable_gallium_radeon" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS radeon/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi if test "x$enable_egl" = xyes; then @@ -1389,7 +1389,7 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS nouveau/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi if test "x$enable_egl" = xyes; then diff --git a/src/gallium/SConscript b/src/gallium/SConscript index c833d83e65b..b8c04f72379 100644 --- a/src/gallium/SConscript +++ b/src/gallium/SConscript @@ -8,7 +8,7 @@ for driver in env['drivers']: SConscript(os.path.join('drivers', driver, 'SConscript')) # Needed by some state trackers -SConscript('winsys/null/SConscript') +SConscript('winsys/sw/null/SConscript') SConscript('state_trackers/python/SConscript') if platform != 'embedded': diff --git a/src/gallium/targets/Makefile.egl b/src/gallium/targets/Makefile.egl index bc5dd3a53b8..30fced7e3c8 100644 --- a/src/gallium/targets/Makefile.egl +++ b/src/gallium/targets/Makefile.egl @@ -14,7 +14,7 @@ EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) common_LIBS = -ldrm -lm -ldl x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ - $(TOP)/src/gallium/winsys/xlib/libws_xlib.a + $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile index 33eaae624f2..facbcb1803a 100644 --- a/src/gallium/targets/dri-i915/Makefile +++ b/src/gallium/targets/dri-i915/Makefile @@ -5,7 +5,7 @@ LIBNAME = i915_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile index e17775a842a..c622bbcaf65 100644 --- a/src/gallium/targets/dri-i965/Makefile +++ b/src/gallium/targets/dri-i965/Makefile @@ -5,9 +5,10 @@ LIBNAME = i965_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ + $(TOP)/src/gallium/winsys/sw/drm/libswdrm.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ $(TOP)/src/gallium/drivers/i965/libi965.a diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile index 680bad79177..9ba5e18ba70 100644 --- a/src/gallium/targets/dri-nouveau/Makefile +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -5,7 +5,7 @@ LIBNAME = nouveau_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile index c6d8c524694..ce25559e946 100644 --- a/src/gallium/targets/dri-radeong/Makefile +++ b/src/gallium/targets/dri-radeong/Makefile @@ -5,7 +5,7 @@ LIBNAME = radeong_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/r300/libr300.a diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile index 1d2ddfe548f..32edc46a3d9 100644 --- a/src/gallium/targets/dri-vmwgfx/Makefile +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -5,7 +5,7 @@ LIBNAME = vmwgfx_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile index 596dd092f75..6c2fc14d70f 100644 --- a/src/gallium/targets/egl-i915/Makefile +++ b/src/gallium/targets/egl-i915/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i915/libi915.a diff --git a/src/gallium/targets/egl-i965/Makefile b/src/gallium/targets/egl-i965/Makefile index e4c1a88f4c6..dfb3cc45a7d 100644 --- a/src/gallium/targets/egl-i965/Makefile +++ b/src/gallium/targets/egl-i965/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i965/libi965.a diff --git a/src/gallium/targets/egl-nouveau/Makefile b/src/gallium/targets/egl-nouveau/Makefile index 46fcdf5e4b0..3da93790f25 100644 --- a/src/gallium/targets/egl-nouveau/Makefile +++ b/src/gallium/targets/egl-nouveau/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_nouveau EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(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/nouveau/libnouveau.a \ diff --git a/src/gallium/targets/egl-radeon/Makefile b/src/gallium/targets/egl-radeon/Makefile index 56818365dda..f55d84de810 100644 --- a/src/gallium/targets/egl-radeon/Makefile +++ b/src/gallium/targets/egl-radeon/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_radeon EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/r300/libr300.a diff --git a/src/gallium/targets/egl-vmwgfx/Makefile b/src/gallium/targets/egl-vmwgfx/Makefile index 007158a6408..6db12e03a75 100644 --- a/src/gallium/targets/egl-vmwgfx/Makefile +++ b/src/gallium/targets/egl-vmwgfx/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile index 4442147e83f..e2cffcd70b3 100644 --- a/src/gallium/targets/xorg-i915/Makefile +++ b/src/gallium/targets/xorg-i915/Makefile @@ -17,7 +17,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/i915/libi915.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-i965/Makefile b/src/gallium/targets/xorg-i965/Makefile index 8d6a741e5d1..104a1434a84 100644 --- a/src/gallium/targets/xorg-i965/Makefile +++ b/src/gallium/targets/xorg-i965/Makefile @@ -17,7 +17,7 @@ CFLAGS = -DHAVE_CONFIG_H \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/i965/libi965.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile index d41de0b3110..b514b570007 100644 --- a/src/gallium/targets/xorg-nouveau/Makefile +++ b/src/gallium/targets/xorg-nouveau/Makefile @@ -16,7 +16,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(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/nouveau/libnouveau.a \ diff --git a/src/gallium/targets/xorg-radeon/Makefile b/src/gallium/targets/xorg-radeon/Makefile index 9618d30b4d6..cd32914c0d3 100644 --- a/src/gallium/targets/xorg-radeon/Makefile +++ b/src/gallium/targets/xorg-radeon/Makefile @@ -17,7 +17,7 @@ CFLAGS = -DHAVE_CONFIG_H \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/r300/libr300.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-vmwgfx/Makefile b/src/gallium/targets/xorg-vmwgfx/Makefile index 3691b883588..12bc307ef9b 100644 --- a/src/gallium/targets/xorg-vmwgfx/Makefile +++ b/src/gallium/targets/xorg-vmwgfx/Makefile @@ -20,7 +20,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a \ $(GALLIUM_AUXILIARIES) diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c index fe9c0393e23..96ee4ff82b4 100644 --- a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c @@ -42,7 +42,7 @@ #include #include "xf86drm.h" -#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" +#include "../../winsys/svga/drm/vmwgfx_drm.h" #include "vmw_driver.h" #include "util/u_debug.h" diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_video.c b/src/gallium/targets/xorg-vmwgfx/vmw_video.c index 7909999edfb..eced60d0ec1 100644 --- a/src/gallium/targets/xorg-vmwgfx/vmw_video.c +++ b/src/gallium/targets/xorg-vmwgfx/vmw_video.c @@ -62,7 +62,7 @@ typedef uint8_t uint8; #include #include "xf86drm.h" -#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" +#include "../../winsys/svga/drm/vmwgfx_drm.h" #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) diff --git a/src/gallium/winsys/SConscript b/src/gallium/winsys/SConscript index 30c3378dfff..97ea82ea761 100644 --- a/src/gallium/winsys/SConscript +++ b/src/gallium/winsys/SConscript @@ -1,16 +1,11 @@ Import('*') -if env['dri']: - SConscript([ - 'drm/SConscript', - ]) - if 'xlib' in env['winsys']: SConscript([ - 'xlib/SConscript', + 'sw/xlib/SConscript', ]) if 'gdi' in env['winsys']: SConscript([ - 'gdi/SConscript', + 'sw/gdi/SConscript', ]) diff --git a/src/gallium/winsys/drm/SConscript b/src/gallium/winsys/drm/SConscript deleted file mode 100644 index 66b73a8bf93..00000000000 --- a/src/gallium/winsys/drm/SConscript +++ /dev/null @@ -1,69 +0,0 @@ -Import('*') - -if env['dri']: - - drienv = env.Clone() - - drienv.Replace(CPPPATH = [ - '#src/mesa/drivers/dri/common', - '#include', - '#include/GL/internal', - '#src/gallium/include', - '#src/gallium/auxiliary', - '#src/gallium/drivers', - '#src/mesa', - '#src/mesa/main', - '#src/mesa/glapi', - '#src/mesa/math', - '#src/mesa/transform', - '#src/mesa/shader', - '#src/mesa/swrast', - '#src/mesa/swrast_setup', - '#src/egl/main', - '#src/egl/drivers/dri', - ]) - - drienv.ParseConfig('pkg-config --cflags --libs libdrm') - - COMMON_GALLIUM_SOURCES = [ - '#src/mesa/drivers/dri/common/utils.c', - '#src/mesa/drivers/dri/common/vblank.c', - '#src/mesa/drivers/dri/common/dri_util.c', - '#src/mesa/drivers/dri/common/xmlconfig.c', - ] - - COMMON_BM_SOURCES = [ - '#src/mesa/drivers/dri/common/dri_bufmgr.c', - '#src/mesa/drivers/dri/common/dri_drmpool.c', - ] - - Export([ - 'drienv', - 'COMMON_GALLIUM_SOURCES', - 'COMMON_BM_SOURCES', - ]) - - # TODO: Installation - #install: $(LIBNAME) - # $(INSTALL) -d $(DRI_DRIVER_INSTALL_DIR) - # $(INSTALL) -m 755 $(LIBNAME) $(DRI_DRIVER_INSTALL_DIR) - - if 'vmware' in env['winsys']: - SConscript([ - 'vmware/SConscript', - ]) - - if 'intel' in env['winsys']: - SConscript([ - 'intel/SConscript', - ]) - - if 'i965' in env['winsys']: - SConscript([ - 'i965/SConscript', - ]) - - if 'radeon' in env['winsys']: - SConscript([ - 'radeon/SConscript', - ]) diff --git a/src/gallium/winsys/drm/i965/Makefile b/src/gallium/winsys/drm/i965/Makefile deleted file mode 100644 index d8feef6824a..00000000000 --- a/src/gallium/winsys/drm/i965/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/intel/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = gem $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/i965/SConscript b/src/gallium/winsys/drm/i965/SConscript deleted file mode 100644 index fdf57eedb94..00000000000 --- a/src/gallium/winsys/drm/i965/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['gem/SConscript',]) diff --git a/src/gallium/winsys/drm/i965/gem/Makefile b/src/gallium/winsys/drm/i965/gem/Makefile deleted file mode 100644 index 6a7497b6be3..00000000000 --- a/src/gallium/winsys/drm/i965/gem/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i965drm - -C_SOURCES = \ - i965_drm_buffer.c \ - i965_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/i965/gem/SConscript b/src/gallium/winsys/drm/i965/gem/SConscript deleted file mode 100644 index 6256ec6eaf0..00000000000 --- a/src/gallium/winsys/drm/i965/gem/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -Import('*') - -env = drienv.Clone() - -i965drm_sources = [ - 'i965_drm_api.c', - 'i965_drm_buffer.c', -] - -i965drm = env.ConvenienceLibrary( - target ='i965drm', - source = i965drm_sources, -) - -Export('i965drm') diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c deleted file mode 100644 index c644eedcb31..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c +++ /dev/null @@ -1,122 +0,0 @@ - -#include -#include "state_tracker/drm_api.h" - -#include "i965_drm_winsys.h" -#include "util/u_memory.h" - -#include "i965/brw_context.h" /* XXX: shouldn't be doing this */ -#include "i965/brw_screen.h" /* XXX: shouldn't be doing this */ - -#include "trace/tr_drm.h" - -#include "../../sw/sw_drm_api.h" - -/* - * Helper functions - */ - - -static void -i965_libdrm_get_device_id(unsigned int *device_id) -{ - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - sscanf(path, "%x", device_id); - fclose(file); -} - -static void -i965_libdrm_winsys_destroy(struct brw_winsys_screen *iws) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(iws); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - drm_intel_bufmgr_destroy(idws->gem); - - FREE(idws); -} - -static struct pipe_screen * -i965_libdrm_create_screen(struct drm_api *api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct i965_libdrm_winsys *idws; - unsigned int deviceID; - - debug_printf("%s\n", __FUNCTION__); - - if (arg != NULL) { - switch(arg->mode) { - case DRM_CREATE_NORMAL: - break; - default: - return NULL; - } - } - - idws = CALLOC_STRUCT(i965_libdrm_winsys); - if (!idws) - return NULL; - - i965_libdrm_get_device_id(&deviceID); - - i965_libdrm_winsys_init_buffer_functions(idws); - - idws->fd = drmFD; - idws->id = deviceID; - - idws->base.destroy = i965_libdrm_winsys_destroy; - - idws->gem = drm_intel_bufmgr_gem_init(idws->fd, BRW_BATCH_SIZE); - drm_intel_bufmgr_gem_enable_reuse(idws->gem); - - idws->send_cmd = !debug_get_bool_option("BRW_NO_HW", FALSE); - - return brw_create_screen(&idws->base, deviceID); -} - - -static void -destroy(struct drm_api *api) -{ - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - -} - -struct drm_api i965_libdrm_api = -{ - .name = "i965", - .create_screen = i965_libdrm_create_screen, - .destroy = destroy, -}; - -struct drm_api * -drm_api_create() -{ - struct drm_api *api = NULL; - - if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) - api = sw_drm_api_create(&i965_libdrm_api); - - if (api == NULL) - api = &i965_libdrm_api; - - return trace_drm_create(api); -} diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c deleted file mode 100644 index 33a17496b2b..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c +++ /dev/null @@ -1,503 +0,0 @@ - -#include "state_tracker/drm_api.h" -#include "i965_drm_winsys.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" - -#include "i915_drm.h" -#include "intel_bufmgr.h" - - - -const char *names[BRW_BUFFER_TYPE_MAX] = { - "TEXTURE", - "SCANOUT", - "VERTEX", - "CURBE", - "QUERY", - "SHADER_CONSTANTS", - "WM_SCRATCH", - "BATCH", - "GENERAL_STATE", - "SURFACE_STATE", - "PIXEL", - "GENERIC", -}; - -const char *usages[BRW_USAGE_MAX] = { - "STATE", - "QUERY_RESULT", - "RENDER_TARGET", - "DEPTH_BUFFER", - "BLIT_SOURCE", - "BLIT_DEST", - "SAMPLER", - "VERTEX", - "SCRATCH" -}; - - -const char *data_types[BRW_DATA_MAX] = -{ - "GS: CC_VP", - "GS: CC_UNIT", - "GS: WM_PROG", - "GS: SAMPLER_DEFAULT_COLOR", - "GS: SAMPLER", - "GS: WM_UNIT", - "GS: SF_PROG", - "GS: SF_VP", - "GS: SF_UNIT", - "GS: VS_UNIT", - "GS: VS_PROG", - "GS: GS_UNIT", - "GS: GS_PROG", - "GS: CLIP_VP", - "GS: CLIP_UNIT", - "GS: CLIP_PROG", - "SS: SURFACE", - "SS: SURF_BIND", - "CONSTANT DATA", - "BATCH DATA", - "(untyped)" -}; - -static enum pipe_error -i965_libdrm_bo_alloc(struct brw_winsys_screen *sws, - enum brw_buffer_type type, - unsigned size, - unsigned alignment, - struct brw_winsys_buffer **bo_out) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); - struct i965_libdrm_buffer *buf; - - if (BRW_DUMP) - debug_printf("%s type %s sz %d align %d\n", - __FUNCTION__, names[type], size, alignment ); - - buf = CALLOC_STRUCT(i965_libdrm_buffer); - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - switch (type) { - case BRW_BUFFER_TYPE_TEXTURE: -/* case BRW_BUFFER_TYPE_SCANOUT:*/ - case BRW_BUFFER_TYPE_VERTEX: - case BRW_BUFFER_TYPE_CURBE: - case BRW_BUFFER_TYPE_QUERY: - case BRW_BUFFER_TYPE_SHADER_CONSTANTS: - case BRW_BUFFER_TYPE_SHADER_SCRATCH: - case BRW_BUFFER_TYPE_BATCH: - case BRW_BUFFER_TYPE_GENERAL_STATE: - case BRW_BUFFER_TYPE_SURFACE_STATE: - case BRW_BUFFER_TYPE_PIXEL: - case BRW_BUFFER_TYPE_GENERIC: - break; - case BRW_BUFFER_TYPE_SCANOUT: - buf->map_gtt = TRUE; - break; - default: - assert(0); - break; - } - - buf->bo = drm_intel_bo_alloc(idws->gem, - names[type], - size, - alignment); - - if (!buf->bo) - goto err; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.size = size; - buf->base.sws = sws; - - *bo_out = &buf->base; - return PIPE_OK; - -err: - assert(0); - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static enum pipe_error -i965_libdrm_bo_from_handle(struct brw_winsys_screen *sws, - struct winsys_handle *whandle, - unsigned *stride, - unsigned *tile, - struct brw_winsys_buffer **bo_out) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); - struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); - uint32_t swizzle = 0; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - pipe_reference_init(&buf->base.reference, 1); - buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, "FROM_HANDLE", whandle->handle); - buf->base.size = buf->bo->size; - buf->base.sws = &idws->base; - buf->flinked = TRUE; - buf->flink = whandle->handle; - - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); - if (buf->tiling != 0) - buf->map_gtt = TRUE; - - *tile = buf->tiling; - *stride = whandle->stride; - - *bo_out = &buf->base; - return PIPE_OK; - -err: - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static enum pipe_error -i965_libdrm_bo_get_handle(struct brw_winsys_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return PIPE_ERROR_BAD_INPUT; - buf->flinked = TRUE; - } - - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } else { - assert(!"unknown usage"); - return PIPE_ERROR_BAD_INPUT; - } - - whandle->stride = stride; - return PIPE_OK; -} - -static void -i965_libdrm_bo_destroy(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - drm_intel_bo_unreference(buf->bo); - FREE(buffer); -} - -static enum pipe_error -i965_libdrm_bo_emit_reloc(struct brw_winsys_buffer *buffer, - enum brw_buffer_usage usage, - unsigned delta, - unsigned offset, - struct brw_winsys_buffer *buffer2) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_buffer *buf2 = i965_libdrm_buffer(buffer2); - int read, write; - int ret; - - if (BRW_DUMP) - debug_printf("%s buf %p offset %x delta %x buf2 %p/%s/%s\n", - __FUNCTION__, (void *)buffer, - offset, delta, - (void *)buffer2, names[buf2->data_type], usages[usage]); - - switch (usage) { - case BRW_USAGE_STATE: - read = I915_GEM_DOMAIN_INSTRUCTION; - write = 0; - break; - case BRW_USAGE_QUERY_RESULT: - read = I915_GEM_DOMAIN_INSTRUCTION; - write = I915_GEM_DOMAIN_INSTRUCTION; - break; - case BRW_USAGE_RENDER_TARGET: - read = I915_GEM_DOMAIN_RENDER; - write = 0; - break; - case BRW_USAGE_DEPTH_BUFFER: - read = I915_GEM_DOMAIN_RENDER; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_BLIT_SOURCE: - read = 0; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_BLIT_DEST: - read = I915_GEM_DOMAIN_RENDER; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_SAMPLER: - read = I915_GEM_DOMAIN_SAMPLER; - write = 0; - break; - case BRW_USAGE_VERTEX: - read = I915_GEM_DOMAIN_VERTEX; - write = 0; - break; - case BRW_USAGE_SCRATCH: - read = 0; - write = 0; - break; - default: - assert(0); - return -1; - } - - /* Needed?? - ((uint32_t *)buf->bo->virtual)[offset/4] = (delta + - buf2->bo->offset); - */ - - ret = dri_bo_emit_reloc( buf->bo, read, write, delta, offset, buf2->bo ); - if (ret) - return -1; - - return 0; -} - -static enum pipe_error -i965_libdrm_bo_exec(struct brw_winsys_buffer *buffer, - unsigned bytes_used) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - int ret; - - if (BRW_DUMP) - debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); - - if (idws->send_cmd) { - ret = dri_bo_exec(buf->bo, bytes_used, NULL, 0, 0); - if (ret) - return PIPE_ERROR; - } - - return PIPE_OK; -} - -static enum pipe_error -i965_libdrm_bo_subdata(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - size_t offset, - size_t size, - const void *data, - const struct brw_winsys_reloc *reloc, - unsigned nr_reloc) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - int ret, i; - - (void)data_type; - - if (BRW_DUMP) - debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", - __FUNCTION__, - (void *)buffer, offset, size, - data_types[data_type], - nr_reloc); - - if (BRW_DUMP) - brw_dump_data( idws->id, - data_type, - buf->bo->offset + offset, - data, size ); - - /* XXX: use bo_map_gtt/memcpy/unmap_gtt under some circumstances??? - */ - ret = drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); - if (ret) - return PIPE_ERROR; - - for (i = 0; i < nr_reloc; i++) { - i965_libdrm_bo_emit_reloc(buffer, reloc[i].usage, reloc[i].delta, - reloc[i].offset, reloc[i].bo); - } - - return PIPE_OK; -} - -static boolean -i965_libdrm_bo_is_busy(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - boolean ret; - - if (BRW_DUMP) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - - ret = drm_intel_bo_busy(buf->bo); - - if (BRW_DUMP) - debug_printf(" --> %d\n", ret); - - return ret; -} - -static boolean -i965_libdrm_bo_references(struct brw_winsys_buffer *a, - struct brw_winsys_buffer *b) -{ - struct i965_libdrm_buffer *bufa = i965_libdrm_buffer(a); - struct i965_libdrm_buffer *bufb = i965_libdrm_buffer(b); - boolean ret; - - if (BRW_DUMP) - debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); - - ret = drm_intel_bo_references(bufa->bo, bufb->bo); - - if (BRW_DUMP) - debug_printf(" --> %d\n", ret); - - return ret; -} - -/* XXX: couldn't this be handled by returning true/false on - * bo_emit_reloc? - */ -static enum pipe_error -i965_libdrm_check_aperture_space(struct brw_winsys_screen *iws, - struct brw_winsys_buffer **buffers, - unsigned count) -{ - static drm_intel_bo *bos[128]; - int i; - int ret; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (count > Elements(bos)) { - assert(0); - return FALSE; - } - - for (i = 0; i < count; i++) - bos[i] = i965_libdrm_buffer(buffers[i])->bo; - - /* XXX: converting from ??? to pipe_error: - */ - ret = dri_bufmgr_check_aperture_space(bos, count); - - if (BRW_DUMP) - debug_printf(" --> %d (ok == %d)\n", ret, PIPE_OK); - - return ret; -} - -static void * -i965_libdrm_bo_map(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - unsigned offset, - unsigned length, - boolean write, - boolean discard, - boolean flush_explicit) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - int ret; - - - if (BRW_DUMP) - debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, - write ? "read/write" : "read", - write ? data_types[data_type] : ""); - - if (!buf->map_count) { - if (buf->map_gtt) { - ret = drm_intel_gem_bo_map_gtt(buf->bo); - if (ret) - return NULL; - } - else { - ret = drm_intel_bo_map(buf->bo, write); - if (ret) - return NULL; - } - } - - buf->data_type = data_type; - buf->map_count++; - return buf->bo->virtual; -} - -static void -i965_libdrm_bo_flush_range(struct brw_winsys_buffer *buffer, - unsigned offset, - unsigned length) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - - if (BRW_DUMP) - debug_printf("%s %s offset %d len %d\n", __FUNCTION__, - data_types[buf->data_type], - offset, length); - - if (BRW_DUMP) - brw_dump_data( idws->id, - buf->data_type, - buf->bo->offset + offset, - buf->bo->virtual + offset, - length ); -} - -static void -i965_libdrm_bo_unmap(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (--buf->map_count > 0) - return; - - if (buf->map_gtt) - drm_intel_gem_bo_unmap_gtt(buf->bo); - else - drm_intel_bo_unmap(buf->bo); -} - -void -i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws) -{ - idws->base.bo_alloc = i965_libdrm_bo_alloc; - idws->base.bo_from_handle = i965_libdrm_bo_from_handle; - idws->base.bo_get_handle = i965_libdrm_bo_get_handle; - idws->base.bo_destroy = i965_libdrm_bo_destroy; - idws->base.bo_emit_reloc = i965_libdrm_bo_emit_reloc; - idws->base.bo_exec = i965_libdrm_bo_exec; - idws->base.bo_subdata = i965_libdrm_bo_subdata; - idws->base.bo_is_busy = i965_libdrm_bo_is_busy; - idws->base.bo_references = i965_libdrm_bo_references; - idws->base.check_aperture_space = i965_libdrm_check_aperture_space; - idws->base.bo_map = i965_libdrm_bo_map; - idws->base.bo_flush_range = i965_libdrm_bo_flush_range; - idws->base.bo_unmap = i965_libdrm_bo_unmap; -} diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h b/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h deleted file mode 100644 index c6a7d4a8c51..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h +++ /dev/null @@ -1,64 +0,0 @@ - -#ifndef INTEL_DRM_WINSYS_H -#define INTEL_DRM_WINSYS_H - -#include "i965/brw_winsys.h" - -#include "drm.h" -#include "intel_bufmgr.h" - - - -/* - * Winsys - */ - - -struct i965_libdrm_winsys -{ - struct brw_winsys_screen base; - drm_intel_bufmgr *gem; - - boolean send_cmd; - - int fd; /**< Drm file discriptor */ - - unsigned id; -}; - -static INLINE struct i965_libdrm_winsys * -i965_libdrm_winsys(struct brw_winsys_screen *iws) -{ - return (struct i965_libdrm_winsys *)iws; -} - -struct i965_libdrm_winsys *i965_libdrm_winsys_create(int fd, unsigned pci_id); - -void i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws); - - -/* Buffer. - */ -struct i965_libdrm_buffer { - struct brw_winsys_buffer base; - - drm_intel_bo *bo; - - void *ptr; - unsigned map_count; - unsigned data_type; /* valid while mapped */ - unsigned tiling; - - boolean map_gtt; - boolean flinked; - unsigned flink; -}; - -static INLINE struct i965_libdrm_buffer * -i965_libdrm_buffer(struct brw_winsys_buffer *buffer) -{ - return (struct i965_libdrm_buffer *)buffer; -} - - -#endif diff --git a/src/gallium/winsys/drm/i965/xlib/Makefile b/src/gallium/winsys/drm/i965/xlib/Makefile deleted file mode 100644 index 0efa0ca6f9a..00000000000 --- a/src/gallium/winsys/drm/i965/xlib/Makefile +++ /dev/null @@ -1,97 +0,0 @@ -# src/gallium/winsys/xlib/Makefile - -# This makefile produces a "stand-alone" libGL.so which is based on -# Xlib (no DRI HW acceleration) - - -TOP = ../../../../../.. -include $(TOP)/configs/current - - -GL_MAJOR = 1 -GL_MINOR = 5 -GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) - - -INCLUDE_DIRS = \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/drivers/i965 \ - -I$(TOP)/src/gallium/drivers/i965/include \ - -I$(TOP)/src/gallium/state_trackers/glx/xlib \ - -I$(TOP)/src/gallium/auxiliary \ - -I/usr/include/drm - -XLIB_WINSYS_SOURCES = \ - xlib_i965.c \ - - - -XLIB_WINSYS_OBJECTS = $(XLIB_WINSYS_SOURCES:.c=.o) - - - -LIBS = \ - $(TOP)/src/gallium/drivers/i965/libi965.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ - $(TOP)/src/mesa/libglapi.a \ - $(TOP)/src/mesa/libmesagallium.a \ - $(GALLIUM_AUXILIARIES) - -# $(TOP)/src/gallium/drivers/i965/lib/libi9xx.a \ - -.SUFFIXES : .cpp - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ - -.cpp.o: - $(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CXXFLAGS) $< -o $@ - - - -default: $(TOP)/$(LIB_DIR)/gallium $(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME) - -$(TOP)/$(LIB_DIR)/gallium: - @ mkdir -p $(TOP)/$(LIB_DIR)/gallium - -# Make the libGL.so library -$(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME): $(XLIB_WINSYS_OBJECTS) $(LIBS) Makefile - $(TOP)/bin/mklib -o $(GL_LIB) \ - -linker "$(CC)" \ - -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ - -install $(TOP)/$(LIB_DIR)/gallium \ - $(MKLIB_OPTIONS) $(XLIB_WINSYS_OBJECTS) \ - -Wl,--start-group $(LIBS) -Wl,--end-group $(GL_LIB_DEPS) - - -depend: $(XLIB_WINSYS_SOURCES) - @ echo "running $(MKDEP)" - @ rm -f depend # workaround oops on gutsy?!? - @ touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(XLIB_WINSYS_SOURCES) \ - > /dev/null 2>/dev/null - - -install: default - $(INSTALL) -d $(INSTALL_DIR)/include/GL - $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR) - $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL - @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \ - $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \ - fi - - -# Emacs tags -tags: - etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h - -clean: - -rm -f *.o - - -include depend diff --git a/src/gallium/winsys/drm/i965/xlib/xlib_i965.c b/src/gallium/winsys/drm/i965/xlib/xlib_i965.c deleted file mode 100644 index 063e9f600b9..00000000000 --- a/src/gallium/winsys/drm/i965/xlib/xlib_i965.c +++ /dev/null @@ -1,503 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA - * 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/* - * Authors: - * Keith Whitwell - * Brian Paul - */ - - -#include "util/u_memory.h" -#include "util/u_math.h" -#include "pipe/p_error.h" -#include "pipe/p_context.h" - -#include "xm_public.h" - -#include "i965/brw_winsys.h" -#include "i965/brw_screen.h" -#include "i965/brw_reg.h" -#include "i965/brw_structs_dump.h" - -#define MAX_VRAM (128*1024*1024) - - - -extern int brw_disasm (FILE *file, - const struct brw_instruction *inst, - unsigned count ); - -extern int intel_decode(const uint32_t *data, - int count, - uint32_t hw_offset, - uint32_t devid); - -struct xlib_brw_buffer -{ - struct brw_winsys_buffer base; - char *virtual; - unsigned offset; - unsigned type; - int map_count; - boolean modified; -}; - - -/** - * Subclass of brw_winsys_screen for Xlib winsys - */ -struct xlib_brw_winsys -{ - struct brw_winsys_screen base; - struct brw_chipset chipset; - - unsigned size; - unsigned used; -}; - -static struct xlib_brw_winsys * -xlib_brw_winsys( struct brw_winsys_screen *screen ) -{ - return (struct xlib_brw_winsys *)screen; -} - - -static struct xlib_brw_buffer * -xlib_brw_buffer( struct brw_winsys_buffer *buffer ) -{ - return (struct xlib_brw_buffer *)buffer; -} - - - -const char *names[BRW_BUFFER_TYPE_MAX] = { - "TEXTURE", - "SCANOUT", - "VERTEX", - "CURBE", - "QUERY", - "SHADER_CONSTANTS", - "WM_SCRATCH", - "BATCH", - "GENERAL_STATE", - "SURFACE_STATE", - "PIXEL", - "GENERIC", -}; - -const char *usages[BRW_USAGE_MAX] = { - "STATE", - "QUERY_RESULT", - "RENDER_TARGET", - "DEPTH_BUFFER", - "BLIT_SOURCE", - "BLIT_DEST", - "SAMPLER", - "VERTEX", - "SCRATCH" -}; - - -const char *data_types[BRW_DATA_MAX] = -{ - "GS: CC_VP", - "GS: CC_UNIT", - "GS: WM_PROG", - "GS: SAMPLER_DEFAULT_COLOR", - "GS: SAMPLER", - "GS: WM_UNIT", - "GS: SF_PROG", - "GS: SF_VP", - "GS: SF_UNIT", - "GS: VS_UNIT", - "GS: VS_PROG", - "GS: GS_UNIT", - "GS: GS_PROG", - "GS: CLIP_VP", - "GS: CLIP_UNIT", - "GS: CLIP_PROG", - "SS: SURFACE", - "SS: SURF_BIND", - "CONSTANT DATA", - "BATCH DATA", - "(untyped)" -}; - - -static enum pipe_error -xlib_brw_bo_alloc( struct brw_winsys_screen *sws, - enum brw_buffer_type type, - unsigned size, - unsigned alignment, - struct brw_winsys_buffer **bo_out ) -{ - struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); - struct xlib_brw_buffer *buf; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s type %s sz %d align %d\n", - __FUNCTION__, names[type], size, alignment ); - - buf = CALLOC_STRUCT(xlib_brw_buffer); - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - pipe_reference_init(&buf->base.reference, 1); - - buf->offset = align(xbw->used, alignment); - buf->type = type; - buf->virtual = MALLOC(size); - buf->base.size = size; - buf->base.sws = sws; - - xbw->used = align(xbw->used, alignment) + size; - if (xbw->used > MAX_VRAM) - goto err; - - /* XXX: possibly rentrant call to bo_destroy: - */ - bo_reference(bo_out, &buf->base); - return PIPE_OK; - -err: - assert(0); - FREE(buf->virtual); - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static void -xlib_brw_bo_destroy( struct brw_winsys_buffer *buffer ) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - FREE(buf); -} - -static int -xlib_brw_bo_emit_reloc( struct brw_winsys_buffer *buffer, - enum brw_buffer_usage usage, - unsigned delta, - unsigned offset, - struct brw_winsys_buffer *buffer2) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - struct xlib_brw_buffer *buf2 = xlib_brw_buffer(buffer2); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s buf %p offset %x val %x + %x buf2 %p/%s/%s\n", - __FUNCTION__, (void *)buffer, offset, - buf2->offset, delta, - (void *)buffer2, names[buf2->type], usages[usage]); - - *(uint32_t *)(buf->virtual + offset) = buf2->offset + delta; - - return 0; -} - -static int -xlib_brw_bo_exec( struct brw_winsys_buffer *buffer, - unsigned bytes_used ) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); - - return 0; -} - - - - -static int -xlib_brw_bo_subdata(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - size_t offset, - size_t size, - const void *data, - const struct brw_winsys_reloc *reloc, - unsigned nr_relocs) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - struct xlib_brw_winsys *xbw = xlib_brw_winsys(buffer->sws); - unsigned i; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", - __FUNCTION__, - (void *)buffer, offset, size, - data_types[data_type], - nr_relocs); - - assert(buf->base.size >= offset + size); - memcpy(buf->virtual + offset, data, size); - - /* Apply the relocations: - */ - for (i = 0; i < nr_relocs; i++) { - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("\treloc[%d] usage %s off %d value %x+%x\n", - i, usages[reloc[i].usage], reloc[i].offset, - xlib_brw_buffer(reloc[i].bo)->offset, reloc[i].delta); - - *(unsigned *)(buf->virtual + offset + reloc[i].offset) = - xlib_brw_buffer(reloc[i].bo)->offset + reloc[i].delta; - } - - if (BRW_DUMP) - brw_dump_data( xbw->chipset.pci_id, - data_type, - buf->offset + offset, - buf->virtual + offset, size ); - - - return 0; -} - - -static boolean -xlib_brw_bo_is_busy(struct brw_winsys_buffer *buffer) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - return TRUE; -} - -static boolean -xlib_brw_bo_references(struct brw_winsys_buffer *a, - struct brw_winsys_buffer *b) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); - return TRUE; -} - -static enum pipe_error -xlib_brw_check_aperture_space( struct brw_winsys_screen *iws, - struct brw_winsys_buffer **buffers, - unsigned count ) -{ - unsigned tot_size = 0; - unsigned i; - - for (i = 0; i < count; i++) - tot_size += buffers[i]->size; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %d bufs, tot_size: %d kb\n", - __FUNCTION__, count, - (tot_size + 1023) / 1024); - - return PIPE_OK; -} - -static void * -xlib_brw_bo_map(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - unsigned offset, - unsigned length, - boolean write, - boolean discard, - boolean explicit) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, - write ? "read/write" : "read", - write ? data_types[data_type] : ""); - - if (write) - buf->modified = 1; - - buf->map_count++; - return buf->virtual; -} - - -static void -xlib_brw_bo_flush_range( struct brw_winsys_buffer *buffer, - unsigned offset, - unsigned length ) -{ -} - - -static void -xlib_brw_bo_unmap(struct brw_winsys_buffer *buffer) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - - --buf->map_count; - assert(buf->map_count >= 0); - - if (buf->map_count == 0 && - buf->modified) { - - buf->modified = 0; - - /* Consider dumping new buffer contents here, using the - * flush-range info to minimize verbosity. - */ - } -} - - -static void -xlib_brw_bo_wait_idle( struct brw_winsys_buffer *buffer ) -{ -} - - -static void -xlib_brw_winsys_destroy( struct brw_winsys_screen *sws ) -{ - struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); - - FREE(xbw); -} - -static struct brw_winsys_screen * -xlib_create_brw_winsys_screen( void ) -{ - struct xlib_brw_winsys *ws; - - ws = CALLOC_STRUCT(xlib_brw_winsys); - if (!ws) - return NULL; - - ws->used = 0; - - ws->base.destroy = xlib_brw_winsys_destroy; - ws->base.bo_alloc = xlib_brw_bo_alloc; - ws->base.bo_destroy = xlib_brw_bo_destroy; - ws->base.bo_emit_reloc = xlib_brw_bo_emit_reloc; - ws->base.bo_exec = xlib_brw_bo_exec; - ws->base.bo_subdata = xlib_brw_bo_subdata; - ws->base.bo_is_busy = xlib_brw_bo_is_busy; - ws->base.bo_references = xlib_brw_bo_references; - ws->base.check_aperture_space = xlib_brw_check_aperture_space; - ws->base.bo_map = xlib_brw_bo_map; - ws->base.bo_flush_range = xlib_brw_bo_flush_range; - ws->base.bo_unmap = xlib_brw_bo_unmap; - ws->base.bo_wait_idle = xlib_brw_bo_wait_idle; - - return &ws->base; -} - - -/*********************************************************************** - * Implementation of Xlib co-state-tracker's winsys interface - */ - -static void -xlib_i965_display_surface(struct xmesa_buffer *xm_buffer, - struct pipe_surface *surf) -{ - struct brw_surface *surface = brw_surface(surf); - struct xlib_brw_buffer *bo = xlib_brw_buffer(surface->bo); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s offset %x+%x sz %dx%d\n", __FUNCTION__, - bo->offset, - surface->draw_offset, - surf->width, - surf->height); -} - -static void -xlib_i965_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, - void *context_private) -{ - xlib_i965_display_surface(NULL, surf); -} - - -static struct pipe_screen * -xlib_create_i965_screen( void ) -{ - struct brw_winsys_screen *winsys; - struct pipe_screen *screen; - - winsys = xlib_create_brw_winsys_screen(); - if (winsys == NULL) - return NULL; - - screen = brw_create_screen(winsys, PCI_CHIP_GM45_GM); - if (screen == NULL) - goto fail; - - xlib_brw_winsys(winsys)->chipset = brw_screen(screen)->chipset; - - screen->flush_frontbuffer = xlib_i965_flush_frontbuffer; - return screen; - -fail: - if (winsys) - winsys->destroy( winsys ); - - return NULL; -} - - - - - -struct xm_driver xlib_i965_driver = -{ - .create_pipe_screen = xlib_create_i965_screen, - .display_surface = xlib_i965_display_surface -}; - - -/* Register this driver at library load: - */ -static void _init( void ) __attribute__((constructor)); -static void _init( void ) -{ - xmesa_set_driver( &xlib_i965_driver ); -} - - - -/*********************************************************************** - * - * Butt-ugly hack to convince the linker not to throw away public GL - * symbols (they are all referenced from getprocaddress, I guess). - */ -extern void (*linker_foo(const unsigned char *procName))(); -extern void (*glXGetProcAddress(const unsigned char *procName))(); - -extern void (*linker_foo(const unsigned char *procName))() -{ - return glXGetProcAddress(procName); -} diff --git a/src/gallium/winsys/drm/intel/Makefile b/src/gallium/winsys/drm/intel/Makefile deleted file mode 100644 index d8feef6824a..00000000000 --- a/src/gallium/winsys/drm/intel/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/intel/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = gem $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/intel/SConscript b/src/gallium/winsys/drm/intel/SConscript deleted file mode 100644 index fdf57eedb94..00000000000 --- a/src/gallium/winsys/drm/intel/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['gem/SConscript',]) diff --git a/src/gallium/winsys/drm/intel/gem/Makefile b/src/gallium/winsys/drm/intel/gem/Makefile deleted file mode 100644 index 0d6d4e37dbd..00000000000 --- a/src/gallium/winsys/drm/intel/gem/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = inteldrm - -C_SOURCES = \ - intel_drm_batchbuffer.c \ - intel_drm_buffer.c \ - intel_drm_fence.c \ - intel_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/intel/gem/SConscript b/src/gallium/winsys/drm/intel/gem/SConscript deleted file mode 100644 index 26717f391fa..00000000000 --- a/src/gallium/winsys/drm/intel/gem/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('*') - -env = drienv.Clone() - -inteldrm_sources = [ - 'intel_drm_api.c', - 'intel_drm_batchbuffer.c', - 'intel_drm_buffer.c', - 'intel_drm_fence.c', -] - -inteldrm = env.ConvenienceLibrary( - target ='inteldrm', - source = inteldrm_sources, -) - -Export('inteldrm') diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c deleted file mode 100644 index e3b980a832b..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c +++ /dev/null @@ -1,109 +0,0 @@ -#include - -#include "state_tracker/drm_api.h" - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915/i915_context.h" -#include "i915/i915_screen.h" - -#include "trace/tr_drm.h" - -/* - * Helper functions - */ - - -static void -intel_drm_get_device_id(unsigned int *device_id) -{ - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - (void) shutup_gcc; - sscanf(path, "%x", device_id); - fclose(file); -} - -static void -intel_drm_winsys_destroy(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - - drm_intel_bufmgr_destroy(idws->pools.gem); - - FREE(idws); -} - -static struct pipe_screen * -intel_drm_create_screen(struct drm_api *api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct intel_drm_winsys *idws; - unsigned int deviceID; - - if (arg != NULL) { - switch(arg->mode) { - case DRM_CREATE_NORMAL: - break; - default: - return NULL; - } - } - - idws = CALLOC_STRUCT(intel_drm_winsys); - if (!idws) - return NULL; - - intel_drm_get_device_id(&deviceID); - - intel_drm_winsys_init_batchbuffer_functions(idws); - intel_drm_winsys_init_buffer_functions(idws); - intel_drm_winsys_init_fence_functions(idws); - - idws->fd = drmFD; - idws->id = deviceID; - idws->max_batch_size = 16 * 4096; - - idws->base.destroy = intel_drm_winsys_destroy; - - idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); - drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); - - idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); - - return i915_create_screen(&idws->base, deviceID); -} - -static void -destroy(struct drm_api *api) -{ - -} - -struct drm_api intel_drm_api = -{ - .name = "i915", - .driver_name = "i915", - .create_screen = intel_drm_create_screen, - .destroy = destroy, -}; - -struct drm_api * -drm_api_create() -{ - return trace_drm_create(&intel_drm_api); -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c b/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c deleted file mode 100644 index 5b4dafc8e41..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c +++ /dev/null @@ -1,244 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -#define BATCH_RESERVED 16 - -#define INTEL_DEFAULT_RELOCS 100 -#define INTEL_MAX_RELOCS 400 - -#define INTEL_BATCH_NO_CLIPRECTS 0x1 -#define INTEL_BATCH_CLIPRECTS 0x2 - -#undef INTEL_RUN_SYNC -#undef INTEL_MAP_BATCHBUFFER -#undef INTEL_MAP_GTT -#define INTEL_ALWAYS_FLUSH - -struct intel_drm_batchbuffer -{ - struct intel_batchbuffer base; - - size_t actual_size; - - drm_intel_bo *bo; -}; - -static INLINE struct intel_drm_batchbuffer * -intel_drm_batchbuffer(struct intel_batchbuffer *batch) -{ - return (struct intel_drm_batchbuffer *)batch; -} - -static void -intel_drm_batchbuffer_reset(struct intel_drm_batchbuffer *batch) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(batch->base.iws); - int ret; - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - batch->bo = drm_intel_bo_alloc(idws->pools.gem, - "gallium3d_batchbuffer", - batch->actual_size, - 4096); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - ret = drm_intel_gem_bo_map_gtt(batch->bo); -#else - ret = drm_intel_bo_map(batch->bo, TRUE); -#endif - assert(ret == 0); - batch->base.map = batch->bo->virtual; -#else - (void)ret; -#endif - - memset(batch->base.map, 0, batch->actual_size); - batch->base.ptr = batch->base.map; - batch->base.size = batch->actual_size - BATCH_RESERVED; - batch->base.relocs = 0; -} - -static struct intel_batchbuffer * -intel_drm_batchbuffer_create(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_batchbuffer *batch = CALLOC_STRUCT(intel_drm_batchbuffer); - - batch->actual_size = idws->max_batch_size; - -#ifdef INTEL_MAP_BATCHBUFFER - batch->base.map = NULL; -#else - batch->base.map = MALLOC(batch->actual_size); -#endif - batch->base.ptr = NULL; - batch->base.size = 0; - - batch->base.relocs = 0; - batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ - - batch->base.iws = iws; - - intel_drm_batchbuffer_reset(batch); - - return &batch->base; -} - -static int -intel_drm_batchbuffer_reloc(struct intel_batchbuffer *ibatch, - struct intel_buffer *buffer, - enum intel_buffer_usage usage, - unsigned pre_add) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned write_domain = 0; - unsigned read_domain = 0; - unsigned offset; - int ret = 0; - - assert(batch->base.relocs < batch->base.max_relocs); - - if (usage == INTEL_USAGE_SAMPLER) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_SAMPLER; - - } else if (usage == INTEL_USAGE_RENDER) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_TARGET) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_SOURCE) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_VERTEX) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_VERTEX; - - } else { - assert(0); - return -1; - } - - offset = (unsigned)(batch->base.ptr - batch->base.map); - - ret = drm_intel_bo_emit_reloc(batch->bo, offset, - intel_bo(buffer), pre_add, - read_domain, - write_domain); - - ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; - batch->base.ptr += 4; - - if (!ret) - batch->base.relocs++; - - return ret; -} - -static void -intel_drm_batchbuffer_flush(struct intel_batchbuffer *ibatch, - struct pipe_fence_handle **fence) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned used = 0; - int ret = 0; - int i; - - assert(intel_batchbuffer_space(ibatch) >= 0); - - used = batch->base.ptr - batch->base.map; - assert((used & 3) == 0); - - -#ifdef INTEL_ALWAYS_FLUSH - /* MI_FLUSH | FLUSH_MAP_CACHE */ - intel_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); - used += 4; -#endif - - if ((used & 4) == 0) { - /* MI_NOOP */ - intel_batchbuffer_dword(ibatch, 0); - } - /* MI_BATCH_BUFFER_END */ - intel_batchbuffer_dword(ibatch, (0xA<<23)); - - used = batch->base.ptr - batch->base.map; - assert((used & 4) == 0); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - drm_intel_gem_bo_unmap_gtt(batch->bo); -#else - drm_intel_bo_unmap(batch->bo); -#endif -#else - drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); -#endif - - /* Do the sending to HW */ - ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); - assert(ret == 0); - - if (intel_drm_winsys(ibatch->iws)->dump_cmd) { - unsigned *ptr; - drm_intel_bo_map(batch->bo, FALSE); - ptr = (unsigned*)batch->bo->virtual; - - debug_printf("%s:\n", __func__); - for (i = 0; i < used / 4; i++, ptr++) { - debug_printf("\t%08x: %08x\n", i*4, *ptr); - } - - drm_intel_bo_unmap(batch->bo); - } else { -#ifdef INTEL_RUN_SYNC - drm_intel_bo_map(batch->bo, FALSE); - drm_intel_bo_unmap(batch->bo); -#endif - } - - if (fence) { - ibatch->iws->fence_reference(ibatch->iws, fence, NULL); - -#ifdef INTEL_RUN_SYNC - /* we run synced to GPU so just pass null */ - (*fence) = intel_drm_fence_create(NULL); -#else - (*fence) = intel_drm_fence_create(batch->bo); -#endif - } - - intel_drm_batchbuffer_reset(batch); -} - -static void -intel_drm_batchbuffer_destroy(struct intel_batchbuffer *ibatch) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - -#ifndef INTEL_MAP_BATCHBUFFER - FREE(batch->base.map); -#endif - FREE(batch); -} - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.batchbuffer_create = intel_drm_batchbuffer_create; - idws->base.batchbuffer_reloc = intel_drm_batchbuffer_reloc; - idws->base.batchbuffer_flush = intel_drm_batchbuffer_flush; - idws->base.batchbuffer_destroy = intel_drm_batchbuffer_destroy; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c b/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c deleted file mode 100644 index cb4f92a3b17..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c +++ /dev/null @@ -1,217 +0,0 @@ - -#include "state_tracker/drm_api.h" -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -static struct intel_buffer * -intel_drm_buffer_create(struct intel_winsys *iws, - unsigned size, unsigned alignment, - enum intel_buffer_type type) -{ - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - drm_intel_bufmgr *pool; - char *name; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->flinked = FALSE; - buf->flink = 0; - buf->map_gtt = FALSE; - - if (type == INTEL_NEW_TEXTURE) { - name = "gallium3d_texture"; - pool = idws->pools.gem; - } else if (type == INTEL_NEW_VERTEX) { - name = "gallium3d_vertex"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else if (type == INTEL_NEW_SCANOUT) { - name = "gallium3d_scanout"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else { - assert(0); - name = "gallium3d_unknown"; - pool = idws->pools.gem; - } - - buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); - - if (!buf->bo) - goto err; - - return (struct intel_buffer *)buf; - -err: - assert(0); - FREE(buf); - return NULL; -} - -static struct intel_buffer * -intel_drm_buffer_from_handle(struct intel_winsys *iws, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - uint32_t tile = 0, swizzle = 0; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); - buf->flinked = TRUE; - buf->flink = whandle->handle; - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); - if (tile != INTEL_TILE_NONE) - buf->map_gtt = TRUE; - - *stride = whandle->stride; - - return (struct intel_buffer *)buf; - -err: - FREE(buf); - return NULL; -} - -static boolean -intel_drm_buffer_get_handle(struct intel_winsys *iws, - struct intel_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return FALSE; - buf->flinked = TRUE; - } - - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } else { - assert(!"unknown usage"); - return FALSE; - } - - whandle->stride = stride; - return TRUE; -} - -static int -intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, - struct intel_buffer *buffer, - unsigned stride, - enum intel_buffer_tile tile) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - assert(I915_TILING_NONE == INTEL_TILE_NONE); - assert(I915_TILING_X == INTEL_TILE_X); - assert(I915_TILING_Y == INTEL_TILE_Y); - - if (tile != INTEL_TILE_NONE) { - assert(buf->map_count == 0); - buf->map_gtt = TRUE; - } - - return drm_intel_bo_set_tiling(buf->bo, &tile, stride); -} - -static void * -intel_drm_buffer_map(struct intel_winsys *iws, - struct intel_buffer *buffer, - boolean write) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - drm_intel_bo *bo = intel_bo(buffer); - int ret = 0; - - assert(bo); - - if (buf->map_count) - goto out; - - if (buf->map_gtt) - ret = drm_intel_gem_bo_map_gtt(bo); - else - ret = drm_intel_bo_map(bo, write); - - buf->ptr = bo->virtual; - - assert(ret == 0); -out: - if (ret) - return NULL; - - buf->map_count++; - return buf->ptr; -} - -static void -intel_drm_buffer_unmap(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (--buf->map_count) - return; - - if (buf->map_gtt) - drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); - else - drm_intel_bo_unmap(intel_bo(buffer)); -} - -static int -intel_drm_buffer_write(struct intel_winsys *iws, - struct intel_buffer *buffer, - size_t offset, - size_t size, - const void *data) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); -} - -static void -intel_drm_buffer_destroy(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - drm_intel_bo_unreference(intel_bo(buffer)); - -#ifdef DEBUG - intel_drm_buffer(buffer)->magic = 0; - intel_drm_buffer(buffer)->bo = NULL; -#endif - - FREE(buffer); -} - -void -intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.buffer_create = intel_drm_buffer_create; - idws->base.buffer_from_handle = intel_drm_buffer_from_handle; - idws->base.buffer_get_handle = intel_drm_buffer_get_handle; - idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; - idws->base.buffer_map = intel_drm_buffer_map; - idws->base.buffer_unmap = intel_drm_buffer_unmap; - idws->base.buffer_write = intel_drm_buffer_write; - idws->base.buffer_destroy = intel_drm_buffer_destroy; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c b/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c deleted file mode 100644 index 102faedfeae..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" -#include "util/u_atomic.h" -#include "util/u_inlines.h" - -/** - * Because gem does not have fence's we have to create our own fences. - * - * They work by keeping the batchbuffer around and checking if that has - * been idled. If bo is NULL fence has expired. - */ -struct intel_drm_fence -{ - struct pipe_reference reference; - drm_intel_bo *bo; -}; - - -struct pipe_fence_handle * -intel_drm_fence_create(drm_intel_bo *bo) -{ - struct intel_drm_fence *fence = CALLOC_STRUCT(intel_drm_fence); - - pipe_reference_init(&fence->reference, 1); - /* bo is null if fence already expired */ - if (bo) { - drm_intel_bo_reference(bo); - fence->bo = bo; - } - - return (struct pipe_fence_handle *)fence; -} - -static void -intel_drm_fence_reference(struct intel_winsys *iws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *old = (struct intel_drm_fence *)*ptr; - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - if (pipe_reference(&((struct intel_drm_fence *)(*ptr))->reference, &f->reference)) { - if (old->bo) - drm_intel_bo_unreference(old->bo); - FREE(old); - } - *ptr = fence; -} - -static int -intel_drm_fence_signalled(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - assert(0); - - return 0; -} - -static int -intel_drm_fence_finish(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - /* fence already expired */ - if (!f->bo) - return 0; - - drm_intel_bo_wait_rendering(f->bo); - drm_intel_bo_unreference(f->bo); - f->bo = NULL; - - return 0; -} - -void -intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws) -{ - idws->base.fence_reference = intel_drm_fence_reference; - idws->base.fence_signalled = intel_drm_fence_signalled; - idws->base.fence_finish = intel_drm_fence_finish; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h b/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h deleted file mode 100644 index 9786ee93650..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h +++ /dev/null @@ -1,77 +0,0 @@ - -#ifndef INTEL_DRM_WINSYS_H -#define INTEL_DRM_WINSYS_H - -#include "i915/intel_batchbuffer.h" - -#include "drm.h" -#include "intel_bufmgr.h" - - -/* - * Winsys - */ - - -struct intel_drm_winsys -{ - struct intel_winsys base; - - boolean dump_cmd; - - int fd; /**< Drm file discriptor */ - - unsigned id; - - size_t max_batch_size; - - struct { - drm_intel_bufmgr *gem; - } pools; -}; - -static INLINE struct intel_drm_winsys * -intel_drm_winsys(struct intel_winsys *iws) -{ - return (struct intel_drm_winsys *)iws; -} - -struct intel_drm_winsys * intel_drm_winsys_create(int fd, unsigned pci_id); -struct pipe_fence_handle * intel_drm_fence_create(drm_intel_bo *bo); - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws); - - -/* - * Buffer - */ - - -struct intel_drm_buffer { - unsigned magic; - - drm_intel_bo *bo; - - void *ptr; - unsigned map_count; - boolean map_gtt; - - boolean flinked; - unsigned flink; -}; - -static INLINE struct intel_drm_buffer * -intel_drm_buffer(struct intel_buffer *buffer) -{ - return (struct intel_drm_buffer *)buffer; -} - -static INLINE drm_intel_bo * -intel_bo(struct intel_buffer *buffer) -{ - return intel_drm_buffer(buffer)->bo; -} - -#endif diff --git a/src/gallium/winsys/drm/nouveau/Makefile b/src/gallium/winsys/drm/nouveau/Makefile deleted file mode 100644 index 6c9cbef26df..00000000000 --- a/src/gallium/winsys/drm/nouveau/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/nouveau/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = drm $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/nouveau/drm/Makefile b/src/gallium/winsys/drm/nouveau/drm/Makefile deleted file mode 100644 index 54c3b26c755..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = nouveaudrm - -C_SOURCES = nouveau_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-I) -LIBRARY_DEFINES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h b/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h deleted file mode 100644 index 1207c2d609c..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _NOUVEAU_DRI_ -#define _NOUVEAU_DRI_ - -#include "xf86drm.h" -#include "drm.h" -#include "nouveau_drm.h" - -struct nouveau_dri { - uint32_t device_id; /**< \brief PCI device ID */ - uint32_t width; /**< \brief width in pixels of display */ - uint32_t height; /**< \brief height in scanlines of display */ - uint32_t depth; /**< \brief depth of display (8, 15, 16, 24) */ - uint32_t bpp; /**< \brief bit depth of display (8, 16, 24, 32) */ - - uint32_t bus_type; /**< \brief ths bus type */ - uint32_t bus_mode; /**< \brief bus mode (used for AGP, maybe also for PCI-E ?) */ - - uint32_t front_offset; /**< \brief front buffer offset */ - uint32_t front_pitch; /**< \brief front buffer pitch */ - uint32_t back_offset; /**< \brief private back buffer offset */ - uint32_t back_pitch; /**< \brief private back buffer pitch */ - uint32_t depth_offset; /**< \brief private depth buffer offset */ - uint32_t depth_pitch; /**< \brief private depth buffer pitch */ - -}; - -#endif - diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c deleted file mode 100644 index 716d4bacd3b..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c +++ /dev/null @@ -1,157 +0,0 @@ -#include "pipe/p_context.h" -#include "pipe/p_state.h" -#include "util/u_format.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" - -#include "nouveau_drm_api.h" - -#include "nouveau_drmif.h" -#include "nouveau_channel.h" -#include "nouveau_bo.h" - -#include "nouveau/nouveau_winsys.h" -#include "nouveau/nouveau_screen.h" - -static struct pipe_surface * -dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, - unsigned handle, enum pipe_format format, - unsigned width, unsigned height, unsigned pitch) -{ - struct pipe_surface *ps = NULL; - struct pipe_texture *pt = NULL; - struct pipe_texture tmpl; - struct winsys_handle whandle; - - memset(&tmpl, 0, sizeof(tmpl)); - tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT; - tmpl.target = PIPE_TEXTURE_2D; - tmpl.last_level = 0; - tmpl.depth0 = 1; - tmpl.format = format; - tmpl.width0 = width; - tmpl.height0 = height; - - memset(&whandle, 0, sizeof(whandle)); - whandle.stride = pitch; - whandle.handle = handle; - - pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle); - if (!pt) - return NULL; - - ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - /* we don't need the texture from this point on */ - pipe_texture_reference(&pt, NULL); - return ps; -} - -static struct pipe_surface * -nouveau_dri1_front_surface(struct pipe_context *pipe) -{ - return nouveau_winsys_screen(pipe->screen)->front; -} - -static struct dri1_api nouveau_dri1_api = { - nouveau_dri1_front_surface, -}; - -static void -nouveau_drm_destroy_winsys(struct pipe_winsys *s) -{ - struct nouveau_winsys *nv_winsys = nouveau_winsys(s); - struct nouveau_screen *nv_screen= nouveau_screen(nv_winsys->pscreen); - nouveau_device_close(&nv_screen->device); - FREE(nv_winsys); -} - -static struct pipe_screen * -nouveau_drm_create_screen(struct drm_api *api, int fd, - struct drm_create_screen_arg *arg) -{ - struct dri1_create_screen_arg *dri1 = (void *)arg; - struct nouveau_winsys *nvws; - struct pipe_winsys *ws; - struct nouveau_device *dev = NULL; - struct pipe_screen *(*init)(struct pipe_winsys *, - struct nouveau_device *); - int ret; - - ret = nouveau_device_open_existing(&dev, 0, fd, 0); - if (ret) - return NULL; - - switch (dev->chipset & 0xf0) { - case 0x30: - case 0x40: - case 0x60: - init = nvfx_screen_create; - break; - case 0x50: - case 0x80: - case 0x90: - case 0xa0: - init = nv50_screen_create; - break; - default: - debug_printf("%s: unknown chipset nv%02x\n", __func__, - dev->chipset); - return NULL; - } - - nvws = CALLOC_STRUCT(nouveau_winsys); - if (!nvws) { - nouveau_device_close(&dev); - return NULL; - } - ws = &nvws->base; - ws->destroy = nouveau_drm_destroy_winsys; - - nvws->pscreen = init(ws, dev); - if (!nvws->pscreen) { - ws->destroy(ws); - return NULL; - } - - if (arg && arg->mode == DRM_CREATE_DRI1) { - struct nouveau_dri *nvdri = dri1->ddx_info; - enum pipe_format format; - - if (nvdri->bpp == 16) - format = PIPE_FORMAT_B5G6R5_UNORM; - else - format = PIPE_FORMAT_B8G8R8A8_UNORM; - - nvws->front = dri_surface_from_handle(api, nvws->pscreen, - nvdri->front_offset, - format, nvdri->width, - nvdri->height, - nvdri->front_pitch * - (nvdri->bpp / 8)); - if (!nvws->front) { - debug_printf("%s: error referencing front buffer\n", - __func__); - ws->destroy(ws); - return NULL; - } - - dri1->api = &nouveau_dri1_api; - } - - return nvws->pscreen; -} - -struct drm_api drm_api_hooks = { - .name = "nouveau", - .driver_name = "nouveau", - .create_screen = nouveau_drm_create_screen, -}; - -struct drm_api * -drm_api_create() { - return &drm_api_hooks; -} - diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h deleted file mode 100644 index a91aad7df8e..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __NOUVEAU_DRM_API_H__ -#define __NOUVEAU_DRM_API_H__ - -#include "state_tracker/drm_api.h" -#include "state_tracker/dri1_api.h" - -#include "util/u_simple_screen.h" - -#include "nouveau_dri.h" - -struct nouveau_winsys { - struct pipe_winsys base; - - struct pipe_screen *pscreen; - - struct pipe_surface *front; -}; - -static INLINE struct nouveau_winsys * -nouveau_winsys(struct pipe_winsys *ws) -{ - return (struct nouveau_winsys *)ws; -} - -static INLINE struct nouveau_winsys * -nouveau_winsys_screen(struct pipe_screen *pscreen) -{ - return nouveau_winsys(pscreen->winsys); -} - -#endif diff --git a/src/gallium/winsys/drm/radeon/Makefile b/src/gallium/winsys/drm/radeon/Makefile deleted file mode 100644 index bacdf3de28a..00000000000 --- a/src/gallium/winsys/drm/radeon/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/radeon/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/radeon/SConscript b/src/gallium/winsys/drm/radeon/SConscript deleted file mode 100644 index eff87e7d010..00000000000 --- a/src/gallium/winsys/drm/radeon/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['core/SConscript',]) diff --git a/src/gallium/winsys/drm/radeon/core/Makefile b/src/gallium/winsys/drm/radeon/core/Makefile deleted file mode 100644 index 13bbbf730d6..00000000000 --- a/src/gallium/winsys/drm/radeon/core/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = radeonwinsys - -C_SOURCES = \ - radeon_drm_buffer.c \ - radeon_drm.c \ - radeon_r300.c - -LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r300 \ - $(shell pkg-config libdrm --cflags-only-I) - -include ../../../../Makefile.template - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/core/SConscript b/src/gallium/winsys/drm/radeon/core/SConscript deleted file mode 100644 index f4e9c397bdf..00000000000 --- a/src/gallium/winsys/drm/radeon/core/SConscript +++ /dev/null @@ -1,18 +0,0 @@ -Import('*') - -env = drienv.Clone() - -radeon_sources = [ - 'radeon_buffer.c', - 'radeon_drm.c', - 'radeon_r300.c', -] - -env.Append(CPPPATH = '#/src/gallium/drivers/r300') - -radeonwinsys = env.ConvenienceLibrary( - target ='radeonwinsys', - source = radeon_sources, -) - -Export('radeonwinsys') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h deleted file mode 100644 index 218a3763018..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2008 Jérôme Glisse - * 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 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 THE COPYRIGHT HOLDERS, AUTHORS - * 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Jérôme Glisse - */ -#ifndef RADEON_BUFFER_H -#define RADEON_BUFFER_H - -#include - -#include "pipe/p_defines.h" -#include "util/u_inlines.h" - -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "radeon_bo.h" -#include "radeon_cs.h" - -#include "radeon_winsys.h" - - -#define RADEON_MAX_BOS 24 - -static INLINE struct pb_buffer * -radeon_pb_buffer(struct r300_winsys_buffer *buffer) -{ - return (struct pb_buffer *)buffer; -} - -static INLINE struct r300_winsys_buffer * -radeon_libdrm_winsys_buffer(struct pb_buffer *buffer) -{ - return (struct r300_winsys_buffer *)buffer; -} - -struct pb_manager * -radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws); - -boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd); - - -void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd, - uint32_t flags); - -struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, - uint32_t handle); - -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled, - uint32_t pitch); - -void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); - -boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, - struct winsys_handle *whandle); - -boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf); -#endif diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.c b/src/gallium/winsys/drm/radeon/core/radeon_drm.c deleted file mode 100644 index 3dfcc5aef07..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * 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 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 THE COPYRIGHT HOLDERS, AUTHORS - * 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - * Joakim Sindholt - */ - -#include "radeon_drm.h" -#include "radeon_r300.h" -#include "radeon_buffer.h" - -#include "r300_winsys.h" -#include "trace/tr_drm.h" - -#include "util/u_memory.h" - -#include "xf86drm.h" -#include - -static struct radeon_libdrm_winsys * -radeon_winsys_create(int fd) -{ - struct radeon_libdrm_winsys *rws; - - rws = CALLOC_STRUCT(radeon_libdrm_winsys); - if (rws == NULL) { - return NULL; - } - - rws->fd = fd; - return rws; -} - -/* Helper function to do the ioctls needed for setup and init. */ -static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) -{ - struct drm_radeon_gem_info gem_info = {0}; - struct drm_radeon_info info = {0}; - int target = 0; - int retval; - drmVersionPtr version; - - info.value = (unsigned long)⌖ - - /* We do things in a specific order here. - * - * DRM version first. We need to be sure we're running on a KMS chipset. - * This is also for some features. - * - * Then, the PCI ID. This is essential and should return usable numbers - * for all Radeons. If this fails, we probably got handed an FD for some - * non-Radeon card. - * - * The GB and Z pipe requests should always succeed, but they might not - * return sensical values for all chipsets, but that's alright because - * the pipe drivers already know that. - * - * The GEM info is actually bogus on the kernel side, as well as our side - * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because - * we don't actually use the info for anything yet. */ - - version = drmGetVersion(fd); - if (version->version_major != 2) { - fprintf(stderr, "%s: DRM version is %d.%d.%d but this driver is " - "only compatible with 2.x.x\n", __FUNCTION__, - version->version_major, version->version_minor, - version->version_patchlevel); - drmFreeVersion(version); - exit(1); - } - -/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ -#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE - // Supported since 2.1.0. - winsys->squaretiling = version->version_major > 2 || - version->version_minor >= 1; -#endif - - info.request = RADEON_INFO_DEVICE_ID; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get PCI ID, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->pci_id = target; - - info.request = RADEON_INFO_NUM_GB_PIPES; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get GB pipe count, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->gb_pipes = target; - - info.request = RADEON_INFO_NUM_Z_PIPES; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get Z pipe count, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->z_pipes = target; - - retval = drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO, - &gem_info, sizeof(gem_info)); - if (retval) { - fprintf(stderr, "%s: Failed to get MM info, error number %d\n", - __FUNCTION__, retval); - exit(1); - } - winsys->gart_size = gem_info.gart_size; - winsys->vram_size = gem_info.vram_size; - - debug_printf("radeon: Successfully grabbed chipset info from kernel!\n" - "radeon: DRM version: %d.%d.%d ID: 0x%04x GB: %d Z: %d\n" - "radeon: GART size: %d MB VRAM size: %d MB\n", - version->version_major, version->version_minor, - version->version_patchlevel, winsys->pci_id, - winsys->gb_pipes, winsys->z_pipes, - winsys->gart_size / 1024 / 1024, - winsys->vram_size / 1024 / 1024); - - drmFreeVersion(version); -} - -/* Create a pipe_screen. */ -struct pipe_screen* radeon_create_screen(struct drm_api* api, - int drmFB, - struct drm_create_screen_arg *arg) -{ - struct radeon_libdrm_winsys* rws; - boolean ret; - - rws = radeon_winsys_create(drmFB); - if (!rws) - return NULL; - - do_ioctls(drmFB, rws); - - /* The state tracker can organize a softpipe fallback if no hw - * driver is found. - */ - if (is_r3xx(rws->pci_id)) { - ret = radeon_setup_winsys(drmFB, rws); - if (ret == FALSE) - goto fail; - return r300_create_screen(&rws->base); - } - -fail: - FREE(rws); - return NULL; -} - -static void radeon_drm_api_destroy(struct drm_api *api) -{ - return; -} - -struct drm_api drm_api_hooks = { - .name = "radeon", - .driver_name = "radeon", - .create_screen = radeon_create_screen, - .destroy = radeon_drm_api_destroy, -}; - -struct drm_api* drm_api_create() -{ -#ifdef DEBUG - return trace_drm_create(&drm_api_hooks); -#else - return &drm_api_hooks; -#endif -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.h b/src/gallium/winsys/drm/radeon/core/radeon_drm.h deleted file mode 100644 index 2dc077c0521..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * 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 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 THE COPYRIGHT HOLDERS, AUTHORS - * 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - */ -#ifndef RADEON_DRM_H -#define RADEON_DRM_H - -#include "state_tracker/drm_api.h" - - -struct pipe_screen* radeon_create_screen(struct drm_api* api, - int drmFB, - struct drm_create_screen_arg *arg); - -boolean radeon_buffer_from_texture(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride); - -boolean radeon_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - -boolean radeon_global_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - -void radeon_destroy_drm_api(struct drm_api* api); - -/* Guess at whether this chipset should use r300g. - * - * I believe that this check is valid, but I haven't been exhaustive. */ -static INLINE boolean is_r3xx(int pciid) -{ - return (pciid > 0x3150) && (pciid < 0x796f); -} - -#endif diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c deleted file mode 100644 index 66f61322457..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ /dev/null @@ -1,385 +0,0 @@ - -#include -#include "radeon_drm.h" -#include "radeon_bo_gem.h" -#include "radeon_cs_gem.h" -#include "radeon_buffer.h" - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_simple_list.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "radeon_winsys.h" -struct radeon_drm_bufmgr; - -struct radeon_drm_buffer { - struct pb_buffer base; - struct radeon_drm_bufmgr *mgr; - - struct radeon_bo *bo; - - boolean flinked; - uint32_t flink; - - struct radeon_drm_buffer *next, *prev; -}; - -extern const struct pb_vtbl radeon_drm_buffer_vtbl; - - -static INLINE struct radeon_drm_buffer * -radeon_drm_buffer(struct pb_buffer *buf) -{ - assert(buf); - assert(buf->vtbl == &radeon_drm_buffer_vtbl); - return (struct radeon_drm_buffer *)buf; -} - -struct radeon_drm_bufmgr { - struct pb_manager base; - struct radeon_libdrm_winsys *rws; - struct radeon_drm_buffer buffer_map_list; -}; - -static INLINE struct radeon_drm_bufmgr * -radeon_drm_bufmgr(struct pb_manager *mgr) -{ - assert(mgr); - return (struct radeon_drm_bufmgr *)mgr; -} - -static void -radeon_drm_buffer_destroy(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - - if (buf->bo->ptr != NULL) { - remove_from_list(buf); - radeon_bo_unmap(buf->bo); - buf->bo->ptr = NULL; - } - radeon_bo_unref(buf->bo); - - FREE(buf); -} - -static void * -radeon_drm_buffer_map(struct pb_buffer *_buf, - unsigned flags) -{ - struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - int write = 0; - - if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || - (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX)) - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) - return NULL; - } - - if (buf->bo->ptr != NULL) - return buf->bo->ptr; - - if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - uint32_t domain; - if (radeon_bo_is_busy(buf->bo, &domain)) - return NULL; - } - - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { - buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); - } - - if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { - write = 1; - } - - if (radeon_bo_map(buf->bo, write)) { - return NULL; - } - insert_at_tail(&buf->mgr->buffer_map_list, buf); - return buf->bo->ptr; -} - -static void -radeon_drm_buffer_unmap(struct pb_buffer *_buf) -{ - (void)_buf; -} - -static void -radeon_drm_buffer_get_base_buffer(struct pb_buffer *buf, - struct pb_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -static enum pipe_error -radeon_drm_buffer_validate(struct pb_buffer *_buf, - struct pb_validate *vl, - unsigned flags) -{ - /* Always pinned */ - return PIPE_OK; -} - -static void -radeon_drm_buffer_fence(struct pb_buffer *buf, - struct pipe_fence_handle *fence) -{ -} - -const struct pb_vtbl radeon_drm_buffer_vtbl = { - radeon_drm_buffer_destroy, - radeon_drm_buffer_map, - radeon_drm_buffer_unmap, - radeon_drm_buffer_validate, - radeon_drm_buffer_fence, - radeon_drm_buffer_get_base_buffer, -}; - - -static uint32_t radeon_domain_from_usage(unsigned usage) -{ - uint32_t domain = 0; - - if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_PIXEL) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_VERTEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - if (usage & PIPE_BUFFER_USAGE_INDEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - - return domain; -} - -struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, - uint32_t handle) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_libdrm_winsys *rws = mgr->rws; - struct radeon_drm_buffer *buf; - struct radeon_bo *bo; - - bo = radeon_bo_open(rws->bom, handle, 0, - 0, 0, 0); - if (bo == NULL) - return NULL; - - buf = CALLOC_STRUCT(radeon_drm_buffer); - if (!buf) { - radeon_bo_unref(bo); - return NULL; - } - - make_empty_list(buf); - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = 0; - buf->base.base.usage = PIPE_BUFFER_USAGE_PIXEL; - buf->base.base.size = 0; - buf->base.vtbl = &radeon_drm_buffer_vtbl; - buf->mgr = mgr; - - buf->bo = bo; - - return &buf->base; -} - -static struct pb_buffer * -radeon_drm_bufmgr_create_buffer(struct pb_manager *_mgr, - pb_size size, - const struct pb_desc *desc) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_libdrm_winsys *rws = mgr->rws; - struct radeon_drm_buffer *buf; - uint32_t domain; - - buf = CALLOC_STRUCT(radeon_drm_buffer); - if (!buf) - goto error1; - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = desc->alignment; - buf->base.base.usage = desc->usage; - buf->base.base.size = size; - buf->base.vtbl = &radeon_drm_buffer_vtbl; - buf->mgr = mgr; - - make_empty_list(buf); - domain = radeon_domain_from_usage(desc->usage); - buf->bo = radeon_bo_open(rws->bom, 0, size, - desc->alignment, domain, 0); - if (buf->bo == NULL) - goto error2; - - return &buf->base; - - error2: - FREE(buf); - error1: - return NULL; -} - -static void -radeon_drm_bufmgr_flush(struct pb_manager *mgr) -{ - /* NOP */ -} - -static void -radeon_drm_bufmgr_destroy(struct pb_manager *_mgr) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - FREE(mgr); -} - -struct pb_manager * -radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws) -{ - struct radeon_drm_bufmgr *mgr; - - mgr = CALLOC_STRUCT(radeon_drm_bufmgr); - if (!mgr) - return NULL; - - mgr->base.destroy = radeon_drm_bufmgr_destroy; - mgr->base.create_buffer = radeon_drm_bufmgr_create_buffer; - mgr->base.flush = radeon_drm_bufmgr_flush; - - mgr->rws = rws; - make_empty_list(&mgr->buffer_map_list); - return &mgr->base; -} - -static struct radeon_drm_buffer *get_drm_buffer(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf; - if (_buf->vtbl == &radeon_drm_buffer_vtbl) { - buf = radeon_drm_buffer(_buf); - } else { - struct pb_buffer *base_buf; - pb_size offset; - pb_get_base_buffer(_buf, &base_buf, &offset); - - buf = radeon_drm_buffer(base_buf); - } - return buf; -} - -boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, - struct winsys_handle *whandle) -{ - int retval, fd; - struct drm_gem_flink flink; - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - fd = buf->mgr->rws->fd; - flink.handle = buf->bo->handle; - - retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); - if (retval) { - return FALSE; - } - - buf->flinked = TRUE; - buf->flink = flink.name; - } - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } - return TRUE; -} - - -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled, - uint32_t pitch) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - uint32_t flags = 0, old_flags, old_pitch; - if (microtiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MICRO_TILE; -/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ -#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE - else if (microtiled == R300_BUFFER_SQUARETILED) - flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; -#endif - if (macrotiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MACRO_TILE; - - radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); - - if (flags != old_flags || pitch != old_pitch) { - /* Tiling determines how DRM treats the buffer data. - * We must flush CS when changing it if the buffer is referenced. */ - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { - buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); - } - } - radeon_bo_set_tiling(buf->bo, flags, pitch); - -} - -boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - radeon_cs_space_add_persistent_bo(buf->mgr->rws->cs, buf->bo, - rd, wd); - return TRUE; -} - -void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd, - uint32_t flags) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - int retval; - - retval = radeon_cs_write_reloc(buf->mgr->rws->cs, - buf->bo, rd, wd, flags); - if (retval) { - debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n", - buf, rd, wd, flags); - } -} - -boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - uint32_t domain; - - return (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs) || - radeon_bo_is_busy(buf->bo, &domain)); -} - - -void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_drm_buffer *rpb, *t_rpb; - - foreach_s(rpb, t_rpb, &mgr->buffer_map_list) { - radeon_bo_unmap(rpb->bo); - rpb->bo->ptr = NULL; - remove_from_list(rpb); - } - - make_empty_list(&mgr->buffer_map_list); -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c deleted file mode 100644 index 38fcf889c8b..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2008 Corbin Simpson - * - * 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 - * on 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 - * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#include "radeon_r300.h" -#include "radeon_buffer.h" - -#include "radeon_bo_gem.h" -#include "radeon_cs_gem.h" -#include "state_tracker/drm_api.h" - -static struct r300_winsys_buffer * -radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct pb_desc desc; - struct pb_manager *provider; - struct pb_buffer *buffer; - - memset(&desc, 0, sizeof(desc)); - desc.alignment = alignment; - desc.usage = usage; - - if (usage & PIPE_BUFFER_USAGE_CONSTANT) - provider = ws->mman; - else if ((usage & PIPE_BUFFER_USAGE_VERTEX) || - (usage & PIPE_BUFFER_USAGE_INDEX)) - provider = ws->cman; - else - provider = ws->kman; - buffer = provider->create_buffer(provider, size, &desc); - if (!buffer) - return NULL; - - return radeon_libdrm_winsys_buffer(buffer); -} - -static void radeon_r300_winsys_buffer_destroy(struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - pb_destroy(_buf); -} -static void radeon_r300_winsys_buffer_set_tiling(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t pitch, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - radeon_drm_bufmgr_set_tiling(_buf, microtiled, macrotiled, pitch); -} - -static void *radeon_r300_winsys_buffer_map(struct r300_winsys_screen *ws, - struct r300_winsys_buffer *buf, - unsigned usage) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return pb_map(_buf, usage); -} - -static void radeon_r300_winsys_buffer_unmap(struct r300_winsys_screen *ws, - struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - pb_unmap(_buf); -} - -static void radeon_r300_winsys_buffer_reference(struct r300_winsys_screen *rws, - struct r300_winsys_buffer **pdst, - struct r300_winsys_buffer *src) -{ - struct pb_buffer *_src = radeon_pb_buffer(src); - struct pb_buffer *_dst = radeon_pb_buffer(*pdst); - - pb_reference(&_dst, _src); - - *pdst = radeon_libdrm_winsys_buffer(_dst); -} - -static boolean radeon_r300_winsys_is_buffer_referenced(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return radeon_drm_bufmgr_is_buffer_referenced(_buf); -} - -static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws, - struct pipe_screen *screen, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct pb_buffer *_buf; - - _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle); - *stride = whandle->stride; - return radeon_libdrm_winsys_buffer(_buf); -} - -static boolean radeon_r300_winsys_buffer_get_handle(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buffer, - unsigned stride, - struct winsys_handle *whandle) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buffer); - boolean ret; - ret = radeon_drm_bufmgr_get_handle(_buf, whandle); - if (ret) - whandle->stride = stride; - return ret; -} - -static void radeon_set_flush_cb(struct r300_winsys_screen *rws, - void (*flush_cb)(void *), - void *data) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - ws->flush_cb = flush_cb; - ws->flush_data = data; - radeon_cs_space_set_flush(ws->cs, flush_cb, data); -} - -static boolean radeon_add_buffer(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t rd, - uint32_t wd) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return radeon_drm_bufmgr_add_buffer(_buf, rd, wd); -} - -static boolean radeon_validate(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - if (radeon_cs_space_check(ws->cs) < 0) { - return FALSE; - } - - /* Things are fine, we can proceed as normal. */ - return TRUE; -} - -static boolean radeon_check_cs(struct r300_winsys_screen *rws, int size) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct radeon_cs *cs = ws->cs; - - return radeon_validate(rws) && cs->cdw + size <= cs->ndw; -} - -static void radeon_begin_cs(struct r300_winsys_screen *rws, - int size, - const char* file, - const char* function, - int line) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_begin(ws->cs, size, file, function, line); -} - -static void radeon_write_cs_dword(struct r300_winsys_screen *rws, - uint32_t dword) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_write_dword(ws->cs, dword); -} - -static void radeon_write_cs_reloc(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t rd, - uint32_t wd, - uint32_t flags) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - radeon_drm_bufmgr_write_reloc(_buf, rd, wd, flags); -} - -static void radeon_reset_bos(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_space_reset_bos(ws->cs); -} - -static void radeon_end_cs(struct r300_winsys_screen *rws, - const char* file, - const char* function, - int line) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_end(ws->cs, file, function, line); -} - -static void radeon_flush_cs(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - int retval; - - /* Don't flush a zero-sized CS. */ - if (!ws->cs->cdw) { - return; - } - - radeon_drm_bufmgr_flush_maps(ws->kman); - /* Emit the CS. */ - retval = radeon_cs_emit(ws->cs); - if (retval) { - debug_printf("radeon: Bad CS, dumping...\n"); - radeon_cs_print(ws->cs, stderr); - } - - /* Reset CS. - * Someday, when we care about performance, we should really find a way - * to rotate between two or three CS objects so that the GPU can be - * spinning through one CS while another one is being filled. */ - radeon_cs_erase(ws->cs); -} - -static uint32_t radeon_get_value(struct r300_winsys_screen *rws, - enum r300_value_id id) -{ - struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; - - switch(id) { - case R300_VID_PCI_ID: - return ws->pci_id; - case R300_VID_GB_PIPES: - return ws->gb_pipes; - case R300_VID_Z_PIPES: - return ws->z_pipes; - case R300_VID_SQUARE_TILING_SUPPORT: - return ws->squaretiling; - } - return 0; -} - -static void -radeon_winsys_destroy(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; - radeon_cs_destroy(ws->cs); - - ws->cman->destroy(ws->cman); - ws->kman->destroy(ws->kman); - ws->mman->destroy(ws->mman); - - radeon_bo_manager_gem_dtor(ws->bom); - radeon_cs_manager_gem_dtor(ws->csm); -} - -boolean -radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) -{ - - ws->csm = radeon_cs_manager_gem_ctor(fd); - if (!ws->csm) - goto fail; - ws->bom = radeon_bo_manager_gem_ctor(fd); - if (!ws->bom) - goto fail; - ws->kman = radeon_drm_bufmgr_create(ws); - if (!ws->kman) - goto fail; - - ws->cman = pb_cache_manager_create(ws->kman, 100000); - if (!ws->cman) - goto fail; - - ws->mman = pb_malloc_bufmgr_create(); - if (!ws->mman) - goto fail; - - /* Size limit on IBs is 64 kibibytes. */ - ws->cs = radeon_cs_create(ws->csm, 1024 * 64 / 4); - if (!ws->cs) - goto fail; - radeon_cs_set_limit(ws->cs, - RADEON_GEM_DOMAIN_GTT, ws->gart_size); - radeon_cs_set_limit(ws->cs, - RADEON_GEM_DOMAIN_VRAM, ws->vram_size); - - ws->base.add_buffer = radeon_add_buffer; - ws->base.validate = radeon_validate; - ws->base.destroy = radeon_winsys_destroy; - ws->base.check_cs = radeon_check_cs; - ws->base.begin_cs = radeon_begin_cs; - ws->base.write_cs_dword = radeon_write_cs_dword; - ws->base.write_cs_reloc = radeon_write_cs_reloc; - ws->base.end_cs = radeon_end_cs; - ws->base.flush_cs = radeon_flush_cs; - ws->base.reset_bos = radeon_reset_bos; - ws->base.set_flush_cb = radeon_set_flush_cb; - ws->base.get_value = radeon_get_value; - - ws->base.buffer_create = radeon_r300_winsys_buffer_create; - ws->base.buffer_destroy = radeon_r300_winsys_buffer_destroy; - ws->base.buffer_set_tiling = radeon_r300_winsys_buffer_set_tiling; - ws->base.buffer_map = radeon_r300_winsys_buffer_map; - ws->base.buffer_unmap = radeon_r300_winsys_buffer_unmap; - ws->base.buffer_reference = radeon_r300_winsys_buffer_reference; - ws->base.buffer_from_handle = radeon_r300_winsys_buffer_from_handle; - ws->base.buffer_get_handle = radeon_r300_winsys_buffer_get_handle; - ws->base.is_buffer_referenced = radeon_r300_winsys_is_buffer_referenced; - return TRUE; - -fail: - if (ws->csm) - radeon_cs_manager_gem_dtor(ws->csm); - - if (ws->bom) - radeon_bo_manager_gem_dtor(ws->bom); - - if (ws->cman) - ws->cman->destroy(ws->cman); - if (ws->kman) - ws->kman->destroy(ws->kman); - if (ws->mman) - ws->mman->destroy(ws->mman); - - if (ws->cs) - radeon_cs_destroy(ws->cs); - return FALSE; -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.h b/src/gallium/winsys/drm/radeon/core/radeon_r300.h deleted file mode 100644 index 2703464ad8f..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2008 Corbin Simpson - * - * 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 - * on 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 - * THE AUTHOR(S) AND/OR THEIR 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 RADEON_R300_H -#define RADEON_R300_H - -#include "radeon_winsys.h" - -boolean radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* winsys); - -#endif /* RADEON_R300_H */ diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h deleted file mode 100644 index 4260dbaad72..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * 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 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 THE COPYRIGHT HOLDERS, AUTHORS - * 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - */ -#ifndef RADEON_WINSYS_H -#define RADEON_WINSYS_H - -#include "r300_winsys.h" - -struct radeon_libdrm_winsys { - /* Parent class. */ - struct r300_winsys_screen base; - - struct pb_manager *kman; - - struct pb_manager *cman; - - struct pb_manager *mman; - - /* PCI ID */ - uint32_t pci_id; - - /* GB pipe count */ - uint32_t gb_pipes; - - /* Z pipe count (rv530 only) */ - uint32_t z_pipes; - - /* GART size. */ - uint32_t gart_size; - - /* VRAM size. */ - uint32_t vram_size; - - /* Square tiling support. */ - boolean squaretiling; - - /* DRM FD */ - int fd; - - /* Radeon BO manager. */ - struct radeon_bo_manager *bom; - - /* Radeon CS manager. */ - struct radeon_cs_manager *csm; - - /* Current CS. */ - struct radeon_cs *cs; - - /* Flush CB */ - void (*flush_cb)(void *); - void *flush_data; -}; - -static INLINE struct radeon_libdrm_winsys * -radeon_winsys_screen(struct r300_winsys_screen *base) -{ - return (struct radeon_libdrm_winsys *)base; -} - -#endif diff --git a/src/gallium/winsys/drm/sw/Makefile b/src/gallium/winsys/drm/sw/Makefile deleted file mode 100644 index 5f3c3ec325d..00000000000 --- a/src/gallium/winsys/drm/sw/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../.. -include $(TOP)/configs/current - -LIBNAME = swdrm - -C_SOURCES = \ - wrapper_sw_winsys.c \ - sw_drm_api.c - -LIBRARY_INCLUDES = - -LIBRARY_DEFINES = - -include ../../../Makefile.template diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c deleted file mode 100644 index 0fd2163913e..00000000000 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ /dev/null @@ -1,97 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "util/u_memory.h" -#include "softpipe/sp_public.h" -#include "state_tracker/drm_api.h" -#include "wrapper_sw_winsys.h" -#include "sw_drm_api.h" - - -/* - * Defines - */ - - -struct sw_drm_api -{ - struct drm_api base; - struct drm_api *api; - struct sw_winsys *sw; -}; - -static INLINE struct sw_drm_api * -sw_drm_api(struct drm_api *api) -{ - return (struct sw_drm_api *)api; -} - - -/* - * Exported functions - */ - - -static struct pipe_screen * -sw_drm_create_screen(struct drm_api *_api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct sw_drm_api *swapi = sw_drm_api(_api); - struct drm_api *api = swapi->api; - struct sw_winsys *sww; - struct pipe_screen *screen; - - screen = api->create_screen(api, drmFD, arg); - - sww = wrapper_sw_winsys_warp_pipe_screen(screen); - - return softpipe_create_screen(sww); -} - -static void -sw_drm_destroy(struct drm_api *api) -{ - struct sw_drm_api *swapi = sw_drm_api(api); - if (swapi->api->destroy) - swapi->api->destroy(swapi->api); - - FREE(swapi); -} - -struct drm_api * -sw_drm_api_create(struct drm_api *api) -{ - struct sw_drm_api *swapi = CALLOC_STRUCT(sw_drm_api); - - swapi->base.name = "sw"; - swapi->base.driver_name = api->driver_name; - swapi->base.create_screen = sw_drm_create_screen; - swapi->base.destroy = sw_drm_destroy; - - swapi->api = api; - - return &swapi->base; -} diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.h b/src/gallium/winsys/drm/sw/sw_drm_api.h deleted file mode 100644 index ce90a04ae0c..00000000000 --- a/src/gallium/winsys/drm/sw/sw_drm_api.h +++ /dev/null @@ -1,34 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#ifndef SW_DRM_API_H -#define SW_DRM_API_H - -struct drm_api; - -struct drm_api * sw_drm_api_create(struct drm_api *api); - -#endif diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c deleted file mode 100644 index 459b1c1e2a3..00000000000 --- a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c +++ /dev/null @@ -1,282 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "wrapper_sw_winsys.h" - -#include "pipe/p_format.h" -#include "pipe/p_state.h" - -#include "state_tracker/sw_winsys.h" - -#include "util/u_memory.h" -#include "util/u_inlines.h" - -/* - * This code wraps a pipe_screen and exposes a sw_winsys interface for use - * with software resterizers. This code is used by the DRM based winsys to - * allow access to the drm driver. - * - * We must borrow the whole stack because only the pipe screen knows how - * to decode the content of a buffer. Or how to create a buffer that - * can still be used by drivers using real hardware (as the case is - * with software st/xorg but hw st/dri). - * - * We also need a pipe context for the transfers. - */ - -struct wrapper_sw_winsys -{ - struct sw_winsys base; - struct pipe_screen *screen; - struct pipe_context *pipe; -}; - -struct wrapper_sw_displaytarget -{ - struct wrapper_sw_winsys *winsys; - struct pipe_texture *tex; - struct pipe_transfer *transfer; - - unsigned width; - unsigned height; - unsigned map_count; - unsigned stride; /**< because we give stride at create */ - void *ptr; -}; - -static INLINE struct wrapper_sw_winsys * -wrapper_sw_winsys(struct sw_winsys *ws) -{ - return (struct wrapper_sw_winsys *)ws; -} - -static INLINE struct wrapper_sw_displaytarget * -wrapper_sw_displaytarget(struct sw_displaytarget *dt) -{ - return (struct wrapper_sw_displaytarget *)dt; -} - - -/* - * Functions - */ - - -static boolean -wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride) -{ - struct pipe_context *pipe = wdt->winsys->pipe; - struct pipe_texture *tex = wdt->tex; - struct pipe_transfer *tr; - - tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, - 0, 0, wdt->width, wdt->height); - if (!tr) - return FALSE; - - *stride = tr->stride; - wdt->stride = tr->stride; - - pipe->tex_transfer_destroy(pipe, tr); - - return TRUE; -} - -static struct sw_displaytarget * -wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, - struct pipe_texture *tex, unsigned *stride) -{ - struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget); - if (!wdt) - goto err_unref; - - wdt->tex = tex; - wdt->winsys = wsw; - - if (!wsw_dt_get_stride(wdt, stride)) - goto err_free; - - return (struct sw_displaytarget *)wdt; - -err_free: - FREE(wdt); -err_unref: - pipe_texture_reference(&tex, NULL); - return NULL; -} - -static struct sw_displaytarget * -wsw_dt_create(struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - struct pipe_texture templ; - struct pipe_texture *tex; - - /* - * XXX Why don't we just get the template. - */ - memset(&templ, 0, sizeof(templ)); - templ.width0 = width; - templ.height0 = height; - templ.format = format; - templ.tex_usage = tex_usage; - - /* XXX alignment: we can't do anything about this */ - - tex = wsw->screen->texture_create(wsw->screen, &templ); - if (!tex) - return NULL; - - return wsw_dt_wrap_texture(wsw, tex, stride); -} - -static struct sw_displaytarget * -wsw_dt_from_handle(struct sw_winsys *ws, - const struct pipe_texture *templ, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - struct pipe_texture *tex; - - tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle); - if (!tex) - return NULL; - - return wsw_dt_wrap_texture(wsw, tex, stride); -} - -static void * -wsw_dt_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - struct pipe_context *pipe = wdt->winsys->pipe; - struct pipe_texture *tex = wdt->tex; - struct pipe_transfer *tr; - void *ptr; - - if (!wdt->map_count) { - - assert(!wdt->transfer); - - tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, - 0, 0, wdt->width, wdt->height); - if (!tr) - return NULL; - - ptr = pipe->transfer_map(pipe, tr); - if (!ptr) - goto err; - - wdt->transfer = tr; - wdt->ptr = ptr; - - /* XXX Handle this case */ - assert(tr->stride == wdt->stride); - } - - wdt->map_count++; - - return wdt->ptr; - -err: - pipe->tex_transfer_destroy(pipe, tr); - return NULL; -} - -static void -wsw_dt_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - struct pipe_context *pipe = wdt->winsys->pipe; - - assert(wdt->transfer); - - wdt->map_count--; - - if (wdt->map_count) - return; - - pipe->transfer_unmap(pipe, wdt->transfer); - pipe->tex_transfer_destroy(pipe, wdt->transfer); - wdt->transfer = NULL; -} - -static void -wsw_dt_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - - pipe_texture_reference(&wdt->tex, NULL); - - FREE(wdt); -} - -static void -wsw_destroy(struct sw_winsys *ws) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - - wsw->pipe->destroy(wsw->pipe); - wsw->screen->destroy(wsw->screen); - - FREE(wsw); -} - -struct sw_winsys * -wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen) -{ - struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); - - wsw->base.displaytarget_create = wsw_dt_create; - wsw->base.displaytarget_from_handle = wsw_dt_from_handle; - wsw->base.displaytarget_map = wsw_dt_map; - wsw->base.displaytarget_unmap = wsw_dt_unmap; - wsw->base.displaytarget_destroy = wsw_dt_destroy; - wsw->base.destroy = wsw_destroy; - - wsw->screen = screen; - wsw->pipe = screen->context_create(screen, NULL); - if (!wsw->pipe) - goto err; - - return &wsw->base; - -err: - FREE(wsw); - return NULL; -} diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h deleted file mode 100644 index b5c25a3c50f..00000000000 --- a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h +++ /dev/null @@ -1,35 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#ifndef WRAPPER_SW_WINSYS -#define WRAPPER_SW_WINSYS - -struct sw_winsys; -struct pipe_screen; - -struct sw_winsys *wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen); - -#endif diff --git a/src/gallium/winsys/drm/vmware/Makefile b/src/gallium/winsys/drm/vmware/Makefile deleted file mode 100644 index 2ae6dead5c1..00000000000 --- a/src/gallium/winsys/drm/vmware/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/vmware/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript deleted file mode 100644 index eff87e7d010..00000000000 --- a/src/gallium/winsys/drm/vmware/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['core/SConscript',]) diff --git a/src/gallium/winsys/drm/vmware/core/Makefile b/src/gallium/winsys/drm/vmware/core/Makefile deleted file mode 100644 index a52957c1a5b..00000000000 --- a/src/gallium/winsys/drm/vmware/core/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = svgadrm - -C_SOURCES = \ - vmw_buffer.c \ - vmw_context.c \ - vmw_fence.c \ - vmw_screen.c \ - vmw_screen_dri.c \ - vmw_screen_ioctl.c \ - vmw_screen_pools.c \ - vmw_screen_svga.c \ - vmw_surface.c - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/drivers/svga \ - -I$(TOP)/src/gallium/drivers/svga/include \ - -I$(GALLIUM)/src/mesa/drivers/dri/common \ - -I$(GALLIUM)/include \ - -I$(GALLIUM)/include/GL/internal \ - -I$(GALLIUM)/src/mesa \ - -I$(GALLIUM)/src/mesa/main \ - -I$(GALLIUM)/src/mesa/glapi \ - -I$(GALLIUM)/src/egl/main \ - -I$(GALLIUM)/src/egl/drivers/dri \ - $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = \ - -std=gnu99 -fvisibility=hidden \ - -DHAVE_STDINT_H -D_FILE_OFFSET_BITS=64 \ - $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/vmware/core/SConscript b/src/gallium/winsys/drm/vmware/core/SConscript deleted file mode 100644 index edaf9458bee..00000000000 --- a/src/gallium/winsys/drm/vmware/core/SConscript +++ /dev/null @@ -1,39 +0,0 @@ -Import('*') - -env = env.Clone() - -if env['gcc']: - env.Append(CCFLAGS = ['-fvisibility=hidden']) - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - '-D_FILE_OFFSET_BITS=64', - ]) - -env.Prepend(CPPPATH = [ - 'include', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', -]) - -env.Append(CPPDEFINES = [ -]) - -sources = [ - 'vmw_buffer.c', - 'vmw_context.c', - 'vmw_fence.c', - 'vmw_screen.c', - 'vmw_screen_dri.c', - 'vmw_screen_ioctl.c', - 'vmw_screen_pools.c', - 'vmw_screen_svga.c', - 'vmw_surface.c', -] - -svgadrm = env.ConvenienceLibrary( - target = 'svgadrm', - source = sources, -) - -Export('svgadrm') diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c b/src/gallium/winsys/drm/vmware/core/vmw_buffer.c deleted file mode 100644 index eca174a6c56..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c +++ /dev/null @@ -1,274 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * SVGA buffer manager for Guest Memory Regions (GMRs). - * - * GMRs are used for pixel and vertex data upload/download to/from the virtual - * SVGA hardware. There is a limited number of GMRs available, and - * creating/destroying them is also a slow operation so we must suballocate - * them. - * - * This file implements a pipebuffer library's buffer manager, so that we can - * use pipepbuffer's suballocation, fencing, and debugging facilities with GMRs. - * - * @author Jose Fonseca - */ - - -#include "svga_cmd.h" - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "svga_winsys.h" - -#include "vmw_screen.h" -#include "vmw_buffer.h" - - -struct vmw_gmr_bufmgr; - - -struct vmw_gmr_buffer -{ - struct pb_buffer base; - - struct vmw_gmr_bufmgr *mgr; - - struct vmw_region *region; - void *map; - -#ifdef DEBUG - struct pipe_fence_handle *last_fence; -#endif -}; - - -extern const struct pb_vtbl vmw_gmr_buffer_vtbl; - - -static INLINE struct vmw_gmr_buffer * -vmw_gmr_buffer(struct pb_buffer *buf) -{ - assert(buf); - assert(buf->vtbl == &vmw_gmr_buffer_vtbl); - return (struct vmw_gmr_buffer *)buf; -} - - -struct vmw_gmr_bufmgr -{ - struct pb_manager base; - - struct vmw_winsys_screen *vws; -}; - - -static INLINE struct vmw_gmr_bufmgr * -vmw_gmr_bufmgr(struct pb_manager *mgr) -{ - assert(mgr); - return (struct vmw_gmr_bufmgr *)mgr; -} - - -static void -vmw_gmr_buffer_destroy(struct pb_buffer *_buf) -{ - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - -#ifdef DEBUG - if(buf->last_fence) { - struct svga_winsys_screen *sws = &buf->mgr->vws->base; - assert(sws->fence_signalled(sws, buf->last_fence, 0) == 0); - } -#endif - - vmw_ioctl_region_unmap(buf->region); - - vmw_ioctl_region_destroy(buf->region); - - FREE(buf); -} - - -static void * -vmw_gmr_buffer_map(struct pb_buffer *_buf, - unsigned flags) -{ - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - return buf->map; -} - - -static void -vmw_gmr_buffer_unmap(struct pb_buffer *_buf) -{ - /* Do nothing */ - (void)_buf; -} - - -static void -vmw_gmr_buffer_get_base_buffer(struct pb_buffer *buf, - struct pb_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -static enum pipe_error -vmw_gmr_buffer_validate( struct pb_buffer *_buf, - struct pb_validate *vl, - unsigned flags ) -{ - /* Always pinned */ - return PIPE_OK; -} - - -static void -vmw_gmr_buffer_fence( struct pb_buffer *_buf, - struct pipe_fence_handle *fence ) -{ - /* We don't need to do anything, as the pipebuffer library - * will take care of delaying the destruction of fenced buffers */ -#ifdef DEBUG - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - if(fence) - buf->last_fence = fence; -#endif -} - - -const struct pb_vtbl vmw_gmr_buffer_vtbl = { - vmw_gmr_buffer_destroy, - vmw_gmr_buffer_map, - vmw_gmr_buffer_unmap, - vmw_gmr_buffer_validate, - vmw_gmr_buffer_fence, - vmw_gmr_buffer_get_base_buffer -}; - - -static struct pb_buffer * -vmw_gmr_bufmgr_create_buffer(struct pb_manager *_mgr, - pb_size size, - const struct pb_desc *desc) -{ - struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); - struct vmw_winsys_screen *vws = mgr->vws; - struct vmw_gmr_buffer *buf; - - buf = CALLOC_STRUCT(vmw_gmr_buffer); - if(!buf) - goto error1; - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = desc->alignment; - buf->base.base.usage = desc->usage; - buf->base.base.size = size; - buf->base.vtbl = &vmw_gmr_buffer_vtbl; - buf->mgr = mgr; - - buf->region = vmw_ioctl_region_create(vws, size); - if(!buf->region) - goto error2; - - buf->map = vmw_ioctl_region_map(buf->region); - if(!buf->map) - goto error3; - - return &buf->base; - -error3: - vmw_ioctl_region_destroy(buf->region); -error2: - FREE(buf); -error1: - return NULL; -} - - -static void -vmw_gmr_bufmgr_flush(struct pb_manager *mgr) -{ - /* No-op */ -} - - -static void -vmw_gmr_bufmgr_destroy(struct pb_manager *_mgr) -{ - struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); - FREE(mgr); -} - - -struct pb_manager * -vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws) -{ - struct vmw_gmr_bufmgr *mgr; - - mgr = CALLOC_STRUCT(vmw_gmr_bufmgr); - if(!mgr) - return NULL; - - mgr->base.destroy = vmw_gmr_bufmgr_destroy; - mgr->base.create_buffer = vmw_gmr_bufmgr_create_buffer; - mgr->base.flush = vmw_gmr_bufmgr_flush; - - mgr->vws = vws; - - return &mgr->base; -} - - -boolean -vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, - struct SVGAGuestPtr *ptr) -{ - struct pb_buffer *base_buf; - unsigned offset = 0; - struct vmw_gmr_buffer *gmr_buf; - - pb_get_base_buffer( buf, &base_buf, &offset ); - - gmr_buf = vmw_gmr_buffer(base_buf); - if(!gmr_buf) - return FALSE; - - *ptr = vmw_ioctl_region_ptr(gmr_buf->region); - - ptr->offset += offset; - - return TRUE; -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h b/src/gallium/winsys/drm/vmware/core/vmw_buffer.h deleted file mode 100644 index 41fb4476da5..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h +++ /dev/null @@ -1,65 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#ifndef VMW_BUFFER_H_ -#define VMW_BUFFER_H_ - -#include -#include "pipe/p_compiler.h" - -struct SVGAGuestPtr; -struct pb_buffer; -struct pb_manager; -struct svga_winsys_buffer; -struct svga_winsys_surface; -struct vmw_winsys_screen; - - -static INLINE struct pb_buffer * -vmw_pb_buffer(struct svga_winsys_buffer *buffer) -{ - assert(buffer); - return (struct pb_buffer *)buffer; -} - - -static INLINE struct svga_winsys_buffer * -vmw_svga_winsys_buffer(struct pb_buffer *buffer) -{ - assert(buffer); - return (struct svga_winsys_buffer *)buffer; -} - - -struct pb_manager * -vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws); - -boolean -vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, - struct SVGAGuestPtr *ptr); - - -#endif /* VMW_BUFFER_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_context.c b/src/gallium/winsys/drm/vmware/core/vmw_context.c deleted file mode 100644 index 90ffc4868f7..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_context.c +++ /dev/null @@ -1,382 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "svga_cmd.h" - -#include "util/u_debug.h" -#include "util/u_memory.h" -#include "util/u_debug_stack.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_validate.h" - -#include "svga_winsys.h" -#include "vmw_context.h" -#include "vmw_screen.h" -#include "vmw_buffer.h" -#include "vmw_surface.h" -#include "vmw_fence.h" - -#define VMW_COMMAND_SIZE (64*1024) -#define VMW_SURFACE_RELOCS (1024) -#define VMW_REGION_RELOCS (512) - -#define VMW_MUST_FLUSH_STACK 8 - -struct vmw_region_relocation -{ - struct SVGAGuestPtr *where; - struct pb_buffer *buffer; - /* TODO: put offset info inside where */ - uint32 offset; -}; - -struct vmw_svga_winsys_context -{ - struct svga_winsys_context base; - - struct vmw_winsys_screen *vws; - -#ifdef DEBUG - boolean must_flush; - struct debug_stack_frame must_flush_stack[VMW_MUST_FLUSH_STACK]; -#endif - - struct { - uint8_t buffer[VMW_COMMAND_SIZE]; - uint32_t size; - uint32_t used; - uint32_t reserved; - } command; - - struct { - struct vmw_svga_winsys_surface *handles[VMW_SURFACE_RELOCS]; - uint32_t size; - uint32_t used; - uint32_t staged; - uint32_t reserved; - } surface; - - struct { - struct vmw_region_relocation relocs[VMW_REGION_RELOCS]; - uint32_t size; - uint32_t used; - uint32_t staged; - uint32_t reserved; - } region; - - struct pb_validate *validate; - - uint32_t last_fence; - - /** - * The amount of GMR that is referred by the commands currently batched - * in the context. - */ - uint32_t seen_regions; - - /** - * Whether this context should fail to reserve more commands, not because it - * ran out of command space, but because a substantial ammount of GMR was - * referred. - */ - boolean preemptive_flush; -}; - - -static INLINE struct vmw_svga_winsys_context * -vmw_svga_winsys_context(struct svga_winsys_context *swc) -{ - assert(swc); - return (struct vmw_svga_winsys_context *)swc; -} - - -static enum pipe_error -vmw_swc_flush(struct svga_winsys_context *swc, - struct pipe_fence_handle **pfence) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct pipe_fence_handle *fence = NULL; - unsigned i; - enum pipe_error ret; - - ret = pb_validate_validate(vswc->validate); - assert(ret == PIPE_OK); - if(ret == PIPE_OK) { - - /* Apply relocations */ - for(i = 0; i < vswc->region.used; ++i) { - struct vmw_region_relocation *reloc = &vswc->region.relocs[i]; - struct SVGAGuestPtr ptr; - - if(!vmw_gmr_bufmgr_region_ptr(reloc->buffer, &ptr)) - assert(0); - - ptr.offset += reloc->offset; - - *reloc->where = ptr; - } - - if (vswc->command.used) - vmw_ioctl_command(vswc->vws, - vswc->command.buffer, - vswc->command.used, - &vswc->last_fence); - - fence = vmw_pipe_fence(vswc->last_fence); - - pb_validate_fence(vswc->validate, fence); - } - - vswc->command.used = 0; - vswc->command.reserved = 0; - - for(i = 0; i < vswc->surface.used + vswc->surface.staged; ++i) { - struct vmw_svga_winsys_surface *vsurf = - vswc->surface.handles[i]; - p_atomic_dec(&vsurf->validated); - vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); - } - - vswc->surface.used = 0; - vswc->surface.reserved = 0; - - for(i = 0; i < vswc->region.used + vswc->region.staged; ++i) { - pb_reference(&vswc->region.relocs[i].buffer, NULL); - } - - vswc->region.used = 0; - vswc->region.reserved = 0; - -#ifdef DEBUG - vswc->must_flush = FALSE; -#endif - vswc->preemptive_flush = FALSE; - vswc->seen_regions = 0; - - if(pfence) - *pfence = fence; - - return ret; -} - - -static void * -vmw_swc_reserve(struct svga_winsys_context *swc, - uint32_t nr_bytes, uint32_t nr_relocs ) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - -#ifdef DEBUG - /* Check if somebody forgot to check the previous failure */ - if(vswc->must_flush) { - debug_printf("Forgot to flush:\n"); - debug_backtrace_dump(vswc->must_flush_stack, VMW_MUST_FLUSH_STACK); - assert(!vswc->must_flush); - } -#endif - - assert(nr_bytes <= vswc->command.size); - if(nr_bytes > vswc->command.size) - return NULL; - - if(vswc->preemptive_flush || - vswc->command.used + nr_bytes > vswc->command.size || - vswc->surface.used + nr_relocs > vswc->surface.size || - vswc->region.used + nr_relocs > vswc->region.size) { -#ifdef DEBUG - vswc->must_flush = TRUE; - debug_backtrace_capture(vswc->must_flush_stack, 1, - VMW_MUST_FLUSH_STACK); -#endif - return NULL; - } - - assert(vswc->command.used + nr_bytes <= vswc->command.size); - assert(vswc->surface.used + nr_relocs <= vswc->surface.size); - assert(vswc->region.used + nr_relocs <= vswc->region.size); - - vswc->command.reserved = nr_bytes; - vswc->surface.reserved = nr_relocs; - vswc->surface.staged = 0; - vswc->region.reserved = nr_relocs; - vswc->region.staged = 0; - - return vswc->command.buffer + vswc->command.used; -} - - -static void -vmw_swc_surface_relocation(struct svga_winsys_context *swc, - uint32 *where, - struct svga_winsys_surface *surface, - unsigned flags) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct vmw_svga_winsys_surface *vsurf; - - if(!surface) { - *where = SVGA3D_INVALID_ID; - return; - } - - assert(vswc->surface.staged < vswc->surface.reserved); - - vsurf = vmw_svga_winsys_surface(surface); - - *where = vsurf->sid; - - vmw_svga_winsys_surface_reference(&vswc->surface.handles[vswc->surface.used + vswc->surface.staged], vsurf); - p_atomic_inc(&vsurf->validated); - ++vswc->surface.staged; -} - - -static void -vmw_swc_region_relocation(struct svga_winsys_context *swc, - struct SVGAGuestPtr *where, - struct svga_winsys_buffer *buffer, - uint32 offset, - unsigned flags) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct vmw_region_relocation *reloc; - enum pipe_error ret; - - assert(vswc->region.staged < vswc->region.reserved); - - reloc = &vswc->region.relocs[vswc->region.used + vswc->region.staged]; - reloc->where = where; - pb_reference(&reloc->buffer, vmw_pb_buffer(buffer)); - reloc->offset = offset; - - ++vswc->region.staged; - - ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags); - /* TODO: Update pipebuffer to reserve buffers and not fail here */ - assert(ret == PIPE_OK); - - /* - * Flush preemptively the FIFO commands to keep the GMR working set within - * the GMR pool size. - * - * This is necessary for applications like SPECviewperf that generate huge - * amounts of immediate vertex data, so that we don't pile up too much of - * that vertex data neither in the guest nor in the host. - * - * Note that in the current implementation if a region is referred twice in - * a command stream, it will be accounted twice. We could detect repeated - * regions and count only once, but there is no incentive to do that, since - * regions are typically short-lived; always referred in a single command; - * and at the worst we just flush the commands a bit sooner, which for the - * SVGA virtual device it's not a performance issue since flushing commands - * to the FIFO won't cause flushing in the host. - */ - vswc->seen_regions += reloc->buffer->base.size; - if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2) - vswc->preemptive_flush = TRUE; -} - - -static void -vmw_swc_commit(struct svga_winsys_context *swc) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - - assert(vswc->command.reserved); - assert(vswc->command.used + vswc->command.reserved <= vswc->command.size); - vswc->command.used += vswc->command.reserved; - vswc->command.reserved = 0; - - assert(vswc->surface.staged <= vswc->surface.reserved); - assert(vswc->surface.used + vswc->surface.staged <= vswc->surface.size); - vswc->surface.used += vswc->surface.staged; - vswc->surface.staged = 0; - vswc->surface.reserved = 0; - - assert(vswc->region.staged <= vswc->region.reserved); - assert(vswc->region.used + vswc->region.staged <= vswc->region.size); - vswc->region.used += vswc->region.staged; - vswc->region.staged = 0; - vswc->region.reserved = 0; -} - - -static void -vmw_swc_destroy(struct svga_winsys_context *swc) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - unsigned i; - - for(i = 0; i < vswc->region.used; ++i) { - pb_reference(&vswc->region.relocs[i].buffer, NULL); - } - - for(i = 0; i < vswc->surface.used; ++i) { - p_atomic_dec(&vswc->surface.handles[i]->validated); - vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); - } - pb_validate_destroy(vswc->validate); - vmw_ioctl_context_destroy(vswc->vws, swc->cid); - FREE(vswc); -} - - -struct svga_winsys_context * -vmw_svga_winsys_context_create(struct svga_winsys_screen *sws) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct vmw_svga_winsys_context *vswc; - - vswc = CALLOC_STRUCT(vmw_svga_winsys_context); - if(!vswc) - return NULL; - - vswc->base.destroy = vmw_swc_destroy; - vswc->base.reserve = vmw_swc_reserve; - vswc->base.surface_relocation = vmw_swc_surface_relocation; - vswc->base.region_relocation = vmw_swc_region_relocation; - vswc->base.commit = vmw_swc_commit; - vswc->base.flush = vmw_swc_flush; - - vswc->base.cid = vmw_ioctl_context_create(vws); - - vswc->vws = vws; - - vswc->command.size = VMW_COMMAND_SIZE; - vswc->surface.size = VMW_SURFACE_RELOCS; - vswc->region.size = VMW_REGION_RELOCS; - - vswc->validate = pb_validate_create(); - if(!vswc->validate) { - FREE(vswc); - return NULL; - } - - return &vswc->base; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_context.h b/src/gallium/winsys/drm/vmware/core/vmw_context.h deleted file mode 100644 index d4884d24e99..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_context.h +++ /dev/null @@ -1,56 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @author Jose Fonseca - */ - - -#ifndef VMW_CONTEXT_H_ -#define VMW_CONTEXT_H_ - -#include "pipe/p_compiler.h" - -struct svga_winsys_screen; -struct svga_winsys_context; -struct pipe_context; -struct pipe_screen; - -#define VMW_DEBUG 0 - -#if VMW_DEBUG -#define vmw_printf debug_printf -#define VMW_FUNC debug_printf("%s\n", __FUNCTION__) -#else -#define VMW_FUNC -#define vmw_printf(...) -#endif - - -struct svga_winsys_context * -vmw_svga_winsys_context_create(struct svga_winsys_screen *sws); - - -#endif /* VMW_CONTEXT_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_fence.c b/src/gallium/winsys/drm/vmware/core/vmw_fence.c deleted file mode 100644 index 873dd51166c..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_fence.c +++ /dev/null @@ -1,108 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer_fenced.h" - -#include "vmw_screen.h" -#include "vmw_fence.h" - - - -struct vmw_fence_ops -{ - struct pb_fence_ops base; - - struct vmw_winsys_screen *vws; -}; - - -static INLINE struct vmw_fence_ops * -vmw_fence_ops(struct pb_fence_ops *ops) -{ - assert(ops); - return (struct vmw_fence_ops *)ops; -} - - -static void -vmw_fence_ops_fence_reference(struct pb_fence_ops *ops, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - *ptr = fence; -} - - -static int -vmw_fence_ops_fence_signalled(struct pb_fence_ops *ops, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; - (void)flag; - return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); -} - - -static int -vmw_fence_ops_fence_finish(struct pb_fence_ops *ops, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; - (void)flag; - return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); -} - - -static void -vmw_fence_ops_destroy(struct pb_fence_ops *ops) -{ - FREE(ops); -} - - -struct pb_fence_ops * -vmw_fence_ops_create(struct vmw_winsys_screen *vws) -{ - struct vmw_fence_ops *ops; - - ops = CALLOC_STRUCT(vmw_fence_ops); - if(!ops) - return NULL; - - ops->base.destroy = &vmw_fence_ops_destroy; - ops->base.fence_reference = &vmw_fence_ops_fence_reference; - ops->base.fence_signalled = &vmw_fence_ops_fence_signalled; - ops->base.fence_finish = &vmw_fence_ops_fence_finish; - - ops->vws = vws; - - return &ops->base; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_fence.h b/src/gallium/winsys/drm/vmware/core/vmw_fence.h deleted file mode 100644 index 5357b4f61de..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_fence.h +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#ifndef VMW_FENCE_H_ -#define VMW_FENCE_H_ - - -#include "pipe/p_compiler.h" - - -struct pipe_fence_handle; -struct pb_fence_ops; -struct vmw_winsys_screen; - - -/** Cast from a pipe_fence_handle pointer into a SVGA fence */ -static INLINE uint32_t -vmw_fence( struct pipe_fence_handle *fence ) -{ - return (uint32_t)(uintptr_t)fence; -} - - -/** Cast from a SVGA fence number to pipe_fence_handle pointer */ -static INLINE struct pipe_fence_handle * -vmw_pipe_fence( uint32_t fence ) -{ - return (struct pipe_fence_handle *)(uintptr_t)fence; -} - - -struct pb_fence_ops * -vmw_fence_ops_create(struct vmw_winsys_screen *vws); - - -#endif /* VMW_FENCE_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen.c b/src/gallium/winsys/drm/vmware/core/vmw_screen.c deleted file mode 100644 index 6cc9b382932..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen.c +++ /dev/null @@ -1,77 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "vmw_screen.h" - -#include "vmw_context.h" - -#include "util/u_memory.h" -#include "pipe/p_compiler.h" - - -/* Called from vmw_drm_create_screen(), creates and initializes the - * vmw_winsys_screen structure, which is the main entity in this - * module. - */ -struct vmw_winsys_screen * -vmw_winsys_create( int fd, boolean use_old_scanout_flag ) -{ - struct vmw_winsys_screen *vws = CALLOC_STRUCT(vmw_winsys_screen); - if (!vws) - goto out_no_vws; - - vws->ioctl.drm_fd = fd; - vws->use_old_scanout_flag = use_old_scanout_flag; - debug_printf("%s: use_old_scanout_flag == %s\n", __FUNCTION__, - use_old_scanout_flag ? "true" : "false"); - - if (!vmw_ioctl_init(vws)) - goto out_no_ioctl; - - if(!vmw_pools_init(vws)) - goto out_no_pools; - - if (!vmw_winsys_screen_init_svga(vws)) - goto out_no_svga; - - return vws; -out_no_svga: - vmw_pools_cleanup(vws); -out_no_pools: - vmw_ioctl_cleanup(vws); -out_no_ioctl: - FREE(vws); -out_no_vws: - return NULL; -} - -void -vmw_winsys_destroy(struct vmw_winsys_screen *vws) -{ - vmw_pools_cleanup(vws); - vmw_ioctl_cleanup(vws); - FREE(vws); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen.h b/src/gallium/winsys/drm/vmware/core/vmw_screen.h deleted file mode 100644 index d3f2c2c7f56..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen.h +++ /dev/null @@ -1,140 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Common definitions for the VMware SVGA winsys. - * - * @author Jose Fonseca - */ - - -#ifndef VMW_SCREEN_H_ -#define VMW_SCREEN_H_ - - -#include "pipe/p_compiler.h" -#include "pipe/p_state.h" - -#include "svga_winsys.h" - - -#define VMW_GMR_POOL_SIZE (16*1024*1024) - - -struct pb_manager; -struct vmw_region; - - -struct vmw_winsys_screen -{ - struct svga_winsys_screen base; - - boolean use_old_scanout_flag; - - struct { - volatile uint32_t *fifo_map; - uint64_t last_fence; - int drm_fd; - } ioctl; - - struct { - struct pb_manager *gmr; - struct pb_manager *gmr_mm; - struct pb_manager *gmr_fenced; - } pools; -}; - - -static INLINE struct vmw_winsys_screen * -vmw_winsys_screen(struct svga_winsys_screen *base) -{ - return (struct vmw_winsys_screen *)base; -} - -/* */ -uint32 -vmw_ioctl_context_create(struct vmw_winsys_screen *vws); - -void -vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, - uint32 cid); - -uint32 -vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32 numFaces, - uint32 numMipLevels); - -void -vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, - uint32 sid); - -void -vmw_ioctl_command(struct vmw_winsys_screen *vws, - void *commands, - uint32_t size, - uint32_t *fence); - -struct vmw_region * -vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size); - -void -vmw_ioctl_region_destroy(struct vmw_region *region); - -struct SVGAGuestPtr -vmw_ioctl_region_ptr(struct vmw_region *region); - -void * -vmw_ioctl_region_map(struct vmw_region *region); -void -vmw_ioctl_region_unmap(struct vmw_region *region); - - -int -vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, - uint32_t fence); - -int -vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, - uint32_t fence); - - -/* Initialize parts of vmw_winsys_screen at startup: - */ -boolean vmw_ioctl_init(struct vmw_winsys_screen *vws); -boolean vmw_pools_init(struct vmw_winsys_screen *vws); -boolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws); - -void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws); -void vmw_pools_cleanup(struct vmw_winsys_screen *vws); - -struct vmw_winsys_screen *vmw_winsys_create(int fd, boolean use_old_scanout_flag); -void vmw_winsys_destroy(struct vmw_winsys_screen *sws); - - -#endif /* VMW_SCREEN_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c deleted file mode 100644 index 657544dcb21..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c +++ /dev/null @@ -1,373 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "pipe/p_compiler.h" -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_format.h" -#include "vmw_screen.h" - -#include "trace/tr_drm.h" - -#include "vmw_screen.h" -#include "vmw_surface.h" -#include "vmw_fence.h" -#include "vmw_context.h" - -#include -#include -#include -#include - -#include - -static struct svga_winsys_surface * -vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, - struct winsys_handle *whandle, - SVGA3dSurfaceFormat *format); -static boolean -vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface, - unsigned stride, - struct winsys_handle *whandle); - -static struct dri1_api dri1_api_hooks; -static struct dri1_api_version ddx_required = { 0, 1, 0 }; -static struct dri1_api_version ddx_compat = { 0, 0, 0 }; -static struct dri1_api_version dri_required = { 4, 0, 0 }; -static struct dri1_api_version dri_compat = { 4, 0, 0 }; -static struct dri1_api_version drm_required = { 1, 0, 0 }; -static struct dri1_api_version drm_compat = { 1, 0, 0 }; -static struct dri1_api_version drm_scanout = { 0, 9, 0 }; - -static boolean -vmw_dri1_check_version(const struct dri1_api_version *cur, - const struct dri1_api_version *required, - const struct dri1_api_version *compat, - const char component[]) -{ - if (cur->major > required->major && cur->major <= compat->major) - return TRUE; - if (cur->major == required->major && cur->minor >= required->minor) - return TRUE; - - fprintf(stderr, "%s version failure.\n", component); - fprintf(stderr, "%s version is %d.%d.%d and this driver can only work\n" - "with versions %d.%d.x through %d.x.x.\n", - component, - cur->major, - cur->minor, - cur->patch_level, required->major, required->minor, compat->major); - return FALSE; -} - -/* This is actually the entrypoint to the entire driver, called by the - * libGL (or EGL, or ...) code via the drm_api_hooks table at the - * bottom of the file. - */ -static struct pipe_screen * -vmw_drm_create_screen(struct drm_api *drm_api, - int fd, - struct drm_create_screen_arg *arg) -{ - struct vmw_winsys_screen *vws; - struct pipe_screen *screen; - struct dri1_create_screen_arg *dri1; - boolean use_old_scanout_flag = FALSE; - - if (!arg || arg->mode == DRM_CREATE_NORMAL) { - struct dri1_api_version drm_ver; - drmVersionPtr ver; - - ver = drmGetVersion(fd); - if (ver == NULL) - return NULL; - - drm_ver.major = ver->version_major; - drm_ver.minor = ver->version_minor; - drm_ver.patch_level = 0; /* ??? */ - - drmFreeVersion(ver); - if (!vmw_dri1_check_version(&drm_ver, &drm_required, - &drm_compat, "vmwgfx drm driver")) - return NULL; - - if (!vmw_dri1_check_version(&drm_ver, &drm_scanout, - &drm_compat, "use old scanout field (not a error)")) - use_old_scanout_flag = TRUE; - } - - if (arg != NULL) { - switch (arg->mode) { - case DRM_CREATE_NORMAL: - break; - case DRM_CREATE_DRI1: - dri1 = (struct dri1_create_screen_arg *)arg; - if (!vmw_dri1_check_version(&dri1->ddx_version, &ddx_required, - &ddx_compat, "ddx - driver api")) - return NULL; - if (!vmw_dri1_check_version(&dri1->dri_version, &dri_required, - &dri_compat, "dri info")) - return NULL; - if (!vmw_dri1_check_version(&dri1->drm_version, &drm_required, - &drm_compat, "vmwgfx drm driver")) - return NULL; - if (!vmw_dri1_check_version(&dri1->drm_version, &drm_scanout, - &drm_compat, "use old scanout field (not a error)")) - use_old_scanout_flag = TRUE; - dri1->api = &dri1_api_hooks; -#if 0 - break; -#else - assert(!"No dri 1 support for now\n"); - return NULL; -#endif - default: - return NULL; - } - } - - vws = vmw_winsys_create( fd, use_old_scanout_flag ); - if (!vws) - goto out_no_vws; - - /* XXX do this properly */ - vws->base.surface_from_handle = vmw_drm_surface_from_handle; - vws->base.surface_get_handle = vmw_drm_surface_get_handle; - - screen = svga_screen_create( &vws->base ); - if (!screen) - goto out_no_screen; - - return screen; - - /* Failure cases: - */ -out_no_screen: - vmw_winsys_destroy( vws ); - -out_no_vws: - return NULL; -} - -static INLINE boolean -vmw_dri1_intersect_src_bbox(struct drm_clip_rect *dst, - int dst_x, - int dst_y, - const struct drm_clip_rect *src, - const struct drm_clip_rect *bbox) -{ - int xy1; - int xy2; - - xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : - (int)bbox->x1 + dst_x; - xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : - (int)bbox->x2 + dst_x; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->x1 = xy1; - dst->x2 = xy2; - - xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : - (int)bbox->y1 + dst_y; - xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : - (int)bbox->y2 + dst_y; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->y1 = xy1; - dst->y2 = xy2; - return TRUE; -} - -/** - * No fancy get-surface-from-sarea stuff here. - * Just use the present blit. - */ - -static void -vmw_dri1_present_locked(struct pipe_context *locked_pipe, - struct pipe_surface *surf, - const struct drm_clip_rect *rect, - unsigned int num_clip, - int x_draw, int y_draw, - const struct drm_clip_rect *bbox, - struct pipe_fence_handle **p_fence) -{ -#if 0 - struct svga_winsys_surface *srf = - svga_screen_texture_get_winsys_surface(surf->texture); - struct vmw_svga_winsys_surface *vsrf = vmw_svga_winsys_surface(srf); - struct vmw_winsys_screen *vws = - vmw_winsys_screen(svga_winsys_screen(locked_pipe->screen)); - struct drm_clip_rect clip; - int i; - struct - { - SVGA3dCmdHeader header; - SVGA3dCmdPresent body; - SVGA3dCopyRect rect; - } cmd; - boolean visible = FALSE; - uint32_t fence_seq = 0; - - VMW_FUNC; - cmd.header.id = SVGA_3D_CMD_PRESENT; - cmd.header.size = sizeof cmd.body + sizeof cmd.rect; - cmd.body.sid = vsrf->sid; - - for (i = 0; i < num_clip; ++i) { - if (!vmw_dri1_intersect_src_bbox(&clip, x_draw, y_draw, rect++, bbox)) - continue; - - cmd.rect.x = clip.x1; - cmd.rect.y = clip.y1; - cmd.rect.w = clip.x2 - clip.x1; - cmd.rect.h = clip.y2 - clip.y1; - cmd.rect.srcx = (int)clip.x1 - x_draw; - cmd.rect.srcy = (int)clip.y1 - y_draw; - - vmw_printf("%s: Clip %d x %d y %d w %d h %d srcx %d srcy %d\n", - __FUNCTION__, - i, - cmd.rect.x, - cmd.rect.y, - cmd.rect.w, cmd.rect.h, cmd.rect.srcx, cmd.rect.srcy); - - vmw_ioctl_command(vws, &cmd, sizeof cmd.header + cmd.header.size, - &fence_seq); - visible = TRUE; - } - - *p_fence = (visible) ? vmw_pipe_fence(fence_seq) : NULL; - vmw_svga_winsys_surface_reference(&vsrf, NULL); -#else - assert(!"No dri 1 support for now\n"); -#endif -} - -static struct svga_winsys_surface * -vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, - struct winsys_handle *whandle, - SVGA3dSurfaceFormat *format) -{ - struct vmw_svga_winsys_surface *vsrf; - struct svga_winsys_surface *ssrf; - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - union drm_vmw_surface_reference_arg arg; - struct drm_vmw_surface_arg *req = &arg.req; - struct drm_vmw_surface_create_req *rep = &arg.rep; - int ret; - int i; - - /** - * The vmware device specific handle is the hardware SID. - * FIXME: We probably want to move this to the ioctl implementations. - */ - - memset(&arg, 0, sizeof(arg)); - req->sid = whandle->handle; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_REF_SURFACE, - &arg, sizeof(arg)); - - if (ret) { - fprintf(stderr, "Failed referencing shared surface. SID %d.\n" - "Error %d (%s).\n", - whandle->handle, ret, strerror(-ret)); - return NULL; - } - - if (rep->mip_levels[0] != 1) { - fprintf(stderr, "Incorrect number of mipmap levels on shared surface." - " SID %d, levels %d\n", - whandle->handle, rep->mip_levels[0]); - goto out_mip; - } - - for (i=1; i < DRM_VMW_MAX_SURFACE_FACES; ++i) { - if (rep->mip_levels[i] != 0) { - fprintf(stderr, "Incorrect number of faces levels on shared surface." - " SID %d, face %d present.\n", - whandle->handle, i); - goto out_mip; - } - } - - vsrf = CALLOC_STRUCT(vmw_svga_winsys_surface); - if (!vsrf) - goto out_mip; - - pipe_reference_init(&vsrf->refcnt, 1); - p_atomic_set(&vsrf->validated, 0); - vsrf->screen = vws; - vsrf->sid = whandle->handle; - ssrf = svga_winsys_surface(vsrf); - *format = rep->format; - - return ssrf; - -out_mip: - vmw_ioctl_surface_destroy(vws, whandle->handle); - return NULL; -} - -static boolean -vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface, - unsigned stride, - struct winsys_handle *whandle) -{ - struct vmw_svga_winsys_surface *vsrf; - - if (!surface) - return FALSE; - - vsrf = vmw_svga_winsys_surface(surface); - whandle->handle = vsrf->sid; - whandle->stride = stride; - - return TRUE; -} - - -static struct dri1_api dri1_api_hooks = { - .front_srf_locked = NULL, - .present_locked = vmw_dri1_present_locked -}; - -static struct drm_api vmw_drm_api_hooks = { - .name = "vmwgfx", - .driver_name = "vmwgfx", - .create_screen = vmw_drm_create_screen, -}; - -struct drm_api* drm_api_create() -{ - return trace_drm_create(&vmw_drm_api_hooks); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c deleted file mode 100644 index 5d81fa8c4a6..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c +++ /dev/null @@ -1,529 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * - * Wrappers for DRM ioctl functionlaity used by the rest of the vmw - * drm winsys. - * - * Based on svgaicd_escape.c - */ - - -#include "svga_cmd.h" -#include "util/u_memory.h" -#include "util/u_math.h" -#include "svgadump/svga_dump.h" -#include "vmw_screen.h" -#include "vmw_context.h" -#include "xf86drm.h" -#include "vmwgfx_drm.h" - -#include -#include -#include - -struct vmw_region -{ - SVGAGuestPtr ptr; - uint32_t handle; - uint64_t map_handle; - void *data; - uint32_t map_count; - int drm_fd; - uint32_t size; -}; - -/* XXX: This isn't a real hardware flag, but just a hack for kernel to - * know about primary surfaces. In newer versions of the kernel - * interface the driver uses a special field. - */ -#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) - -static void -vmw_check_last_cmd(struct vmw_winsys_screen *vws) -{ - static uint32_t buffer[16384]; - struct drm_vmw_fifo_debug_arg arg; - int ret; - - return; - memset(&arg, 0, sizeof(arg)); - arg.debug_buffer = (unsigned long)buffer; - arg.debug_buffer_size = 65536; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FIFO_DEBUG, - &arg, sizeof(arg)); - - if (ret) { - debug_printf("%s Ioctl error: \"%s\".\n", __FUNCTION__, strerror(-ret)); - return; - } - - if (arg.did_not_fit) { - debug_printf("%s Command did not fit completely.\n", __FUNCTION__); - } - - svga_dump_commands(buffer, arg.used_size); -} - -static void -vmw_ioctl_fifo_unmap(struct vmw_winsys_screen *vws, void *mapping) -{ - VMW_FUNC; - (void)munmap(mapping, getpagesize()); -} - - -static void * -vmw_ioctl_fifo_map(struct vmw_winsys_screen *vws, - uint32_t fifo_offset ) -{ - void *map; - - VMW_FUNC; - - map = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, - vws->ioctl.drm_fd, fifo_offset); - - if (map == MAP_FAILED) { - debug_printf("Map failed %s\n", strerror(errno)); - return NULL; - } - - vmw_printf("Fifo (min) is 0x%08x\n", ((uint32_t *) map)[SVGA_FIFO_MIN]); - - return map; -} - -uint32 -vmw_ioctl_context_create(struct vmw_winsys_screen *vws) -{ - struct drm_vmw_context_arg c_arg; - int ret; - - VMW_FUNC; - - ret = drmCommandRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_CONTEXT, - &c_arg, sizeof(c_arg)); - - if (ret) - return -1; - - vmw_check_last_cmd(vws); - vmw_printf("Context id is %d\n", c_arg.cid); - - return c_arg.cid; -} - -void -vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, uint32 cid) -{ - struct drm_vmw_context_arg c_arg; - - VMW_FUNC; - - memset(&c_arg, 0, sizeof(c_arg)); - c_arg.cid = cid; - - (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_CONTEXT, - &c_arg, sizeof(c_arg)); - - vmw_check_last_cmd(vws); -} - -uint32 -vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32_t numFaces, uint32_t numMipLevels) -{ - union drm_vmw_surface_create_arg s_arg; - struct drm_vmw_surface_create_req *req = &s_arg.req; - struct drm_vmw_surface_arg *rep = &s_arg.rep; - struct drm_vmw_size sizes[DRM_VMW_MAX_SURFACE_FACES* - DRM_VMW_MAX_MIP_LEVELS]; - struct drm_vmw_size *cur_size; - uint32_t iFace; - uint32_t iMipLevel; - int ret; - - vmw_printf("%s flags %d format %d\n", __FUNCTION__, flags, format); - - memset(&s_arg, 0, sizeof(s_arg)); - if (vws->use_old_scanout_flag && - (flags & SVGA3D_SURFACE_HINT_SCANOUT)) { - req->flags = (uint32_t) flags; - req->scanout = false; - } else if (flags & SVGA3D_SURFACE_HINT_SCANOUT) { - req->flags = (uint32_t) (flags & ~SVGA3D_SURFACE_HINT_SCANOUT); - req->scanout = true; - } else { - req->flags = (uint32_t) flags; - req->scanout = false; - } - req->format = (uint32_t) format; - req->shareable = 1; - - assert(numFaces * numMipLevels < DRM_VMW_MAX_SURFACE_FACES* - DRM_VMW_MAX_MIP_LEVELS); - cur_size = sizes; - for (iFace = 0; iFace < numFaces; ++iFace) { - SVGA3dSize mipSize = size; - - req->mip_levels[iFace] = numMipLevels; - for (iMipLevel = 0; iMipLevel < numMipLevels; ++iMipLevel) { - cur_size->width = mipSize.width; - cur_size->height = mipSize.height; - cur_size->depth = mipSize.depth; - mipSize.width = MAX2(mipSize.width >> 1, 1); - mipSize.height = MAX2(mipSize.height >> 1, 1); - mipSize.depth = MAX2(mipSize.depth >> 1, 1); - cur_size++; - } - } - for (iFace = numFaces; iFace < SVGA3D_MAX_SURFACE_FACES; ++iFace) { - req->mip_levels[iFace] = 0; - } - - req->size_addr = (unsigned long)&sizes; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_SURFACE, - &s_arg, sizeof(s_arg)); - - if (ret) - return -1; - - vmw_printf("Surface id is %d\n", rep->sid); - vmw_check_last_cmd(vws); - - return rep->sid; -} - -void -vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, uint32 sid) -{ - struct drm_vmw_surface_arg s_arg; - - VMW_FUNC; - - memset(&s_arg, 0, sizeof(s_arg)); - s_arg.sid = sid; - - (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_SURFACE, - &s_arg, sizeof(s_arg)); - vmw_check_last_cmd(vws); - -} - -void -vmw_ioctl_command(struct vmw_winsys_screen *vws, void *commands, uint32_t size, - uint32_t * pfence) -{ - struct drm_vmw_execbuf_arg arg; - struct drm_vmw_fence_rep rep; - int ret; - -#ifdef DEBUG - { - static boolean firsttime = TRUE; - static boolean debug = FALSE; - static boolean skip = FALSE; - if (firsttime) { - debug = debug_get_bool_option("SVGA_DUMP_CMD", FALSE); - skip = debug_get_bool_option("SVGA_SKIP_CMD", FALSE); - } - if (debug) { - VMW_FUNC; - svga_dump_commands(commands, size); - } - firsttime = FALSE; - if (skip) { - size = 0; - } - } -#endif - - memset(&arg, 0, sizeof(arg)); - memset(&rep, 0, sizeof(rep)); - - rep.error = -EFAULT; - arg.fence_rep = (unsigned long)&rep; - arg.commands = (unsigned long)commands; - arg.command_size = size; - - do { - ret = drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg)); - } while(ret == -ERESTART); - if (ret) { - debug_printf("%s error %s.\n", __FUNCTION__, strerror(-ret)); - } - if (rep.error) { - - /* - * Kernel has synced and put the last fence sequence in the FIFO - * register. - */ - - if (rep.error == -EFAULT) - rep.fence_seq = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - - debug_printf("%s Fence error %s.\n", __FUNCTION__, - strerror(-rep.error)); - } - - vws->ioctl.last_fence = rep.fence_seq; - - if (pfence) - *pfence = rep.fence_seq; - vmw_check_last_cmd(vws); - -} - - -struct vmw_region * -vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size) -{ - struct vmw_region *region; - union drm_vmw_alloc_dmabuf_arg arg; - struct drm_vmw_alloc_dmabuf_req *req = &arg.req; - struct drm_vmw_dmabuf_rep *rep = &arg.rep; - int ret; - - vmw_printf("%s: size = %u\n", __FUNCTION__, size); - - region = CALLOC_STRUCT(vmw_region); - if (!region) - goto out_err1; - - memset(&arg, 0, sizeof(arg)); - req->size = size; - do { - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_ALLOC_DMABUF, &arg, - sizeof(arg)); - } while (ret == -ERESTART); - - if (ret) { - debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); - goto out_err1; - } - - region->ptr.gmrId = rep->cur_gmr_id; - region->ptr.offset = rep->cur_gmr_offset; - region->data = NULL; - region->handle = rep->handle; - region->map_handle = rep->map_handle; - region->map_count = 0; - region->size = size; - region->drm_fd = vws->ioctl.drm_fd; - - vmw_printf(" gmrId = %u, offset = %u\n", - region->ptr.gmrId, region->ptr.offset); - - return region; - - out_err1: - FREE(region); - return NULL; -} - -void -vmw_ioctl_region_destroy(struct vmw_region *region) -{ - struct drm_vmw_unref_dmabuf_arg arg; - - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - - if (region->data) { - munmap(region->data, region->size); - region->data = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = region->handle; - drmCommandWrite(region->drm_fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); - - FREE(region); -} - -SVGAGuestPtr -vmw_ioctl_region_ptr(struct vmw_region *region) -{ - return region->ptr; -} - -void * -vmw_ioctl_region_map(struct vmw_region *region) -{ - void *map; - - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - - if (region->data == NULL) { - map = mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED, - region->drm_fd, region->map_handle); - if (map == MAP_FAILED) { - debug_printf("%s: Map failed.\n", __FUNCTION__); - return NULL; - } - - region->data = map; - } - - ++region->map_count; - - return region->data; -} - -void -vmw_ioctl_region_unmap(struct vmw_region *region) -{ - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - --region->map_count; -} - - -int -vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - uint32_t expected; - uint32_t current; - - assert(fence); - if(!fence) - return 0; - - expected = fence; - current = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - - if ((int32)(current - expected) >= 0) - return 0; /* fence passed */ - else - return -1; -} - - -static void -vmw_ioctl_sync(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - uint32_t cur_fence; - struct drm_vmw_fence_wait_arg arg; - int ret; - - vmw_printf("%s: fence = %lu\n", __FUNCTION__, - (unsigned long)fence); - - cur_fence = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - vmw_printf("%s: Fence id read is 0x%08x\n", __FUNCTION__, - (unsigned int)cur_fence); - - if ((cur_fence - fence) < (1 << 24)) - return; - - memset(&arg, 0, sizeof(arg)); - arg.sequence = fence; - - do { - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FENCE_WAIT, &arg, - sizeof(arg)); - } while (ret == -ERESTART); -} - - -int -vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - assert(fence); - - if(fence) { - if(vmw_ioctl_fence_signalled(vws, fence) != 0) { - vmw_ioctl_sync(vws, fence); - } - } - - return 0; -} - - -boolean -vmw_ioctl_init(struct vmw_winsys_screen *vws) -{ - struct drm_vmw_getparam_arg gp_arg; - int ret; - - VMW_FUNC; - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = DRM_VMW_PARAM_3D; - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - if (ret || gp_arg.value == 0) { - debug_printf("No 3D enabled (%i, %s)\n", ret, strerror(-ret)); - goto out_err1; - } - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = DRM_VMW_PARAM_FIFO_OFFSET; - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - - if (ret) { - debug_printf("GET_PARAM on %d returned %d: %s\n", - vws->ioctl.drm_fd, ret, strerror(-ret)); - goto out_err1; - } - - vmw_printf("Offset to map is 0x%08llx\n", - (unsigned long long)gp_arg.value); - - vws->ioctl.fifo_map = vmw_ioctl_fifo_map(vws, gp_arg.value); - if (vws->ioctl.fifo_map == NULL) - goto out_err1; - - vmw_printf("%s OK\n", __FUNCTION__); - return TRUE; - - out_err1: - debug_printf("%s Failed\n", __FUNCTION__); - return FALSE; -} - - - -void -vmw_ioctl_cleanup(struct vmw_winsys_screen *vws) -{ - VMW_FUNC; - - vmw_ioctl_fifo_unmap(vws, (void *)vws->ioctl.fifo_map); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c deleted file mode 100644 index b9823d78575..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c +++ /dev/null @@ -1,97 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "vmw_screen.h" - -#include "vmw_buffer.h" -#include "vmw_fence.h" - -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -void -vmw_pools_cleanup(struct vmw_winsys_screen *vws) -{ - if(vws->pools.gmr_fenced) - vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced); - - /* gmr_mm pool is already destroyed above */ - - if(vws->pools.gmr) - vws->pools.gmr->destroy(vws->pools.gmr); -} - - -boolean -vmw_pools_init(struct vmw_winsys_screen *vws) -{ - vws->pools.gmr = vmw_gmr_bufmgr_create(vws); - if(!vws->pools.gmr) - goto error; - - vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr, - VMW_GMR_POOL_SIZE, - 12 /* 4096 alignment */); - if(!vws->pools.gmr_mm) - goto error; - - /* - * GMR buffers are typically shortlived, but it's possible that at a given - * instance a buffer is mapped. So to avoid stalling we tell pipebuffer to - * forbid creation of buffers beyond half the GMR pool size, - * - * XXX: It is unclear weather we want to limit the total amount of temporary - * malloc memory used to backup unvalidated GMR buffers. On one hand it is - * preferrable to fail an allocation than exhausting the guest memory with - * temporary data, but on the other hand it is possible that a stupid - * application creates large vertex buffers and does not use them for a long - * time -- since the svga pipe driver only emits the DMA uploads when a - * buffer is used for drawing this would effectively disabling swapping GMR - * buffers to memory. So far, the preemptively flush already seems to keep - * total allocated memory within relatively small numbers, so we don't - * limit. - */ - vws->pools.gmr_fenced = fenced_bufmgr_create( - vws->pools.gmr_mm, - vmw_fence_ops_create(vws), - VMW_GMR_POOL_SIZE/2, - ~0); - -#ifdef DEBUG - vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced, - 4096, - 4096); -#endif - if(!vws->pools.gmr_fenced) - goto error; - - return TRUE; - -error: - vmw_pools_cleanup(vws); - return FALSE; -} - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c deleted file mode 100644 index 2b4e80f0039..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c +++ /dev/null @@ -1,295 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * This file implements the SVGA interface into this winsys, defined - * in drivers/svga/svga_winsys.h. - * - * @author Keith Whitwell - * @author Jose Fonseca - */ - - -#include "svga_cmd.h" -#include "svga3d_caps.h" - -#include "util/u_inlines.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" -#include "svga_winsys.h" -#include "vmw_context.h" -#include "vmw_screen.h" -#include "vmw_surface.h" -#include "vmw_buffer.h" -#include "vmw_fence.h" - - -static struct svga_winsys_buffer * -vmw_svga_winsys_buffer_create(struct svga_winsys_screen *sws, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct pb_desc desc; - struct pb_manager *provider; - struct pb_buffer *buffer; - - memset(&desc, 0, sizeof desc); - desc.alignment = alignment; - desc.usage = usage; - - provider = vws->pools.gmr_fenced; - - assert(provider); - buffer = provider->create_buffer(provider, size, &desc); - if(!buffer) - return NULL; - - return vmw_svga_winsys_buffer(buffer); -} - - -static void * -vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf, - unsigned flags) -{ - (void)sws; - return pb_map(vmw_pb_buffer(buf), flags); -} - - -static void -vmw_svga_winsys_buffer_unmap(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf) -{ - (void)sws; - pb_unmap(vmw_pb_buffer(buf)); -} - - -static void -vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf) -{ - struct pb_buffer *pbuf = vmw_pb_buffer(buf); - (void)sws; - pb_reference(&pbuf, NULL); -} - - -static void -vmw_svga_winsys_fence_reference(struct svga_winsys_screen *sws, - struct pipe_fence_handle **pdst, - struct pipe_fence_handle *src) -{ - (void)sws; - *pdst = src; -} - - -static int -vmw_svga_winsys_fence_signalled(struct svga_winsys_screen *sws, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - (void)flag; - return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); -} - - -static int -vmw_svga_winsys_fence_finish(struct svga_winsys_screen *sws, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - (void)flag; - return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); -} - - - -static struct svga_winsys_surface * -vmw_svga_winsys_surface_create(struct svga_winsys_screen *sws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32 numFaces, - uint32 numMipLevels) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct vmw_svga_winsys_surface *surface; - - surface = CALLOC_STRUCT(vmw_svga_winsys_surface); - if(!surface) - goto no_surface; - - pipe_reference_init(&surface->refcnt, 1); - p_atomic_set(&surface->validated, 0); - surface->screen = vws; - surface->sid = vmw_ioctl_surface_create(vws, - flags, format, size, - numFaces, numMipLevels); - if(surface->sid == SVGA3D_INVALID_ID) - goto no_sid; - - return svga_winsys_surface(surface); - -no_sid: - FREE(surface); -no_surface: - return NULL; -} - - -static boolean -vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface) -{ - struct vmw_svga_winsys_surface *vsurf = vmw_svga_winsys_surface(surface); - return (p_atomic_read(&vsurf->validated) == 0); -} - - -static void -vmw_svga_winsys_surface_ref(struct svga_winsys_screen *sws, - struct svga_winsys_surface **pDst, - struct svga_winsys_surface *src) -{ - struct vmw_svga_winsys_surface *d_vsurf = vmw_svga_winsys_surface(*pDst); - struct vmw_svga_winsys_surface *s_vsurf = vmw_svga_winsys_surface(src); - - vmw_svga_winsys_surface_reference(&d_vsurf, s_vsurf); - *pDst = svga_winsys_surface(d_vsurf); -} - - -static void -vmw_svga_winsys_destroy(struct svga_winsys_screen *sws) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - - vmw_winsys_destroy(vws); -} - - -static boolean -vmw_svga_winsys_get_cap(struct svga_winsys_screen *sws, - SVGA3dDevCapIndex index, - SVGA3dDevCapResult *result) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - const uint32 *capsBlock; - const SVGA3dCapsRecord *capsRecord = NULL; - uint32 offset; - const SVGA3dCapPair *capArray; - int numCaps, first, last; - - if(!vws->ioctl.fifo_map) - return FALSE; - - if(vws->ioctl.fifo_map[SVGA_FIFO_3D_HWVERSION] < SVGA3D_HWVERSION_WS6_B1) - return FALSE; - - /* - * Search linearly through the caps block records for the specified type. - */ - capsBlock = (const uint32 *)&vws->ioctl.fifo_map[SVGA_FIFO_3D_CAPS]; - for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { - const SVGA3dCapsRecord *record; - assert(offset < SVGA_FIFO_3D_CAPS_SIZE); - record = (const SVGA3dCapsRecord *) (capsBlock + offset); - if ((record->header.type >= SVGA3DCAPS_RECORD_DEVCAPS_MIN) && - (record->header.type <= SVGA3DCAPS_RECORD_DEVCAPS_MAX) && - (!capsRecord || (record->header.type > capsRecord->header.type))) { - capsRecord = record; - } - } - - if(!capsRecord) - return FALSE; - - /* - * Calculate the number of caps from the size of the record. - */ - capArray = (const SVGA3dCapPair *) capsRecord->data; - numCaps = (int) ((capsRecord->header.length * sizeof(uint32) - - sizeof capsRecord->header) / (2 * sizeof(uint32))); - - /* - * Binary-search for the cap with the specified index. - */ - for (first = 0, last = numCaps - 1; first <= last; ) { - int mid = (first + last) / 2; - - if ((SVGA3dDevCapIndex) capArray[mid][0] == index) { - /* - * Found it. - */ - result->u = capArray[mid][1]; - return TRUE; - } - - /* - * Divide and conquer. - */ - if ((SVGA3dDevCapIndex) capArray[mid][0] > index) { - last = mid - 1; - } else { - first = mid + 1; - } - } - - return FALSE; -} - - -boolean -vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws) -{ - vws->base.destroy = vmw_svga_winsys_destroy; - vws->base.get_cap = vmw_svga_winsys_get_cap; - vws->base.context_create = vmw_svga_winsys_context_create; - vws->base.surface_create = vmw_svga_winsys_surface_create; - vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed; - vws->base.surface_reference = vmw_svga_winsys_surface_ref; - vws->base.buffer_create = vmw_svga_winsys_buffer_create; - vws->base.buffer_map = vmw_svga_winsys_buffer_map; - vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap; - vws->base.buffer_destroy = vmw_svga_winsys_buffer_destroy; - vws->base.fence_reference = vmw_svga_winsys_fence_reference; - vws->base.fence_signalled = vmw_svga_winsys_fence_signalled; - vws->base.fence_finish = vmw_svga_winsys_fence_finish; - - return TRUE; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_surface.c b/src/gallium/winsys/drm/vmware/core/vmw_surface.c deleted file mode 100644 index 5f1b9ad5770..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_surface.c +++ /dev/null @@ -1,61 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - - -#include "svga_cmd.h" -#include "util/u_debug.h" -#include "util/u_memory.h" - -#include "vmw_surface.h" -#include "vmw_screen.h" - -void -vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, - struct vmw_svga_winsys_surface *src) -{ - struct pipe_reference *src_ref; - struct pipe_reference *dst_ref; - struct vmw_svga_winsys_surface *dst; - - if(pdst == NULL || *pdst == src) - return; - - dst = *pdst; - - src_ref = src ? &src->refcnt : NULL; - dst_ref = dst ? &dst->refcnt : NULL; - - if (pipe_reference(dst_ref, src_ref)) { - vmw_ioctl_surface_destroy(dst->screen, dst->sid); -#ifdef DEBUG - /* to detect dangling pointers */ - assert(p_atomic_read(&dst->validated) == 0); - dst->sid = SVGA3D_INVALID_ID; -#endif - FREE(dst); - } - - *pdst = src; -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_surface.h b/src/gallium/winsys/drm/vmware/core/vmw_surface.h deleted file mode 100644 index 3d61595c288..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_surface.h +++ /dev/null @@ -1,79 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, 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. - * - **********************************************************/ - -/** - * @file - * Surfaces for VMware SVGA winsys. - * - * @author Jose Fonseca - */ - - -#ifndef VMW_SURFACE_H_ -#define VMW_SURFACE_H_ - - -#include "pipe/p_compiler.h" -#include "util/u_atomic.h" -#include "util/u_inlines.h" - -#define VMW_MAX_PRESENTS 3 - - - -struct vmw_svga_winsys_surface -{ - int32_t validated; /* atomic */ - struct pipe_reference refcnt; - - struct vmw_winsys_screen *screen; - uint32_t sid; - - /* FIXME: make this thread safe */ - unsigned next_present_no; - uint32_t present_fences[VMW_MAX_PRESENTS]; -}; - - -static INLINE struct svga_winsys_surface * -svga_winsys_surface(struct vmw_svga_winsys_surface *surf) -{ - assert(!surf || surf->sid != SVGA3D_INVALID_ID); - return (struct svga_winsys_surface *)surf; -} - - -static INLINE struct vmw_svga_winsys_surface * -vmw_svga_winsys_surface(struct svga_winsys_surface *surf) -{ - return (struct vmw_svga_winsys_surface *)surf; -} - - -void -vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, - struct vmw_svga_winsys_surface *src); - -#endif /* VMW_SURFACE_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h b/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h deleted file mode 100644 index 47914bdb711..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h +++ /dev/null @@ -1,545 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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 __VMWGFX_DRM_H__ -#define __VMWGFX_DRM_H__ - -#define DRM_VMW_MAX_SURFACE_FACES 6 -#define DRM_VMW_MAX_MIP_LEVELS 24 - -#define DRM_VMW_EXT_NAME_LEN 128 - -#define DRM_VMW_GET_PARAM 0 -#define DRM_VMW_ALLOC_DMABUF 1 -#define DRM_VMW_UNREF_DMABUF 2 -#define DRM_VMW_CURSOR_BYPASS 3 -/* guarded by DRM_VMW_PARAM_NUM_STREAMS != 0*/ -#define DRM_VMW_CONTROL_STREAM 4 -#define DRM_VMW_CLAIM_STREAM 5 -#define DRM_VMW_UNREF_STREAM 6 -/* guarded by DRM_VMW_PARAM_3D == 1 */ -#define DRM_VMW_CREATE_CONTEXT 7 -#define DRM_VMW_UNREF_CONTEXT 8 -#define DRM_VMW_CREATE_SURFACE 9 -#define DRM_VMW_UNREF_SURFACE 10 -#define DRM_VMW_REF_SURFACE 11 -#define DRM_VMW_EXECBUF 12 -#define DRM_VMW_FIFO_DEBUG 13 -#define DRM_VMW_FENCE_WAIT 14 - - -/*************************************************************************/ -/** - * DRM_VMW_GET_PARAM - get device information. - * - * DRM_VMW_PARAM_FIFO_OFFSET: - * Offset to use to map the first page of the FIFO read-only. - * The fifo is mapped using the mmap() system call on the drm device. - * - * DRM_VMW_PARAM_OVERLAY_IOCTL: - * Does the driver support the overlay ioctl. - */ - -#define DRM_VMW_PARAM_NUM_STREAMS 0 -#define DRM_VMW_PARAM_NUM_FREE_STREAMS 1 -#define DRM_VMW_PARAM_3D 2 -#define DRM_VMW_PARAM_FIFO_OFFSET 3 -#define DRM_VMW_PARAM_HW_CAPS 4 -#define DRM_VMW_PARAM_FIFO_CAPS 5 - -/** - * struct drm_vmw_getparam_arg - * - * @value: Returned value. //Out - * @param: Parameter to query. //In. - * - * Argument to the DRM_VMW_GET_PARAM Ioctl. - */ - -struct drm_vmw_getparam_arg { - uint64_t value; - uint32_t param; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CREATE_CONTEXT - Create a host context. - * - * Allocates a device unique context id, and queues a create context command - * for the host. Does not wait for host completion. - */ - -/** - * struct drm_vmw_context_arg - * - * @cid: Device unique context ID. - * - * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. - * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. - */ - -struct drm_vmw_context_arg { - int32_t cid; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_CONTEXT - Create a host context. - * - * Frees a global context id, and queues a destroy host command for the host. - * Does not wait for host completion. The context ID can be used directly - * in the command stream and shows up as the same context ID on the host. - */ - -/*************************************************************************/ -/** - * DRM_VMW_CREATE_SURFACE - Create a host suface. - * - * Allocates a device unique surface id, and queues a create surface command - * for the host. Does not wait for host completion. The surface ID can be - * used directly in the command stream and shows up as the same surface - * ID on the host. - */ - -/** - * struct drm_wmv_surface_create_req - * - * @flags: Surface flags as understood by the host. - * @format: Surface format as understood by the host. - * @mip_levels: Number of mip levels for each face. - * An unused face should have 0 encoded. - * @size_addr: Address of a user-space array of sruct drm_vmw_size - * cast to an uint64_t for 32-64 bit compatibility. - * The size of the array should equal the total number of mipmap levels. - * @shareable: Boolean whether other clients (as identified by file descriptors) - * may reference this surface. - * @scanout: Boolean whether the surface is intended to be used as a - * scanout. - * - * Input data to the DRM_VMW_CREATE_SURFACE Ioctl. - * Output data from the DRM_VMW_REF_SURFACE Ioctl. - */ - -struct drm_vmw_surface_create_req { - uint32_t flags; - uint32_t format; - uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; - uint64_t size_addr; - int32_t shareable; - int32_t scanout; -}; - -/** - * struct drm_wmv_surface_arg - * - * @sid: Surface id of created surface or surface to destroy or reference. - * - * Output data from the DRM_VMW_CREATE_SURFACE Ioctl. - * Input argument to the DRM_VMW_UNREF_SURFACE Ioctl. - * Input argument to the DRM_VMW_REF_SURFACE Ioctl. - */ - -struct drm_vmw_surface_arg { - int32_t sid; - uint32_t pad64; -}; - -/** - * struct drm_vmw_size ioctl. - * - * @width - mip level width - * @height - mip level height - * @depth - mip level depth - * - * Description of a mip level. - * Input data to the DRM_WMW_CREATE_SURFACE Ioctl. - */ - -struct drm_vmw_size { - uint32_t width; - uint32_t height; - uint32_t depth; - uint32_t pad64; -}; - -/** - * union drm_vmw_surface_create_arg - * - * @rep: Output data as described above. - * @req: Input data as described above. - * - * Argument to the DRM_VMW_CREATE_SURFACE Ioctl. - */ - -union drm_vmw_surface_create_arg { - struct drm_vmw_surface_arg rep; - struct drm_vmw_surface_create_req req; -}; - -/*************************************************************************/ -/** - * DRM_VMW_REF_SURFACE - Reference a host surface. - * - * Puts a reference on a host surface with a give sid, as previously - * returned by the DRM_VMW_CREATE_SURFACE ioctl. - * A reference will make sure the surface isn't destroyed while we hold - * it and will allow the calling client to use the surface ID in the command - * stream. - * - * On successful return, the Ioctl returns the surface information given - * in the DRM_VMW_CREATE_SURFACE ioctl. - */ - -/** - * union drm_vmw_surface_reference_arg - * - * @rep: Output data as described above. - * @req: Input data as described above. - * - * Argument to the DRM_VMW_REF_SURFACE Ioctl. - */ - -union drm_vmw_surface_reference_arg { - struct drm_vmw_surface_create_req rep; - struct drm_vmw_surface_arg req; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_SURFACE - Unreference a host surface. - * - * Clear a reference previously put on a host surface. - * When all references are gone, including the one implicitly placed - * on creation, - * a destroy surface command will be queued for the host. - * Does not wait for completion. - */ - -/*************************************************************************/ -/** - * DRM_VMW_EXECBUF - * - * Submit a command buffer for execution on the host, and return a - * fence sequence that when signaled, indicates that the command buffer has - * executed. - */ - -/** - * struct drm_vmw_execbuf_arg - * - * @commands: User-space address of a command buffer cast to an uint64_t. - * @command-size: Size in bytes of the command buffer. - * @throttle-us: Sleep until software is less than @throttle_us - * microseconds ahead of hardware. The driver may round this value - * to the nearest kernel tick. - * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an - * uint64_t. - * @version: Allows expanding the execbuf ioctl parameters without breaking - * backwards compatibility, since user-space will always tell the kernel - * which version it uses. - * @flags: Execbuf flags. None currently. - * - * Argument to the DRM_VMW_EXECBUF Ioctl. - */ - -#define DRM_VMW_EXECBUF_VERSION 0 - -struct drm_vmw_execbuf_arg { - uint64_t commands; - uint32_t command_size; - uint32_t throttle_us; - uint64_t fence_rep; - uint32_t version; - uint32_t flags; -}; - -/** - * struct drm_vmw_fence_rep - * - * @fence_seq: Fence sequence associated with a command submission. - * @error: This member should've been set to -EFAULT on submission. - * The following actions should be take on completion: - * error == -EFAULT: Fence communication failed. The host is synchronized. - * Use the last fence id read from the FIFO fence register. - * error != 0 && error != -EFAULT: - * Fence submission failed. The host is synchronized. Use the fence_seq member. - * error == 0: All is OK, The host may not be synchronized. - * Use the fence_seq member. - * - * Input / Output data to the DRM_VMW_EXECBUF Ioctl. - */ - -struct drm_vmw_fence_rep { - uint64_t fence_seq; - int32_t error; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_ALLOC_DMABUF - * - * Allocate a DMA buffer that is visible also to the host. - * NOTE: The buffer is - * identified by a handle and an offset, which are private to the guest, but - * useable in the command stream. The guest kernel may translate these - * and patch up the command stream accordingly. In the future, the offset may - * be zero at all times, or it may disappear from the interface before it is - * fixed. - * - * The DMA buffer may stay user-space mapped in the guest at all times, - * and is thus suitable for sub-allocation. - * - * DMA buffers are mapped using the mmap() syscall on the drm device. - */ - -/** - * struct drm_vmw_alloc_dmabuf_req - * - * @size: Required minimum size of the buffer. - * - * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -struct drm_vmw_alloc_dmabuf_req { - uint32_t size; - uint32_t pad64; -}; - -/** - * struct drm_vmw_dmabuf_rep - * - * @map_handle: Offset to use in the mmap() call used to map the buffer. - * @handle: Handle unique to this buffer. Used for unreferencing. - * @cur_gmr_id: GMR id to use in the command stream when this buffer is - * referenced. See not above. - * @cur_gmr_offset: Offset to use in the command stream when this buffer is - * referenced. See note above. - * - * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -struct drm_vmw_dmabuf_rep { - uint64_t map_handle; - uint32_t handle; - uint32_t cur_gmr_id; - uint32_t cur_gmr_offset; - uint32_t pad64; -}; - -/** - * union drm_vmw_dmabuf_arg - * - * @req: Input data as described above. - * @rep: Output data as described above. - * - * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -union drm_vmw_alloc_dmabuf_arg { - struct drm_vmw_alloc_dmabuf_req req; - struct drm_vmw_dmabuf_rep rep; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_DMABUF - Free a DMA buffer. - * - */ - -/** - * struct drm_vmw_unref_dmabuf_arg - * - * @handle: Handle indicating what buffer to free. Obtained from the - * DRM_VMW_ALLOC_DMABUF Ioctl. - * - * Argument to the DRM_VMW_UNREF_DMABUF Ioctl. - */ - -struct drm_vmw_unref_dmabuf_arg { - uint32_t handle; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_FIFO_DEBUG - Get last FIFO submission. - * - * This IOCTL copies the last FIFO submission directly out of the FIFO buffer. - */ - -/** - * struct drm_vmw_fifo_debug_arg - * - * @debug_buffer: User space address of a debug_buffer cast to an uint64_t //In - * @debug_buffer_size: Size in bytes of debug buffer //In - * @used_size: Number of bytes copied to the buffer // Out - * @did_not_fit: Boolean indicating that the fifo contents did not fit. //Out - * - * Argument to the DRM_VMW_FIFO_DEBUG Ioctl. - */ - -struct drm_vmw_fifo_debug_arg { - uint64_t debug_buffer; - uint32_t debug_buffer_size; - uint32_t used_size; - int32_t did_not_fit; - uint32_t pad64; -}; - -struct drm_vmw_fence_wait_arg { - uint64_t sequence; - uint64_t kernel_cookie; - int32_t cookie_valid; - int32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CONTROL_STREAM - Control overlays, aka streams. - * - * This IOCTL controls the overlay units of the svga device. - * The SVGA overlay units does not work like regular hardware units in - * that they do not automaticaly read back the contents of the given dma - * buffer. But instead only read back for each call to this ioctl, and - * at any point between this call being made and a following call that - * either changes the buffer or disables the stream. - */ - -/** - * struct drm_vmw_rect - * - * Defines a rectangle. Used in the overlay ioctl to define - * source and destination rectangle. - */ - -struct drm_vmw_rect { - int32_t x; - int32_t y; - uint32_t w; - uint32_t h; -}; - -/** - * struct drm_vmw_control_stream_arg - * - * @stream_id: Stearm to control - * @enabled: If false all following arguments are ignored. - * @handle: Handle to buffer for getting data from. - * @format: Format of the overlay as understood by the host. - * @width: Width of the overlay. - * @height: Height of the overlay. - * @size: Size of the overlay in bytes. - * @pitch: Array of pitches, the two last are only used for YUV12 formats. - * @offset: Offset from start of dma buffer to overlay. - * @src: Source rect, must be within the defined area above. - * @dst: Destination rect, x and y may be negative. - * - * Argument to the DRM_VMW_CONTROL_STREAM Ioctl. - */ - -struct drm_vmw_control_stream_arg { - uint32_t stream_id; - uint32_t enabled; - - uint32_t flags; - uint32_t color_key; - - uint32_t handle; - uint32_t offset; - int32_t format; - uint32_t size; - uint32_t width; - uint32_t height; - uint32_t pitch[3]; - - uint32_t pad64; - struct drm_vmw_rect src; - struct drm_vmw_rect dst; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CURSOR_BYPASS - Give extra information about cursor bypass. - * - */ - -#define DRM_VMW_CURSOR_BYPASS_ALL (1 << 0) -#define DRM_VMW_CURSOR_BYPASS_FLAGS (1) - -/** - * struct drm_vmw_cursor_bypass_arg - * - * @flags: Flags. - * @crtc_id: Crtc id, only used if DMR_CURSOR_BYPASS_ALL isn't passed. - * @xpos: X position of cursor. - * @ypos: Y position of cursor. - * @xhot: X hotspot. - * @yhot: Y hotspot. - * - * Argument to the DRM_VMW_CURSOR_BYPASS Ioctl. - */ - -struct drm_vmw_cursor_bypass_arg { - uint32_t flags; - uint32_t crtc_id; - int32_t xpos; - int32_t ypos; - int32_t xhot; - int32_t yhot; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CLAIM_STREAM - Claim a single stream. - */ - -/** - * struct drm_vmw_context_arg - * - * @stream_id: Device unique context ID. - * - * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. - * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. - */ - -struct drm_vmw_stream_arg { - uint32_t stream_id; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_STREAM - Unclaim a stream. - * - * Return a single stream that was claimed by this process. Also makes - * sure that the stream has been stopped. - */ - -#endif diff --git a/src/gallium/winsys/gdi/SConscript b/src/gallium/winsys/gdi/SConscript deleted file mode 100644 index 1267fc6eea4..00000000000 --- a/src/gallium/winsys/gdi/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -if env['platform'] == 'windows': - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', - ]) - - ws_gdi = env.ConvenienceLibrary( - target = 'ws_gdi', - source = [ - 'gdi_sw_winsys.c', - ] - ) - Export('ws_gdi') diff --git a/src/gallium/winsys/gdi/gdi_sw_winsys.c b/src/gallium/winsys/gdi/gdi_sw_winsys.c deleted file mode 100644 index 4dba4b577b8..00000000000 --- a/src/gallium/winsys/gdi/gdi_sw_winsys.c +++ /dev/null @@ -1,247 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/** - * @file - * GDI software rasterizer support. - * - * @author Jose Fonseca - */ - - -#include - -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "state_tracker/sw_winsys.h" -#include "gdi_sw_winsys.h" - - -struct gdi_sw_displaytarget -{ - enum pipe_format format; - unsigned width; - unsigned height; - unsigned stride; - - unsigned size; - - void *data; - - BITMAPINFO bmi; -}; - - -/** Cast wrapper */ -static INLINE struct gdi_sw_displaytarget * -gdi_sw_displaytarget( struct sw_displaytarget *buf ) -{ - return (struct gdi_sw_displaytarget *)buf; -} - - -static boolean -gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - switch(format) { - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B8G8R8A8_UNORM: - return TRUE; - - /* TODO: Support other formats possible with BMPs, as described in - * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */ - - default: - return FALSE; - } -} - - -static void * -gdi_sw_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags ) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - return gdt->data; -} - - -static void -gdi_sw_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt ) -{ - -} - - -static void -gdi_sw_displaytarget_destroy(struct sw_winsys *winsys, - struct sw_displaytarget *dt) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - align_free(gdt->data); - FREE(gdt); -} - - -static struct sw_displaytarget * -gdi_sw_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct gdi_sw_displaytarget *gdt; - unsigned cpp; - unsigned bpp; - - gdt = CALLOC_STRUCT(gdi_sw_displaytarget); - if(!gdt) - goto no_gdt; - - gdt->format = format; - gdt->width = width; - gdt->height = height; - - bpp = util_format_get_blocksizebits(format); - cpp = util_format_get_blocksize(format); - - gdt->stride = align(width * cpp, alignment); - gdt->size = gdt->stride * height; - - gdt->data = align_malloc(gdt->size, alignment); - if(!gdt->data) - goto no_data; - - gdt->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - gdt->bmi.bmiHeader.biWidth = gdt->stride / cpp; - gdt->bmi.bmiHeader.biHeight= -(long)height; - gdt->bmi.bmiHeader.biPlanes = 1; - gdt->bmi.bmiHeader.biBitCount = bpp; - gdt->bmi.bmiHeader.biCompression = BI_RGB; - gdt->bmi.bmiHeader.biSizeImage = 0; - gdt->bmi.bmiHeader.biXPelsPerMeter = 0; - gdt->bmi.bmiHeader.biYPelsPerMeter = 0; - gdt->bmi.bmiHeader.biClrUsed = 0; - gdt->bmi.bmiHeader.biClrImportant = 0; - - *stride = gdt->stride; - return (struct sw_displaytarget *)gdt; - -no_data: - FREE(gdt); -no_gdt: - return NULL; -} - - -static struct sw_displaytarget * -gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - assert(0); - return NULL; -} - - -static boolean -gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -void -gdi_sw_display( struct sw_winsys *winsys, - struct sw_displaytarget *dt, - HDC hDC ) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - StretchDIBits(hDC, - 0, 0, gdt->width, gdt->height, - 0, 0, gdt->width, gdt->height, - gdt->data, &gdt->bmi, 0, SRCCOPY); -} - -static void -gdi_sw_displaytarget_display(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - void *context_private) -{ - /* nasty: - */ - HDC hDC = (HDC)context_private; - - gdi_sw_display(winsys, dt, hDC); -} - - -static void -gdi_sw_destroy(struct sw_winsys *winsys) -{ - FREE(winsys); -} - -struct sw_winsys * -gdi_create_sw_winsys(void) -{ - static struct sw_winsys *winsys; - - winsys = CALLOC_STRUCT(sw_winsys); - if(!winsys) - return NULL; - - winsys->destroy = gdi_sw_destroy; - winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported; - winsys->displaytarget_create = gdi_sw_displaytarget_create; - winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle; - winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle; - winsys->displaytarget_map = gdi_sw_displaytarget_map; - winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap; - winsys->displaytarget_display = gdi_sw_displaytarget_display; - winsys->displaytarget_destroy = gdi_sw_displaytarget_destroy; - - return winsys; -} - diff --git a/src/gallium/winsys/gdi/gdi_sw_winsys.h b/src/gallium/winsys/gdi/gdi_sw_winsys.h deleted file mode 100644 index 4bbcb47848b..00000000000 --- a/src/gallium/winsys/gdi/gdi_sw_winsys.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GDI_SW_WINSYS_H -#define GDI_SW_WINSYS_H - -#include - -#include "pipe/p_compiler.h" -#include "state_tracker/sw_winsys.h" - -void gdi_sw_display( struct sw_winsys *winsys, - struct sw_displaytarget *dt, - HDC hDC ); - -struct sw_winsys * -gdi_create_sw_winsys(void); - -#endif diff --git a/src/gallium/winsys/i915/drm/Makefile b/src/gallium/winsys/i915/drm/Makefile new file mode 100644 index 00000000000..4aac3309aa7 --- /dev/null +++ b/src/gallium/winsys/i915/drm/Makefile @@ -0,0 +1,16 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = inteldrm + +C_SOURCES = \ + intel_drm_batchbuffer.c \ + intel_drm_buffer.c \ + intel_drm_fence.c \ + intel_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/i915/drm/SConscript b/src/gallium/winsys/i915/drm/SConscript new file mode 100644 index 00000000000..26717f391fa --- /dev/null +++ b/src/gallium/winsys/i915/drm/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = drienv.Clone() + +inteldrm_sources = [ + 'intel_drm_api.c', + 'intel_drm_batchbuffer.c', + 'intel_drm_buffer.c', + 'intel_drm_fence.c', +] + +inteldrm = env.ConvenienceLibrary( + target ='inteldrm', + source = inteldrm_sources, +) + +Export('inteldrm') diff --git a/src/gallium/winsys/i915/drm/intel_drm_api.c b/src/gallium/winsys/i915/drm/intel_drm_api.c new file mode 100644 index 00000000000..e3b980a832b --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_api.c @@ -0,0 +1,109 @@ +#include + +#include "state_tracker/drm_api.h" + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915/i915_context.h" +#include "i915/i915_screen.h" + +#include "trace/tr_drm.h" + +/* + * Helper functions + */ + + +static void +intel_drm_get_device_id(unsigned int *device_id) +{ + char path[512]; + FILE *file; + void *shutup_gcc; + + /* + * FIXME: Fix this up to use a drm ioctl or whatever. + */ + + snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); + file = fopen(path, "r"); + if (!file) { + return; + } + + shutup_gcc = fgets(path, sizeof(path), file); + (void) shutup_gcc; + sscanf(path, "%x", device_id); + fclose(file); +} + +static void +intel_drm_winsys_destroy(struct intel_winsys *iws) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + + drm_intel_bufmgr_destroy(idws->pools.gem); + + FREE(idws); +} + +static struct pipe_screen * +intel_drm_create_screen(struct drm_api *api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct intel_drm_winsys *idws; + unsigned int deviceID; + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_NORMAL: + break; + default: + return NULL; + } + } + + idws = CALLOC_STRUCT(intel_drm_winsys); + if (!idws) + return NULL; + + intel_drm_get_device_id(&deviceID); + + intel_drm_winsys_init_batchbuffer_functions(idws); + intel_drm_winsys_init_buffer_functions(idws); + intel_drm_winsys_init_fence_functions(idws); + + idws->fd = drmFD; + idws->id = deviceID; + idws->max_batch_size = 16 * 4096; + + idws->base.destroy = intel_drm_winsys_destroy; + + idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); + drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); + + idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); + + return i915_create_screen(&idws->base, deviceID); +} + +static void +destroy(struct drm_api *api) +{ + +} + +struct drm_api intel_drm_api = +{ + .name = "i915", + .driver_name = "i915", + .create_screen = intel_drm_create_screen, + .destroy = destroy, +}; + +struct drm_api * +drm_api_create() +{ + return trace_drm_create(&intel_drm_api); +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c b/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c new file mode 100644 index 00000000000..5b4dafc8e41 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c @@ -0,0 +1,244 @@ + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +#define BATCH_RESERVED 16 + +#define INTEL_DEFAULT_RELOCS 100 +#define INTEL_MAX_RELOCS 400 + +#define INTEL_BATCH_NO_CLIPRECTS 0x1 +#define INTEL_BATCH_CLIPRECTS 0x2 + +#undef INTEL_RUN_SYNC +#undef INTEL_MAP_BATCHBUFFER +#undef INTEL_MAP_GTT +#define INTEL_ALWAYS_FLUSH + +struct intel_drm_batchbuffer +{ + struct intel_batchbuffer base; + + size_t actual_size; + + drm_intel_bo *bo; +}; + +static INLINE struct intel_drm_batchbuffer * +intel_drm_batchbuffer(struct intel_batchbuffer *batch) +{ + return (struct intel_drm_batchbuffer *)batch; +} + +static void +intel_drm_batchbuffer_reset(struct intel_drm_batchbuffer *batch) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(batch->base.iws); + int ret; + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + batch->bo = drm_intel_bo_alloc(idws->pools.gem, + "gallium3d_batchbuffer", + batch->actual_size, + 4096); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + ret = drm_intel_gem_bo_map_gtt(batch->bo); +#else + ret = drm_intel_bo_map(batch->bo, TRUE); +#endif + assert(ret == 0); + batch->base.map = batch->bo->virtual; +#else + (void)ret; +#endif + + memset(batch->base.map, 0, batch->actual_size); + batch->base.ptr = batch->base.map; + batch->base.size = batch->actual_size - BATCH_RESERVED; + batch->base.relocs = 0; +} + +static struct intel_batchbuffer * +intel_drm_batchbuffer_create(struct intel_winsys *iws) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + struct intel_drm_batchbuffer *batch = CALLOC_STRUCT(intel_drm_batchbuffer); + + batch->actual_size = idws->max_batch_size; + +#ifdef INTEL_MAP_BATCHBUFFER + batch->base.map = NULL; +#else + batch->base.map = MALLOC(batch->actual_size); +#endif + batch->base.ptr = NULL; + batch->base.size = 0; + + batch->base.relocs = 0; + batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ + + batch->base.iws = iws; + + intel_drm_batchbuffer_reset(batch); + + return &batch->base; +} + +static int +intel_drm_batchbuffer_reloc(struct intel_batchbuffer *ibatch, + struct intel_buffer *buffer, + enum intel_buffer_usage usage, + unsigned pre_add) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + unsigned write_domain = 0; + unsigned read_domain = 0; + unsigned offset; + int ret = 0; + + assert(batch->base.relocs < batch->base.max_relocs); + + if (usage == INTEL_USAGE_SAMPLER) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_SAMPLER; + + } else if (usage == INTEL_USAGE_RENDER) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_2D_TARGET) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_2D_SOURCE) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_VERTEX) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_VERTEX; + + } else { + assert(0); + return -1; + } + + offset = (unsigned)(batch->base.ptr - batch->base.map); + + ret = drm_intel_bo_emit_reloc(batch->bo, offset, + intel_bo(buffer), pre_add, + read_domain, + write_domain); + + ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; + batch->base.ptr += 4; + + if (!ret) + batch->base.relocs++; + + return ret; +} + +static void +intel_drm_batchbuffer_flush(struct intel_batchbuffer *ibatch, + struct pipe_fence_handle **fence) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + unsigned used = 0; + int ret = 0; + int i; + + assert(intel_batchbuffer_space(ibatch) >= 0); + + used = batch->base.ptr - batch->base.map; + assert((used & 3) == 0); + + +#ifdef INTEL_ALWAYS_FLUSH + /* MI_FLUSH | FLUSH_MAP_CACHE */ + intel_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); + used += 4; +#endif + + if ((used & 4) == 0) { + /* MI_NOOP */ + intel_batchbuffer_dword(ibatch, 0); + } + /* MI_BATCH_BUFFER_END */ + intel_batchbuffer_dword(ibatch, (0xA<<23)); + + used = batch->base.ptr - batch->base.map; + assert((used & 4) == 0); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + drm_intel_gem_bo_unmap_gtt(batch->bo); +#else + drm_intel_bo_unmap(batch->bo); +#endif +#else + drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); +#endif + + /* Do the sending to HW */ + ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); + assert(ret == 0); + + if (intel_drm_winsys(ibatch->iws)->dump_cmd) { + unsigned *ptr; + drm_intel_bo_map(batch->bo, FALSE); + ptr = (unsigned*)batch->bo->virtual; + + debug_printf("%s:\n", __func__); + for (i = 0; i < used / 4; i++, ptr++) { + debug_printf("\t%08x: %08x\n", i*4, *ptr); + } + + drm_intel_bo_unmap(batch->bo); + } else { +#ifdef INTEL_RUN_SYNC + drm_intel_bo_map(batch->bo, FALSE); + drm_intel_bo_unmap(batch->bo); +#endif + } + + if (fence) { + ibatch->iws->fence_reference(ibatch->iws, fence, NULL); + +#ifdef INTEL_RUN_SYNC + /* we run synced to GPU so just pass null */ + (*fence) = intel_drm_fence_create(NULL); +#else + (*fence) = intel_drm_fence_create(batch->bo); +#endif + } + + intel_drm_batchbuffer_reset(batch); +} + +static void +intel_drm_batchbuffer_destroy(struct intel_batchbuffer *ibatch) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + +#ifndef INTEL_MAP_BATCHBUFFER + FREE(batch->base.map); +#endif + FREE(batch); +} + +void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws) +{ + idws->base.batchbuffer_create = intel_drm_batchbuffer_create; + idws->base.batchbuffer_reloc = intel_drm_batchbuffer_reloc; + idws->base.batchbuffer_flush = intel_drm_batchbuffer_flush; + idws->base.batchbuffer_destroy = intel_drm_batchbuffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_buffer.c b/src/gallium/winsys/i915/drm/intel_drm_buffer.c new file mode 100644 index 00000000000..cb4f92a3b17 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_buffer.c @@ -0,0 +1,217 @@ + +#include "state_tracker/drm_api.h" +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +static struct intel_buffer * +intel_drm_buffer_create(struct intel_winsys *iws, + unsigned size, unsigned alignment, + enum intel_buffer_type type) +{ + struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + drm_intel_bufmgr *pool; + char *name; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->flinked = FALSE; + buf->flink = 0; + buf->map_gtt = FALSE; + + if (type == INTEL_NEW_TEXTURE) { + name = "gallium3d_texture"; + pool = idws->pools.gem; + } else if (type == INTEL_NEW_VERTEX) { + name = "gallium3d_vertex"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else if (type == INTEL_NEW_SCANOUT) { + name = "gallium3d_scanout"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else { + assert(0); + name = "gallium3d_unknown"; + pool = idws->pools.gem; + } + + buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); + + if (!buf->bo) + goto err; + + return (struct intel_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static struct intel_buffer * +intel_drm_buffer_from_handle(struct intel_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); + uint32_t tile = 0, swizzle = 0; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); + buf->flinked = TRUE; + buf->flink = whandle->handle; + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); + if (tile != INTEL_TILE_NONE) + buf->map_gtt = TRUE; + + *stride = whandle->stride; + + return (struct intel_buffer *)buf; + +err: + FREE(buf); + return NULL; +} + +static boolean +intel_drm_buffer_get_handle(struct intel_winsys *iws, + struct intel_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return FALSE; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return FALSE; + } + + whandle->stride = stride; + return TRUE; +} + +static int +intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, + struct intel_buffer *buffer, + unsigned stride, + enum intel_buffer_tile tile) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + assert(I915_TILING_NONE == INTEL_TILE_NONE); + assert(I915_TILING_X == INTEL_TILE_X); + assert(I915_TILING_Y == INTEL_TILE_Y); + + if (tile != INTEL_TILE_NONE) { + assert(buf->map_count == 0); + buf->map_gtt = TRUE; + } + + return drm_intel_bo_set_tiling(buf->bo, &tile, stride); +} + +static void * +intel_drm_buffer_map(struct intel_winsys *iws, + struct intel_buffer *buffer, + boolean write) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + drm_intel_bo *bo = intel_bo(buffer); + int ret = 0; + + assert(bo); + + if (buf->map_count) + goto out; + + if (buf->map_gtt) + ret = drm_intel_gem_bo_map_gtt(bo); + else + ret = drm_intel_bo_map(bo, write); + + buf->ptr = bo->virtual; + + assert(ret == 0); +out: + if (ret) + return NULL; + + buf->map_count++; + return buf->ptr; +} + +static void +intel_drm_buffer_unmap(struct intel_winsys *iws, + struct intel_buffer *buffer) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + if (--buf->map_count) + return; + + if (buf->map_gtt) + drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); + else + drm_intel_bo_unmap(intel_bo(buffer)); +} + +static int +intel_drm_buffer_write(struct intel_winsys *iws, + struct intel_buffer *buffer, + size_t offset, + size_t size, + const void *data) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); +} + +static void +intel_drm_buffer_destroy(struct intel_winsys *iws, + struct intel_buffer *buffer) +{ + drm_intel_bo_unreference(intel_bo(buffer)); + +#ifdef DEBUG + intel_drm_buffer(buffer)->magic = 0; + intel_drm_buffer(buffer)->bo = NULL; +#endif + + FREE(buffer); +} + +void +intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) +{ + idws->base.buffer_create = intel_drm_buffer_create; + idws->base.buffer_from_handle = intel_drm_buffer_from_handle; + idws->base.buffer_get_handle = intel_drm_buffer_get_handle; + idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; + idws->base.buffer_map = intel_drm_buffer_map; + idws->base.buffer_unmap = intel_drm_buffer_unmap; + idws->base.buffer_write = intel_drm_buffer_write; + idws->base.buffer_destroy = intel_drm_buffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_fence.c b/src/gallium/winsys/i915/drm/intel_drm_fence.c new file mode 100644 index 00000000000..102faedfeae --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_fence.c @@ -0,0 +1,83 @@ + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +/** + * Because gem does not have fence's we have to create our own fences. + * + * They work by keeping the batchbuffer around and checking if that has + * been idled. If bo is NULL fence has expired. + */ +struct intel_drm_fence +{ + struct pipe_reference reference; + drm_intel_bo *bo; +}; + + +struct pipe_fence_handle * +intel_drm_fence_create(drm_intel_bo *bo) +{ + struct intel_drm_fence *fence = CALLOC_STRUCT(intel_drm_fence); + + pipe_reference_init(&fence->reference, 1); + /* bo is null if fence already expired */ + if (bo) { + drm_intel_bo_reference(bo); + fence->bo = bo; + } + + return (struct pipe_fence_handle *)fence; +} + +static void +intel_drm_fence_reference(struct intel_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct intel_drm_fence *old = (struct intel_drm_fence *)*ptr; + struct intel_drm_fence *f = (struct intel_drm_fence *)fence; + + if (pipe_reference(&((struct intel_drm_fence *)(*ptr))->reference, &f->reference)) { + if (old->bo) + drm_intel_bo_unreference(old->bo); + FREE(old); + } + *ptr = fence; +} + +static int +intel_drm_fence_signalled(struct intel_winsys *iws, + struct pipe_fence_handle *fence) +{ + assert(0); + + return 0; +} + +static int +intel_drm_fence_finish(struct intel_winsys *iws, + struct pipe_fence_handle *fence) +{ + struct intel_drm_fence *f = (struct intel_drm_fence *)fence; + + /* fence already expired */ + if (!f->bo) + return 0; + + drm_intel_bo_wait_rendering(f->bo); + drm_intel_bo_unreference(f->bo); + f->bo = NULL; + + return 0; +} + +void +intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws) +{ + idws->base.fence_reference = intel_drm_fence_reference; + idws->base.fence_signalled = intel_drm_fence_signalled; + idws->base.fence_finish = intel_drm_fence_finish; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_winsys.h b/src/gallium/winsys/i915/drm/intel_drm_winsys.h new file mode 100644 index 00000000000..9786ee93650 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_winsys.h @@ -0,0 +1,77 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i915/intel_batchbuffer.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + +/* + * Winsys + */ + + +struct intel_drm_winsys +{ + struct intel_winsys base; + + boolean dump_cmd; + + int fd; /**< Drm file discriptor */ + + unsigned id; + + size_t max_batch_size; + + struct { + drm_intel_bufmgr *gem; + } pools; +}; + +static INLINE struct intel_drm_winsys * +intel_drm_winsys(struct intel_winsys *iws) +{ + return (struct intel_drm_winsys *)iws; +} + +struct intel_drm_winsys * intel_drm_winsys_create(int fd, unsigned pci_id); +struct pipe_fence_handle * intel_drm_fence_create(drm_intel_bo *bo); + +void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws); +void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws); +void intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws); + + +/* + * Buffer + */ + + +struct intel_drm_buffer { + unsigned magic; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + boolean map_gtt; + + boolean flinked; + unsigned flink; +}; + +static INLINE struct intel_drm_buffer * +intel_drm_buffer(struct intel_buffer *buffer) +{ + return (struct intel_drm_buffer *)buffer; +} + +static INLINE drm_intel_bo * +intel_bo(struct intel_buffer *buffer) +{ + return intel_drm_buffer(buffer)->bo; +} + +#endif diff --git a/src/gallium/winsys/i965/drm/Makefile b/src/gallium/winsys/i965/drm/Makefile new file mode 100644 index 00000000000..bbb71e25d84 --- /dev/null +++ b/src/gallium/winsys/i965/drm/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = i965drm + +C_SOURCES = \ + i965_drm_buffer.c \ + i965_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/i965/drm/SConscript b/src/gallium/winsys/i965/drm/SConscript new file mode 100644 index 00000000000..6256ec6eaf0 --- /dev/null +++ b/src/gallium/winsys/i965/drm/SConscript @@ -0,0 +1,15 @@ +Import('*') + +env = drienv.Clone() + +i965drm_sources = [ + 'i965_drm_api.c', + 'i965_drm_buffer.c', +] + +i965drm = env.ConvenienceLibrary( + target ='i965drm', + source = i965drm_sources, +) + +Export('i965drm') diff --git a/src/gallium/winsys/i965/drm/i965_drm_api.c b/src/gallium/winsys/i965/drm/i965_drm_api.c new file mode 100644 index 00000000000..9072a186384 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_api.c @@ -0,0 +1,122 @@ + +#include +#include "state_tracker/drm_api.h" + +#include "i965_drm_winsys.h" +#include "util/u_memory.h" + +#include "i965/brw_context.h" /* XXX: shouldn't be doing this */ +#include "i965/brw_screen.h" /* XXX: shouldn't be doing this */ + +#include "trace/tr_drm.h" + +#include "../../sw/drm/sw_drm_api.h" + +/* + * Helper functions + */ + + +static void +i965_libdrm_get_device_id(unsigned int *device_id) +{ + char path[512]; + FILE *file; + void *shutup_gcc; + + /* + * FIXME: Fix this up to use a drm ioctl or whatever. + */ + + snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); + file = fopen(path, "r"); + if (!file) { + return; + } + + shutup_gcc = fgets(path, sizeof(path), file); + sscanf(path, "%x", device_id); + fclose(file); +} + +static void +i965_libdrm_winsys_destroy(struct brw_winsys_screen *iws) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(iws); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + drm_intel_bufmgr_destroy(idws->gem); + + FREE(idws); +} + +static struct pipe_screen * +i965_libdrm_create_screen(struct drm_api *api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct i965_libdrm_winsys *idws; + unsigned int deviceID; + + debug_printf("%s\n", __FUNCTION__); + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_NORMAL: + break; + default: + return NULL; + } + } + + idws = CALLOC_STRUCT(i965_libdrm_winsys); + if (!idws) + return NULL; + + i965_libdrm_get_device_id(&deviceID); + + i965_libdrm_winsys_init_buffer_functions(idws); + + idws->fd = drmFD; + idws->id = deviceID; + + idws->base.destroy = i965_libdrm_winsys_destroy; + + idws->gem = drm_intel_bufmgr_gem_init(idws->fd, BRW_BATCH_SIZE); + drm_intel_bufmgr_gem_enable_reuse(idws->gem); + + idws->send_cmd = !debug_get_bool_option("BRW_NO_HW", FALSE); + + return brw_create_screen(&idws->base, deviceID); +} + + +static void +destroy(struct drm_api *api) +{ + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + +} + +struct drm_api i965_libdrm_api = +{ + .name = "i965", + .create_screen = i965_libdrm_create_screen, + .destroy = destroy, +}; + +struct drm_api * +drm_api_create() +{ + struct drm_api *api = NULL; + + if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) + api = sw_drm_api_create(&i965_libdrm_api); + + if (api == NULL) + api = &i965_libdrm_api; + + return trace_drm_create(api); +} diff --git a/src/gallium/winsys/i965/drm/i965_drm_buffer.c b/src/gallium/winsys/i965/drm/i965_drm_buffer.c new file mode 100644 index 00000000000..33a17496b2b --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_buffer.c @@ -0,0 +1,503 @@ + +#include "state_tracker/drm_api.h" +#include "i965_drm_winsys.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "i915_drm.h" +#include "intel_bufmgr.h" + + + +const char *names[BRW_BUFFER_TYPE_MAX] = { + "TEXTURE", + "SCANOUT", + "VERTEX", + "CURBE", + "QUERY", + "SHADER_CONSTANTS", + "WM_SCRATCH", + "BATCH", + "GENERAL_STATE", + "SURFACE_STATE", + "PIXEL", + "GENERIC", +}; + +const char *usages[BRW_USAGE_MAX] = { + "STATE", + "QUERY_RESULT", + "RENDER_TARGET", + "DEPTH_BUFFER", + "BLIT_SOURCE", + "BLIT_DEST", + "SAMPLER", + "VERTEX", + "SCRATCH" +}; + + +const char *data_types[BRW_DATA_MAX] = +{ + "GS: CC_VP", + "GS: CC_UNIT", + "GS: WM_PROG", + "GS: SAMPLER_DEFAULT_COLOR", + "GS: SAMPLER", + "GS: WM_UNIT", + "GS: SF_PROG", + "GS: SF_VP", + "GS: SF_UNIT", + "GS: VS_UNIT", + "GS: VS_PROG", + "GS: GS_UNIT", + "GS: GS_PROG", + "GS: CLIP_VP", + "GS: CLIP_UNIT", + "GS: CLIP_PROG", + "SS: SURFACE", + "SS: SURF_BIND", + "CONSTANT DATA", + "BATCH DATA", + "(untyped)" +}; + +static enum pipe_error +i965_libdrm_bo_alloc(struct brw_winsys_screen *sws, + enum brw_buffer_type type, + unsigned size, + unsigned alignment, + struct brw_winsys_buffer **bo_out) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); + struct i965_libdrm_buffer *buf; + + if (BRW_DUMP) + debug_printf("%s type %s sz %d align %d\n", + __FUNCTION__, names[type], size, alignment ); + + buf = CALLOC_STRUCT(i965_libdrm_buffer); + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + switch (type) { + case BRW_BUFFER_TYPE_TEXTURE: +/* case BRW_BUFFER_TYPE_SCANOUT:*/ + case BRW_BUFFER_TYPE_VERTEX: + case BRW_BUFFER_TYPE_CURBE: + case BRW_BUFFER_TYPE_QUERY: + case BRW_BUFFER_TYPE_SHADER_CONSTANTS: + case BRW_BUFFER_TYPE_SHADER_SCRATCH: + case BRW_BUFFER_TYPE_BATCH: + case BRW_BUFFER_TYPE_GENERAL_STATE: + case BRW_BUFFER_TYPE_SURFACE_STATE: + case BRW_BUFFER_TYPE_PIXEL: + case BRW_BUFFER_TYPE_GENERIC: + break; + case BRW_BUFFER_TYPE_SCANOUT: + buf->map_gtt = TRUE; + break; + default: + assert(0); + break; + } + + buf->bo = drm_intel_bo_alloc(idws->gem, + names[type], + size, + alignment); + + if (!buf->bo) + goto err; + + pipe_reference_init(&buf->base.reference, 1); + buf->base.size = size; + buf->base.sws = sws; + + *bo_out = &buf->base; + return PIPE_OK; + +err: + assert(0); + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static enum pipe_error +i965_libdrm_bo_from_handle(struct brw_winsys_screen *sws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *tile, + struct brw_winsys_buffer **bo_out) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); + struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); + uint32_t swizzle = 0; + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + pipe_reference_init(&buf->base.reference, 1); + buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, "FROM_HANDLE", whandle->handle); + buf->base.size = buf->bo->size; + buf->base.sws = &idws->base; + buf->flinked = TRUE; + buf->flink = whandle->handle; + + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); + if (buf->tiling != 0) + buf->map_gtt = TRUE; + + *tile = buf->tiling; + *stride = whandle->stride; + + *bo_out = &buf->base; + return PIPE_OK; + +err: + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static enum pipe_error +i965_libdrm_bo_get_handle(struct brw_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return PIPE_ERROR_BAD_INPUT; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return PIPE_ERROR_BAD_INPUT; + } + + whandle->stride = stride; + return PIPE_OK; +} + +static void +i965_libdrm_bo_destroy(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + drm_intel_bo_unreference(buf->bo); + FREE(buffer); +} + +static enum pipe_error +i965_libdrm_bo_emit_reloc(struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *buffer2) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_buffer *buf2 = i965_libdrm_buffer(buffer2); + int read, write; + int ret; + + if (BRW_DUMP) + debug_printf("%s buf %p offset %x delta %x buf2 %p/%s/%s\n", + __FUNCTION__, (void *)buffer, + offset, delta, + (void *)buffer2, names[buf2->data_type], usages[usage]); + + switch (usage) { + case BRW_USAGE_STATE: + read = I915_GEM_DOMAIN_INSTRUCTION; + write = 0; + break; + case BRW_USAGE_QUERY_RESULT: + read = I915_GEM_DOMAIN_INSTRUCTION; + write = I915_GEM_DOMAIN_INSTRUCTION; + break; + case BRW_USAGE_RENDER_TARGET: + read = I915_GEM_DOMAIN_RENDER; + write = 0; + break; + case BRW_USAGE_DEPTH_BUFFER: + read = I915_GEM_DOMAIN_RENDER; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_BLIT_SOURCE: + read = 0; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_BLIT_DEST: + read = I915_GEM_DOMAIN_RENDER; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_SAMPLER: + read = I915_GEM_DOMAIN_SAMPLER; + write = 0; + break; + case BRW_USAGE_VERTEX: + read = I915_GEM_DOMAIN_VERTEX; + write = 0; + break; + case BRW_USAGE_SCRATCH: + read = 0; + write = 0; + break; + default: + assert(0); + return -1; + } + + /* Needed?? + ((uint32_t *)buf->bo->virtual)[offset/4] = (delta + + buf2->bo->offset); + */ + + ret = dri_bo_emit_reloc( buf->bo, read, write, delta, offset, buf2->bo ); + if (ret) + return -1; + + return 0; +} + +static enum pipe_error +i965_libdrm_bo_exec(struct brw_winsys_buffer *buffer, + unsigned bytes_used) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + int ret; + + if (BRW_DUMP) + debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); + + if (idws->send_cmd) { + ret = dri_bo_exec(buf->bo, bytes_used, NULL, 0, 0); + if (ret) + return PIPE_ERROR; + } + + return PIPE_OK; +} + +static enum pipe_error +i965_libdrm_bo_subdata(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + size_t offset, + size_t size, + const void *data, + const struct brw_winsys_reloc *reloc, + unsigned nr_reloc) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + int ret, i; + + (void)data_type; + + if (BRW_DUMP) + debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", + __FUNCTION__, + (void *)buffer, offset, size, + data_types[data_type], + nr_reloc); + + if (BRW_DUMP) + brw_dump_data( idws->id, + data_type, + buf->bo->offset + offset, + data, size ); + + /* XXX: use bo_map_gtt/memcpy/unmap_gtt under some circumstances??? + */ + ret = drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); + if (ret) + return PIPE_ERROR; + + for (i = 0; i < nr_reloc; i++) { + i965_libdrm_bo_emit_reloc(buffer, reloc[i].usage, reloc[i].delta, + reloc[i].offset, reloc[i].bo); + } + + return PIPE_OK; +} + +static boolean +i965_libdrm_bo_is_busy(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + boolean ret; + + if (BRW_DUMP) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + + ret = drm_intel_bo_busy(buf->bo); + + if (BRW_DUMP) + debug_printf(" --> %d\n", ret); + + return ret; +} + +static boolean +i965_libdrm_bo_references(struct brw_winsys_buffer *a, + struct brw_winsys_buffer *b) +{ + struct i965_libdrm_buffer *bufa = i965_libdrm_buffer(a); + struct i965_libdrm_buffer *bufb = i965_libdrm_buffer(b); + boolean ret; + + if (BRW_DUMP) + debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); + + ret = drm_intel_bo_references(bufa->bo, bufb->bo); + + if (BRW_DUMP) + debug_printf(" --> %d\n", ret); + + return ret; +} + +/* XXX: couldn't this be handled by returning true/false on + * bo_emit_reloc? + */ +static enum pipe_error +i965_libdrm_check_aperture_space(struct brw_winsys_screen *iws, + struct brw_winsys_buffer **buffers, + unsigned count) +{ + static drm_intel_bo *bos[128]; + int i; + int ret; + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (count > Elements(bos)) { + assert(0); + return FALSE; + } + + for (i = 0; i < count; i++) + bos[i] = i965_libdrm_buffer(buffers[i])->bo; + + /* XXX: converting from ??? to pipe_error: + */ + ret = dri_bufmgr_check_aperture_space(bos, count); + + if (BRW_DUMP) + debug_printf(" --> %d (ok == %d)\n", ret, PIPE_OK); + + return ret; +} + +static void * +i965_libdrm_bo_map(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + unsigned offset, + unsigned length, + boolean write, + boolean discard, + boolean flush_explicit) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + int ret; + + + if (BRW_DUMP) + debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, + write ? "read/write" : "read", + write ? data_types[data_type] : ""); + + if (!buf->map_count) { + if (buf->map_gtt) { + ret = drm_intel_gem_bo_map_gtt(buf->bo); + if (ret) + return NULL; + } + else { + ret = drm_intel_bo_map(buf->bo, write); + if (ret) + return NULL; + } + } + + buf->data_type = data_type; + buf->map_count++; + return buf->bo->virtual; +} + +static void +i965_libdrm_bo_flush_range(struct brw_winsys_buffer *buffer, + unsigned offset, + unsigned length) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + + if (BRW_DUMP) + debug_printf("%s %s offset %d len %d\n", __FUNCTION__, + data_types[buf->data_type], + offset, length); + + if (BRW_DUMP) + brw_dump_data( idws->id, + buf->data_type, + buf->bo->offset + offset, + buf->bo->virtual + offset, + length ); +} + +static void +i965_libdrm_bo_unmap(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (--buf->map_count > 0) + return; + + if (buf->map_gtt) + drm_intel_gem_bo_unmap_gtt(buf->bo); + else + drm_intel_bo_unmap(buf->bo); +} + +void +i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws) +{ + idws->base.bo_alloc = i965_libdrm_bo_alloc; + idws->base.bo_from_handle = i965_libdrm_bo_from_handle; + idws->base.bo_get_handle = i965_libdrm_bo_get_handle; + idws->base.bo_destroy = i965_libdrm_bo_destroy; + idws->base.bo_emit_reloc = i965_libdrm_bo_emit_reloc; + idws->base.bo_exec = i965_libdrm_bo_exec; + idws->base.bo_subdata = i965_libdrm_bo_subdata; + idws->base.bo_is_busy = i965_libdrm_bo_is_busy; + idws->base.bo_references = i965_libdrm_bo_references; + idws->base.check_aperture_space = i965_libdrm_check_aperture_space; + idws->base.bo_map = i965_libdrm_bo_map; + idws->base.bo_flush_range = i965_libdrm_bo_flush_range; + idws->base.bo_unmap = i965_libdrm_bo_unmap; +} diff --git a/src/gallium/winsys/i965/drm/i965_drm_winsys.h b/src/gallium/winsys/i965/drm/i965_drm_winsys.h new file mode 100644 index 00000000000..c6a7d4a8c51 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_winsys.h @@ -0,0 +1,64 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i965/brw_winsys.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + + +/* + * Winsys + */ + + +struct i965_libdrm_winsys +{ + struct brw_winsys_screen base; + drm_intel_bufmgr *gem; + + boolean send_cmd; + + int fd; /**< Drm file discriptor */ + + unsigned id; +}; + +static INLINE struct i965_libdrm_winsys * +i965_libdrm_winsys(struct brw_winsys_screen *iws) +{ + return (struct i965_libdrm_winsys *)iws; +} + +struct i965_libdrm_winsys *i965_libdrm_winsys_create(int fd, unsigned pci_id); + +void i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws); + + +/* Buffer. + */ +struct i965_libdrm_buffer { + struct brw_winsys_buffer base; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + unsigned data_type; /* valid while mapped */ + unsigned tiling; + + boolean map_gtt; + boolean flinked; + unsigned flink; +}; + +static INLINE struct i965_libdrm_buffer * +i965_libdrm_buffer(struct brw_winsys_buffer *buffer) +{ + return (struct i965_libdrm_buffer *)buffer; +} + + +#endif diff --git a/src/gallium/winsys/i965/xlib/Makefile b/src/gallium/winsys/i965/xlib/Makefile new file mode 100644 index 00000000000..3730db6997e --- /dev/null +++ b/src/gallium/winsys/i965/xlib/Makefile @@ -0,0 +1,97 @@ +# src/gallium/winsys/i965/xlib/Makefile + +# This makefile produces a "stand-alone" libGL.so which is based on +# Xlib (no DRI HW acceleration) + + +TOP = ../../../../.. +include $(TOP)/configs/current + + +GL_MAJOR = 1 +GL_MINOR = 5 +GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/drivers/i965 \ + -I$(TOP)/src/gallium/drivers/i965/include \ + -I$(TOP)/src/gallium/state_trackers/glx/xlib \ + -I$(TOP)/src/gallium/auxiliary \ + -I/usr/include/drm + +XLIB_WINSYS_SOURCES = \ + xlib_i965.c \ + + + +XLIB_WINSYS_OBJECTS = $(XLIB_WINSYS_SOURCES:.c=.o) + + + +LIBS = \ + $(TOP)/src/gallium/drivers/i965/libi965.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ + $(TOP)/src/mesa/libglapi.a \ + $(TOP)/src/mesa/libmesagallium.a \ + $(GALLIUM_AUXILIARIES) + +# $(TOP)/src/gallium/drivers/i965/lib/libi9xx.a \ + +.SUFFIXES : .cpp + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CXXFLAGS) $< -o $@ + + + +default: $(TOP)/$(LIB_DIR)/gallium $(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME) + +$(TOP)/$(LIB_DIR)/gallium: + @ mkdir -p $(TOP)/$(LIB_DIR)/gallium + +# Make the libGL.so library +$(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME): $(XLIB_WINSYS_OBJECTS) $(LIBS) Makefile + $(TOP)/bin/mklib -o $(GL_LIB) \ + -linker "$(CC)" \ + -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ + -install $(TOP)/$(LIB_DIR)/gallium \ + $(MKLIB_OPTIONS) $(XLIB_WINSYS_OBJECTS) \ + -Wl,--start-group $(LIBS) -Wl,--end-group $(GL_LIB_DEPS) + + +depend: $(XLIB_WINSYS_SOURCES) + @ echo "running $(MKDEP)" + @ rm -f depend # workaround oops on gutsy?!? + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(XLIB_WINSYS_SOURCES) \ + > /dev/null 2>/dev/null + + +install: default + $(INSTALL) -d $(INSTALL_DIR)/include/GL + $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR) + $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL + @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \ + $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \ + fi + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h + +clean: + -rm -f *.o + + +include depend diff --git a/src/gallium/winsys/i965/xlib/xlib_i965.c b/src/gallium/winsys/i965/xlib/xlib_i965.c new file mode 100644 index 00000000000..063e9f600b9 --- /dev/null +++ b/src/gallium/winsys/i965/xlib/xlib_i965.c @@ -0,0 +1,503 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA + * 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 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * Brian Paul + */ + + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "pipe/p_error.h" +#include "pipe/p_context.h" + +#include "xm_public.h" + +#include "i965/brw_winsys.h" +#include "i965/brw_screen.h" +#include "i965/brw_reg.h" +#include "i965/brw_structs_dump.h" + +#define MAX_VRAM (128*1024*1024) + + + +extern int brw_disasm (FILE *file, + const struct brw_instruction *inst, + unsigned count ); + +extern int intel_decode(const uint32_t *data, + int count, + uint32_t hw_offset, + uint32_t devid); + +struct xlib_brw_buffer +{ + struct brw_winsys_buffer base; + char *virtual; + unsigned offset; + unsigned type; + int map_count; + boolean modified; +}; + + +/** + * Subclass of brw_winsys_screen for Xlib winsys + */ +struct xlib_brw_winsys +{ + struct brw_winsys_screen base; + struct brw_chipset chipset; + + unsigned size; + unsigned used; +}; + +static struct xlib_brw_winsys * +xlib_brw_winsys( struct brw_winsys_screen *screen ) +{ + return (struct xlib_brw_winsys *)screen; +} + + +static struct xlib_brw_buffer * +xlib_brw_buffer( struct brw_winsys_buffer *buffer ) +{ + return (struct xlib_brw_buffer *)buffer; +} + + + +const char *names[BRW_BUFFER_TYPE_MAX] = { + "TEXTURE", + "SCANOUT", + "VERTEX", + "CURBE", + "QUERY", + "SHADER_CONSTANTS", + "WM_SCRATCH", + "BATCH", + "GENERAL_STATE", + "SURFACE_STATE", + "PIXEL", + "GENERIC", +}; + +const char *usages[BRW_USAGE_MAX] = { + "STATE", + "QUERY_RESULT", + "RENDER_TARGET", + "DEPTH_BUFFER", + "BLIT_SOURCE", + "BLIT_DEST", + "SAMPLER", + "VERTEX", + "SCRATCH" +}; + + +const char *data_types[BRW_DATA_MAX] = +{ + "GS: CC_VP", + "GS: CC_UNIT", + "GS: WM_PROG", + "GS: SAMPLER_DEFAULT_COLOR", + "GS: SAMPLER", + "GS: WM_UNIT", + "GS: SF_PROG", + "GS: SF_VP", + "GS: SF_UNIT", + "GS: VS_UNIT", + "GS: VS_PROG", + "GS: GS_UNIT", + "GS: GS_PROG", + "GS: CLIP_VP", + "GS: CLIP_UNIT", + "GS: CLIP_PROG", + "SS: SURFACE", + "SS: SURF_BIND", + "CONSTANT DATA", + "BATCH DATA", + "(untyped)" +}; + + +static enum pipe_error +xlib_brw_bo_alloc( struct brw_winsys_screen *sws, + enum brw_buffer_type type, + unsigned size, + unsigned alignment, + struct brw_winsys_buffer **bo_out ) +{ + struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); + struct xlib_brw_buffer *buf; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s type %s sz %d align %d\n", + __FUNCTION__, names[type], size, alignment ); + + buf = CALLOC_STRUCT(xlib_brw_buffer); + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + pipe_reference_init(&buf->base.reference, 1); + + buf->offset = align(xbw->used, alignment); + buf->type = type; + buf->virtual = MALLOC(size); + buf->base.size = size; + buf->base.sws = sws; + + xbw->used = align(xbw->used, alignment) + size; + if (xbw->used > MAX_VRAM) + goto err; + + /* XXX: possibly rentrant call to bo_destroy: + */ + bo_reference(bo_out, &buf->base); + return PIPE_OK; + +err: + assert(0); + FREE(buf->virtual); + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static void +xlib_brw_bo_destroy( struct brw_winsys_buffer *buffer ) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + FREE(buf); +} + +static int +xlib_brw_bo_emit_reloc( struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *buffer2) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + struct xlib_brw_buffer *buf2 = xlib_brw_buffer(buffer2); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s buf %p offset %x val %x + %x buf2 %p/%s/%s\n", + __FUNCTION__, (void *)buffer, offset, + buf2->offset, delta, + (void *)buffer2, names[buf2->type], usages[usage]); + + *(uint32_t *)(buf->virtual + offset) = buf2->offset + delta; + + return 0; +} + +static int +xlib_brw_bo_exec( struct brw_winsys_buffer *buffer, + unsigned bytes_used ) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); + + return 0; +} + + + + +static int +xlib_brw_bo_subdata(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + size_t offset, + size_t size, + const void *data, + const struct brw_winsys_reloc *reloc, + unsigned nr_relocs) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + struct xlib_brw_winsys *xbw = xlib_brw_winsys(buffer->sws); + unsigned i; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", + __FUNCTION__, + (void *)buffer, offset, size, + data_types[data_type], + nr_relocs); + + assert(buf->base.size >= offset + size); + memcpy(buf->virtual + offset, data, size); + + /* Apply the relocations: + */ + for (i = 0; i < nr_relocs; i++) { + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("\treloc[%d] usage %s off %d value %x+%x\n", + i, usages[reloc[i].usage], reloc[i].offset, + xlib_brw_buffer(reloc[i].bo)->offset, reloc[i].delta); + + *(unsigned *)(buf->virtual + offset + reloc[i].offset) = + xlib_brw_buffer(reloc[i].bo)->offset + reloc[i].delta; + } + + if (BRW_DUMP) + brw_dump_data( xbw->chipset.pci_id, + data_type, + buf->offset + offset, + buf->virtual + offset, size ); + + + return 0; +} + + +static boolean +xlib_brw_bo_is_busy(struct brw_winsys_buffer *buffer) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + return TRUE; +} + +static boolean +xlib_brw_bo_references(struct brw_winsys_buffer *a, + struct brw_winsys_buffer *b) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); + return TRUE; +} + +static enum pipe_error +xlib_brw_check_aperture_space( struct brw_winsys_screen *iws, + struct brw_winsys_buffer **buffers, + unsigned count ) +{ + unsigned tot_size = 0; + unsigned i; + + for (i = 0; i < count; i++) + tot_size += buffers[i]->size; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %d bufs, tot_size: %d kb\n", + __FUNCTION__, count, + (tot_size + 1023) / 1024); + + return PIPE_OK; +} + +static void * +xlib_brw_bo_map(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + unsigned offset, + unsigned length, + boolean write, + boolean discard, + boolean explicit) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, + write ? "read/write" : "read", + write ? data_types[data_type] : ""); + + if (write) + buf->modified = 1; + + buf->map_count++; + return buf->virtual; +} + + +static void +xlib_brw_bo_flush_range( struct brw_winsys_buffer *buffer, + unsigned offset, + unsigned length ) +{ +} + + +static void +xlib_brw_bo_unmap(struct brw_winsys_buffer *buffer) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + + --buf->map_count; + assert(buf->map_count >= 0); + + if (buf->map_count == 0 && + buf->modified) { + + buf->modified = 0; + + /* Consider dumping new buffer contents here, using the + * flush-range info to minimize verbosity. + */ + } +} + + +static void +xlib_brw_bo_wait_idle( struct brw_winsys_buffer *buffer ) +{ +} + + +static void +xlib_brw_winsys_destroy( struct brw_winsys_screen *sws ) +{ + struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); + + FREE(xbw); +} + +static struct brw_winsys_screen * +xlib_create_brw_winsys_screen( void ) +{ + struct xlib_brw_winsys *ws; + + ws = CALLOC_STRUCT(xlib_brw_winsys); + if (!ws) + return NULL; + + ws->used = 0; + + ws->base.destroy = xlib_brw_winsys_destroy; + ws->base.bo_alloc = xlib_brw_bo_alloc; + ws->base.bo_destroy = xlib_brw_bo_destroy; + ws->base.bo_emit_reloc = xlib_brw_bo_emit_reloc; + ws->base.bo_exec = xlib_brw_bo_exec; + ws->base.bo_subdata = xlib_brw_bo_subdata; + ws->base.bo_is_busy = xlib_brw_bo_is_busy; + ws->base.bo_references = xlib_brw_bo_references; + ws->base.check_aperture_space = xlib_brw_check_aperture_space; + ws->base.bo_map = xlib_brw_bo_map; + ws->base.bo_flush_range = xlib_brw_bo_flush_range; + ws->base.bo_unmap = xlib_brw_bo_unmap; + ws->base.bo_wait_idle = xlib_brw_bo_wait_idle; + + return &ws->base; +} + + +/*********************************************************************** + * Implementation of Xlib co-state-tracker's winsys interface + */ + +static void +xlib_i965_display_surface(struct xmesa_buffer *xm_buffer, + struct pipe_surface *surf) +{ + struct brw_surface *surface = brw_surface(surf); + struct xlib_brw_buffer *bo = xlib_brw_buffer(surface->bo); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s offset %x+%x sz %dx%d\n", __FUNCTION__, + bo->offset, + surface->draw_offset, + surf->width, + surf->height); +} + +static void +xlib_i965_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, + void *context_private) +{ + xlib_i965_display_surface(NULL, surf); +} + + +static struct pipe_screen * +xlib_create_i965_screen( void ) +{ + struct brw_winsys_screen *winsys; + struct pipe_screen *screen; + + winsys = xlib_create_brw_winsys_screen(); + if (winsys == NULL) + return NULL; + + screen = brw_create_screen(winsys, PCI_CHIP_GM45_GM); + if (screen == NULL) + goto fail; + + xlib_brw_winsys(winsys)->chipset = brw_screen(screen)->chipset; + + screen->flush_frontbuffer = xlib_i965_flush_frontbuffer; + return screen; + +fail: + if (winsys) + winsys->destroy( winsys ); + + return NULL; +} + + + + + +struct xm_driver xlib_i965_driver = +{ + .create_pipe_screen = xlib_create_i965_screen, + .display_surface = xlib_i965_display_surface +}; + + +/* Register this driver at library load: + */ +static void _init( void ) __attribute__((constructor)); +static void _init( void ) +{ + xmesa_set_driver( &xlib_i965_driver ); +} + + + +/*********************************************************************** + * + * Butt-ugly hack to convince the linker not to throw away public GL + * symbols (they are all referenced from getprocaddress, I guess). + */ +extern void (*linker_foo(const unsigned char *procName))(); +extern void (*glXGetProcAddress(const unsigned char *procName))(); + +extern void (*linker_foo(const unsigned char *procName))() +{ + return glXGetProcAddress(procName); +} diff --git a/src/gallium/winsys/nouveau/drm/Makefile b/src/gallium/winsys/nouveau/drm/Makefile new file mode 100644 index 00000000000..71029858f75 --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveaudrm + +C_SOURCES = nouveau_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-I) +LIBRARY_DEFINES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/nouveau/drm/nouveau_dri.h b/src/gallium/winsys/nouveau/drm/nouveau_dri.h new file mode 100644 index 00000000000..1207c2d609c --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_dri.h @@ -0,0 +1,28 @@ +#ifndef _NOUVEAU_DRI_ +#define _NOUVEAU_DRI_ + +#include "xf86drm.h" +#include "drm.h" +#include "nouveau_drm.h" + +struct nouveau_dri { + uint32_t device_id; /**< \brief PCI device ID */ + uint32_t width; /**< \brief width in pixels of display */ + uint32_t height; /**< \brief height in scanlines of display */ + uint32_t depth; /**< \brief depth of display (8, 15, 16, 24) */ + uint32_t bpp; /**< \brief bit depth of display (8, 16, 24, 32) */ + + uint32_t bus_type; /**< \brief ths bus type */ + uint32_t bus_mode; /**< \brief bus mode (used for AGP, maybe also for PCI-E ?) */ + + uint32_t front_offset; /**< \brief front buffer offset */ + uint32_t front_pitch; /**< \brief front buffer pitch */ + uint32_t back_offset; /**< \brief private back buffer offset */ + uint32_t back_pitch; /**< \brief private back buffer pitch */ + uint32_t depth_offset; /**< \brief private depth buffer offset */ + uint32_t depth_pitch; /**< \brief private depth buffer pitch */ + +}; + +#endif + diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c new file mode 100644 index 00000000000..716d4bacd3b --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c @@ -0,0 +1,157 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "nouveau_drm_api.h" + +#include "nouveau_drmif.h" +#include "nouveau_channel.h" +#include "nouveau_bo.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_screen.h" + +static struct pipe_surface * +dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, + unsigned handle, enum pipe_format format, + unsigned width, unsigned height, unsigned pitch) +{ + struct pipe_surface *ps = NULL; + struct pipe_texture *pt = NULL; + struct pipe_texture tmpl; + struct winsys_handle whandle; + + memset(&tmpl, 0, sizeof(tmpl)); + tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT; + tmpl.target = PIPE_TEXTURE_2D; + tmpl.last_level = 0; + tmpl.depth0 = 1; + tmpl.format = format; + tmpl.width0 = width; + tmpl.height0 = height; + + memset(&whandle, 0, sizeof(whandle)); + whandle.stride = pitch; + whandle.handle = handle; + + pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle); + if (!pt) + return NULL; + + ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + /* we don't need the texture from this point on */ + pipe_texture_reference(&pt, NULL); + return ps; +} + +static struct pipe_surface * +nouveau_dri1_front_surface(struct pipe_context *pipe) +{ + return nouveau_winsys_screen(pipe->screen)->front; +} + +static struct dri1_api nouveau_dri1_api = { + nouveau_dri1_front_surface, +}; + +static void +nouveau_drm_destroy_winsys(struct pipe_winsys *s) +{ + struct nouveau_winsys *nv_winsys = nouveau_winsys(s); + struct nouveau_screen *nv_screen= nouveau_screen(nv_winsys->pscreen); + nouveau_device_close(&nv_screen->device); + FREE(nv_winsys); +} + +static struct pipe_screen * +nouveau_drm_create_screen(struct drm_api *api, int fd, + struct drm_create_screen_arg *arg) +{ + struct dri1_create_screen_arg *dri1 = (void *)arg; + struct nouveau_winsys *nvws; + struct pipe_winsys *ws; + struct nouveau_device *dev = NULL; + struct pipe_screen *(*init)(struct pipe_winsys *, + struct nouveau_device *); + int ret; + + ret = nouveau_device_open_existing(&dev, 0, fd, 0); + if (ret) + return NULL; + + switch (dev->chipset & 0xf0) { + case 0x30: + case 0x40: + case 0x60: + init = nvfx_screen_create; + break; + case 0x50: + case 0x80: + case 0x90: + case 0xa0: + init = nv50_screen_create; + break; + default: + debug_printf("%s: unknown chipset nv%02x\n", __func__, + dev->chipset); + return NULL; + } + + nvws = CALLOC_STRUCT(nouveau_winsys); + if (!nvws) { + nouveau_device_close(&dev); + return NULL; + } + ws = &nvws->base; + ws->destroy = nouveau_drm_destroy_winsys; + + nvws->pscreen = init(ws, dev); + if (!nvws->pscreen) { + ws->destroy(ws); + return NULL; + } + + if (arg && arg->mode == DRM_CREATE_DRI1) { + struct nouveau_dri *nvdri = dri1->ddx_info; + enum pipe_format format; + + if (nvdri->bpp == 16) + format = PIPE_FORMAT_B5G6R5_UNORM; + else + format = PIPE_FORMAT_B8G8R8A8_UNORM; + + nvws->front = dri_surface_from_handle(api, nvws->pscreen, + nvdri->front_offset, + format, nvdri->width, + nvdri->height, + nvdri->front_pitch * + (nvdri->bpp / 8)); + if (!nvws->front) { + debug_printf("%s: error referencing front buffer\n", + __func__); + ws->destroy(ws); + return NULL; + } + + dri1->api = &nouveau_dri1_api; + } + + return nvws->pscreen; +} + +struct drm_api drm_api_hooks = { + .name = "nouveau", + .driver_name = "nouveau", + .create_screen = nouveau_drm_create_screen, +}; + +struct drm_api * +drm_api_create() { + return &drm_api_hooks; +} + diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h new file mode 100644 index 00000000000..a91aad7df8e --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h @@ -0,0 +1,31 @@ +#ifndef __NOUVEAU_DRM_API_H__ +#define __NOUVEAU_DRM_API_H__ + +#include "state_tracker/drm_api.h" +#include "state_tracker/dri1_api.h" + +#include "util/u_simple_screen.h" + +#include "nouveau_dri.h" + +struct nouveau_winsys { + struct pipe_winsys base; + + struct pipe_screen *pscreen; + + struct pipe_surface *front; +}; + +static INLINE struct nouveau_winsys * +nouveau_winsys(struct pipe_winsys *ws) +{ + return (struct nouveau_winsys *)ws; +} + +static INLINE struct nouveau_winsys * +nouveau_winsys_screen(struct pipe_screen *pscreen) +{ + return nouveau_winsys(pscreen->winsys); +} + +#endif diff --git a/src/gallium/winsys/null/Makefile b/src/gallium/winsys/null/Makefile deleted file mode 100644 index 3a3fb75ab36..00000000000 --- a/src/gallium/winsys/null/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = ws_null - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary - -C_SOURCES = \ - null_sw_winsys.c - -include ../../Makefile.template - - diff --git a/src/gallium/winsys/null/SConscript b/src/gallium/winsys/null/SConscript deleted file mode 100644 index 21837dc60c2..00000000000 --- a/src/gallium/winsys/null/SConscript +++ /dev/null @@ -1,21 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -env = env.Clone() - -env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', -]) - -ws_null = env.ConvenienceLibrary( - target = 'ws_null', - source = [ - 'null_sw_winsys.c', - ] -) -Export('ws_null') diff --git a/src/gallium/winsys/null/null_sw_winsys.c b/src/gallium/winsys/null/null_sw_winsys.c deleted file mode 100644 index 5027e57b303..00000000000 --- a/src/gallium/winsys/null/null_sw_winsys.c +++ /dev/null @@ -1,148 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - -/** - * @file - * Null software rasterizer winsys. - * - * There is no present support. Framebuffer data needs to be obtained via - * transfers. - * - * @author Jose Fonseca - */ - - -#include "pipe/p_format.h" -#include "util/u_memory.h" -#include "state_tracker/sw_winsys.h" -#include "null_sw_winsys.h" - - -static boolean -null_sw_is_displaytarget_format_supported(struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - return FALSE; -} - - -static void * -null_sw_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags ) -{ - assert(0); - return NULL; -} - - -static void -null_sw_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt ) -{ - assert(0); -} - - -static void -null_sw_displaytarget_destroy(struct sw_winsys *winsys, - struct sw_displaytarget *dt) -{ - assert(0); -} - - -static struct sw_displaytarget * -null_sw_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - return NULL; -} - - -static struct sw_displaytarget * -null_sw_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - return NULL; -} - - -static boolean -null_sw_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -static void -null_sw_displaytarget_display(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - void *context_private) -{ - assert(0); -} - - -static void -null_sw_destroy(struct sw_winsys *winsys) -{ - FREE(winsys); -} - - -struct sw_winsys * -null_sw_create(void) -{ - static struct sw_winsys *winsys; - - winsys = CALLOC_STRUCT(sw_winsys); - if (!winsys) - return NULL; - - winsys->destroy = null_sw_destroy; - winsys->is_displaytarget_format_supported = null_sw_is_displaytarget_format_supported; - winsys->displaytarget_create = null_sw_displaytarget_create; - winsys->displaytarget_from_handle = null_sw_displaytarget_from_handle; - winsys->displaytarget_get_handle = null_sw_displaytarget_get_handle; - winsys->displaytarget_map = null_sw_displaytarget_map; - winsys->displaytarget_unmap = null_sw_displaytarget_unmap; - winsys->displaytarget_display = null_sw_displaytarget_display; - winsys->displaytarget_destroy = null_sw_displaytarget_destroy; - - return winsys; -} diff --git a/src/gallium/winsys/null/null_sw_winsys.h b/src/gallium/winsys/null/null_sw_winsys.h deleted file mode 100644 index 1986186febe..00000000000 --- a/src/gallium/winsys/null/null_sw_winsys.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - - -#ifndef NULL_SW_WINSYS_H_ -#define NULL_SW_WINSYS_H_ - - -struct sw_winsys; - - -struct sw_winsys * -null_sw_create(void); - - -#endif /* NULL_SW_WINSYS_H_ */ diff --git a/src/gallium/winsys/radeon/drm/Makefile b/src/gallium/winsys/radeon/drm/Makefile new file mode 100644 index 00000000000..7f69e392735 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/Makefile @@ -0,0 +1,17 @@ + +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = radeonwinsys + +C_SOURCES = \ + radeon_drm_buffer.c \ + radeon_drm.c \ + radeon_r300.c + +LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r300 \ + $(shell pkg-config libdrm --cflags-only-I) + +include ../../../Makefile.template + +symlinks: diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript new file mode 100644 index 00000000000..f4e9c397bdf --- /dev/null +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -0,0 +1,18 @@ +Import('*') + +env = drienv.Clone() + +radeon_sources = [ + 'radeon_buffer.c', + 'radeon_drm.c', + 'radeon_r300.c', +] + +env.Append(CPPPATH = '#/src/gallium/drivers/r300') + +radeonwinsys = env.ConvenienceLibrary( + target ='radeonwinsys', + source = radeon_sources, +) + +Export('radeonwinsys') diff --git a/src/gallium/winsys/radeon/drm/radeon_buffer.h b/src/gallium/winsys/radeon/drm/radeon_buffer.h new file mode 100644 index 00000000000..218a3763018 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_buffer.h @@ -0,0 +1,86 @@ +/* + * Copyright © 2008 Jérôme Glisse + * 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 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 THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef RADEON_BUFFER_H +#define RADEON_BUFFER_H + +#include + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "radeon_bo.h" +#include "radeon_cs.h" + +#include "radeon_winsys.h" + + +#define RADEON_MAX_BOS 24 + +static INLINE struct pb_buffer * +radeon_pb_buffer(struct r300_winsys_buffer *buffer) +{ + return (struct pb_buffer *)buffer; +} + +static INLINE struct r300_winsys_buffer * +radeon_libdrm_winsys_buffer(struct pb_buffer *buffer) +{ + return (struct r300_winsys_buffer *)buffer; +} + +struct pb_manager * +radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws); + +boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd); + + +void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd, + uint32_t flags); + +struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, + uint32_t handle); + +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch); + +void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); + +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle); + +boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf); +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_drm.c b/src/gallium/winsys/radeon/drm/radeon_drm.c new file mode 100644 index 00000000000..3dfcc5aef07 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm.c @@ -0,0 +1,200 @@ +/* + * Copyright © 2009 Corbin Simpson + * 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 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 THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + * Joakim Sindholt + */ + +#include "radeon_drm.h" +#include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "r300_winsys.h" +#include "trace/tr_drm.h" + +#include "util/u_memory.h" + +#include "xf86drm.h" +#include + +static struct radeon_libdrm_winsys * +radeon_winsys_create(int fd) +{ + struct radeon_libdrm_winsys *rws; + + rws = CALLOC_STRUCT(radeon_libdrm_winsys); + if (rws == NULL) { + return NULL; + } + + rws->fd = fd; + return rws; +} + +/* Helper function to do the ioctls needed for setup and init. */ +static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) +{ + struct drm_radeon_gem_info gem_info = {0}; + struct drm_radeon_info info = {0}; + int target = 0; + int retval; + drmVersionPtr version; + + info.value = (unsigned long)⌖ + + /* We do things in a specific order here. + * + * DRM version first. We need to be sure we're running on a KMS chipset. + * This is also for some features. + * + * Then, the PCI ID. This is essential and should return usable numbers + * for all Radeons. If this fails, we probably got handed an FD for some + * non-Radeon card. + * + * The GB and Z pipe requests should always succeed, but they might not + * return sensical values for all chipsets, but that's alright because + * the pipe drivers already know that. + * + * The GEM info is actually bogus on the kernel side, as well as our side + * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because + * we don't actually use the info for anything yet. */ + + version = drmGetVersion(fd); + if (version->version_major != 2) { + fprintf(stderr, "%s: DRM version is %d.%d.%d but this driver is " + "only compatible with 2.x.x\n", __FUNCTION__, + version->version_major, version->version_minor, + version->version_patchlevel); + drmFreeVersion(version); + exit(1); + } + +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE + // Supported since 2.1.0. + winsys->squaretiling = version->version_major > 2 || + version->version_minor >= 1; +#endif + + info.request = RADEON_INFO_DEVICE_ID; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get PCI ID, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->pci_id = target; + + info.request = RADEON_INFO_NUM_GB_PIPES; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get GB pipe count, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->gb_pipes = target; + + info.request = RADEON_INFO_NUM_Z_PIPES; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get Z pipe count, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->z_pipes = target; + + retval = drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO, + &gem_info, sizeof(gem_info)); + if (retval) { + fprintf(stderr, "%s: Failed to get MM info, error number %d\n", + __FUNCTION__, retval); + exit(1); + } + winsys->gart_size = gem_info.gart_size; + winsys->vram_size = gem_info.vram_size; + + debug_printf("radeon: Successfully grabbed chipset info from kernel!\n" + "radeon: DRM version: %d.%d.%d ID: 0x%04x GB: %d Z: %d\n" + "radeon: GART size: %d MB VRAM size: %d MB\n", + version->version_major, version->version_minor, + version->version_patchlevel, winsys->pci_id, + winsys->gb_pipes, winsys->z_pipes, + winsys->gart_size / 1024 / 1024, + winsys->vram_size / 1024 / 1024); + + drmFreeVersion(version); +} + +/* Create a pipe_screen. */ +struct pipe_screen* radeon_create_screen(struct drm_api* api, + int drmFB, + struct drm_create_screen_arg *arg) +{ + struct radeon_libdrm_winsys* rws; + boolean ret; + + rws = radeon_winsys_create(drmFB); + if (!rws) + return NULL; + + do_ioctls(drmFB, rws); + + /* The state tracker can organize a softpipe fallback if no hw + * driver is found. + */ + if (is_r3xx(rws->pci_id)) { + ret = radeon_setup_winsys(drmFB, rws); + if (ret == FALSE) + goto fail; + return r300_create_screen(&rws->base); + } + +fail: + FREE(rws); + return NULL; +} + +static void radeon_drm_api_destroy(struct drm_api *api) +{ + return; +} + +struct drm_api drm_api_hooks = { + .name = "radeon", + .driver_name = "radeon", + .create_screen = radeon_create_screen, + .destroy = radeon_drm_api_destroy, +}; + +struct drm_api* drm_api_create() +{ +#ifdef DEBUG + return trace_drm_create(&drm_api_hooks); +#else + return &drm_api_hooks; +#endif +} diff --git a/src/gallium/winsys/radeon/drm/radeon_drm.h b/src/gallium/winsys/radeon/drm/radeon_drm.h new file mode 100644 index 00000000000..2dc077c0521 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm.h @@ -0,0 +1,66 @@ +/* + * Copyright © 2009 Corbin Simpson + * 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 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 THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + */ +#ifndef RADEON_DRM_H +#define RADEON_DRM_H + +#include "state_tracker/drm_api.h" + + +struct pipe_screen* radeon_create_screen(struct drm_api* api, + int drmFB, + struct drm_create_screen_arg *arg); + +boolean radeon_buffer_from_texture(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + +boolean radeon_handle_from_buffer(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +boolean radeon_global_handle_from_buffer(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +void radeon_destroy_drm_api(struct drm_api* api); + +/* Guess at whether this chipset should use r300g. + * + * I believe that this check is valid, but I haven't been exhaustive. */ +static INLINE boolean is_r3xx(int pciid) +{ + return (pciid > 0x3150) && (pciid < 0x796f); +} + +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c new file mode 100644 index 00000000000..66f61322457 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c @@ -0,0 +1,385 @@ + +#include +#include "radeon_drm.h" +#include "radeon_bo_gem.h" +#include "radeon_cs_gem.h" +#include "radeon_buffer.h" + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "radeon_winsys.h" +struct radeon_drm_bufmgr; + +struct radeon_drm_buffer { + struct pb_buffer base; + struct radeon_drm_bufmgr *mgr; + + struct radeon_bo *bo; + + boolean flinked; + uint32_t flink; + + struct radeon_drm_buffer *next, *prev; +}; + +extern const struct pb_vtbl radeon_drm_buffer_vtbl; + + +static INLINE struct radeon_drm_buffer * +radeon_drm_buffer(struct pb_buffer *buf) +{ + assert(buf); + assert(buf->vtbl == &radeon_drm_buffer_vtbl); + return (struct radeon_drm_buffer *)buf; +} + +struct radeon_drm_bufmgr { + struct pb_manager base; + struct radeon_libdrm_winsys *rws; + struct radeon_drm_buffer buffer_map_list; +}; + +static INLINE struct radeon_drm_bufmgr * +radeon_drm_bufmgr(struct pb_manager *mgr) +{ + assert(mgr); + return (struct radeon_drm_bufmgr *)mgr; +} + +static void +radeon_drm_buffer_destroy(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + + if (buf->bo->ptr != NULL) { + remove_from_list(buf); + radeon_bo_unmap(buf->bo); + buf->bo->ptr = NULL; + } + radeon_bo_unref(buf->bo); + + FREE(buf); +} + +static void * +radeon_drm_buffer_map(struct pb_buffer *_buf, + unsigned flags) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + int write = 0; + + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { + if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || + (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX)) + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) + return NULL; + } + + if (buf->bo->ptr != NULL) + return buf->bo->ptr; + + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { + uint32_t domain; + if (radeon_bo_is_busy(buf->bo, &domain)) + return NULL; + } + + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { + buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); + } + + if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { + write = 1; + } + + if (radeon_bo_map(buf->bo, write)) { + return NULL; + } + insert_at_tail(&buf->mgr->buffer_map_list, buf); + return buf->bo->ptr; +} + +static void +radeon_drm_buffer_unmap(struct pb_buffer *_buf) +{ + (void)_buf; +} + +static void +radeon_drm_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +static enum pipe_error +radeon_drm_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + /* Always pinned */ + return PIPE_OK; +} + +static void +radeon_drm_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ +} + +const struct pb_vtbl radeon_drm_buffer_vtbl = { + radeon_drm_buffer_destroy, + radeon_drm_buffer_map, + radeon_drm_buffer_unmap, + radeon_drm_buffer_validate, + radeon_drm_buffer_fence, + radeon_drm_buffer_get_base_buffer, +}; + + +static uint32_t radeon_domain_from_usage(unsigned usage) +{ + uint32_t domain = 0; + + if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) { + domain |= RADEON_GEM_DOMAIN_VRAM; + } + if (usage & PIPE_BUFFER_USAGE_PIXEL) { + domain |= RADEON_GEM_DOMAIN_VRAM; + } + if (usage & PIPE_BUFFER_USAGE_VERTEX) { + domain |= RADEON_GEM_DOMAIN_GTT; + } + if (usage & PIPE_BUFFER_USAGE_INDEX) { + domain |= RADEON_GEM_DOMAIN_GTT; + } + + return domain; +} + +struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, + uint32_t handle) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_libdrm_winsys *rws = mgr->rws; + struct radeon_drm_buffer *buf; + struct radeon_bo *bo; + + bo = radeon_bo_open(rws->bom, handle, 0, + 0, 0, 0); + if (bo == NULL) + return NULL; + + buf = CALLOC_STRUCT(radeon_drm_buffer); + if (!buf) { + radeon_bo_unref(bo); + return NULL; + } + + make_empty_list(buf); + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = 0; + buf->base.base.usage = PIPE_BUFFER_USAGE_PIXEL; + buf->base.base.size = 0; + buf->base.vtbl = &radeon_drm_buffer_vtbl; + buf->mgr = mgr; + + buf->bo = bo; + + return &buf->base; +} + +static struct pb_buffer * +radeon_drm_bufmgr_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_libdrm_winsys *rws = mgr->rws; + struct radeon_drm_buffer *buf; + uint32_t domain; + + buf = CALLOC_STRUCT(radeon_drm_buffer); + if (!buf) + goto error1; + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + buf->base.vtbl = &radeon_drm_buffer_vtbl; + buf->mgr = mgr; + + make_empty_list(buf); + domain = radeon_domain_from_usage(desc->usage); + buf->bo = radeon_bo_open(rws->bom, 0, size, + desc->alignment, domain, 0); + if (buf->bo == NULL) + goto error2; + + return &buf->base; + + error2: + FREE(buf); + error1: + return NULL; +} + +static void +radeon_drm_bufmgr_flush(struct pb_manager *mgr) +{ + /* NOP */ +} + +static void +radeon_drm_bufmgr_destroy(struct pb_manager *_mgr) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + FREE(mgr); +} + +struct pb_manager * +radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws) +{ + struct radeon_drm_bufmgr *mgr; + + mgr = CALLOC_STRUCT(radeon_drm_bufmgr); + if (!mgr) + return NULL; + + mgr->base.destroy = radeon_drm_bufmgr_destroy; + mgr->base.create_buffer = radeon_drm_bufmgr_create_buffer; + mgr->base.flush = radeon_drm_bufmgr_flush; + + mgr->rws = rws; + make_empty_list(&mgr->buffer_map_list); + return &mgr->base; +} + +static struct radeon_drm_buffer *get_drm_buffer(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf; + if (_buf->vtbl == &radeon_drm_buffer_vtbl) { + buf = radeon_drm_buffer(_buf); + } else { + struct pb_buffer *base_buf; + pb_size offset; + pb_get_base_buffer(_buf, &base_buf, &offset); + + buf = radeon_drm_buffer(base_buf); + } + return buf; +} + +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle) +{ + int retval, fd; + struct drm_gem_flink flink; + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + fd = buf->mgr->rws->fd; + flink.handle = buf->bo->handle; + + retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); + if (retval) { + return FALSE; + } + + buf->flinked = TRUE; + buf->flink = flink.name; + } + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } + return TRUE; +} + + +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + uint32_t flags = 0, old_flags, old_pitch; + if (microtiled == R300_BUFFER_TILED) + flags |= RADEON_BO_FLAGS_MICRO_TILE; +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE + else if (microtiled == R300_BUFFER_SQUARETILED) + flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; +#endif + if (macrotiled == R300_BUFFER_TILED) + flags |= RADEON_BO_FLAGS_MACRO_TILE; + + radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); + + if (flags != old_flags || pitch != old_pitch) { + /* Tiling determines how DRM treats the buffer data. + * We must flush CS when changing it if the buffer is referenced. */ + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { + buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); + } + } + radeon_bo_set_tiling(buf->bo, flags, pitch); + +} + +boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + radeon_cs_space_add_persistent_bo(buf->mgr->rws->cs, buf->bo, + rd, wd); + return TRUE; +} + +void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd, + uint32_t flags) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + int retval; + + retval = radeon_cs_write_reloc(buf->mgr->rws->cs, + buf->bo, rd, wd, flags); + if (retval) { + debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n", + buf, rd, wd, flags); + } +} + +boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + uint32_t domain; + + return (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs) || + radeon_bo_is_busy(buf->bo, &domain)); +} + + +void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_drm_buffer *rpb, *t_rpb; + + foreach_s(rpb, t_rpb, &mgr->buffer_map_list) { + radeon_bo_unmap(rpb->bo); + rpb->bo->ptr = NULL; + remove_from_list(rpb); + } + + make_empty_list(&mgr->buffer_map_list); +} diff --git a/src/gallium/winsys/radeon/drm/radeon_r300.c b/src/gallium/winsys/radeon/drm/radeon_r300.c new file mode 100644 index 00000000000..38fcf889c8b --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_r300.c @@ -0,0 +1,348 @@ +/* + * Copyright 2008 Corbin Simpson + * + * 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 + * on 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 + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "radeon_bo_gem.h" +#include "radeon_cs_gem.h" +#include "state_tracker/drm_api.h" + +static struct r300_winsys_buffer * +radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, + unsigned alignment, + unsigned usage, + unsigned size) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct pb_desc desc; + struct pb_manager *provider; + struct pb_buffer *buffer; + + memset(&desc, 0, sizeof(desc)); + desc.alignment = alignment; + desc.usage = usage; + + if (usage & PIPE_BUFFER_USAGE_CONSTANT) + provider = ws->mman; + else if ((usage & PIPE_BUFFER_USAGE_VERTEX) || + (usage & PIPE_BUFFER_USAGE_INDEX)) + provider = ws->cman; + else + provider = ws->kman; + buffer = provider->create_buffer(provider, size, &desc); + if (!buffer) + return NULL; + + return radeon_libdrm_winsys_buffer(buffer); +} + +static void radeon_r300_winsys_buffer_destroy(struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + pb_destroy(_buf); +} +static void radeon_r300_winsys_buffer_set_tiling(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t pitch, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + radeon_drm_bufmgr_set_tiling(_buf, microtiled, macrotiled, pitch); +} + +static void *radeon_r300_winsys_buffer_map(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + unsigned usage) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return pb_map(_buf, usage); +} + +static void radeon_r300_winsys_buffer_unmap(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + pb_unmap(_buf); +} + +static void radeon_r300_winsys_buffer_reference(struct r300_winsys_screen *rws, + struct r300_winsys_buffer **pdst, + struct r300_winsys_buffer *src) +{ + struct pb_buffer *_src = radeon_pb_buffer(src); + struct pb_buffer *_dst = radeon_pb_buffer(*pdst); + + pb_reference(&_dst, _src); + + *pdst = radeon_libdrm_winsys_buffer(_dst); +} + +static boolean radeon_r300_winsys_is_buffer_referenced(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return radeon_drm_bufmgr_is_buffer_referenced(_buf); +} + +static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws, + struct pipe_screen *screen, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct pb_buffer *_buf; + + _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle); + *stride = whandle->stride; + return radeon_libdrm_winsys_buffer(_buf); +} + +static boolean radeon_r300_winsys_buffer_get_handle(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buffer, + unsigned stride, + struct winsys_handle *whandle) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buffer); + boolean ret; + ret = radeon_drm_bufmgr_get_handle(_buf, whandle); + if (ret) + whandle->stride = stride; + return ret; +} + +static void radeon_set_flush_cb(struct r300_winsys_screen *rws, + void (*flush_cb)(void *), + void *data) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + ws->flush_cb = flush_cb; + ws->flush_data = data; + radeon_cs_space_set_flush(ws->cs, flush_cb, data); +} + +static boolean radeon_add_buffer(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t rd, + uint32_t wd) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return radeon_drm_bufmgr_add_buffer(_buf, rd, wd); +} + +static boolean radeon_validate(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + if (radeon_cs_space_check(ws->cs) < 0) { + return FALSE; + } + + /* Things are fine, we can proceed as normal. */ + return TRUE; +} + +static boolean radeon_check_cs(struct r300_winsys_screen *rws, int size) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct radeon_cs *cs = ws->cs; + + return radeon_validate(rws) && cs->cdw + size <= cs->ndw; +} + +static void radeon_begin_cs(struct r300_winsys_screen *rws, + int size, + const char* file, + const char* function, + int line) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_begin(ws->cs, size, file, function, line); +} + +static void radeon_write_cs_dword(struct r300_winsys_screen *rws, + uint32_t dword) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_write_dword(ws->cs, dword); +} + +static void radeon_write_cs_reloc(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t rd, + uint32_t wd, + uint32_t flags) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + radeon_drm_bufmgr_write_reloc(_buf, rd, wd, flags); +} + +static void radeon_reset_bos(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_space_reset_bos(ws->cs); +} + +static void radeon_end_cs(struct r300_winsys_screen *rws, + const char* file, + const char* function, + int line) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_end(ws->cs, file, function, line); +} + +static void radeon_flush_cs(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + int retval; + + /* Don't flush a zero-sized CS. */ + if (!ws->cs->cdw) { + return; + } + + radeon_drm_bufmgr_flush_maps(ws->kman); + /* Emit the CS. */ + retval = radeon_cs_emit(ws->cs); + if (retval) { + debug_printf("radeon: Bad CS, dumping...\n"); + radeon_cs_print(ws->cs, stderr); + } + + /* Reset CS. + * Someday, when we care about performance, we should really find a way + * to rotate between two or three CS objects so that the GPU can be + * spinning through one CS while another one is being filled. */ + radeon_cs_erase(ws->cs); +} + +static uint32_t radeon_get_value(struct r300_winsys_screen *rws, + enum r300_value_id id) +{ + struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; + + switch(id) { + case R300_VID_PCI_ID: + return ws->pci_id; + case R300_VID_GB_PIPES: + return ws->gb_pipes; + case R300_VID_Z_PIPES: + return ws->z_pipes; + case R300_VID_SQUARE_TILING_SUPPORT: + return ws->squaretiling; + } + return 0; +} + +static void +radeon_winsys_destroy(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; + radeon_cs_destroy(ws->cs); + + ws->cman->destroy(ws->cman); + ws->kman->destroy(ws->kman); + ws->mman->destroy(ws->mman); + + radeon_bo_manager_gem_dtor(ws->bom); + radeon_cs_manager_gem_dtor(ws->csm); +} + +boolean +radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) +{ + + ws->csm = radeon_cs_manager_gem_ctor(fd); + if (!ws->csm) + goto fail; + ws->bom = radeon_bo_manager_gem_ctor(fd); + if (!ws->bom) + goto fail; + ws->kman = radeon_drm_bufmgr_create(ws); + if (!ws->kman) + goto fail; + + ws->cman = pb_cache_manager_create(ws->kman, 100000); + if (!ws->cman) + goto fail; + + ws->mman = pb_malloc_bufmgr_create(); + if (!ws->mman) + goto fail; + + /* Size limit on IBs is 64 kibibytes. */ + ws->cs = radeon_cs_create(ws->csm, 1024 * 64 / 4); + if (!ws->cs) + goto fail; + radeon_cs_set_limit(ws->cs, + RADEON_GEM_DOMAIN_GTT, ws->gart_size); + radeon_cs_set_limit(ws->cs, + RADEON_GEM_DOMAIN_VRAM, ws->vram_size); + + ws->base.add_buffer = radeon_add_buffer; + ws->base.validate = radeon_validate; + ws->base.destroy = radeon_winsys_destroy; + ws->base.check_cs = radeon_check_cs; + ws->base.begin_cs = radeon_begin_cs; + ws->base.write_cs_dword = radeon_write_cs_dword; + ws->base.write_cs_reloc = radeon_write_cs_reloc; + ws->base.end_cs = radeon_end_cs; + ws->base.flush_cs = radeon_flush_cs; + ws->base.reset_bos = radeon_reset_bos; + ws->base.set_flush_cb = radeon_set_flush_cb; + ws->base.get_value = radeon_get_value; + + ws->base.buffer_create = radeon_r300_winsys_buffer_create; + ws->base.buffer_destroy = radeon_r300_winsys_buffer_destroy; + ws->base.buffer_set_tiling = radeon_r300_winsys_buffer_set_tiling; + ws->base.buffer_map = radeon_r300_winsys_buffer_map; + ws->base.buffer_unmap = radeon_r300_winsys_buffer_unmap; + ws->base.buffer_reference = radeon_r300_winsys_buffer_reference; + ws->base.buffer_from_handle = radeon_r300_winsys_buffer_from_handle; + ws->base.buffer_get_handle = radeon_r300_winsys_buffer_get_handle; + ws->base.is_buffer_referenced = radeon_r300_winsys_is_buffer_referenced; + return TRUE; + +fail: + if (ws->csm) + radeon_cs_manager_gem_dtor(ws->csm); + + if (ws->bom) + radeon_bo_manager_gem_dtor(ws->bom); + + if (ws->cman) + ws->cman->destroy(ws->cman); + if (ws->kman) + ws->kman->destroy(ws->kman); + if (ws->mman) + ws->mman->destroy(ws->mman); + + if (ws->cs) + radeon_cs_destroy(ws->cs); + return FALSE; +} diff --git a/src/gallium/winsys/radeon/drm/radeon_r300.h b/src/gallium/winsys/radeon/drm/radeon_r300.h new file mode 100644 index 00000000000..2703464ad8f --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_r300.h @@ -0,0 +1,30 @@ +/* + * Copyright 2008 Corbin Simpson + * + * 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 + * on 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 + * THE AUTHOR(S) AND/OR THEIR 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 RADEON_R300_H +#define RADEON_R300_H + +#include "radeon_winsys.h" + +boolean radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* winsys); + +#endif /* RADEON_R300_H */ diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h new file mode 100644 index 00000000000..4260dbaad72 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -0,0 +1,86 @@ +/* + * Copyright © 2009 Corbin Simpson + * 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 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 THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + */ +#ifndef RADEON_WINSYS_H +#define RADEON_WINSYS_H + +#include "r300_winsys.h" + +struct radeon_libdrm_winsys { + /* Parent class. */ + struct r300_winsys_screen base; + + struct pb_manager *kman; + + struct pb_manager *cman; + + struct pb_manager *mman; + + /* PCI ID */ + uint32_t pci_id; + + /* GB pipe count */ + uint32_t gb_pipes; + + /* Z pipe count (rv530 only) */ + uint32_t z_pipes; + + /* GART size. */ + uint32_t gart_size; + + /* VRAM size. */ + uint32_t vram_size; + + /* Square tiling support. */ + boolean squaretiling; + + /* DRM FD */ + int fd; + + /* Radeon BO manager. */ + struct radeon_bo_manager *bom; + + /* Radeon CS manager. */ + struct radeon_cs_manager *csm; + + /* Current CS. */ + struct radeon_cs *cs; + + /* Flush CB */ + void (*flush_cb)(void *); + void *flush_data; +}; + +static INLINE struct radeon_libdrm_winsys * +radeon_winsys_screen(struct r300_winsys_screen *base) +{ + return (struct radeon_libdrm_winsys *)base; +} + +#endif diff --git a/src/gallium/winsys/svga/drm/Makefile b/src/gallium/winsys/svga/drm/Makefile new file mode 100644 index 00000000000..c2f59e01b0d --- /dev/null +++ b/src/gallium/winsys/svga/drm/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = svgadrm + +C_SOURCES = \ + vmw_buffer.c \ + vmw_context.c \ + vmw_fence.c \ + vmw_screen.c \ + vmw_screen_dri.c \ + vmw_screen_ioctl.c \ + vmw_screen_pools.c \ + vmw_screen_svga.c \ + vmw_surface.c + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/drivers/svga \ + -I$(TOP)/src/gallium/drivers/svga/include \ + $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = \ + -std=gnu99 -fvisibility=hidden \ + -DHAVE_STDINT_H -D_FILE_OFFSET_BITS=64 \ + $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/svga/drm/SConscript b/src/gallium/winsys/svga/drm/SConscript new file mode 100644 index 00000000000..edaf9458bee --- /dev/null +++ b/src/gallium/winsys/svga/drm/SConscript @@ -0,0 +1,39 @@ +Import('*') + +env = env.Clone() + +if env['gcc']: + env.Append(CCFLAGS = ['-fvisibility=hidden']) + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + '-D_FILE_OFFSET_BITS=64', + ]) + +env.Prepend(CPPPATH = [ + 'include', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', +]) + +env.Append(CPPDEFINES = [ +]) + +sources = [ + 'vmw_buffer.c', + 'vmw_context.c', + 'vmw_fence.c', + 'vmw_screen.c', + 'vmw_screen_dri.c', + 'vmw_screen_ioctl.c', + 'vmw_screen_pools.c', + 'vmw_screen_svga.c', + 'vmw_surface.c', +] + +svgadrm = env.ConvenienceLibrary( + target = 'svgadrm', + source = sources, +) + +Export('svgadrm') diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.c b/src/gallium/winsys/svga/drm/vmw_buffer.c new file mode 100644 index 00000000000..eca174a6c56 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_buffer.c @@ -0,0 +1,274 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * SVGA buffer manager for Guest Memory Regions (GMRs). + * + * GMRs are used for pixel and vertex data upload/download to/from the virtual + * SVGA hardware. There is a limited number of GMRs available, and + * creating/destroying them is also a slow operation so we must suballocate + * them. + * + * This file implements a pipebuffer library's buffer manager, so that we can + * use pipepbuffer's suballocation, fencing, and debugging facilities with GMRs. + * + * @author Jose Fonseca + */ + + +#include "svga_cmd.h" + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "svga_winsys.h" + +#include "vmw_screen.h" +#include "vmw_buffer.h" + + +struct vmw_gmr_bufmgr; + + +struct vmw_gmr_buffer +{ + struct pb_buffer base; + + struct vmw_gmr_bufmgr *mgr; + + struct vmw_region *region; + void *map; + +#ifdef DEBUG + struct pipe_fence_handle *last_fence; +#endif +}; + + +extern const struct pb_vtbl vmw_gmr_buffer_vtbl; + + +static INLINE struct vmw_gmr_buffer * +vmw_gmr_buffer(struct pb_buffer *buf) +{ + assert(buf); + assert(buf->vtbl == &vmw_gmr_buffer_vtbl); + return (struct vmw_gmr_buffer *)buf; +} + + +struct vmw_gmr_bufmgr +{ + struct pb_manager base; + + struct vmw_winsys_screen *vws; +}; + + +static INLINE struct vmw_gmr_bufmgr * +vmw_gmr_bufmgr(struct pb_manager *mgr) +{ + assert(mgr); + return (struct vmw_gmr_bufmgr *)mgr; +} + + +static void +vmw_gmr_buffer_destroy(struct pb_buffer *_buf) +{ + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + +#ifdef DEBUG + if(buf->last_fence) { + struct svga_winsys_screen *sws = &buf->mgr->vws->base; + assert(sws->fence_signalled(sws, buf->last_fence, 0) == 0); + } +#endif + + vmw_ioctl_region_unmap(buf->region); + + vmw_ioctl_region_destroy(buf->region); + + FREE(buf); +} + + +static void * +vmw_gmr_buffer_map(struct pb_buffer *_buf, + unsigned flags) +{ + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + return buf->map; +} + + +static void +vmw_gmr_buffer_unmap(struct pb_buffer *_buf) +{ + /* Do nothing */ + (void)_buf; +} + + +static void +vmw_gmr_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +static enum pipe_error +vmw_gmr_buffer_validate( struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags ) +{ + /* Always pinned */ + return PIPE_OK; +} + + +static void +vmw_gmr_buffer_fence( struct pb_buffer *_buf, + struct pipe_fence_handle *fence ) +{ + /* We don't need to do anything, as the pipebuffer library + * will take care of delaying the destruction of fenced buffers */ +#ifdef DEBUG + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + if(fence) + buf->last_fence = fence; +#endif +} + + +const struct pb_vtbl vmw_gmr_buffer_vtbl = { + vmw_gmr_buffer_destroy, + vmw_gmr_buffer_map, + vmw_gmr_buffer_unmap, + vmw_gmr_buffer_validate, + vmw_gmr_buffer_fence, + vmw_gmr_buffer_get_base_buffer +}; + + +static struct pb_buffer * +vmw_gmr_bufmgr_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); + struct vmw_winsys_screen *vws = mgr->vws; + struct vmw_gmr_buffer *buf; + + buf = CALLOC_STRUCT(vmw_gmr_buffer); + if(!buf) + goto error1; + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + buf->base.vtbl = &vmw_gmr_buffer_vtbl; + buf->mgr = mgr; + + buf->region = vmw_ioctl_region_create(vws, size); + if(!buf->region) + goto error2; + + buf->map = vmw_ioctl_region_map(buf->region); + if(!buf->map) + goto error3; + + return &buf->base; + +error3: + vmw_ioctl_region_destroy(buf->region); +error2: + FREE(buf); +error1: + return NULL; +} + + +static void +vmw_gmr_bufmgr_flush(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static void +vmw_gmr_bufmgr_destroy(struct pb_manager *_mgr) +{ + struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); + FREE(mgr); +} + + +struct pb_manager * +vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws) +{ + struct vmw_gmr_bufmgr *mgr; + + mgr = CALLOC_STRUCT(vmw_gmr_bufmgr); + if(!mgr) + return NULL; + + mgr->base.destroy = vmw_gmr_bufmgr_destroy; + mgr->base.create_buffer = vmw_gmr_bufmgr_create_buffer; + mgr->base.flush = vmw_gmr_bufmgr_flush; + + mgr->vws = vws; + + return &mgr->base; +} + + +boolean +vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, + struct SVGAGuestPtr *ptr) +{ + struct pb_buffer *base_buf; + unsigned offset = 0; + struct vmw_gmr_buffer *gmr_buf; + + pb_get_base_buffer( buf, &base_buf, &offset ); + + gmr_buf = vmw_gmr_buffer(base_buf); + if(!gmr_buf) + return FALSE; + + *ptr = vmw_ioctl_region_ptr(gmr_buf->region); + + ptr->offset += offset; + + return TRUE; +} diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.h b/src/gallium/winsys/svga/drm/vmw_buffer.h new file mode 100644 index 00000000000..41fb4476da5 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_buffer.h @@ -0,0 +1,65 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#ifndef VMW_BUFFER_H_ +#define VMW_BUFFER_H_ + +#include +#include "pipe/p_compiler.h" + +struct SVGAGuestPtr; +struct pb_buffer; +struct pb_manager; +struct svga_winsys_buffer; +struct svga_winsys_surface; +struct vmw_winsys_screen; + + +static INLINE struct pb_buffer * +vmw_pb_buffer(struct svga_winsys_buffer *buffer) +{ + assert(buffer); + return (struct pb_buffer *)buffer; +} + + +static INLINE struct svga_winsys_buffer * +vmw_svga_winsys_buffer(struct pb_buffer *buffer) +{ + assert(buffer); + return (struct svga_winsys_buffer *)buffer; +} + + +struct pb_manager * +vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws); + +boolean +vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, + struct SVGAGuestPtr *ptr); + + +#endif /* VMW_BUFFER_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c new file mode 100644 index 00000000000..90ffc4868f7 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.c @@ -0,0 +1,382 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "svga_cmd.h" + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_debug_stack.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_validate.h" + +#include "svga_winsys.h" +#include "vmw_context.h" +#include "vmw_screen.h" +#include "vmw_buffer.h" +#include "vmw_surface.h" +#include "vmw_fence.h" + +#define VMW_COMMAND_SIZE (64*1024) +#define VMW_SURFACE_RELOCS (1024) +#define VMW_REGION_RELOCS (512) + +#define VMW_MUST_FLUSH_STACK 8 + +struct vmw_region_relocation +{ + struct SVGAGuestPtr *where; + struct pb_buffer *buffer; + /* TODO: put offset info inside where */ + uint32 offset; +}; + +struct vmw_svga_winsys_context +{ + struct svga_winsys_context base; + + struct vmw_winsys_screen *vws; + +#ifdef DEBUG + boolean must_flush; + struct debug_stack_frame must_flush_stack[VMW_MUST_FLUSH_STACK]; +#endif + + struct { + uint8_t buffer[VMW_COMMAND_SIZE]; + uint32_t size; + uint32_t used; + uint32_t reserved; + } command; + + struct { + struct vmw_svga_winsys_surface *handles[VMW_SURFACE_RELOCS]; + uint32_t size; + uint32_t used; + uint32_t staged; + uint32_t reserved; + } surface; + + struct { + struct vmw_region_relocation relocs[VMW_REGION_RELOCS]; + uint32_t size; + uint32_t used; + uint32_t staged; + uint32_t reserved; + } region; + + struct pb_validate *validate; + + uint32_t last_fence; + + /** + * The amount of GMR that is referred by the commands currently batched + * in the context. + */ + uint32_t seen_regions; + + /** + * Whether this context should fail to reserve more commands, not because it + * ran out of command space, but because a substantial ammount of GMR was + * referred. + */ + boolean preemptive_flush; +}; + + +static INLINE struct vmw_svga_winsys_context * +vmw_svga_winsys_context(struct svga_winsys_context *swc) +{ + assert(swc); + return (struct vmw_svga_winsys_context *)swc; +} + + +static enum pipe_error +vmw_swc_flush(struct svga_winsys_context *swc, + struct pipe_fence_handle **pfence) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct pipe_fence_handle *fence = NULL; + unsigned i; + enum pipe_error ret; + + ret = pb_validate_validate(vswc->validate); + assert(ret == PIPE_OK); + if(ret == PIPE_OK) { + + /* Apply relocations */ + for(i = 0; i < vswc->region.used; ++i) { + struct vmw_region_relocation *reloc = &vswc->region.relocs[i]; + struct SVGAGuestPtr ptr; + + if(!vmw_gmr_bufmgr_region_ptr(reloc->buffer, &ptr)) + assert(0); + + ptr.offset += reloc->offset; + + *reloc->where = ptr; + } + + if (vswc->command.used) + vmw_ioctl_command(vswc->vws, + vswc->command.buffer, + vswc->command.used, + &vswc->last_fence); + + fence = vmw_pipe_fence(vswc->last_fence); + + pb_validate_fence(vswc->validate, fence); + } + + vswc->command.used = 0; + vswc->command.reserved = 0; + + for(i = 0; i < vswc->surface.used + vswc->surface.staged; ++i) { + struct vmw_svga_winsys_surface *vsurf = + vswc->surface.handles[i]; + p_atomic_dec(&vsurf->validated); + vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); + } + + vswc->surface.used = 0; + vswc->surface.reserved = 0; + + for(i = 0; i < vswc->region.used + vswc->region.staged; ++i) { + pb_reference(&vswc->region.relocs[i].buffer, NULL); + } + + vswc->region.used = 0; + vswc->region.reserved = 0; + +#ifdef DEBUG + vswc->must_flush = FALSE; +#endif + vswc->preemptive_flush = FALSE; + vswc->seen_regions = 0; + + if(pfence) + *pfence = fence; + + return ret; +} + + +static void * +vmw_swc_reserve(struct svga_winsys_context *swc, + uint32_t nr_bytes, uint32_t nr_relocs ) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + +#ifdef DEBUG + /* Check if somebody forgot to check the previous failure */ + if(vswc->must_flush) { + debug_printf("Forgot to flush:\n"); + debug_backtrace_dump(vswc->must_flush_stack, VMW_MUST_FLUSH_STACK); + assert(!vswc->must_flush); + } +#endif + + assert(nr_bytes <= vswc->command.size); + if(nr_bytes > vswc->command.size) + return NULL; + + if(vswc->preemptive_flush || + vswc->command.used + nr_bytes > vswc->command.size || + vswc->surface.used + nr_relocs > vswc->surface.size || + vswc->region.used + nr_relocs > vswc->region.size) { +#ifdef DEBUG + vswc->must_flush = TRUE; + debug_backtrace_capture(vswc->must_flush_stack, 1, + VMW_MUST_FLUSH_STACK); +#endif + return NULL; + } + + assert(vswc->command.used + nr_bytes <= vswc->command.size); + assert(vswc->surface.used + nr_relocs <= vswc->surface.size); + assert(vswc->region.used + nr_relocs <= vswc->region.size); + + vswc->command.reserved = nr_bytes; + vswc->surface.reserved = nr_relocs; + vswc->surface.staged = 0; + vswc->region.reserved = nr_relocs; + vswc->region.staged = 0; + + return vswc->command.buffer + vswc->command.used; +} + + +static void +vmw_swc_surface_relocation(struct svga_winsys_context *swc, + uint32 *where, + struct svga_winsys_surface *surface, + unsigned flags) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct vmw_svga_winsys_surface *vsurf; + + if(!surface) { + *where = SVGA3D_INVALID_ID; + return; + } + + assert(vswc->surface.staged < vswc->surface.reserved); + + vsurf = vmw_svga_winsys_surface(surface); + + *where = vsurf->sid; + + vmw_svga_winsys_surface_reference(&vswc->surface.handles[vswc->surface.used + vswc->surface.staged], vsurf); + p_atomic_inc(&vsurf->validated); + ++vswc->surface.staged; +} + + +static void +vmw_swc_region_relocation(struct svga_winsys_context *swc, + struct SVGAGuestPtr *where, + struct svga_winsys_buffer *buffer, + uint32 offset, + unsigned flags) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct vmw_region_relocation *reloc; + enum pipe_error ret; + + assert(vswc->region.staged < vswc->region.reserved); + + reloc = &vswc->region.relocs[vswc->region.used + vswc->region.staged]; + reloc->where = where; + pb_reference(&reloc->buffer, vmw_pb_buffer(buffer)); + reloc->offset = offset; + + ++vswc->region.staged; + + ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags); + /* TODO: Update pipebuffer to reserve buffers and not fail here */ + assert(ret == PIPE_OK); + + /* + * Flush preemptively the FIFO commands to keep the GMR working set within + * the GMR pool size. + * + * This is necessary for applications like SPECviewperf that generate huge + * amounts of immediate vertex data, so that we don't pile up too much of + * that vertex data neither in the guest nor in the host. + * + * Note that in the current implementation if a region is referred twice in + * a command stream, it will be accounted twice. We could detect repeated + * regions and count only once, but there is no incentive to do that, since + * regions are typically short-lived; always referred in a single command; + * and at the worst we just flush the commands a bit sooner, which for the + * SVGA virtual device it's not a performance issue since flushing commands + * to the FIFO won't cause flushing in the host. + */ + vswc->seen_regions += reloc->buffer->base.size; + if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2) + vswc->preemptive_flush = TRUE; +} + + +static void +vmw_swc_commit(struct svga_winsys_context *swc) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + + assert(vswc->command.reserved); + assert(vswc->command.used + vswc->command.reserved <= vswc->command.size); + vswc->command.used += vswc->command.reserved; + vswc->command.reserved = 0; + + assert(vswc->surface.staged <= vswc->surface.reserved); + assert(vswc->surface.used + vswc->surface.staged <= vswc->surface.size); + vswc->surface.used += vswc->surface.staged; + vswc->surface.staged = 0; + vswc->surface.reserved = 0; + + assert(vswc->region.staged <= vswc->region.reserved); + assert(vswc->region.used + vswc->region.staged <= vswc->region.size); + vswc->region.used += vswc->region.staged; + vswc->region.staged = 0; + vswc->region.reserved = 0; +} + + +static void +vmw_swc_destroy(struct svga_winsys_context *swc) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + unsigned i; + + for(i = 0; i < vswc->region.used; ++i) { + pb_reference(&vswc->region.relocs[i].buffer, NULL); + } + + for(i = 0; i < vswc->surface.used; ++i) { + p_atomic_dec(&vswc->surface.handles[i]->validated); + vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); + } + pb_validate_destroy(vswc->validate); + vmw_ioctl_context_destroy(vswc->vws, swc->cid); + FREE(vswc); +} + + +struct svga_winsys_context * +vmw_svga_winsys_context_create(struct svga_winsys_screen *sws) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct vmw_svga_winsys_context *vswc; + + vswc = CALLOC_STRUCT(vmw_svga_winsys_context); + if(!vswc) + return NULL; + + vswc->base.destroy = vmw_swc_destroy; + vswc->base.reserve = vmw_swc_reserve; + vswc->base.surface_relocation = vmw_swc_surface_relocation; + vswc->base.region_relocation = vmw_swc_region_relocation; + vswc->base.commit = vmw_swc_commit; + vswc->base.flush = vmw_swc_flush; + + vswc->base.cid = vmw_ioctl_context_create(vws); + + vswc->vws = vws; + + vswc->command.size = VMW_COMMAND_SIZE; + vswc->surface.size = VMW_SURFACE_RELOCS; + vswc->region.size = VMW_REGION_RELOCS; + + vswc->validate = pb_validate_create(); + if(!vswc->validate) { + FREE(vswc); + return NULL; + } + + return &vswc->base; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_context.h b/src/gallium/winsys/svga/drm/vmw_context.h new file mode 100644 index 00000000000..d4884d24e99 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.h @@ -0,0 +1,56 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @author Jose Fonseca + */ + + +#ifndef VMW_CONTEXT_H_ +#define VMW_CONTEXT_H_ + +#include "pipe/p_compiler.h" + +struct svga_winsys_screen; +struct svga_winsys_context; +struct pipe_context; +struct pipe_screen; + +#define VMW_DEBUG 0 + +#if VMW_DEBUG +#define vmw_printf debug_printf +#define VMW_FUNC debug_printf("%s\n", __FUNCTION__) +#else +#define VMW_FUNC +#define vmw_printf(...) +#endif + + +struct svga_winsys_context * +vmw_svga_winsys_context_create(struct svga_winsys_screen *sws); + + +#endif /* VMW_CONTEXT_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_fence.c b/src/gallium/winsys/svga/drm/vmw_fence.c new file mode 100644 index 00000000000..873dd51166c --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_fence.c @@ -0,0 +1,108 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer_fenced.h" + +#include "vmw_screen.h" +#include "vmw_fence.h" + + + +struct vmw_fence_ops +{ + struct pb_fence_ops base; + + struct vmw_winsys_screen *vws; +}; + + +static INLINE struct vmw_fence_ops * +vmw_fence_ops(struct pb_fence_ops *ops) +{ + assert(ops); + return (struct vmw_fence_ops *)ops; +} + + +static void +vmw_fence_ops_fence_reference(struct pb_fence_ops *ops, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + *ptr = fence; +} + + +static int +vmw_fence_ops_fence_signalled(struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; + (void)flag; + return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); +} + + +static int +vmw_fence_ops_fence_finish(struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; + (void)flag; + return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); +} + + +static void +vmw_fence_ops_destroy(struct pb_fence_ops *ops) +{ + FREE(ops); +} + + +struct pb_fence_ops * +vmw_fence_ops_create(struct vmw_winsys_screen *vws) +{ + struct vmw_fence_ops *ops; + + ops = CALLOC_STRUCT(vmw_fence_ops); + if(!ops) + return NULL; + + ops->base.destroy = &vmw_fence_ops_destroy; + ops->base.fence_reference = &vmw_fence_ops_fence_reference; + ops->base.fence_signalled = &vmw_fence_ops_fence_signalled; + ops->base.fence_finish = &vmw_fence_ops_fence_finish; + + ops->vws = vws; + + return &ops->base; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_fence.h b/src/gallium/winsys/svga/drm/vmw_fence.h new file mode 100644 index 00000000000..5357b4f61de --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_fence.h @@ -0,0 +1,59 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#ifndef VMW_FENCE_H_ +#define VMW_FENCE_H_ + + +#include "pipe/p_compiler.h" + + +struct pipe_fence_handle; +struct pb_fence_ops; +struct vmw_winsys_screen; + + +/** Cast from a pipe_fence_handle pointer into a SVGA fence */ +static INLINE uint32_t +vmw_fence( struct pipe_fence_handle *fence ) +{ + return (uint32_t)(uintptr_t)fence; +} + + +/** Cast from a SVGA fence number to pipe_fence_handle pointer */ +static INLINE struct pipe_fence_handle * +vmw_pipe_fence( uint32_t fence ) +{ + return (struct pipe_fence_handle *)(uintptr_t)fence; +} + + +struct pb_fence_ops * +vmw_fence_ops_create(struct vmw_winsys_screen *vws); + + +#endif /* VMW_FENCE_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c new file mode 100644 index 00000000000..6cc9b382932 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -0,0 +1,77 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "vmw_screen.h" + +#include "vmw_context.h" + +#include "util/u_memory.h" +#include "pipe/p_compiler.h" + + +/* Called from vmw_drm_create_screen(), creates and initializes the + * vmw_winsys_screen structure, which is the main entity in this + * module. + */ +struct vmw_winsys_screen * +vmw_winsys_create( int fd, boolean use_old_scanout_flag ) +{ + struct vmw_winsys_screen *vws = CALLOC_STRUCT(vmw_winsys_screen); + if (!vws) + goto out_no_vws; + + vws->ioctl.drm_fd = fd; + vws->use_old_scanout_flag = use_old_scanout_flag; + debug_printf("%s: use_old_scanout_flag == %s\n", __FUNCTION__, + use_old_scanout_flag ? "true" : "false"); + + if (!vmw_ioctl_init(vws)) + goto out_no_ioctl; + + if(!vmw_pools_init(vws)) + goto out_no_pools; + + if (!vmw_winsys_screen_init_svga(vws)) + goto out_no_svga; + + return vws; +out_no_svga: + vmw_pools_cleanup(vws); +out_no_pools: + vmw_ioctl_cleanup(vws); +out_no_ioctl: + FREE(vws); +out_no_vws: + return NULL; +} + +void +vmw_winsys_destroy(struct vmw_winsys_screen *vws) +{ + vmw_pools_cleanup(vws); + vmw_ioctl_cleanup(vws); + FREE(vws); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h new file mode 100644 index 00000000000..d3f2c2c7f56 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.h @@ -0,0 +1,140 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Common definitions for the VMware SVGA winsys. + * + * @author Jose Fonseca + */ + + +#ifndef VMW_SCREEN_H_ +#define VMW_SCREEN_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "svga_winsys.h" + + +#define VMW_GMR_POOL_SIZE (16*1024*1024) + + +struct pb_manager; +struct vmw_region; + + +struct vmw_winsys_screen +{ + struct svga_winsys_screen base; + + boolean use_old_scanout_flag; + + struct { + volatile uint32_t *fifo_map; + uint64_t last_fence; + int drm_fd; + } ioctl; + + struct { + struct pb_manager *gmr; + struct pb_manager *gmr_mm; + struct pb_manager *gmr_fenced; + } pools; +}; + + +static INLINE struct vmw_winsys_screen * +vmw_winsys_screen(struct svga_winsys_screen *base) +{ + return (struct vmw_winsys_screen *)base; +} + +/* */ +uint32 +vmw_ioctl_context_create(struct vmw_winsys_screen *vws); + +void +vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, + uint32 cid); + +uint32 +vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32 numFaces, + uint32 numMipLevels); + +void +vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, + uint32 sid); + +void +vmw_ioctl_command(struct vmw_winsys_screen *vws, + void *commands, + uint32_t size, + uint32_t *fence); + +struct vmw_region * +vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size); + +void +vmw_ioctl_region_destroy(struct vmw_region *region); + +struct SVGAGuestPtr +vmw_ioctl_region_ptr(struct vmw_region *region); + +void * +vmw_ioctl_region_map(struct vmw_region *region); +void +vmw_ioctl_region_unmap(struct vmw_region *region); + + +int +vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, + uint32_t fence); + +int +vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, + uint32_t fence); + + +/* Initialize parts of vmw_winsys_screen at startup: + */ +boolean vmw_ioctl_init(struct vmw_winsys_screen *vws); +boolean vmw_pools_init(struct vmw_winsys_screen *vws); +boolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws); + +void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws); +void vmw_pools_cleanup(struct vmw_winsys_screen *vws); + +struct vmw_winsys_screen *vmw_winsys_create(int fd, boolean use_old_scanout_flag); +void vmw_winsys_destroy(struct vmw_winsys_screen *sws); + + +#endif /* VMW_SCREEN_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_screen_dri.c b/src/gallium/winsys/svga/drm/vmw_screen_dri.c new file mode 100644 index 00000000000..657544dcb21 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c @@ -0,0 +1,373 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "vmw_screen.h" + +#include "trace/tr_drm.h" + +#include "vmw_screen.h" +#include "vmw_surface.h" +#include "vmw_fence.h" +#include "vmw_context.h" + +#include +#include +#include +#include + +#include + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + +static struct dri1_api dri1_api_hooks; +static struct dri1_api_version ddx_required = { 0, 1, 0 }; +static struct dri1_api_version ddx_compat = { 0, 0, 0 }; +static struct dri1_api_version dri_required = { 4, 0, 0 }; +static struct dri1_api_version dri_compat = { 4, 0, 0 }; +static struct dri1_api_version drm_required = { 1, 0, 0 }; +static struct dri1_api_version drm_compat = { 1, 0, 0 }; +static struct dri1_api_version drm_scanout = { 0, 9, 0 }; + +static boolean +vmw_dri1_check_version(const struct dri1_api_version *cur, + const struct dri1_api_version *required, + const struct dri1_api_version *compat, + const char component[]) +{ + if (cur->major > required->major && cur->major <= compat->major) + return TRUE; + if (cur->major == required->major && cur->minor >= required->minor) + return TRUE; + + fprintf(stderr, "%s version failure.\n", component); + fprintf(stderr, "%s version is %d.%d.%d and this driver can only work\n" + "with versions %d.%d.x through %d.x.x.\n", + component, + cur->major, + cur->minor, + cur->patch_level, required->major, required->minor, compat->major); + return FALSE; +} + +/* This is actually the entrypoint to the entire driver, called by the + * libGL (or EGL, or ...) code via the drm_api_hooks table at the + * bottom of the file. + */ +static struct pipe_screen * +vmw_drm_create_screen(struct drm_api *drm_api, + int fd, + struct drm_create_screen_arg *arg) +{ + struct vmw_winsys_screen *vws; + struct pipe_screen *screen; + struct dri1_create_screen_arg *dri1; + boolean use_old_scanout_flag = FALSE; + + if (!arg || arg->mode == DRM_CREATE_NORMAL) { + struct dri1_api_version drm_ver; + drmVersionPtr ver; + + ver = drmGetVersion(fd); + if (ver == NULL) + return NULL; + + drm_ver.major = ver->version_major; + drm_ver.minor = ver->version_minor; + drm_ver.patch_level = 0; /* ??? */ + + drmFreeVersion(ver); + if (!vmw_dri1_check_version(&drm_ver, &drm_required, + &drm_compat, "vmwgfx drm driver")) + return NULL; + + if (!vmw_dri1_check_version(&drm_ver, &drm_scanout, + &drm_compat, "use old scanout field (not a error)")) + use_old_scanout_flag = TRUE; + } + + if (arg != NULL) { + switch (arg->mode) { + case DRM_CREATE_NORMAL: + break; + case DRM_CREATE_DRI1: + dri1 = (struct dri1_create_screen_arg *)arg; + if (!vmw_dri1_check_version(&dri1->ddx_version, &ddx_required, + &ddx_compat, "ddx - driver api")) + return NULL; + if (!vmw_dri1_check_version(&dri1->dri_version, &dri_required, + &dri_compat, "dri info")) + return NULL; + if (!vmw_dri1_check_version(&dri1->drm_version, &drm_required, + &drm_compat, "vmwgfx drm driver")) + return NULL; + if (!vmw_dri1_check_version(&dri1->drm_version, &drm_scanout, + &drm_compat, "use old scanout field (not a error)")) + use_old_scanout_flag = TRUE; + dri1->api = &dri1_api_hooks; +#if 0 + break; +#else + assert(!"No dri 1 support for now\n"); + return NULL; +#endif + default: + return NULL; + } + } + + vws = vmw_winsys_create( fd, use_old_scanout_flag ); + if (!vws) + goto out_no_vws; + + /* XXX do this properly */ + vws->base.surface_from_handle = vmw_drm_surface_from_handle; + vws->base.surface_get_handle = vmw_drm_surface_get_handle; + + screen = svga_screen_create( &vws->base ); + if (!screen) + goto out_no_screen; + + return screen; + + /* Failure cases: + */ +out_no_screen: + vmw_winsys_destroy( vws ); + +out_no_vws: + return NULL; +} + +static INLINE boolean +vmw_dri1_intersect_src_bbox(struct drm_clip_rect *dst, + int dst_x, + int dst_y, + const struct drm_clip_rect *src, + const struct drm_clip_rect *bbox) +{ + int xy1; + int xy2; + + xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : + (int)bbox->x1 + dst_x; + xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : + (int)bbox->x2 + dst_x; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->x1 = xy1; + dst->x2 = xy2; + + xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : + (int)bbox->y1 + dst_y; + xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : + (int)bbox->y2 + dst_y; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->y1 = xy1; + dst->y2 = xy2; + return TRUE; +} + +/** + * No fancy get-surface-from-sarea stuff here. + * Just use the present blit. + */ + +static void +vmw_dri1_present_locked(struct pipe_context *locked_pipe, + struct pipe_surface *surf, + const struct drm_clip_rect *rect, + unsigned int num_clip, + int x_draw, int y_draw, + const struct drm_clip_rect *bbox, + struct pipe_fence_handle **p_fence) +{ +#if 0 + struct svga_winsys_surface *srf = + svga_screen_texture_get_winsys_surface(surf->texture); + struct vmw_svga_winsys_surface *vsrf = vmw_svga_winsys_surface(srf); + struct vmw_winsys_screen *vws = + vmw_winsys_screen(svga_winsys_screen(locked_pipe->screen)); + struct drm_clip_rect clip; + int i; + struct + { + SVGA3dCmdHeader header; + SVGA3dCmdPresent body; + SVGA3dCopyRect rect; + } cmd; + boolean visible = FALSE; + uint32_t fence_seq = 0; + + VMW_FUNC; + cmd.header.id = SVGA_3D_CMD_PRESENT; + cmd.header.size = sizeof cmd.body + sizeof cmd.rect; + cmd.body.sid = vsrf->sid; + + for (i = 0; i < num_clip; ++i) { + if (!vmw_dri1_intersect_src_bbox(&clip, x_draw, y_draw, rect++, bbox)) + continue; + + cmd.rect.x = clip.x1; + cmd.rect.y = clip.y1; + cmd.rect.w = clip.x2 - clip.x1; + cmd.rect.h = clip.y2 - clip.y1; + cmd.rect.srcx = (int)clip.x1 - x_draw; + cmd.rect.srcy = (int)clip.y1 - y_draw; + + vmw_printf("%s: Clip %d x %d y %d w %d h %d srcx %d srcy %d\n", + __FUNCTION__, + i, + cmd.rect.x, + cmd.rect.y, + cmd.rect.w, cmd.rect.h, cmd.rect.srcx, cmd.rect.srcy); + + vmw_ioctl_command(vws, &cmd, sizeof cmd.header + cmd.header.size, + &fence_seq); + visible = TRUE; + } + + *p_fence = (visible) ? vmw_pipe_fence(fence_seq) : NULL; + vmw_svga_winsys_surface_reference(&vsrf, NULL); +#else + assert(!"No dri 1 support for now\n"); +#endif +} + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format) +{ + struct vmw_svga_winsys_surface *vsrf; + struct svga_winsys_surface *ssrf; + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + union drm_vmw_surface_reference_arg arg; + struct drm_vmw_surface_arg *req = &arg.req; + struct drm_vmw_surface_create_req *rep = &arg.rep; + int ret; + int i; + + /** + * The vmware device specific handle is the hardware SID. + * FIXME: We probably want to move this to the ioctl implementations. + */ + + memset(&arg, 0, sizeof(arg)); + req->sid = whandle->handle; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_REF_SURFACE, + &arg, sizeof(arg)); + + if (ret) { + fprintf(stderr, "Failed referencing shared surface. SID %d.\n" + "Error %d (%s).\n", + whandle->handle, ret, strerror(-ret)); + return NULL; + } + + if (rep->mip_levels[0] != 1) { + fprintf(stderr, "Incorrect number of mipmap levels on shared surface." + " SID %d, levels %d\n", + whandle->handle, rep->mip_levels[0]); + goto out_mip; + } + + for (i=1; i < DRM_VMW_MAX_SURFACE_FACES; ++i) { + if (rep->mip_levels[i] != 0) { + fprintf(stderr, "Incorrect number of faces levels on shared surface." + " SID %d, face %d present.\n", + whandle->handle, i); + goto out_mip; + } + } + + vsrf = CALLOC_STRUCT(vmw_svga_winsys_surface); + if (!vsrf) + goto out_mip; + + pipe_reference_init(&vsrf->refcnt, 1); + p_atomic_set(&vsrf->validated, 0); + vsrf->screen = vws; + vsrf->sid = whandle->handle; + ssrf = svga_winsys_surface(vsrf); + *format = rep->format; + + return ssrf; + +out_mip: + vmw_ioctl_surface_destroy(vws, whandle->handle); + return NULL; +} + +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle) +{ + struct vmw_svga_winsys_surface *vsrf; + + if (!surface) + return FALSE; + + vsrf = vmw_svga_winsys_surface(surface); + whandle->handle = vsrf->sid; + whandle->stride = stride; + + return TRUE; +} + + +static struct dri1_api dri1_api_hooks = { + .front_srf_locked = NULL, + .present_locked = vmw_dri1_present_locked +}; + +static struct drm_api vmw_drm_api_hooks = { + .name = "vmwgfx", + .driver_name = "vmwgfx", + .create_screen = vmw_drm_create_screen, +}; + +struct drm_api* drm_api_create() +{ + return trace_drm_create(&vmw_drm_api_hooks); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c new file mode 100644 index 00000000000..5d81fa8c4a6 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c @@ -0,0 +1,529 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * + * Wrappers for DRM ioctl functionlaity used by the rest of the vmw + * drm winsys. + * + * Based on svgaicd_escape.c + */ + + +#include "svga_cmd.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "svgadump/svga_dump.h" +#include "vmw_screen.h" +#include "vmw_context.h" +#include "xf86drm.h" +#include "vmwgfx_drm.h" + +#include +#include +#include + +struct vmw_region +{ + SVGAGuestPtr ptr; + uint32_t handle; + uint64_t map_handle; + void *data; + uint32_t map_count; + int drm_fd; + uint32_t size; +}; + +/* XXX: This isn't a real hardware flag, but just a hack for kernel to + * know about primary surfaces. In newer versions of the kernel + * interface the driver uses a special field. + */ +#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) + +static void +vmw_check_last_cmd(struct vmw_winsys_screen *vws) +{ + static uint32_t buffer[16384]; + struct drm_vmw_fifo_debug_arg arg; + int ret; + + return; + memset(&arg, 0, sizeof(arg)); + arg.debug_buffer = (unsigned long)buffer; + arg.debug_buffer_size = 65536; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FIFO_DEBUG, + &arg, sizeof(arg)); + + if (ret) { + debug_printf("%s Ioctl error: \"%s\".\n", __FUNCTION__, strerror(-ret)); + return; + } + + if (arg.did_not_fit) { + debug_printf("%s Command did not fit completely.\n", __FUNCTION__); + } + + svga_dump_commands(buffer, arg.used_size); +} + +static void +vmw_ioctl_fifo_unmap(struct vmw_winsys_screen *vws, void *mapping) +{ + VMW_FUNC; + (void)munmap(mapping, getpagesize()); +} + + +static void * +vmw_ioctl_fifo_map(struct vmw_winsys_screen *vws, + uint32_t fifo_offset ) +{ + void *map; + + VMW_FUNC; + + map = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, + vws->ioctl.drm_fd, fifo_offset); + + if (map == MAP_FAILED) { + debug_printf("Map failed %s\n", strerror(errno)); + return NULL; + } + + vmw_printf("Fifo (min) is 0x%08x\n", ((uint32_t *) map)[SVGA_FIFO_MIN]); + + return map; +} + +uint32 +vmw_ioctl_context_create(struct vmw_winsys_screen *vws) +{ + struct drm_vmw_context_arg c_arg; + int ret; + + VMW_FUNC; + + ret = drmCommandRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_CONTEXT, + &c_arg, sizeof(c_arg)); + + if (ret) + return -1; + + vmw_check_last_cmd(vws); + vmw_printf("Context id is %d\n", c_arg.cid); + + return c_arg.cid; +} + +void +vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, uint32 cid) +{ + struct drm_vmw_context_arg c_arg; + + VMW_FUNC; + + memset(&c_arg, 0, sizeof(c_arg)); + c_arg.cid = cid; + + (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_CONTEXT, + &c_arg, sizeof(c_arg)); + + vmw_check_last_cmd(vws); +} + +uint32 +vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32_t numFaces, uint32_t numMipLevels) +{ + union drm_vmw_surface_create_arg s_arg; + struct drm_vmw_surface_create_req *req = &s_arg.req; + struct drm_vmw_surface_arg *rep = &s_arg.rep; + struct drm_vmw_size sizes[DRM_VMW_MAX_SURFACE_FACES* + DRM_VMW_MAX_MIP_LEVELS]; + struct drm_vmw_size *cur_size; + uint32_t iFace; + uint32_t iMipLevel; + int ret; + + vmw_printf("%s flags %d format %d\n", __FUNCTION__, flags, format); + + memset(&s_arg, 0, sizeof(s_arg)); + if (vws->use_old_scanout_flag && + (flags & SVGA3D_SURFACE_HINT_SCANOUT)) { + req->flags = (uint32_t) flags; + req->scanout = false; + } else if (flags & SVGA3D_SURFACE_HINT_SCANOUT) { + req->flags = (uint32_t) (flags & ~SVGA3D_SURFACE_HINT_SCANOUT); + req->scanout = true; + } else { + req->flags = (uint32_t) flags; + req->scanout = false; + } + req->format = (uint32_t) format; + req->shareable = 1; + + assert(numFaces * numMipLevels < DRM_VMW_MAX_SURFACE_FACES* + DRM_VMW_MAX_MIP_LEVELS); + cur_size = sizes; + for (iFace = 0; iFace < numFaces; ++iFace) { + SVGA3dSize mipSize = size; + + req->mip_levels[iFace] = numMipLevels; + for (iMipLevel = 0; iMipLevel < numMipLevels; ++iMipLevel) { + cur_size->width = mipSize.width; + cur_size->height = mipSize.height; + cur_size->depth = mipSize.depth; + mipSize.width = MAX2(mipSize.width >> 1, 1); + mipSize.height = MAX2(mipSize.height >> 1, 1); + mipSize.depth = MAX2(mipSize.depth >> 1, 1); + cur_size++; + } + } + for (iFace = numFaces; iFace < SVGA3D_MAX_SURFACE_FACES; ++iFace) { + req->mip_levels[iFace] = 0; + } + + req->size_addr = (unsigned long)&sizes; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_SURFACE, + &s_arg, sizeof(s_arg)); + + if (ret) + return -1; + + vmw_printf("Surface id is %d\n", rep->sid); + vmw_check_last_cmd(vws); + + return rep->sid; +} + +void +vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, uint32 sid) +{ + struct drm_vmw_surface_arg s_arg; + + VMW_FUNC; + + memset(&s_arg, 0, sizeof(s_arg)); + s_arg.sid = sid; + + (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_SURFACE, + &s_arg, sizeof(s_arg)); + vmw_check_last_cmd(vws); + +} + +void +vmw_ioctl_command(struct vmw_winsys_screen *vws, void *commands, uint32_t size, + uint32_t * pfence) +{ + struct drm_vmw_execbuf_arg arg; + struct drm_vmw_fence_rep rep; + int ret; + +#ifdef DEBUG + { + static boolean firsttime = TRUE; + static boolean debug = FALSE; + static boolean skip = FALSE; + if (firsttime) { + debug = debug_get_bool_option("SVGA_DUMP_CMD", FALSE); + skip = debug_get_bool_option("SVGA_SKIP_CMD", FALSE); + } + if (debug) { + VMW_FUNC; + svga_dump_commands(commands, size); + } + firsttime = FALSE; + if (skip) { + size = 0; + } + } +#endif + + memset(&arg, 0, sizeof(arg)); + memset(&rep, 0, sizeof(rep)); + + rep.error = -EFAULT; + arg.fence_rep = (unsigned long)&rep; + arg.commands = (unsigned long)commands; + arg.command_size = size; + + do { + ret = drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg)); + } while(ret == -ERESTART); + if (ret) { + debug_printf("%s error %s.\n", __FUNCTION__, strerror(-ret)); + } + if (rep.error) { + + /* + * Kernel has synced and put the last fence sequence in the FIFO + * register. + */ + + if (rep.error == -EFAULT) + rep.fence_seq = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + + debug_printf("%s Fence error %s.\n", __FUNCTION__, + strerror(-rep.error)); + } + + vws->ioctl.last_fence = rep.fence_seq; + + if (pfence) + *pfence = rep.fence_seq; + vmw_check_last_cmd(vws); + +} + + +struct vmw_region * +vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size) +{ + struct vmw_region *region; + union drm_vmw_alloc_dmabuf_arg arg; + struct drm_vmw_alloc_dmabuf_req *req = &arg.req; + struct drm_vmw_dmabuf_rep *rep = &arg.rep; + int ret; + + vmw_printf("%s: size = %u\n", __FUNCTION__, size); + + region = CALLOC_STRUCT(vmw_region); + if (!region) + goto out_err1; + + memset(&arg, 0, sizeof(arg)); + req->size = size; + do { + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_ALLOC_DMABUF, &arg, + sizeof(arg)); + } while (ret == -ERESTART); + + if (ret) { + debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); + goto out_err1; + } + + region->ptr.gmrId = rep->cur_gmr_id; + region->ptr.offset = rep->cur_gmr_offset; + region->data = NULL; + region->handle = rep->handle; + region->map_handle = rep->map_handle; + region->map_count = 0; + region->size = size; + region->drm_fd = vws->ioctl.drm_fd; + + vmw_printf(" gmrId = %u, offset = %u\n", + region->ptr.gmrId, region->ptr.offset); + + return region; + + out_err1: + FREE(region); + return NULL; +} + +void +vmw_ioctl_region_destroy(struct vmw_region *region) +{ + struct drm_vmw_unref_dmabuf_arg arg; + + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + + if (region->data) { + munmap(region->data, region->size); + region->data = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = region->handle; + drmCommandWrite(region->drm_fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); + + FREE(region); +} + +SVGAGuestPtr +vmw_ioctl_region_ptr(struct vmw_region *region) +{ + return region->ptr; +} + +void * +vmw_ioctl_region_map(struct vmw_region *region) +{ + void *map; + + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + + if (region->data == NULL) { + map = mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED, + region->drm_fd, region->map_handle); + if (map == MAP_FAILED) { + debug_printf("%s: Map failed.\n", __FUNCTION__); + return NULL; + } + + region->data = map; + } + + ++region->map_count; + + return region->data; +} + +void +vmw_ioctl_region_unmap(struct vmw_region *region) +{ + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + --region->map_count; +} + + +int +vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + uint32_t expected; + uint32_t current; + + assert(fence); + if(!fence) + return 0; + + expected = fence; + current = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + + if ((int32)(current - expected) >= 0) + return 0; /* fence passed */ + else + return -1; +} + + +static void +vmw_ioctl_sync(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + uint32_t cur_fence; + struct drm_vmw_fence_wait_arg arg; + int ret; + + vmw_printf("%s: fence = %lu\n", __FUNCTION__, + (unsigned long)fence); + + cur_fence = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + vmw_printf("%s: Fence id read is 0x%08x\n", __FUNCTION__, + (unsigned int)cur_fence); + + if ((cur_fence - fence) < (1 << 24)) + return; + + memset(&arg, 0, sizeof(arg)); + arg.sequence = fence; + + do { + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FENCE_WAIT, &arg, + sizeof(arg)); + } while (ret == -ERESTART); +} + + +int +vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + assert(fence); + + if(fence) { + if(vmw_ioctl_fence_signalled(vws, fence) != 0) { + vmw_ioctl_sync(vws, fence); + } + } + + return 0; +} + + +boolean +vmw_ioctl_init(struct vmw_winsys_screen *vws) +{ + struct drm_vmw_getparam_arg gp_arg; + int ret; + + VMW_FUNC; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_3D; + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + if (ret || gp_arg.value == 0) { + debug_printf("No 3D enabled (%i, %s)\n", ret, strerror(-ret)); + goto out_err1; + } + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_FIFO_OFFSET; + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + + if (ret) { + debug_printf("GET_PARAM on %d returned %d: %s\n", + vws->ioctl.drm_fd, ret, strerror(-ret)); + goto out_err1; + } + + vmw_printf("Offset to map is 0x%08llx\n", + (unsigned long long)gp_arg.value); + + vws->ioctl.fifo_map = vmw_ioctl_fifo_map(vws, gp_arg.value); + if (vws->ioctl.fifo_map == NULL) + goto out_err1; + + vmw_printf("%s OK\n", __FUNCTION__); + return TRUE; + + out_err1: + debug_printf("%s Failed\n", __FUNCTION__); + return FALSE; +} + + + +void +vmw_ioctl_cleanup(struct vmw_winsys_screen *vws) +{ + VMW_FUNC; + + vmw_ioctl_fifo_unmap(vws, (void *)vws->ioctl.fifo_map); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen_pools.c b/src/gallium/winsys/svga/drm/vmw_screen_pools.c new file mode 100644 index 00000000000..b9823d78575 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_pools.c @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "vmw_screen.h" + +#include "vmw_buffer.h" +#include "vmw_fence.h" + +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +void +vmw_pools_cleanup(struct vmw_winsys_screen *vws) +{ + if(vws->pools.gmr_fenced) + vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced); + + /* gmr_mm pool is already destroyed above */ + + if(vws->pools.gmr) + vws->pools.gmr->destroy(vws->pools.gmr); +} + + +boolean +vmw_pools_init(struct vmw_winsys_screen *vws) +{ + vws->pools.gmr = vmw_gmr_bufmgr_create(vws); + if(!vws->pools.gmr) + goto error; + + vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr, + VMW_GMR_POOL_SIZE, + 12 /* 4096 alignment */); + if(!vws->pools.gmr_mm) + goto error; + + /* + * GMR buffers are typically shortlived, but it's possible that at a given + * instance a buffer is mapped. So to avoid stalling we tell pipebuffer to + * forbid creation of buffers beyond half the GMR pool size, + * + * XXX: It is unclear weather we want to limit the total amount of temporary + * malloc memory used to backup unvalidated GMR buffers. On one hand it is + * preferrable to fail an allocation than exhausting the guest memory with + * temporary data, but on the other hand it is possible that a stupid + * application creates large vertex buffers and does not use them for a long + * time -- since the svga pipe driver only emits the DMA uploads when a + * buffer is used for drawing this would effectively disabling swapping GMR + * buffers to memory. So far, the preemptively flush already seems to keep + * total allocated memory within relatively small numbers, so we don't + * limit. + */ + vws->pools.gmr_fenced = fenced_bufmgr_create( + vws->pools.gmr_mm, + vmw_fence_ops_create(vws), + VMW_GMR_POOL_SIZE/2, + ~0); + +#ifdef DEBUG + vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced, + 4096, + 4096); +#endif + if(!vws->pools.gmr_fenced) + goto error; + + return TRUE; + +error: + vmw_pools_cleanup(vws); + return FALSE; +} + diff --git a/src/gallium/winsys/svga/drm/vmw_screen_svga.c b/src/gallium/winsys/svga/drm/vmw_screen_svga.c new file mode 100644 index 00000000000..2b4e80f0039 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_svga.c @@ -0,0 +1,295 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * This file implements the SVGA interface into this winsys, defined + * in drivers/svga/svga_winsys.h. + * + * @author Keith Whitwell + * @author Jose Fonseca + */ + + +#include "svga_cmd.h" +#include "svga3d_caps.h" + +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" +#include "svga_winsys.h" +#include "vmw_context.h" +#include "vmw_screen.h" +#include "vmw_surface.h" +#include "vmw_buffer.h" +#include "vmw_fence.h" + + +static struct svga_winsys_buffer * +vmw_svga_winsys_buffer_create(struct svga_winsys_screen *sws, + unsigned alignment, + unsigned usage, + unsigned size) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct pb_desc desc; + struct pb_manager *provider; + struct pb_buffer *buffer; + + memset(&desc, 0, sizeof desc); + desc.alignment = alignment; + desc.usage = usage; + + provider = vws->pools.gmr_fenced; + + assert(provider); + buffer = provider->create_buffer(provider, size, &desc); + if(!buffer) + return NULL; + + return vmw_svga_winsys_buffer(buffer); +} + + +static void * +vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf, + unsigned flags) +{ + (void)sws; + return pb_map(vmw_pb_buffer(buf), flags); +} + + +static void +vmw_svga_winsys_buffer_unmap(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf) +{ + (void)sws; + pb_unmap(vmw_pb_buffer(buf)); +} + + +static void +vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf) +{ + struct pb_buffer *pbuf = vmw_pb_buffer(buf); + (void)sws; + pb_reference(&pbuf, NULL); +} + + +static void +vmw_svga_winsys_fence_reference(struct svga_winsys_screen *sws, + struct pipe_fence_handle **pdst, + struct pipe_fence_handle *src) +{ + (void)sws; + *pdst = src; +} + + +static int +vmw_svga_winsys_fence_signalled(struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + (void)flag; + return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); +} + + +static int +vmw_svga_winsys_fence_finish(struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + (void)flag; + return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); +} + + + +static struct svga_winsys_surface * +vmw_svga_winsys_surface_create(struct svga_winsys_screen *sws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32 numFaces, + uint32 numMipLevels) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct vmw_svga_winsys_surface *surface; + + surface = CALLOC_STRUCT(vmw_svga_winsys_surface); + if(!surface) + goto no_surface; + + pipe_reference_init(&surface->refcnt, 1); + p_atomic_set(&surface->validated, 0); + surface->screen = vws; + surface->sid = vmw_ioctl_surface_create(vws, + flags, format, size, + numFaces, numMipLevels); + if(surface->sid == SVGA3D_INVALID_ID) + goto no_sid; + + return svga_winsys_surface(surface); + +no_sid: + FREE(surface); +no_surface: + return NULL; +} + + +static boolean +vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface) +{ + struct vmw_svga_winsys_surface *vsurf = vmw_svga_winsys_surface(surface); + return (p_atomic_read(&vsurf->validated) == 0); +} + + +static void +vmw_svga_winsys_surface_ref(struct svga_winsys_screen *sws, + struct svga_winsys_surface **pDst, + struct svga_winsys_surface *src) +{ + struct vmw_svga_winsys_surface *d_vsurf = vmw_svga_winsys_surface(*pDst); + struct vmw_svga_winsys_surface *s_vsurf = vmw_svga_winsys_surface(src); + + vmw_svga_winsys_surface_reference(&d_vsurf, s_vsurf); + *pDst = svga_winsys_surface(d_vsurf); +} + + +static void +vmw_svga_winsys_destroy(struct svga_winsys_screen *sws) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + + vmw_winsys_destroy(vws); +} + + +static boolean +vmw_svga_winsys_get_cap(struct svga_winsys_screen *sws, + SVGA3dDevCapIndex index, + SVGA3dDevCapResult *result) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + const uint32 *capsBlock; + const SVGA3dCapsRecord *capsRecord = NULL; + uint32 offset; + const SVGA3dCapPair *capArray; + int numCaps, first, last; + + if(!vws->ioctl.fifo_map) + return FALSE; + + if(vws->ioctl.fifo_map[SVGA_FIFO_3D_HWVERSION] < SVGA3D_HWVERSION_WS6_B1) + return FALSE; + + /* + * Search linearly through the caps block records for the specified type. + */ + capsBlock = (const uint32 *)&vws->ioctl.fifo_map[SVGA_FIFO_3D_CAPS]; + for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { + const SVGA3dCapsRecord *record; + assert(offset < SVGA_FIFO_3D_CAPS_SIZE); + record = (const SVGA3dCapsRecord *) (capsBlock + offset); + if ((record->header.type >= SVGA3DCAPS_RECORD_DEVCAPS_MIN) && + (record->header.type <= SVGA3DCAPS_RECORD_DEVCAPS_MAX) && + (!capsRecord || (record->header.type > capsRecord->header.type))) { + capsRecord = record; + } + } + + if(!capsRecord) + return FALSE; + + /* + * Calculate the number of caps from the size of the record. + */ + capArray = (const SVGA3dCapPair *) capsRecord->data; + numCaps = (int) ((capsRecord->header.length * sizeof(uint32) - + sizeof capsRecord->header) / (2 * sizeof(uint32))); + + /* + * Binary-search for the cap with the specified index. + */ + for (first = 0, last = numCaps - 1; first <= last; ) { + int mid = (first + last) / 2; + + if ((SVGA3dDevCapIndex) capArray[mid][0] == index) { + /* + * Found it. + */ + result->u = capArray[mid][1]; + return TRUE; + } + + /* + * Divide and conquer. + */ + if ((SVGA3dDevCapIndex) capArray[mid][0] > index) { + last = mid - 1; + } else { + first = mid + 1; + } + } + + return FALSE; +} + + +boolean +vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws) +{ + vws->base.destroy = vmw_svga_winsys_destroy; + vws->base.get_cap = vmw_svga_winsys_get_cap; + vws->base.context_create = vmw_svga_winsys_context_create; + vws->base.surface_create = vmw_svga_winsys_surface_create; + vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed; + vws->base.surface_reference = vmw_svga_winsys_surface_ref; + vws->base.buffer_create = vmw_svga_winsys_buffer_create; + vws->base.buffer_map = vmw_svga_winsys_buffer_map; + vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap; + vws->base.buffer_destroy = vmw_svga_winsys_buffer_destroy; + vws->base.fence_reference = vmw_svga_winsys_fence_reference; + vws->base.fence_signalled = vmw_svga_winsys_fence_signalled; + vws->base.fence_finish = vmw_svga_winsys_fence_finish; + + return TRUE; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_surface.c b/src/gallium/winsys/svga/drm/vmw_surface.c new file mode 100644 index 00000000000..5f1b9ad5770 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_surface.c @@ -0,0 +1,61 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "svga_cmd.h" +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "vmw_surface.h" +#include "vmw_screen.h" + +void +vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, + struct vmw_svga_winsys_surface *src) +{ + struct pipe_reference *src_ref; + struct pipe_reference *dst_ref; + struct vmw_svga_winsys_surface *dst; + + if(pdst == NULL || *pdst == src) + return; + + dst = *pdst; + + src_ref = src ? &src->refcnt : NULL; + dst_ref = dst ? &dst->refcnt : NULL; + + if (pipe_reference(dst_ref, src_ref)) { + vmw_ioctl_surface_destroy(dst->screen, dst->sid); +#ifdef DEBUG + /* to detect dangling pointers */ + assert(p_atomic_read(&dst->validated) == 0); + dst->sid = SVGA3D_INVALID_ID; +#endif + FREE(dst); + } + + *pdst = src; +} diff --git a/src/gallium/winsys/svga/drm/vmw_surface.h b/src/gallium/winsys/svga/drm/vmw_surface.h new file mode 100644 index 00000000000..3d61595c288 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_surface.h @@ -0,0 +1,79 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + +/** + * @file + * Surfaces for VMware SVGA winsys. + * + * @author Jose Fonseca + */ + + +#ifndef VMW_SURFACE_H_ +#define VMW_SURFACE_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +#define VMW_MAX_PRESENTS 3 + + + +struct vmw_svga_winsys_surface +{ + int32_t validated; /* atomic */ + struct pipe_reference refcnt; + + struct vmw_winsys_screen *screen; + uint32_t sid; + + /* FIXME: make this thread safe */ + unsigned next_present_no; + uint32_t present_fences[VMW_MAX_PRESENTS]; +}; + + +static INLINE struct svga_winsys_surface * +svga_winsys_surface(struct vmw_svga_winsys_surface *surf) +{ + assert(!surf || surf->sid != SVGA3D_INVALID_ID); + return (struct svga_winsys_surface *)surf; +} + + +static INLINE struct vmw_svga_winsys_surface * +vmw_svga_winsys_surface(struct svga_winsys_surface *surf) +{ + return (struct vmw_svga_winsys_surface *)surf; +} + + +void +vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, + struct vmw_svga_winsys_surface *src); + +#endif /* VMW_SURFACE_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmwgfx_drm.h b/src/gallium/winsys/svga/drm/vmwgfx_drm.h new file mode 100644 index 00000000000..47914bdb711 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmwgfx_drm.h @@ -0,0 +1,545 @@ +/************************************************************************** + * + * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA + * 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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 __VMWGFX_DRM_H__ +#define __VMWGFX_DRM_H__ + +#define DRM_VMW_MAX_SURFACE_FACES 6 +#define DRM_VMW_MAX_MIP_LEVELS 24 + +#define DRM_VMW_EXT_NAME_LEN 128 + +#define DRM_VMW_GET_PARAM 0 +#define DRM_VMW_ALLOC_DMABUF 1 +#define DRM_VMW_UNREF_DMABUF 2 +#define DRM_VMW_CURSOR_BYPASS 3 +/* guarded by DRM_VMW_PARAM_NUM_STREAMS != 0*/ +#define DRM_VMW_CONTROL_STREAM 4 +#define DRM_VMW_CLAIM_STREAM 5 +#define DRM_VMW_UNREF_STREAM 6 +/* guarded by DRM_VMW_PARAM_3D == 1 */ +#define DRM_VMW_CREATE_CONTEXT 7 +#define DRM_VMW_UNREF_CONTEXT 8 +#define DRM_VMW_CREATE_SURFACE 9 +#define DRM_VMW_UNREF_SURFACE 10 +#define DRM_VMW_REF_SURFACE 11 +#define DRM_VMW_EXECBUF 12 +#define DRM_VMW_FIFO_DEBUG 13 +#define DRM_VMW_FENCE_WAIT 14 + + +/*************************************************************************/ +/** + * DRM_VMW_GET_PARAM - get device information. + * + * DRM_VMW_PARAM_FIFO_OFFSET: + * Offset to use to map the first page of the FIFO read-only. + * The fifo is mapped using the mmap() system call on the drm device. + * + * DRM_VMW_PARAM_OVERLAY_IOCTL: + * Does the driver support the overlay ioctl. + */ + +#define DRM_VMW_PARAM_NUM_STREAMS 0 +#define DRM_VMW_PARAM_NUM_FREE_STREAMS 1 +#define DRM_VMW_PARAM_3D 2 +#define DRM_VMW_PARAM_FIFO_OFFSET 3 +#define DRM_VMW_PARAM_HW_CAPS 4 +#define DRM_VMW_PARAM_FIFO_CAPS 5 + +/** + * struct drm_vmw_getparam_arg + * + * @value: Returned value. //Out + * @param: Parameter to query. //In. + * + * Argument to the DRM_VMW_GET_PARAM Ioctl. + */ + +struct drm_vmw_getparam_arg { + uint64_t value; + uint32_t param; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CREATE_CONTEXT - Create a host context. + * + * Allocates a device unique context id, and queues a create context command + * for the host. Does not wait for host completion. + */ + +/** + * struct drm_vmw_context_arg + * + * @cid: Device unique context ID. + * + * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. + * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. + */ + +struct drm_vmw_context_arg { + int32_t cid; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_CONTEXT - Create a host context. + * + * Frees a global context id, and queues a destroy host command for the host. + * Does not wait for host completion. The context ID can be used directly + * in the command stream and shows up as the same context ID on the host. + */ + +/*************************************************************************/ +/** + * DRM_VMW_CREATE_SURFACE - Create a host suface. + * + * Allocates a device unique surface id, and queues a create surface command + * for the host. Does not wait for host completion. The surface ID can be + * used directly in the command stream and shows up as the same surface + * ID on the host. + */ + +/** + * struct drm_wmv_surface_create_req + * + * @flags: Surface flags as understood by the host. + * @format: Surface format as understood by the host. + * @mip_levels: Number of mip levels for each face. + * An unused face should have 0 encoded. + * @size_addr: Address of a user-space array of sruct drm_vmw_size + * cast to an uint64_t for 32-64 bit compatibility. + * The size of the array should equal the total number of mipmap levels. + * @shareable: Boolean whether other clients (as identified by file descriptors) + * may reference this surface. + * @scanout: Boolean whether the surface is intended to be used as a + * scanout. + * + * Input data to the DRM_VMW_CREATE_SURFACE Ioctl. + * Output data from the DRM_VMW_REF_SURFACE Ioctl. + */ + +struct drm_vmw_surface_create_req { + uint32_t flags; + uint32_t format; + uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; + uint64_t size_addr; + int32_t shareable; + int32_t scanout; +}; + +/** + * struct drm_wmv_surface_arg + * + * @sid: Surface id of created surface or surface to destroy or reference. + * + * Output data from the DRM_VMW_CREATE_SURFACE Ioctl. + * Input argument to the DRM_VMW_UNREF_SURFACE Ioctl. + * Input argument to the DRM_VMW_REF_SURFACE Ioctl. + */ + +struct drm_vmw_surface_arg { + int32_t sid; + uint32_t pad64; +}; + +/** + * struct drm_vmw_size ioctl. + * + * @width - mip level width + * @height - mip level height + * @depth - mip level depth + * + * Description of a mip level. + * Input data to the DRM_WMW_CREATE_SURFACE Ioctl. + */ + +struct drm_vmw_size { + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t pad64; +}; + +/** + * union drm_vmw_surface_create_arg + * + * @rep: Output data as described above. + * @req: Input data as described above. + * + * Argument to the DRM_VMW_CREATE_SURFACE Ioctl. + */ + +union drm_vmw_surface_create_arg { + struct drm_vmw_surface_arg rep; + struct drm_vmw_surface_create_req req; +}; + +/*************************************************************************/ +/** + * DRM_VMW_REF_SURFACE - Reference a host surface. + * + * Puts a reference on a host surface with a give sid, as previously + * returned by the DRM_VMW_CREATE_SURFACE ioctl. + * A reference will make sure the surface isn't destroyed while we hold + * it and will allow the calling client to use the surface ID in the command + * stream. + * + * On successful return, the Ioctl returns the surface information given + * in the DRM_VMW_CREATE_SURFACE ioctl. + */ + +/** + * union drm_vmw_surface_reference_arg + * + * @rep: Output data as described above. + * @req: Input data as described above. + * + * Argument to the DRM_VMW_REF_SURFACE Ioctl. + */ + +union drm_vmw_surface_reference_arg { + struct drm_vmw_surface_create_req rep; + struct drm_vmw_surface_arg req; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_SURFACE - Unreference a host surface. + * + * Clear a reference previously put on a host surface. + * When all references are gone, including the one implicitly placed + * on creation, + * a destroy surface command will be queued for the host. + * Does not wait for completion. + */ + +/*************************************************************************/ +/** + * DRM_VMW_EXECBUF + * + * Submit a command buffer for execution on the host, and return a + * fence sequence that when signaled, indicates that the command buffer has + * executed. + */ + +/** + * struct drm_vmw_execbuf_arg + * + * @commands: User-space address of a command buffer cast to an uint64_t. + * @command-size: Size in bytes of the command buffer. + * @throttle-us: Sleep until software is less than @throttle_us + * microseconds ahead of hardware. The driver may round this value + * to the nearest kernel tick. + * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an + * uint64_t. + * @version: Allows expanding the execbuf ioctl parameters without breaking + * backwards compatibility, since user-space will always tell the kernel + * which version it uses. + * @flags: Execbuf flags. None currently. + * + * Argument to the DRM_VMW_EXECBUF Ioctl. + */ + +#define DRM_VMW_EXECBUF_VERSION 0 + +struct drm_vmw_execbuf_arg { + uint64_t commands; + uint32_t command_size; + uint32_t throttle_us; + uint64_t fence_rep; + uint32_t version; + uint32_t flags; +}; + +/** + * struct drm_vmw_fence_rep + * + * @fence_seq: Fence sequence associated with a command submission. + * @error: This member should've been set to -EFAULT on submission. + * The following actions should be take on completion: + * error == -EFAULT: Fence communication failed. The host is synchronized. + * Use the last fence id read from the FIFO fence register. + * error != 0 && error != -EFAULT: + * Fence submission failed. The host is synchronized. Use the fence_seq member. + * error == 0: All is OK, The host may not be synchronized. + * Use the fence_seq member. + * + * Input / Output data to the DRM_VMW_EXECBUF Ioctl. + */ + +struct drm_vmw_fence_rep { + uint64_t fence_seq; + int32_t error; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_ALLOC_DMABUF + * + * Allocate a DMA buffer that is visible also to the host. + * NOTE: The buffer is + * identified by a handle and an offset, which are private to the guest, but + * useable in the command stream. The guest kernel may translate these + * and patch up the command stream accordingly. In the future, the offset may + * be zero at all times, or it may disappear from the interface before it is + * fixed. + * + * The DMA buffer may stay user-space mapped in the guest at all times, + * and is thus suitable for sub-allocation. + * + * DMA buffers are mapped using the mmap() syscall on the drm device. + */ + +/** + * struct drm_vmw_alloc_dmabuf_req + * + * @size: Required minimum size of the buffer. + * + * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +struct drm_vmw_alloc_dmabuf_req { + uint32_t size; + uint32_t pad64; +}; + +/** + * struct drm_vmw_dmabuf_rep + * + * @map_handle: Offset to use in the mmap() call used to map the buffer. + * @handle: Handle unique to this buffer. Used for unreferencing. + * @cur_gmr_id: GMR id to use in the command stream when this buffer is + * referenced. See not above. + * @cur_gmr_offset: Offset to use in the command stream when this buffer is + * referenced. See note above. + * + * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +struct drm_vmw_dmabuf_rep { + uint64_t map_handle; + uint32_t handle; + uint32_t cur_gmr_id; + uint32_t cur_gmr_offset; + uint32_t pad64; +}; + +/** + * union drm_vmw_dmabuf_arg + * + * @req: Input data as described above. + * @rep: Output data as described above. + * + * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +union drm_vmw_alloc_dmabuf_arg { + struct drm_vmw_alloc_dmabuf_req req; + struct drm_vmw_dmabuf_rep rep; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_DMABUF - Free a DMA buffer. + * + */ + +/** + * struct drm_vmw_unref_dmabuf_arg + * + * @handle: Handle indicating what buffer to free. Obtained from the + * DRM_VMW_ALLOC_DMABUF Ioctl. + * + * Argument to the DRM_VMW_UNREF_DMABUF Ioctl. + */ + +struct drm_vmw_unref_dmabuf_arg { + uint32_t handle; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_FIFO_DEBUG - Get last FIFO submission. + * + * This IOCTL copies the last FIFO submission directly out of the FIFO buffer. + */ + +/** + * struct drm_vmw_fifo_debug_arg + * + * @debug_buffer: User space address of a debug_buffer cast to an uint64_t //In + * @debug_buffer_size: Size in bytes of debug buffer //In + * @used_size: Number of bytes copied to the buffer // Out + * @did_not_fit: Boolean indicating that the fifo contents did not fit. //Out + * + * Argument to the DRM_VMW_FIFO_DEBUG Ioctl. + */ + +struct drm_vmw_fifo_debug_arg { + uint64_t debug_buffer; + uint32_t debug_buffer_size; + uint32_t used_size; + int32_t did_not_fit; + uint32_t pad64; +}; + +struct drm_vmw_fence_wait_arg { + uint64_t sequence; + uint64_t kernel_cookie; + int32_t cookie_valid; + int32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CONTROL_STREAM - Control overlays, aka streams. + * + * This IOCTL controls the overlay units of the svga device. + * The SVGA overlay units does not work like regular hardware units in + * that they do not automaticaly read back the contents of the given dma + * buffer. But instead only read back for each call to this ioctl, and + * at any point between this call being made and a following call that + * either changes the buffer or disables the stream. + */ + +/** + * struct drm_vmw_rect + * + * Defines a rectangle. Used in the overlay ioctl to define + * source and destination rectangle. + */ + +struct drm_vmw_rect { + int32_t x; + int32_t y; + uint32_t w; + uint32_t h; +}; + +/** + * struct drm_vmw_control_stream_arg + * + * @stream_id: Stearm to control + * @enabled: If false all following arguments are ignored. + * @handle: Handle to buffer for getting data from. + * @format: Format of the overlay as understood by the host. + * @width: Width of the overlay. + * @height: Height of the overlay. + * @size: Size of the overlay in bytes. + * @pitch: Array of pitches, the two last are only used for YUV12 formats. + * @offset: Offset from start of dma buffer to overlay. + * @src: Source rect, must be within the defined area above. + * @dst: Destination rect, x and y may be negative. + * + * Argument to the DRM_VMW_CONTROL_STREAM Ioctl. + */ + +struct drm_vmw_control_stream_arg { + uint32_t stream_id; + uint32_t enabled; + + uint32_t flags; + uint32_t color_key; + + uint32_t handle; + uint32_t offset; + int32_t format; + uint32_t size; + uint32_t width; + uint32_t height; + uint32_t pitch[3]; + + uint32_t pad64; + struct drm_vmw_rect src; + struct drm_vmw_rect dst; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CURSOR_BYPASS - Give extra information about cursor bypass. + * + */ + +#define DRM_VMW_CURSOR_BYPASS_ALL (1 << 0) +#define DRM_VMW_CURSOR_BYPASS_FLAGS (1) + +/** + * struct drm_vmw_cursor_bypass_arg + * + * @flags: Flags. + * @crtc_id: Crtc id, only used if DMR_CURSOR_BYPASS_ALL isn't passed. + * @xpos: X position of cursor. + * @ypos: Y position of cursor. + * @xhot: X hotspot. + * @yhot: Y hotspot. + * + * Argument to the DRM_VMW_CURSOR_BYPASS Ioctl. + */ + +struct drm_vmw_cursor_bypass_arg { + uint32_t flags; + uint32_t crtc_id; + int32_t xpos; + int32_t ypos; + int32_t xhot; + int32_t yhot; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CLAIM_STREAM - Claim a single stream. + */ + +/** + * struct drm_vmw_context_arg + * + * @stream_id: Device unique context ID. + * + * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. + * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. + */ + +struct drm_vmw_stream_arg { + uint32_t stream_id; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_STREAM - Unclaim a stream. + * + * Return a single stream that was claimed by this process. Also makes + * sure that the stream has been stopped. + */ + +#endif diff --git a/src/gallium/winsys/sw/Makefile b/src/gallium/winsys/sw/Makefile new file mode 100644 index 00000000000..e9182ea5b1b --- /dev/null +++ b/src/gallium/winsys/sw/Makefile @@ -0,0 +1,12 @@ +# src/gallium/winsys/sw/Makefile +TOP = ../../../.. +include $(TOP)/configs/current + +SUBDIRS = null wrapper + +default install clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1; \ + fi \ + done diff --git a/src/gallium/winsys/sw/drm/Makefile b/src/gallium/winsys/sw/drm/Makefile new file mode 100644 index 00000000000..79664536aa0 --- /dev/null +++ b/src/gallium/winsys/sw/drm/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = swdrm + +C_SOURCES = sw_drm_api.c + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/drm/sw_drm_api.c b/src/gallium/winsys/sw/drm/sw_drm_api.c new file mode 100644 index 00000000000..eb81d26a593 --- /dev/null +++ b/src/gallium/winsys/sw/drm/sw_drm_api.c @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "util/u_memory.h" +#include "softpipe/sp_public.h" +#include "state_tracker/drm_api.h" +#include "../../sw/wrapper/wrapper_sw_winsys.h" +#include "sw_drm_api.h" + + +/* + * Defines + */ + + +struct sw_drm_api +{ + struct drm_api base; + struct drm_api *api; + struct sw_winsys *sw; +}; + +static INLINE struct sw_drm_api * +sw_drm_api(struct drm_api *api) +{ + return (struct sw_drm_api *)api; +} + + +/* + * Exported functions + */ + + +static struct pipe_screen * +sw_drm_create_screen(struct drm_api *_api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct sw_drm_api *swapi = sw_drm_api(_api); + struct drm_api *api = swapi->api; + struct sw_winsys *sww; + struct pipe_screen *screen; + + screen = api->create_screen(api, drmFD, arg); + + sww = wrapper_sw_winsys_warp_pipe_screen(screen); + + return softpipe_create_screen(sww); +} + +static void +sw_drm_destroy(struct drm_api *api) +{ + struct sw_drm_api *swapi = sw_drm_api(api); + if (swapi->api->destroy) + swapi->api->destroy(swapi->api); + + FREE(swapi); +} + +struct drm_api * +sw_drm_api_create(struct drm_api *api) +{ + struct sw_drm_api *swapi = CALLOC_STRUCT(sw_drm_api); + + swapi->base.name = "sw"; + swapi->base.driver_name = api->driver_name; + swapi->base.create_screen = sw_drm_create_screen; + swapi->base.destroy = sw_drm_destroy; + + swapi->api = api; + + return &swapi->base; +} diff --git a/src/gallium/winsys/sw/drm/sw_drm_api.h b/src/gallium/winsys/sw/drm/sw_drm_api.h new file mode 100644 index 00000000000..ce90a04ae0c --- /dev/null +++ b/src/gallium/winsys/sw/drm/sw_drm_api.h @@ -0,0 +1,34 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#ifndef SW_DRM_API_H +#define SW_DRM_API_H + +struct drm_api; + +struct drm_api * sw_drm_api_create(struct drm_api *api); + +#endif diff --git a/src/gallium/winsys/sw/gdi/SConscript b/src/gallium/winsys/sw/gdi/SConscript new file mode 100644 index 00000000000..1267fc6eea4 --- /dev/null +++ b/src/gallium/winsys/sw/gdi/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] == 'windows': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_gdi = env.ConvenienceLibrary( + target = 'ws_gdi', + source = [ + 'gdi_sw_winsys.c', + ] + ) + Export('ws_gdi') diff --git a/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c new file mode 100644 index 00000000000..4dba4b577b8 --- /dev/null +++ b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c @@ -0,0 +1,247 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/** + * @file + * GDI software rasterizer support. + * + * @author Jose Fonseca + */ + + +#include + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "state_tracker/sw_winsys.h" +#include "gdi_sw_winsys.h" + + +struct gdi_sw_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + unsigned size; + + void *data; + + BITMAPINFO bmi; +}; + + +/** Cast wrapper */ +static INLINE struct gdi_sw_displaytarget * +gdi_sw_displaytarget( struct sw_displaytarget *buf ) +{ + return (struct gdi_sw_displaytarget *)buf; +} + + +static boolean +gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + switch(format) { + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + return TRUE; + + /* TODO: Support other formats possible with BMPs, as described in + * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */ + + default: + return FALSE; + } +} + + +static void * +gdi_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags ) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + return gdt->data; +} + + +static void +gdi_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt ) +{ + +} + + +static void +gdi_sw_displaytarget_destroy(struct sw_winsys *winsys, + struct sw_displaytarget *dt) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + align_free(gdt->data); + FREE(gdt); +} + + +static struct sw_displaytarget * +gdi_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct gdi_sw_displaytarget *gdt; + unsigned cpp; + unsigned bpp; + + gdt = CALLOC_STRUCT(gdi_sw_displaytarget); + if(!gdt) + goto no_gdt; + + gdt->format = format; + gdt->width = width; + gdt->height = height; + + bpp = util_format_get_blocksizebits(format); + cpp = util_format_get_blocksize(format); + + gdt->stride = align(width * cpp, alignment); + gdt->size = gdt->stride * height; + + gdt->data = align_malloc(gdt->size, alignment); + if(!gdt->data) + goto no_data; + + gdt->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + gdt->bmi.bmiHeader.biWidth = gdt->stride / cpp; + gdt->bmi.bmiHeader.biHeight= -(long)height; + gdt->bmi.bmiHeader.biPlanes = 1; + gdt->bmi.bmiHeader.biBitCount = bpp; + gdt->bmi.bmiHeader.biCompression = BI_RGB; + gdt->bmi.bmiHeader.biSizeImage = 0; + gdt->bmi.bmiHeader.biXPelsPerMeter = 0; + gdt->bmi.bmiHeader.biYPelsPerMeter = 0; + gdt->bmi.bmiHeader.biClrUsed = 0; + gdt->bmi.bmiHeader.biClrImportant = 0; + + *stride = gdt->stride; + return (struct sw_displaytarget *)gdt; + +no_data: + FREE(gdt); +no_gdt: + return NULL; +} + + +static struct sw_displaytarget * +gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +void +gdi_sw_display( struct sw_winsys *winsys, + struct sw_displaytarget *dt, + HDC hDC ) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + StretchDIBits(hDC, + 0, 0, gdt->width, gdt->height, + 0, 0, gdt->width, gdt->height, + gdt->data, &gdt->bmi, 0, SRCCOPY); +} + +static void +gdi_sw_displaytarget_display(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + void *context_private) +{ + /* nasty: + */ + HDC hDC = (HDC)context_private; + + gdi_sw_display(winsys, dt, hDC); +} + + +static void +gdi_sw_destroy(struct sw_winsys *winsys) +{ + FREE(winsys); +} + +struct sw_winsys * +gdi_create_sw_winsys(void) +{ + static struct sw_winsys *winsys; + + winsys = CALLOC_STRUCT(sw_winsys); + if(!winsys) + return NULL; + + winsys->destroy = gdi_sw_destroy; + winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported; + winsys->displaytarget_create = gdi_sw_displaytarget_create; + winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle; + winsys->displaytarget_map = gdi_sw_displaytarget_map; + winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap; + winsys->displaytarget_display = gdi_sw_displaytarget_display; + winsys->displaytarget_destroy = gdi_sw_displaytarget_destroy; + + return winsys; +} + diff --git a/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h new file mode 100644 index 00000000000..4bbcb47848b --- /dev/null +++ b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h @@ -0,0 +1,16 @@ +#ifndef GDI_SW_WINSYS_H +#define GDI_SW_WINSYS_H + +#include + +#include "pipe/p_compiler.h" +#include "state_tracker/sw_winsys.h" + +void gdi_sw_display( struct sw_winsys *winsys, + struct sw_displaytarget *dt, + HDC hDC ); + +struct sw_winsys * +gdi_create_sw_winsys(void); + +#endif diff --git a/src/gallium/winsys/sw/null/Makefile b/src/gallium/winsys/sw/null/Makefile new file mode 100644 index 00000000000..b1882b582e9 --- /dev/null +++ b/src/gallium/winsys/sw/null/Makefile @@ -0,0 +1,16 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = ws_null + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary + +C_SOURCES = \ + null_sw_winsys.c + +include ../../../Makefile.template + + diff --git a/src/gallium/winsys/sw/null/SConscript b/src/gallium/winsys/sw/null/SConscript new file mode 100644 index 00000000000..21837dc60c2 --- /dev/null +++ b/src/gallium/winsys/sw/null/SConscript @@ -0,0 +1,21 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', +]) + +ws_null = env.ConvenienceLibrary( + target = 'ws_null', + source = [ + 'null_sw_winsys.c', + ] +) +Export('ws_null') diff --git a/src/gallium/winsys/sw/null/null_sw_winsys.c b/src/gallium/winsys/sw/null/null_sw_winsys.c new file mode 100644 index 00000000000..5027e57b303 --- /dev/null +++ b/src/gallium/winsys/sw/null/null_sw_winsys.c @@ -0,0 +1,148 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +/** + * @file + * Null software rasterizer winsys. + * + * There is no present support. Framebuffer data needs to be obtained via + * transfers. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "state_tracker/sw_winsys.h" +#include "null_sw_winsys.h" + + +static boolean +null_sw_is_displaytarget_format_supported(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + return FALSE; +} + + +static void * +null_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags ) +{ + assert(0); + return NULL; +} + + +static void +null_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt ) +{ + assert(0); +} + + +static void +null_sw_displaytarget_destroy(struct sw_winsys *winsys, + struct sw_displaytarget *dt) +{ + assert(0); +} + + +static struct sw_displaytarget * +null_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + return NULL; +} + + +static struct sw_displaytarget * +null_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + return NULL; +} + + +static boolean +null_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +static void +null_sw_displaytarget_display(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + void *context_private) +{ + assert(0); +} + + +static void +null_sw_destroy(struct sw_winsys *winsys) +{ + FREE(winsys); +} + + +struct sw_winsys * +null_sw_create(void) +{ + static struct sw_winsys *winsys; + + winsys = CALLOC_STRUCT(sw_winsys); + if (!winsys) + return NULL; + + winsys->destroy = null_sw_destroy; + winsys->is_displaytarget_format_supported = null_sw_is_displaytarget_format_supported; + winsys->displaytarget_create = null_sw_displaytarget_create; + winsys->displaytarget_from_handle = null_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = null_sw_displaytarget_get_handle; + winsys->displaytarget_map = null_sw_displaytarget_map; + winsys->displaytarget_unmap = null_sw_displaytarget_unmap; + winsys->displaytarget_display = null_sw_displaytarget_display; + winsys->displaytarget_destroy = null_sw_displaytarget_destroy; + + return winsys; +} diff --git a/src/gallium/winsys/sw/null/null_sw_winsys.h b/src/gallium/winsys/sw/null/null_sw_winsys.h new file mode 100644 index 00000000000..1986186febe --- /dev/null +++ b/src/gallium/winsys/sw/null/null_sw_winsys.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef NULL_SW_WINSYS_H_ +#define NULL_SW_WINSYS_H_ + + +struct sw_winsys; + + +struct sw_winsys * +null_sw_create(void); + + +#endif /* NULL_SW_WINSYS_H_ */ diff --git a/src/gallium/winsys/sw/wrapper/Makefile b/src/gallium/winsys/sw/wrapper/Makefile new file mode 100644 index 00000000000..4771fbcf700 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = wsw + +C_SOURCES = wrapper_sw_winsys.c + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c new file mode 100644 index 00000000000..459b1c1e2a3 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c @@ -0,0 +1,282 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#include "wrapper_sw_winsys.h" + +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#include "state_tracker/sw_winsys.h" + +#include "util/u_memory.h" +#include "util/u_inlines.h" + +/* + * This code wraps a pipe_screen and exposes a sw_winsys interface for use + * with software resterizers. This code is used by the DRM based winsys to + * allow access to the drm driver. + * + * We must borrow the whole stack because only the pipe screen knows how + * to decode the content of a buffer. Or how to create a buffer that + * can still be used by drivers using real hardware (as the case is + * with software st/xorg but hw st/dri). + * + * We also need a pipe context for the transfers. + */ + +struct wrapper_sw_winsys +{ + struct sw_winsys base; + struct pipe_screen *screen; + struct pipe_context *pipe; +}; + +struct wrapper_sw_displaytarget +{ + struct wrapper_sw_winsys *winsys; + struct pipe_texture *tex; + struct pipe_transfer *transfer; + + unsigned width; + unsigned height; + unsigned map_count; + unsigned stride; /**< because we give stride at create */ + void *ptr; +}; + +static INLINE struct wrapper_sw_winsys * +wrapper_sw_winsys(struct sw_winsys *ws) +{ + return (struct wrapper_sw_winsys *)ws; +} + +static INLINE struct wrapper_sw_displaytarget * +wrapper_sw_displaytarget(struct sw_displaytarget *dt) +{ + return (struct wrapper_sw_displaytarget *)dt; +} + + +/* + * Functions + */ + + +static boolean +wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride) +{ + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return FALSE; + + *stride = tr->stride; + wdt->stride = tr->stride; + + pipe->tex_transfer_destroy(pipe, tr); + + return TRUE; +} + +static struct sw_displaytarget * +wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, + struct pipe_texture *tex, unsigned *stride) +{ + struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget); + if (!wdt) + goto err_unref; + + wdt->tex = tex; + wdt->winsys = wsw; + + if (!wsw_dt_get_stride(wdt, stride)) + goto err_free; + + return (struct sw_displaytarget *)wdt; + +err_free: + FREE(wdt); +err_unref: + pipe_texture_reference(&tex, NULL); + return NULL; +} + +static struct sw_displaytarget * +wsw_dt_create(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture templ; + struct pipe_texture *tex; + + /* + * XXX Why don't we just get the template. + */ + memset(&templ, 0, sizeof(templ)); + templ.width0 = width; + templ.height0 = height; + templ.format = format; + templ.tex_usage = tex_usage; + + /* XXX alignment: we can't do anything about this */ + + tex = wsw->screen->texture_create(wsw->screen, &templ); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static struct sw_displaytarget * +wsw_dt_from_handle(struct sw_winsys *ws, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture *tex; + + tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static void * +wsw_dt_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + void *ptr; + + if (!wdt->map_count) { + + assert(!wdt->transfer); + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return NULL; + + ptr = pipe->transfer_map(pipe, tr); + if (!ptr) + goto err; + + wdt->transfer = tr; + wdt->ptr = ptr; + + /* XXX Handle this case */ + assert(tr->stride == wdt->stride); + } + + wdt->map_count++; + + return wdt->ptr; + +err: + pipe->tex_transfer_destroy(pipe, tr); + return NULL; +} + +static void +wsw_dt_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + + assert(wdt->transfer); + + wdt->map_count--; + + if (wdt->map_count) + return; + + pipe->transfer_unmap(pipe, wdt->transfer); + pipe->tex_transfer_destroy(pipe, wdt->transfer); + wdt->transfer = NULL; +} + +static void +wsw_dt_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + + pipe_texture_reference(&wdt->tex, NULL); + + FREE(wdt); +} + +static void +wsw_destroy(struct sw_winsys *ws) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + + wsw->pipe->destroy(wsw->pipe); + wsw->screen->destroy(wsw->screen); + + FREE(wsw); +} + +struct sw_winsys * +wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen) +{ + struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); + + wsw->base.displaytarget_create = wsw_dt_create; + wsw->base.displaytarget_from_handle = wsw_dt_from_handle; + wsw->base.displaytarget_map = wsw_dt_map; + wsw->base.displaytarget_unmap = wsw_dt_unmap; + wsw->base.displaytarget_destroy = wsw_dt_destroy; + wsw->base.destroy = wsw_destroy; + + wsw->screen = screen; + wsw->pipe = screen->context_create(screen, NULL); + if (!wsw->pipe) + goto err; + + return &wsw->base; + +err: + FREE(wsw); + return NULL; +} diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h new file mode 100644 index 00000000000..b5c25a3c50f --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h @@ -0,0 +1,35 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, 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. + * + **********************************************************/ + + +#ifndef WRAPPER_SW_WINSYS +#define WRAPPER_SW_WINSYS + +struct sw_winsys; +struct pipe_screen; + +struct sw_winsys *wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/winsys/sw/xlib/Makefile b/src/gallium/winsys/sw/xlib/Makefile new file mode 100644 index 00000000000..c6693899281 --- /dev/null +++ b/src/gallium/winsys/sw/xlib/Makefile @@ -0,0 +1,17 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = ws_xlib + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + $(X11_CFLAGS) + +C_SOURCES = \ + xlib_sw_winsys.c + +include ../../../Makefile.template + + diff --git a/src/gallium/winsys/sw/xlib/SConscript b/src/gallium/winsys/sw/xlib/SConscript new file mode 100644 index 00000000000..2af6153b4c7 --- /dev/null +++ b/src/gallium/winsys/sw/xlib/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_xlib = env.ConvenienceLibrary( + target = 'ws_xlib', + source = [ + 'xlib_sw_winsys.c', + ] + ) + Export('ws_xlib') diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c new file mode 100644 index 00000000000..54789d7a87c --- /dev/null +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c @@ -0,0 +1,464 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA + * 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 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "state_tracker/xlib_sw_winsys.h" + +#include +#include +#include +#include +#include +#include + +/** + * Subclass of pipe_buffer for Xlib winsys. + * Low-level OS/window system memory buffer + */ +struct xm_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + void *data; + void *mapped; + + Display *display; + Visual *visual; + XImage *tempImage; + GC gc; + + /* This is the last drawable that this display target was presented + * against. May need to recreate gc, tempImage when this changes?? + */ + Drawable drawable; + + XShmSegmentInfo shminfo; + int shm; +}; + + +/** + * Subclass of sw_winsys for Xlib winsys + */ +struct xlib_sw_winsys +{ + struct sw_winsys base; + + + + Display *display; +}; + + + +/** Cast wrapper */ +static INLINE struct xm_displaytarget * +xm_displaytarget( struct sw_displaytarget *dt ) +{ + return (struct xm_displaytarget *)dt; +} + + +/** + * X Shared Memory Image extension code + */ + +static volatile int mesaXErrorFlag = 0; + +/** + * Catches potential Xlib errors. + */ +static int +mesaHandleXError(Display *dpy, XErrorEvent *event) +{ + (void) dpy; + (void) event; + mesaXErrorFlag = 1; + return 0; +} + + +static char *alloc_shm(struct xm_displaytarget *buf, unsigned size) +{ + XShmSegmentInfo *const shminfo = & buf->shminfo; + + shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777); + if (shminfo->shmid < 0) { + return NULL; + } + + shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0); + if (shminfo->shmaddr == (char *) -1) { + shmctl(shminfo->shmid, IPC_RMID, 0); + return NULL; + } + + shminfo->readOnly = False; + return shminfo->shmaddr; +} + + +/** + * Allocate a shared memory XImage back buffer for the given XMesaBuffer. + */ +static void +alloc_shm_ximage(struct xm_displaytarget *xm_dt, + struct xlib_drawable *xmb, + unsigned width, unsigned height) +{ + /* + * We have to do a _lot_ of error checking here to be sure we can + * really use the XSHM extension. It seems different servers trigger + * errors at different points if the extension won't work. Therefore + * we have to be very careful... + */ + int (*old_handler)(Display *, XErrorEvent *); + + xm_dt->tempImage = XShmCreateImage(xm_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, + NULL, + &xm_dt->shminfo, + width, height); + if (xm_dt->tempImage == NULL) { + xm_dt->shm = 0; + return; + } + + + mesaXErrorFlag = 0; + old_handler = XSetErrorHandler(mesaHandleXError); + /* This may trigger the X protocol error we're ready to catch: */ + XShmAttach(xm_dt->display, &xm_dt->shminfo); + XSync(xm_dt->display, False); + + if (mesaXErrorFlag) { + /* we are on a remote display, this error is normal, don't print it */ + XFlush(xm_dt->display); + mesaXErrorFlag = 0; + XDestroyImage(xm_dt->tempImage); + xm_dt->tempImage = NULL; + xm_dt->shm = 0; + (void) XSetErrorHandler(old_handler); + return; + } + + xm_dt->shm = 1; +} + + +static void +alloc_ximage(struct xm_displaytarget *xm_dt, + struct xlib_drawable *xmb, + unsigned width, unsigned height) +{ + if (xm_dt->shm) { + alloc_shm_ximage(xm_dt, xmb, width, height); + return; + } + + xm_dt->tempImage = XCreateImage(xm_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, 0, + NULL, width, height, + 8, 0); +} + +static boolean +xm_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + /* TODO: check visuals or other sensible thing here */ + return TRUE; +} + + +static void * +xm_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = xm_dt->data; + return xm_dt->mapped; +} + +static void +xm_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = NULL; +} + +static void +xm_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + + if (xm_dt->data) { + if (xm_dt->shminfo.shmid >= 0) { + shmdt(xm_dt->shminfo.shmaddr); + shmctl(xm_dt->shminfo.shmid, IPC_RMID, 0); + + xm_dt->shminfo.shmid = -1; + xm_dt->shminfo.shmaddr = (char *) -1; + } + else { + FREE(xm_dt->data); + } + } + + if (xm_dt->tempImage) + XDestroyImage(xm_dt->tempImage); + + if (xm_dt->gc) + XFreeGC(xm_dt->display, xm_dt->gc); + + FREE(xm_dt); +} + + +/** + * Display/copy the image in the surface into the X window specified + * by the XMesaBuffer. + */ +static void +xlib_sw_display(struct xlib_drawable *xlib_drawable, + struct sw_displaytarget *dt) +{ + static boolean no_swap = 0; + static boolean firsttime = 1; + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + Display *display = xm_dt->display; + XImage *ximage; + + if (firsttime) { + no_swap = getenv("SP_NO_RAST") != NULL; + firsttime = 0; + } + + if (no_swap) + return; + + if (xm_dt->drawable != xlib_drawable->drawable) { + if (xm_dt->gc) { + XFreeGC( display, xm_dt->gc ); + xm_dt->gc = NULL; + } + + if (xm_dt->tempImage) { + XDestroyImage( xm_dt->tempImage ); + xm_dt->tempImage = NULL; + } + + xm_dt->drawable = xlib_drawable->drawable; + } + + if (xm_dt->tempImage == NULL) { + assert(util_format_get_blockwidth(xm_dt->format) == 1); + assert(util_format_get_blockheight(xm_dt->format) == 1); + alloc_ximage(xm_dt, xlib_drawable, + xm_dt->stride / util_format_get_blocksize(xm_dt->format), + xm_dt->height); + if (!xm_dt->tempImage) + return; + } + + if (xm_dt->gc == NULL) { + xm_dt->gc = XCreateGC( display, xlib_drawable->drawable, 0, NULL ); + XSetFunction( display, xm_dt->gc, GXcopy ); + } + + if (xm_dt->shm) + { + ximage = xm_dt->tempImage; + ximage->data = xm_dt->data; + + /* _debug_printf("XSHM\n"); */ + XShmPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, + ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height, False); + } + else { + /* display image in Window */ + ximage = xm_dt->tempImage; + ximage->data = xm_dt->data; + + /* check that the XImage has been previously initialized */ + assert(ximage->format); + assert(ximage->bitmap_unit); + + /* update XImage's fields */ + ximage->width = xm_dt->width; + ximage->height = xm_dt->height; + ximage->bytes_per_line = xm_dt->stride; + + /* _debug_printf("XPUT\n"); */ + XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, + ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height); + } +} + +/** + * Display/copy the image in the surface into the X window specified + * by the XMesaBuffer. + */ +static void +xm_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) +{ + struct xlib_drawable *xlib_drawable = (struct xlib_drawable *)context_private; + xlib_sw_display(xlib_drawable, dt); +} + + +static struct sw_displaytarget * +xm_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct xm_displaytarget *xm_dt; + unsigned nblocksy, size; + + xm_dt = CALLOC_STRUCT(xm_displaytarget); + if(!xm_dt) + goto no_xm_dt; + + xm_dt->display = ((struct xlib_sw_winsys *)winsys)->display; + xm_dt->format = format; + xm_dt->width = width; + xm_dt->height = height; + + nblocksy = util_format_get_nblocksy(format, height); + xm_dt->stride = align(util_format_get_stride(format, width), alignment); + size = xm_dt->stride * nblocksy; + + if (!debug_get_bool_option("XLIB_NO_SHM", FALSE)) + { + xm_dt->shminfo.shmid = -1; + xm_dt->shminfo.shmaddr = (char *) -1; + xm_dt->shm = TRUE; + + xm_dt->data = alloc_shm(xm_dt, size); + if(!xm_dt->data) + goto no_data; + } + + if(!xm_dt->data) { + xm_dt->data = align_malloc(size, alignment); + if(!xm_dt->data) + goto no_data; + } + + *stride = xm_dt->stride; + return (struct sw_displaytarget *)xm_dt; + +no_data: + FREE(xm_dt); +no_xm_dt: + return NULL; +} + + +static struct sw_displaytarget * +xm_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +xm_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +static void +xm_destroy( struct sw_winsys *ws ) +{ + FREE(ws); +} + + +struct sw_winsys * +xlib_create_sw_winsys( Display *display ) +{ + struct xlib_sw_winsys *ws; + + ws = CALLOC_STRUCT(xlib_sw_winsys); + if (!ws) + return NULL; + + ws->display = display; + ws->base.destroy = xm_destroy; + + ws->base.is_displaytarget_format_supported = xm_is_displaytarget_format_supported; + + ws->base.displaytarget_create = xm_displaytarget_create; + ws->base.displaytarget_from_handle = xm_displaytarget_from_handle; + ws->base.displaytarget_get_handle = xm_displaytarget_get_handle; + ws->base.displaytarget_map = xm_displaytarget_map; + ws->base.displaytarget_unmap = xm_displaytarget_unmap; + ws->base.displaytarget_destroy = xm_displaytarget_destroy; + + ws->base.displaytarget_display = xm_displaytarget_display; + + return &ws->base; +} + diff --git a/src/gallium/winsys/xlib/Makefile b/src/gallium/winsys/xlib/Makefile deleted file mode 100644 index 83d53c59542..00000000000 --- a/src/gallium/winsys/xlib/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = ws_xlib - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - $(X11_CFLAGS) - -C_SOURCES = \ - xlib_sw_winsys.c - -include ../../Makefile.template - - diff --git a/src/gallium/winsys/xlib/SConscript b/src/gallium/winsys/xlib/SConscript deleted file mode 100644 index 2af6153b4c7..00000000000 --- a/src/gallium/winsys/xlib/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -if env['platform'] == 'linux': - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', - ]) - - ws_xlib = env.ConvenienceLibrary( - target = 'ws_xlib', - source = [ - 'xlib_sw_winsys.c', - ] - ) - Export('ws_xlib') diff --git a/src/gallium/winsys/xlib/xlib_sw_winsys.c b/src/gallium/winsys/xlib/xlib_sw_winsys.c deleted file mode 100644 index 54789d7a87c..00000000000 --- a/src/gallium/winsys/xlib/xlib_sw_winsys.c +++ /dev/null @@ -1,464 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA - * 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/* - * Authors: - * Keith Whitwell - * Brian Paul - */ - -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" - -#include "state_tracker/xlib_sw_winsys.h" - -#include -#include -#include -#include -#include -#include - -/** - * Subclass of pipe_buffer for Xlib winsys. - * Low-level OS/window system memory buffer - */ -struct xm_displaytarget -{ - enum pipe_format format; - unsigned width; - unsigned height; - unsigned stride; - - void *data; - void *mapped; - - Display *display; - Visual *visual; - XImage *tempImage; - GC gc; - - /* This is the last drawable that this display target was presented - * against. May need to recreate gc, tempImage when this changes?? - */ - Drawable drawable; - - XShmSegmentInfo shminfo; - int shm; -}; - - -/** - * Subclass of sw_winsys for Xlib winsys - */ -struct xlib_sw_winsys -{ - struct sw_winsys base; - - - - Display *display; -}; - - - -/** Cast wrapper */ -static INLINE struct xm_displaytarget * -xm_displaytarget( struct sw_displaytarget *dt ) -{ - return (struct xm_displaytarget *)dt; -} - - -/** - * X Shared Memory Image extension code - */ - -static volatile int mesaXErrorFlag = 0; - -/** - * Catches potential Xlib errors. - */ -static int -mesaHandleXError(Display *dpy, XErrorEvent *event) -{ - (void) dpy; - (void) event; - mesaXErrorFlag = 1; - return 0; -} - - -static char *alloc_shm(struct xm_displaytarget *buf, unsigned size) -{ - XShmSegmentInfo *const shminfo = & buf->shminfo; - - shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777); - if (shminfo->shmid < 0) { - return NULL; - } - - shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0); - if (shminfo->shmaddr == (char *) -1) { - shmctl(shminfo->shmid, IPC_RMID, 0); - return NULL; - } - - shminfo->readOnly = False; - return shminfo->shmaddr; -} - - -/** - * Allocate a shared memory XImage back buffer for the given XMesaBuffer. - */ -static void -alloc_shm_ximage(struct xm_displaytarget *xm_dt, - struct xlib_drawable *xmb, - unsigned width, unsigned height) -{ - /* - * We have to do a _lot_ of error checking here to be sure we can - * really use the XSHM extension. It seems different servers trigger - * errors at different points if the extension won't work. Therefore - * we have to be very careful... - */ - int (*old_handler)(Display *, XErrorEvent *); - - xm_dt->tempImage = XShmCreateImage(xm_dt->display, - xmb->visual, - xmb->depth, - ZPixmap, - NULL, - &xm_dt->shminfo, - width, height); - if (xm_dt->tempImage == NULL) { - xm_dt->shm = 0; - return; - } - - - mesaXErrorFlag = 0; - old_handler = XSetErrorHandler(mesaHandleXError); - /* This may trigger the X protocol error we're ready to catch: */ - XShmAttach(xm_dt->display, &xm_dt->shminfo); - XSync(xm_dt->display, False); - - if (mesaXErrorFlag) { - /* we are on a remote display, this error is normal, don't print it */ - XFlush(xm_dt->display); - mesaXErrorFlag = 0; - XDestroyImage(xm_dt->tempImage); - xm_dt->tempImage = NULL; - xm_dt->shm = 0; - (void) XSetErrorHandler(old_handler); - return; - } - - xm_dt->shm = 1; -} - - -static void -alloc_ximage(struct xm_displaytarget *xm_dt, - struct xlib_drawable *xmb, - unsigned width, unsigned height) -{ - if (xm_dt->shm) { - alloc_shm_ximage(xm_dt, xmb, width, height); - return; - } - - xm_dt->tempImage = XCreateImage(xm_dt->display, - xmb->visual, - xmb->depth, - ZPixmap, 0, - NULL, width, height, - 8, 0); -} - -static boolean -xm_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - /* TODO: check visuals or other sensible thing here */ - return TRUE; -} - - -static void * -xm_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = xm_dt->data; - return xm_dt->mapped; -} - -static void -xm_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = NULL; -} - -static void -xm_displaytarget_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - - if (xm_dt->data) { - if (xm_dt->shminfo.shmid >= 0) { - shmdt(xm_dt->shminfo.shmaddr); - shmctl(xm_dt->shminfo.shmid, IPC_RMID, 0); - - xm_dt->shminfo.shmid = -1; - xm_dt->shminfo.shmaddr = (char *) -1; - } - else { - FREE(xm_dt->data); - } - } - - if (xm_dt->tempImage) - XDestroyImage(xm_dt->tempImage); - - if (xm_dt->gc) - XFreeGC(xm_dt->display, xm_dt->gc); - - FREE(xm_dt); -} - - -/** - * Display/copy the image in the surface into the X window specified - * by the XMesaBuffer. - */ -static void -xlib_sw_display(struct xlib_drawable *xlib_drawable, - struct sw_displaytarget *dt) -{ - static boolean no_swap = 0; - static boolean firsttime = 1; - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - Display *display = xm_dt->display; - XImage *ximage; - - if (firsttime) { - no_swap = getenv("SP_NO_RAST") != NULL; - firsttime = 0; - } - - if (no_swap) - return; - - if (xm_dt->drawable != xlib_drawable->drawable) { - if (xm_dt->gc) { - XFreeGC( display, xm_dt->gc ); - xm_dt->gc = NULL; - } - - if (xm_dt->tempImage) { - XDestroyImage( xm_dt->tempImage ); - xm_dt->tempImage = NULL; - } - - xm_dt->drawable = xlib_drawable->drawable; - } - - if (xm_dt->tempImage == NULL) { - assert(util_format_get_blockwidth(xm_dt->format) == 1); - assert(util_format_get_blockheight(xm_dt->format) == 1); - alloc_ximage(xm_dt, xlib_drawable, - xm_dt->stride / util_format_get_blocksize(xm_dt->format), - xm_dt->height); - if (!xm_dt->tempImage) - return; - } - - if (xm_dt->gc == NULL) { - xm_dt->gc = XCreateGC( display, xlib_drawable->drawable, 0, NULL ); - XSetFunction( display, xm_dt->gc, GXcopy ); - } - - if (xm_dt->shm) - { - ximage = xm_dt->tempImage; - ximage->data = xm_dt->data; - - /* _debug_printf("XSHM\n"); */ - XShmPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, - ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height, False); - } - else { - /* display image in Window */ - ximage = xm_dt->tempImage; - ximage->data = xm_dt->data; - - /* check that the XImage has been previously initialized */ - assert(ximage->format); - assert(ximage->bitmap_unit); - - /* update XImage's fields */ - ximage->width = xm_dt->width; - ximage->height = xm_dt->height; - ximage->bytes_per_line = xm_dt->stride; - - /* _debug_printf("XPUT\n"); */ - XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, - ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height); - } -} - -/** - * Display/copy the image in the surface into the X window specified - * by the XMesaBuffer. - */ -static void -xm_displaytarget_display(struct sw_winsys *ws, - struct sw_displaytarget *dt, - void *context_private) -{ - struct xlib_drawable *xlib_drawable = (struct xlib_drawable *)context_private; - xlib_sw_display(xlib_drawable, dt); -} - - -static struct sw_displaytarget * -xm_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct xm_displaytarget *xm_dt; - unsigned nblocksy, size; - - xm_dt = CALLOC_STRUCT(xm_displaytarget); - if(!xm_dt) - goto no_xm_dt; - - xm_dt->display = ((struct xlib_sw_winsys *)winsys)->display; - xm_dt->format = format; - xm_dt->width = width; - xm_dt->height = height; - - nblocksy = util_format_get_nblocksy(format, height); - xm_dt->stride = align(util_format_get_stride(format, width), alignment); - size = xm_dt->stride * nblocksy; - - if (!debug_get_bool_option("XLIB_NO_SHM", FALSE)) - { - xm_dt->shminfo.shmid = -1; - xm_dt->shminfo.shmaddr = (char *) -1; - xm_dt->shm = TRUE; - - xm_dt->data = alloc_shm(xm_dt, size); - if(!xm_dt->data) - goto no_data; - } - - if(!xm_dt->data) { - xm_dt->data = align_malloc(size, alignment); - if(!xm_dt->data) - goto no_data; - } - - *stride = xm_dt->stride; - return (struct sw_displaytarget *)xm_dt; - -no_data: - FREE(xm_dt); -no_xm_dt: - return NULL; -} - - -static struct sw_displaytarget * -xm_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - assert(0); - return NULL; -} - - -static boolean -xm_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -static void -xm_destroy( struct sw_winsys *ws ) -{ - FREE(ws); -} - - -struct sw_winsys * -xlib_create_sw_winsys( Display *display ) -{ - struct xlib_sw_winsys *ws; - - ws = CALLOC_STRUCT(xlib_sw_winsys); - if (!ws) - return NULL; - - ws->display = display; - ws->base.destroy = xm_destroy; - - ws->base.is_displaytarget_format_supported = xm_is_displaytarget_format_supported; - - ws->base.displaytarget_create = xm_displaytarget_create; - ws->base.displaytarget_from_handle = xm_displaytarget_from_handle; - ws->base.displaytarget_get_handle = xm_displaytarget_get_handle; - ws->base.displaytarget_map = xm_displaytarget_map; - ws->base.displaytarget_unmap = xm_displaytarget_unmap; - ws->base.displaytarget_destroy = xm_displaytarget_destroy; - - ws->base.displaytarget_display = xm_displaytarget_display; - - return &ws->base; -} - -- cgit v1.2.3 From 992e9572bdbc1f3d5243ca8eecbd6a372721a62b Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: swrastg_dri: add state_tracker --- configure.ac | 2 +- src/gallium/state_trackers/drisw/Makefile | 26 +++++++++++++++++++++++ src/gallium/state_trackers/drisw/dri1_helper.c | 1 + src/gallium/state_trackers/drisw/dri_context.c | 1 + src/gallium/state_trackers/drisw/dri_drawable.c | 1 + src/gallium/state_trackers/drisw/dri_extensions.c | 1 + src/gallium/state_trackers/drisw/dri_screen.c | 1 + src/gallium/state_trackers/drisw/dri_st_api.c | 1 + src/gallium/state_trackers/drisw/drisw.c | 1 + 9 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/gallium/state_trackers/drisw/Makefile create mode 120000 src/gallium/state_trackers/drisw/dri1_helper.c create mode 120000 src/gallium/state_trackers/drisw/dri_context.c create mode 120000 src/gallium/state_trackers/drisw/dri_drawable.c create mode 120000 src/gallium/state_trackers/drisw/dri_extensions.c create mode 120000 src/gallium/state_trackers/drisw/dri_screen.c create mode 120000 src/gallium/state_trackers/drisw/dri_st_api.c create mode 120000 src/gallium/state_trackers/drisw/drisw.c (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index edf2363a717..1b9500b8b5a 100644 --- a/configure.ac +++ b/configure.ac @@ -1204,7 +1204,7 @@ yes) GALLIUM_STATE_TRACKERS_DIRS=glx ;; dri) - GALLIUM_STATE_TRACKERS_DIRS="dri" + GALLIUM_STATE_TRACKERS_DIRS="dri drisw" if test "x$enable_egl" = xyes; then GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" fi diff --git a/src/gallium/state_trackers/drisw/Makefile b/src/gallium/state_trackers/drisw/Makefile new file mode 100644 index 00000000000..dec9a39edec --- /dev/null +++ b/src/gallium/state_trackers/drisw/Makefile @@ -0,0 +1,26 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = drisw + +LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H + +LIBRARY_INCLUDES = \ + -I../dri \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + -D__NOT_HAVE_DRM_H + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + drisw.c + +include ../../Makefile.template diff --git a/src/gallium/state_trackers/drisw/dri1_helper.c b/src/gallium/state_trackers/drisw/dri1_helper.c new file mode 120000 index 00000000000..e704e382e05 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri1_helper.c @@ -0,0 +1 @@ +../dri/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_context.c b/src/gallium/state_trackers/drisw/dri_context.c new file mode 120000 index 00000000000..e4e879dc867 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_context.c @@ -0,0 +1 @@ +../dri/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_drawable.c b/src/gallium/state_trackers/drisw/dri_drawable.c new file mode 120000 index 00000000000..d7f65c85d20 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_drawable.c @@ -0,0 +1 @@ +../dri/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_extensions.c b/src/gallium/state_trackers/drisw/dri_extensions.c new file mode 120000 index 00000000000..60ecde9547d --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_extensions.c @@ -0,0 +1 @@ +../dri/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_screen.c b/src/gallium/state_trackers/drisw/dri_screen.c new file mode 120000 index 00000000000..f22c562c84f --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_screen.c @@ -0,0 +1 @@ +../dri/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_st_api.c b/src/gallium/state_trackers/drisw/dri_st_api.c new file mode 120000 index 00000000000..eac8ec66905 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_st_api.c @@ -0,0 +1 @@ +../dri/dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/drisw.c b/src/gallium/state_trackers/drisw/drisw.c new file mode 120000 index 00000000000..258a79021ef --- /dev/null +++ b/src/gallium/state_trackers/drisw/drisw.c @@ -0,0 +1 @@ +../dri/drisw.c \ No newline at end of file -- cgit v1.2.3 From 7b333298fc4efd1a8e44aaebaae77bf88c28ce19 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:54 +0200 Subject: configure:ac add swrastg_dri --- configure.ac | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 1b9500b8b5a..4e0ce268492 100644 --- a/configure.ac +++ b/configure.ac @@ -474,7 +474,7 @@ xlib) dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/drm" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri sw/drm" ;; osmesa) DRIVER_DIRS="osmesa" @@ -1409,12 +1409,10 @@ AC_ARG_ENABLE([gallium-swrast], [build gallium swrast @<:@default=auto@:>@])], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) -if test "x$enable_gallium_swrast" = xyes; then - if test "x$enable_egl" != xyes; then - AC_MSG_ERROR([EGL needs to be enabled for egl-swrast target]) +if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then + if test "x$mesa_driver" = xdri; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" fi - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" -elif test "x$enable_gallium_swrast" = xauto; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" fi -- cgit v1.2.3 From a82e37b9e9e34175b7542d0c9b4e462833eab202 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 22:21:39 +0100 Subject: gallium: Add propper sanity checks in configure.ac --- configure.ac | 93 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 47 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 4e0ce268492..d6d952d7a58 100644 --- a/configure.ac +++ b/configure.ac @@ -1205,13 +1205,16 @@ yes) ;; dri) GALLIUM_STATE_TRACKERS_DIRS="dri drisw" + HAVE_ST_DRI="yes" + HAVE_ST_DRISW="yes" if test "x$enable_egl" = xyes; then GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" + HAVE_ST_EGL="yes" fi # Have only tested st/xorg on 1.6.0 servers PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED], - HAVE_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg", - HAVE_XORG="no") + HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg", + HAVE_ST_XORG="no") ;; esac ;; @@ -1223,15 +1226,28 @@ yes) AC_MSG_ERROR([state tracker '$tracker' doesn't exist]) case "$tracker" in + dri) + if test "x$mesa_driver" != xdri; then + AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri]) + fi + HAVE_ST_DRI="yes" + ;; + drisw) + if test "x$mesa_driver" != xdri; then + AC_MSG_ERROR([cannot build drisw state tracker without mesa driver set to dri]) + fi + HAVE_ST_DRISW="yes" + ;; egl) if test "x$enable_egl" != xyes; then AC_MSG_ERROR([cannot build egl state tracker without EGL library]) fi + HAVE_ST_EGL="yes" ;; xorg) PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED]) PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED]) - HAVE_XORG="yes" + HAVE_ST_XORG="yes" ;; es) # mesa/es is required to build es state tracker @@ -1243,7 +1259,7 @@ yes) ;; esac -if test "x$HAVE_XORG" = xyes; then +if test "x$HAVE_ST_XORG" = xyes; then PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1], HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71", HAVE_XEXTPROTO_71="no") @@ -1307,6 +1323,25 @@ AC_ARG_WITH([max-height], [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])] ) +dnl +dnl Gallium helper functions +dnl +gallium_check_st() { + if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_EGL" = xyes || test "x$HAVE_ST_XORG" = xyes; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1" + fi + if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2" + fi + if test "x$HAVE_ST_EGL" = xyes && test "x$3" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3" + fi + if test "x$HAVE_ST_XORG" = xyes && test "x$4" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $4" + fi +} + + dnl dnl Gallium SVGA configuration dnl @@ -1316,17 +1351,8 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga="$enableval"], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then - if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS svga/drm" - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" - fi - if test "x$enable_egl" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-vmwgfx" - fi - if test "x$HAVE_XORG" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-vmwgfx" - fi - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga/drm" + gallium_check_st "svga/drm" "dri-vmwgfx" "egl-vmwgfx" "xorg-vmwgfx" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" fi @@ -1340,17 +1366,8 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel="$enableval"], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then - if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/drm i965/drm" - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" - fi - if test "x$enable_egl" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-i915 egl-i965" - fi - if test "x$HAVE_XORG" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-i915 xorg-i965" - fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" + gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" fi @@ -1364,17 +1381,8 @@ AC_ARG_ENABLE([gallium-radeon], [enable_gallium_radeon="$enableval"], [enable_gallium_radeon=auto]) if test "x$enable_gallium_radeon" = xyes; then - if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS radeon/drm" - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" - fi - if test "x$enable_egl" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-radeon" - fi - if test "x$HAVE_XORG" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-radeon" - fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-radeong" "egl-radeon" "xorg-radeon" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" fi @@ -1388,17 +1396,8 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau="$enableval"], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then - if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS nouveau/drm" - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" - fi - if test "x$enable_egl" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-nouveau" - fi - if test "x$HAVE_XORG" = xyes; then - GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-nouveau" - fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" + gallium_check_st "nouveau/drm" "dri-nouveau" "egl-nouveau" "xorg-nouveau" fi dnl @@ -1410,10 +1409,10 @@ AC_ARG_ENABLE([gallium-swrast], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then - if test "x$mesa_driver" = xdri; then + if test "x$HAVE_ST_DRISW" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" fi - if test "x$enable_egl" = xyes; then + if test "x$HAVE_ST_EGL" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" fi fi -- cgit v1.2.3 From 5b1fc14627ae37c5def70e2d5fe28bf7a4becee6 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 18:29:51 +0100 Subject: st/dri: Reshuffle files and make it obvious which files are shared In short: git mv ../drisw/Makefile dri/sw git mv drisw.[c|h] sw git mv dri2.[c|h] dri1.[c|h] Makefile drm git rm ../drisw ln -s drm/* ln -s sw/* --- configure.ac | 11 +- src/gallium/state_trackers/dri/Makefile | 36 +- src/gallium/state_trackers/dri/SConscript | 28 +- src/gallium/state_trackers/dri/dri1.c | 526 --------------------- src/gallium/state_trackers/dri/dri1.h | 59 --- src/gallium/state_trackers/dri/dri2.c | 413 ---------------- src/gallium/state_trackers/dri/dri2.h | 46 -- src/gallium/state_trackers/dri/drisw.c | 318 ------------- src/gallium/state_trackers/dri/drisw.h | 54 --- src/gallium/state_trackers/dri/drm/Makefile | 33 ++ src/gallium/state_trackers/dri/drm/SConscript | 28 ++ src/gallium/state_trackers/dri/drm/dri1.c | 526 +++++++++++++++++++++ src/gallium/state_trackers/dri/drm/dri1.h | 59 +++ src/gallium/state_trackers/dri/drm/dri1_helper.c | 1 + src/gallium/state_trackers/dri/drm/dri2.c | 413 ++++++++++++++++ src/gallium/state_trackers/dri/drm/dri2.h | 46 ++ src/gallium/state_trackers/dri/drm/dri_context.c | 1 + src/gallium/state_trackers/dri/drm/dri_drawable.c | 1 + .../state_trackers/dri/drm/dri_extensions.c | 1 + src/gallium/state_trackers/dri/drm/dri_screen.c | 1 + src/gallium/state_trackers/dri/drm/dri_st_api.c | 1 + src/gallium/state_trackers/dri/sw/Makefile | 27 ++ src/gallium/state_trackers/dri/sw/dri1_helper.c | 1 + src/gallium/state_trackers/dri/sw/dri_context.c | 1 + src/gallium/state_trackers/dri/sw/dri_drawable.c | 1 + src/gallium/state_trackers/dri/sw/dri_extensions.c | 1 + src/gallium/state_trackers/dri/sw/dri_screen.c | 1 + src/gallium/state_trackers/dri/sw/dri_st_api.c | 1 + src/gallium/state_trackers/dri/sw/drisw.c | 318 +++++++++++++ src/gallium/state_trackers/dri/sw/drisw.h | 54 +++ src/gallium/state_trackers/drisw/Makefile | 26 - src/gallium/state_trackers/drisw/dri1_helper.c | 1 - src/gallium/state_trackers/drisw/dri_context.c | 1 - src/gallium/state_trackers/drisw/dri_drawable.c | 1 - src/gallium/state_trackers/drisw/dri_extensions.c | 1 - src/gallium/state_trackers/drisw/dri_screen.c | 1 - src/gallium/state_trackers/drisw/dri_st_api.c | 1 - src/gallium/state_trackers/drisw/drisw.c | 1 - src/gallium/targets/dri-i915/Makefile | 2 +- src/gallium/targets/dri-i965/Makefile | 2 +- src/gallium/targets/dri-nouveau/Makefile | 2 +- src/gallium/targets/dri-radeong/Makefile | 2 +- src/gallium/targets/dri-swrast/Makefile | 2 +- src/gallium/targets/dri-vmwgfx/Makefile | 2 +- 44 files changed, 1535 insertions(+), 1517 deletions(-) delete mode 100644 src/gallium/state_trackers/dri/dri1.c delete mode 100644 src/gallium/state_trackers/dri/dri1.h delete mode 100644 src/gallium/state_trackers/dri/dri2.c delete mode 100644 src/gallium/state_trackers/dri/dri2.h delete mode 100644 src/gallium/state_trackers/dri/drisw.c delete mode 100644 src/gallium/state_trackers/dri/drisw.h create mode 100644 src/gallium/state_trackers/dri/drm/Makefile create mode 100644 src/gallium/state_trackers/dri/drm/SConscript create mode 100644 src/gallium/state_trackers/dri/drm/dri1.c create mode 100644 src/gallium/state_trackers/dri/drm/dri1.h create mode 120000 src/gallium/state_trackers/dri/drm/dri1_helper.c create mode 100644 src/gallium/state_trackers/dri/drm/dri2.c create mode 100644 src/gallium/state_trackers/dri/drm/dri2.h create mode 120000 src/gallium/state_trackers/dri/drm/dri_context.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_drawable.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_extensions.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_screen.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/sw/Makefile create mode 120000 src/gallium/state_trackers/dri/sw/dri1_helper.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_context.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_drawable.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_extensions.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_screen.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/sw/drisw.c create mode 100644 src/gallium/state_trackers/dri/sw/drisw.h delete mode 100644 src/gallium/state_trackers/drisw/Makefile delete mode 120000 src/gallium/state_trackers/drisw/dri1_helper.c delete mode 120000 src/gallium/state_trackers/drisw/dri_context.c delete mode 120000 src/gallium/state_trackers/drisw/dri_drawable.c delete mode 120000 src/gallium/state_trackers/drisw/dri_extensions.c delete mode 120000 src/gallium/state_trackers/drisw/dri_screen.c delete mode 120000 src/gallium/state_trackers/drisw/dri_st_api.c delete mode 120000 src/gallium/state_trackers/drisw/drisw.c (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index d6d952d7a58..caa2cf65766 100644 --- a/configure.ac +++ b/configure.ac @@ -1204,9 +1204,8 @@ yes) GALLIUM_STATE_TRACKERS_DIRS=glx ;; dri) - GALLIUM_STATE_TRACKERS_DIRS="dri drisw" + GALLIUM_STATE_TRACKERS_DIRS="dri" HAVE_ST_DRI="yes" - HAVE_ST_DRISW="yes" if test "x$enable_egl" = xyes; then GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" HAVE_ST_EGL="yes" @@ -1232,12 +1231,6 @@ yes) fi HAVE_ST_DRI="yes" ;; - drisw) - if test "x$mesa_driver" != xdri; then - AC_MSG_ERROR([cannot build drisw state tracker without mesa driver set to dri]) - fi - HAVE_ST_DRISW="yes" - ;; egl) if test "x$enable_egl" != xyes; then AC_MSG_ERROR([cannot build egl state tracker without EGL library]) @@ -1409,7 +1402,7 @@ AC_ARG_ENABLE([gallium-swrast], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then - if test "x$HAVE_ST_DRISW" = xyes; then + if test "x$HAVE_ST_DRI" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" fi if test "x$HAVE_ST_EGL" = xyes; then diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index f1a54e80b61..72e70577b3d 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -1,32 +1,12 @@ +# src/gallium/state_trackers/dri/Makefile TOP = ../../../.. include $(TOP)/configs/current -LIBNAME = dridrm +SUBDIRS = drm sw -LIBRARY_INCLUDES = \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -I$(TOP)/src/mesa/main \ - $(shell pkg-config --cflags-only-I libdrm) - - -C_SOURCES = \ - dri_context.c \ - dri_screen.c \ - dri_drawable.c \ - dri_extensions.c \ - dri_st_api.c \ - dri1_helper.c \ - dri1.c \ - dri2.c - -# $(TOP)/src/mesa/drivers/dri/common/utils.c \ - $(TOP)/src/mesa/drivers/dri/common/vblank.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ - $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c \ - $(TOP)/src/mesa/drivers/common/driverfuncs.c \ - $(TOP)/src/mesa/drivers/dri/common/texmem.c \ - $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c - -include ../../Makefile.template +default install clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1; \ + fi \ + done diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index 2ca9f420683..b4a276cf29d 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -1,27 +1,5 @@ -####################################################################### -# SConscript for dri state_tracker - Import('*') -if env['dri']: - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/mesa', - '#/src/mesa/drivers/dri/common', - ]) - - st_dri = env.ConvenienceLibrary( - target = 'st_dri', - source = [ 'dri_context.c', - 'dri_drawable.c', - 'dri_extensions.c', - 'dri_screen.c', - 'dri_st_api.c', - 'dri1_helper.c', - 'dri1.c', - 'dri2.c', - ] - ) - Export('st_dri') +SConscript([ + 'drm/SConscript', +]) diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c deleted file mode 100644 index 98bdb2936a1..00000000000 --- a/src/gallium/state_trackers/dri/dri1.c +++ /dev/null @@ -1,526 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -/* XXX DRI1 is untested after the switch to st_api.h */ - -#include "util/u_memory.h" -#include "util/u_rect.h" -#include "util/u_inlines.h" -#include "pipe/p_context.h" -#include "state_tracker/dri1_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#include "dri1.h" - -static INLINE void -dri1_lock(struct dri_context *ctx) -{ - drm_context_t hw_context = ctx->cPriv->hHWContext; - char ret = 0; - - DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); - if (ret) { - drmGetLock(ctx->sPriv->fd, hw_context, 0); - ctx->stLostLock = TRUE; - ctx->wsLostLock = TRUE; - } - ctx->isLocked = TRUE; -} - -static INLINE void -dri1_unlock(struct dri_context *ctx) -{ - ctx->isLocked = FALSE; - DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); -} - -static void -dri1_update_drawables_locked(struct dri_context *ctx, - __DRIdrawable * driDrawPriv, - __DRIdrawable * driReadPriv) -{ - if (ctx->stLostLock) { - ctx->stLostLock = FALSE; - if (driDrawPriv == driReadPriv) - DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); - else - DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, - driReadPriv); - } -} - -/** - * This ensures all contexts which bind to a drawable pick up the - * drawable change and signal new buffer state. - */ -static void -dri1_propagate_drawable_change(struct dri_context *ctx) -{ - __DRIdrawable *dPriv = ctx->dPriv; - __DRIdrawable *rPriv = ctx->rPriv; - struct dri_drawable *draw = dri_drawable(dPriv); - struct dri_drawable *read = dri_drawable(rPriv); - boolean flushed = FALSE; - - if (dPriv && draw->texture_stamp != dPriv->lastStamp) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - flushed = TRUE; - ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb); - } - - if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) { - if (!flushed) - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb); - } -} - -static INLINE boolean -dri1_intersect_src_bbox(struct drm_clip_rect *dst, - int dst_x, - int dst_y, - const struct drm_clip_rect *src, - const struct drm_clip_rect *bbox) -{ - int xy1; - int xy2; - - xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : - (int)bbox->x1 + dst_x; - xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : - (int)bbox->x2 + dst_x; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->x1 = xy1; - dst->x2 = xy2; - - xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : - (int)bbox->y1 + dst_y; - xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : - (int)bbox->y2 + dst_y; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->y1 = xy1; - dst->y2 = xy2; - return TRUE; -} - -static void -dri1_swap_copy(struct pipe_context *pipe, - struct pipe_surface *dst, - struct pipe_surface *src, - __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) -{ - struct drm_clip_rect clip; - struct drm_clip_rect *cur; - int i; - - cur = dPriv->pClipRects; - - for (i = 0; i < dPriv->numClipRects; ++i) { - if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { - if (pipe->surface_copy) { - pipe->surface_copy(pipe, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } else { - util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } - } - } -} - -static void -dri1_present_texture_locked(__DRIdrawable * dPriv, - struct pipe_texture *ptex, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; - struct pipe_surface *psurf; - struct drm_clip_rect bbox; - boolean visible = TRUE; - - *fence = NULL; - - bbox.x1 = 0; - bbox.x2 = ptex->width0; - bbox.y1 = 0; - bbox.y2 = ptex->height0; - - if (sub_box) - visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); - if (!visible) - return; - - pipe = dri1_get_pipe_context(screen); - psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) - return; - - if (__dri1_api_hooks->present_locked) { - __dri1_api_hooks->present_locked(pipe, psurf, - dPriv->pClipRects, dPriv->numClipRects, - dPriv->x, dPriv->y, &bbox, fence); - } else if (__dri1_api_hooks->front_srf_locked) { - struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); - - if (front) - dri1_swap_copy(pipe, front, psurf, dPriv, &bbox); - - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, fence); - } -} - -static void -dri1_copy_to_front(struct dri_context *ctx, - struct pipe_texture *ptex, - __DRIdrawable * dPriv, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) -{ - boolean save_lost_lock; - - dri1_lock(ctx); - save_lost_lock = ctx->stLostLock; - dri1_update_drawables_locked(ctx, dPriv, dPriv); - - dri1_present_texture_locked(dPriv, ptex, sub_box, fence); - - ctx->stLostLock = save_lost_lock; - - /** - * FIXME: Revisit this: Update drawables on copy_sub_buffer ? - */ - - if (!sub_box) - dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); - - dri1_unlock(ctx); - dri1_propagate_drawable_change(ctx); -} - -/* - * Backend functions for st_framebuffer interface and swap_buffers. - */ - -void -dri1_flush_frontbuffer(struct dri_drawable *draw, - enum st_attachment_type statt) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_screen *screen = dri_screen(draw->sPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; - - if (!ctx) - return; /* For now */ - - ptex = draw->textures[statt]; - if (ptex) { - dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); - pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); - } - - /** - * FIXME: Do we need swap throttling here? - */ -} - -void -dri1_swap_buffers(__DRIdrawable * dPriv) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_drawable *draw = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(draw->sPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct pipe_fence_handle *fence; - struct pipe_texture *ptex; - - assert(__dri1_api_hooks != NULL); - - if (!ctx) - return; /* For now */ - - ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - fence = dri1_swap_fences_pop_front(draw); - if (fence) { - (void)pipe_screen->fence_finish(pipe_screen, fence, 0); - pipe_screen->fence_reference(pipe_screen, &fence, NULL); - } - dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); - dri1_swap_fences_push_back(draw, fence); - pipe_screen->fence_reference(pipe_screen, &fence, NULL); - } -} - -void -dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_screen *screen = dri_screen(dPriv->driScreenPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct drm_clip_rect sub_bbox; - struct dri_drawable *draw = dri_drawable(dPriv); - struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; - - assert(__dri1_api_hooks != NULL); - - if (!ctx) - return; - - sub_bbox.x1 = x; - sub_bbox.x2 = x + w; - sub_bbox.y1 = y; - sub_bbox.y2 = y + h; - - ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - dri1_copy_to_front(ctx, ptex, dPriv, &sub_bbox, &dummy_fence); - pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); - } -} - -/** - * Allocate framebuffer attachments. - * - * During fixed-size operation, the function keeps allocating new attachments - * as they are requested. Unused attachments are not removed, not until the - * framebuffer is resized or destroyed. - */ -void -dri1_allocate_textures(struct dri_drawable *drawable, - unsigned mask) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; - unsigned width, height; - boolean resized; - int i; - - width = drawable->dPriv->w; - height = drawable->dPriv->h; - - resized = (drawable->old_w != width || - drawable->old_h != height); - - /* remove outdated textures */ - if (resized) { - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - } - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.width0 = width; - templ.height0 = height; - templ.depth0 = 1; - templ.last_level = 0; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - enum pipe_format format; - unsigned tex_usage; - - /* the texture already exists or not requested */ - if (drawable->textures[i] || !(mask & (1 << i))) { - continue; - } - - switch (i) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - if (format != PIPE_FORMAT_NONE) { - templ.format = format; - templ.tex_usage = tex_usage; - - drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); - } - } - - drawable->old_w = width; - drawable->old_h = height; -} - -static void -st_dri_lock(struct pipe_context *pipe) -{ - dri1_lock((struct dri_context *)pipe->priv); -} - -static void -st_dri_unlock(struct pipe_context *pipe) -{ - dri1_unlock((struct dri_context *)pipe->priv); -} - -static boolean -st_dri_is_locked(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->isLocked; -} - -static boolean -st_dri_lost_lock(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->wsLostLock; -} - -static void -st_dri_clear_lost_lock(struct pipe_context *pipe) -{ - ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; -} - -static struct dri1_api_lock_funcs dri1_lf = { - .lock = st_dri_lock, - .unlock = st_dri_unlock, - .is_locked = st_dri_is_locked, - .is_lock_lost = st_dri_lost_lock, - .clear_lost_lock = st_dri_clear_lost_lock -}; - -/* - * Backend function for init_screen. - */ - -static const __DRIextension *dri1_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - NULL -}; - -struct dri1_api *__dri1_api_hooks = NULL; - -static INLINE void -dri1_copy_version(struct dri1_api_version *dst, - const struct __DRIversionRec *src) -{ - dst->major = src->major; - dst->minor = src->minor; - dst->patch_level = src->patch; -} - -const __DRIconfig ** -dri1_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - const __DRIconfig **configs; - struct dri1_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; - - sPriv->private = (void *)screen; - sPriv->extensions = dri1_screen_extensions; - - arg.base.mode = DRM_CREATE_DRI1; - arg.lf = &dri1_lf; - arg.ddx_info = sPriv->pDevPriv; - arg.ddx_info_size = sPriv->devPrivSize; - arg.sarea = sPriv->pSAREA; - dri1_copy_version(&arg.ddx_version, &sPriv->ddx_version); - dri1_copy_version(&arg.dri_version, &sPriv->dri_version); - dri1_copy_version(&arg.drm_version, &sPriv->drm_version); - arg.api = NULL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); - - if (!screen->pipe_screen || !arg.api) { - debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); - goto out_no_screen; - } - - __dri1_api_hooks = arg.api; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - /** - * FIXME: If the driver supports format conversion swapbuffer blits, we might - * want to support other color bit depths than the server is currently - * using. - */ - - configs = dri_fill_in_modes(screen, sPriv->fbBPP); - if (!configs) - goto out_no_configs; - - return configs; - out_no_configs: - screen->pipe_screen->destroy(screen->pipe_screen); - out_no_screen: - FREE(screen); - return NULL; -} diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h deleted file mode 100644 index f7441f98abc..00000000000 --- a/src/gallium/state_trackers/dri/dri1.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#ifndef DRI1_H -#define DRI1_H - -#include "dri_context.h" -#include "dri_drawable.h" - -#include "state_tracker/st_api.h" -#include "dri_wrapper.h" - -extern struct dri1_api *__dri1_api_hooks; - -const __DRIconfig ** -dri1_init_screen(__DRIscreen * sPriv); - -void -dri1_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -dri1_allocate_textures(struct dri_drawable *drawable, - unsigned mask); - -void dri1_swap_buffers(__DRIdrawable * dPriv); - -void -dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); - -#endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c deleted file mode 100644 index 108b18e9d3c..00000000000 --- a/src/gallium/state_trackers/dri/dri2.c +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * 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 - * BRIAN PAUL 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: - * Keith Whitwell - * Jakob Bornecrantz - * Chia-I Wu - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_debug.h" -#include "state_tracker/drm_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri2.h" - -/** - * DRI2 flush extension. - */ -static void -dri2_flush_drawable(__DRIdrawable *draw) -{ -} - -static void -dri2_invalidate_drawable(__DRIdrawable *dPriv) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_context *ctx = dri_context(dPriv->driContextPriv); - - dri2InvalidateDrawable(dPriv); - drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; - - if (ctx) - ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); -} - -static const __DRI2flushExtension dri2FlushExtension = { - { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, - dri2_flush_drawable, - dri2_invalidate_drawable, -}; - -/** - * These are used for GLX_EXT_texture_from_pixmap - */ -static void -dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, - GLint format, __DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_context(pDRICtx); - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *pt; - - dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); - - pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; - - if (pt) { - ctx->st->teximage(ctx->st, - (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, - 0, drawable->stvis.color_format, pt, FALSE); - } -} - -static void -dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, - __DRIdrawable *dPriv) -{ - dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); -} - -static const __DRItexBufferExtension dri2TexBufferExtension = { - { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, - dri2_set_tex_buffer, - dri2_set_tex_buffer2, -}; - -/** - * Get the format of an attachment. - */ -static INLINE enum pipe_format -dri2_drawable_get_format(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - enum pipe_format format; - - switch (statt) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - return format; -} - -/** - * Retrieve __DRIbuffer from the DRI loader. - */ -static __DRIbuffer * -dri2_drawable_get_buffers(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned *count) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - boolean with_format; - __DRIbuffer *buffers; - int num_buffers; - unsigned attachments[10]; - unsigned num_attachments, i; - - assert(loader); - with_format = dri_with_format(drawable->sPriv); - - num_attachments = 0; - - /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ - if (!with_format) - attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; - - for (i = 0; i < *count; i++) { - enum pipe_format format; - int att, bpp; - - format = dri2_drawable_get_format(drawable, statts[i]); - if (format == PIPE_FORMAT_NONE) - continue; - - switch (statts[i]) { - case ST_ATTACHMENT_FRONT_LEFT: - /* already added */ - if (!with_format) - continue; - att = __DRI_BUFFER_FRONT_LEFT; - break; - case ST_ATTACHMENT_BACK_LEFT: - att = __DRI_BUFFER_BACK_LEFT; - break; - case ST_ATTACHMENT_FRONT_RIGHT: - att = __DRI_BUFFER_FRONT_RIGHT; - break; - case ST_ATTACHMENT_BACK_RIGHT: - att = __DRI_BUFFER_BACK_RIGHT; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - att = __DRI_BUFFER_DEPTH_STENCIL; - break; - default: - att = -1; - break; - } - - bpp = util_format_get_blocksizebits(format); - - if (att >= 0) { - attachments[num_attachments++] = att; - if (with_format) { - attachments[num_attachments++] = bpp; - } - } - } - - if (with_format) { - num_attachments /= 2; - buffers = loader->getBuffersWithFormat(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - else { - buffers = loader->getBuffers(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - - if (buffers) { - /* set one cliprect to cover the whole dri_drawable */ - dri_drawable->x = 0; - dri_drawable->y = 0; - dri_drawable->backX = 0; - dri_drawable->backY = 0; - dri_drawable->numClipRects = 1; - dri_drawable->pClipRects[0].x1 = 0; - dri_drawable->pClipRects[0].y1 = 0; - dri_drawable->pClipRects[0].x2 = dri_drawable->w; - dri_drawable->pClipRects[0].y2 = dri_drawable->h; - dri_drawable->numBackClipRects = 1; - dri_drawable->pBackClipRects[0].x1 = 0; - dri_drawable->pBackClipRects[0].y1 = 0; - dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; - dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; - - *count = num_buffers; - } - - return buffers; -} - -/** - * Process __DRIbuffer and convert them into pipe_textures. - */ -static void -dri2_drawable_process_buffers(struct dri_drawable *drawable, - __DRIbuffer *buffers, unsigned count) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - __DRIdrawable *dri_drawable = drawable->dPriv; - struct pipe_texture templ; - struct winsys_handle whandle; - boolean have_depth = FALSE; - unsigned i; - - if (drawable->old_num == count && - drawable->old_w == dri_drawable->w && - drawable->old_h == dri_drawable->h && - memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) - return; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - - memset(&templ, 0, sizeof(templ)); - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri_drawable->w; - templ.height0 = dri_drawable->h; - templ.depth0 = 1; - - memset(&whandle, 0, sizeof(whandle)); - - for (i = 0; i < count; i++) { - __DRIbuffer *buf = &buffers[i]; - enum st_attachment_type statt; - enum pipe_format format; - - switch (buf->attachment) { - case __DRI_BUFFER_FRONT_LEFT: - if (!screen->auto_fake_front) { - statt = ST_ATTACHMENT_INVALID; - break; - } - /* fallthrough */ - case __DRI_BUFFER_FAKE_FRONT_LEFT: - statt = ST_ATTACHMENT_FRONT_LEFT; - break; - case __DRI_BUFFER_BACK_LEFT: - statt = ST_ATTACHMENT_BACK_LEFT; - break; - case __DRI_BUFFER_DEPTH: - case __DRI_BUFFER_DEPTH_STENCIL: - case __DRI_BUFFER_STENCIL: - /* use only the first depth/stencil buffer */ - if (!have_depth) { - have_depth = TRUE; - statt = ST_ATTACHMENT_DEPTH_STENCIL; - } - else { - statt = ST_ATTACHMENT_INVALID; - } - break; - default: - statt = ST_ATTACHMENT_INVALID; - break; - } - - format = dri2_drawable_get_format(drawable, statt); - if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) - continue; - - templ.format = format; - whandle.handle = buf->name; - whandle.stride = buf->pitch; - - drawable->textures[statt] = - screen->pipe_screen->texture_from_handle(screen->pipe_screen, - &templ, &whandle); - } - - drawable->old_num = count; - drawable->old_w = dri_drawable->w; - drawable->old_h = dri_drawable->h; - memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); -} - -/* - * Backend functions for st_framebuffer interface. - */ - -void -dri2_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count) -{ - __DRIbuffer *buffers; - unsigned num_buffers = count; - - buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); - dri2_drawable_process_buffers(drawable, buffers, num_buffers); -} - -void -dri2_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - - if (loader->flushFrontBuffer == NULL) - return; - - if (statt == ST_ATTACHMENT_FRONT_LEFT) { - loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); - } -} - -/* - * Backend function init_screen. - */ - -static const __DRIextension *dri_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - &dri2TexBufferExtension.base, - &dri2FlushExtension.base, - NULL -}; - -/** - * This is the driver specific part of the createNewScreen entry point. - * - * Returns the __GLcontextModes supported by this driver. - */ -const __DRIconfig ** -dri2_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - struct drm_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - sPriv->private = (void *)screen; - sPriv->extensions = dri_screen_extensions; - arg.mode = DRM_CREATE_NORMAL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } - - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) - goto fail; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - screen->auto_fake_front = dri_with_format(sPriv); - - return dri_fill_in_modes(screen, 32); -fail: - dri_destroy_screen(sPriv); - return NULL; -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri2.h b/src/gallium/state_trackers/dri/dri2.h deleted file mode 100644 index 379963431fb..00000000000 --- a/src/gallium/state_trackers/dri/dri2.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef DRI2_H -#define DRI2_H - -#include "dri_drawable.h" -#include "dri_wrapper.h" - -const __DRIconfig ** -dri2_init_screen(__DRIscreen * sPriv); - -void -dri2_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -dri2_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count); - -#endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c deleted file mode 100644 index 73bc45d9060..00000000000 --- a/src/gallium/state_trackers/dri/drisw.c +++ /dev/null @@ -1,318 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * Copyright 2010 George Sapountzis - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/* TODO: - * - * stride: - * - * The driver and the loaders (libGL, xserver/glx) compute the stride from the - * width independently. winsys has a workaround that works for softpipe but may - * explode for other drivers or platforms, rendering- or performance-wise. - * Solving this issue properly requires extending the DRISW loader extension, - * in order to make the stride available to the putImage callback. - * - * drisw_api: - * - * Define drisw_api similarly to dri_api and use it to call the loader. This is - * predicated on support for calling the loader from the winsys, which has to - * grow for DRI2 as well. - * - * xshm: - * - * Allow the loaders to use the XSHM extension. It probably requires callbacks - * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth - * it, given the scope of DRISW, unless it falls naturally from properly - * solving the above two issues. - * - * swrast_create_screen: - * - * Allow for any software renderer to be used. Factor out the code from - * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and - * use it in all software targets. - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "pipe/p_context.h" -#include "state_tracker/drm_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#include "drisw.h" - - -static INLINE void -get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) -{ - __DRIscreen *sPriv = dPriv->driScreenPriv; - const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; - int x, y; - - loader->getDrawableInfo(dPriv, - &x, &y, w, h, - dPriv->loaderPrivate); -} - -static INLINE void -put_image(__DRIdrawable *dPriv, void *data) -{ - __DRIscreen *sPriv = dPriv->driScreenPriv; - const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; - - loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, - 0, 0, dPriv->w, dPriv->h, - data, dPriv->loaderPrivate); -} - -void -drisw_update_drawable_info(__DRIdrawable *dPriv) -{ - get_drawable_info(dPriv, &dPriv->w, &dPriv->h); -} - -static INLINE void -drisw_present_texture(__DRIdrawable *dPriv, - struct pipe_texture *ptex) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; - struct pipe_surface *psurf; - struct pipe_transfer *ptrans; - void *pmap; - - pipe = dri1_get_pipe_context(screen); - psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) - return; - - ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, dPriv->w, dPriv->h); - - pmap = pipe->transfer_map(pipe, ptrans); - - assert(pmap); - - put_image(dPriv, pmap); - - pipe->transfer_unmap(pipe, ptrans); - - pipe->tex_transfer_destroy(pipe, ptrans); -} - -static INLINE void -drisw_invalidate_drawable(__DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_get_current(); - 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->stfb); -} - -static INLINE void -drisw_copy_to_front(__DRIdrawable * dPriv, - struct pipe_texture *ptex) -{ - drisw_present_texture(dPriv, ptex); - - drisw_invalidate_drawable(dPriv); -} - -/* - * Backend functions for st_framebuffer interface and swap_buffers. - */ - -void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - struct dri_context *ctx = dri_get_current(); - struct pipe_texture *ptex; - - if (!ctx) - return; - - ptex = drawable->textures[statt]; - - if (ptex) { - drisw_copy_to_front(ctx->dPriv, ptex); - } -} - -void -drisw_swap_buffers(__DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *ptex; - - if (!ctx) - return; - - ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; - - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - drisw_copy_to_front(dPriv, ptex); - } -} - -/** - * Allocate framebuffer attachments. - * - * During fixed-size operation, the function keeps allocating new attachments - * as they are requested. Unused attachments are not removed, not until the - * framebuffer is resized or destroyed. - * - * It should be possible for DRI1 and DRISW to share this function, but it - * seems a better seperation and safer for each DRI version to provide its own - * function. - */ -void -drisw_allocate_textures(struct dri_drawable *drawable, - unsigned mask) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; - unsigned width, height; - boolean resized; - int i; - - width = drawable->dPriv->w; - height = drawable->dPriv->h; - - resized = (drawable->old_w != width || - drawable->old_h != height); - - /* remove outdated textures */ - if (resized) { - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - } - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.width0 = width; - templ.height0 = height; - templ.depth0 = 1; - templ.last_level = 0; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - enum pipe_format format; - unsigned tex_usage; - - /* the texture already exists or not requested */ - if (drawable->textures[i] || !(mask & (1 << i))) { - continue; - } - - switch (i) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - if (format != PIPE_FORMAT_NONE) { - templ.format = format; - templ.tex_usage = tex_usage; - - drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); - } - } - - drawable->old_w = width; - drawable->old_h = height; -} - -/* - * Backend function for init_screen. - */ - -static const __DRIextension *drisw_screen_extensions[] = { - NULL -}; - -const __DRIconfig ** -drisw_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - struct drm_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = -1; - sPriv->private = (void *)screen; - sPriv->extensions = drisw_screen_extensions; - arg.mode = DRM_CREATE_DRISW; - - screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } - - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) - goto fail; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - return dri_fill_in_modes(screen, 32); -fail: - dri_destroy_screen(sPriv); - return NULL; -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drisw.h b/src/gallium/state_trackers/dri/drisw.h deleted file mode 100644 index 2c0d5610fac..00000000000 --- a/src/gallium/state_trackers/dri/drisw.h +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * Copyright 2010 George Sapountzis - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef DRISW_H -#define DRISW_H - -#include "dri_context.h" -#include "dri_drawable.h" - -#include "state_tracker/st_api.h" -#include "dri_wrapper.h" - -const __DRIconfig ** -drisw_init_screen(__DRIscreen * sPriv); - -void -drisw_update_drawable_info(__DRIdrawable *dPriv); - -void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -drisw_allocate_textures(struct dri_drawable *drawable, - unsigned mask); - -void drisw_swap_buffers(__DRIdrawable * dPriv); - -#endif /* DRISW_H */ diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile new file mode 100644 index 00000000000..c43bfee8b8f --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/Makefile @@ -0,0 +1,33 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = dridrm + +LIBRARY_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + $(shell pkg-config --cflags-only-I libdrm) + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + dri1.c \ + dri2.c + +# $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/vblank.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c \ + $(TOP)/src/mesa/drivers/common/driverfuncs.c \ + $(TOP)/src/mesa/drivers/dri/common/texmem.c \ + $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript new file mode 100644 index 00000000000..a9c359c2e89 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -0,0 +1,28 @@ +####################################################################### +# SConscript for dri state_tracker + +Import('*') + +if env['dri']: + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/mesa', + '#/src/gallium/state_trackers/dri', + '#/src/mesa/drivers/dri/common', + ]) + + st_dri = env.ConvenienceLibrary( + target = 'st_dri', + source = [ 'dri_context.c', + 'dri_drawable.c', + 'dri_extensions.c', + 'dri_screen.c', + 'dri_st_api.c', + 'dri1_helper.c', + 'dri1.c', + 'dri2.c', + ] + ) + Export('st_dri') diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c new file mode 100644 index 00000000000..98bdb2936a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -0,0 +1,526 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +/* XXX DRI1 is untested after the switch to st_api.h */ + +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/dri1_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#include "dri1.h" + +static INLINE void +dri1_lock(struct dri_context *ctx) +{ + drm_context_t hw_context = ctx->cPriv->hHWContext; + char ret = 0; + + DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); + if (ret) { + drmGetLock(ctx->sPriv->fd, hw_context, 0); + ctx->stLostLock = TRUE; + ctx->wsLostLock = TRUE; + } + ctx->isLocked = TRUE; +} + +static INLINE void +dri1_unlock(struct dri_context *ctx) +{ + ctx->isLocked = FALSE; + DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); +} + +static void +dri1_update_drawables_locked(struct dri_context *ctx, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv) +{ + if (ctx->stLostLock) { + ctx->stLostLock = FALSE; + if (driDrawPriv == driReadPriv) + DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); + else + DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, + driReadPriv); + } +} + +/** + * This ensures all contexts which bind to a drawable pick up the + * drawable change and signal new buffer state. + */ +static void +dri1_propagate_drawable_change(struct dri_context *ctx) +{ + __DRIdrawable *dPriv = ctx->dPriv; + __DRIdrawable *rPriv = ctx->rPriv; + struct dri_drawable *draw = dri_drawable(dPriv); + struct dri_drawable *read = dri_drawable(rPriv); + boolean flushed = FALSE; + + if (dPriv && draw->texture_stamp != dPriv->lastStamp) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + flushed = TRUE; + ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb); + } + + if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) { + if (!flushed) + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb); + } +} + +static INLINE boolean +dri1_intersect_src_bbox(struct drm_clip_rect *dst, + int dst_x, + int dst_y, + const struct drm_clip_rect *src, + const struct drm_clip_rect *bbox) +{ + int xy1; + int xy2; + + xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : + (int)bbox->x1 + dst_x; + xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : + (int)bbox->x2 + dst_x; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->x1 = xy1; + dst->x2 = xy2; + + xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : + (int)bbox->y1 + dst_y; + xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : + (int)bbox->y2 + dst_y; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->y1 = xy1; + dst->y2 = xy2; + return TRUE; +} + +static void +dri1_swap_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + struct pipe_surface *src, + __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) +{ + struct drm_clip_rect clip; + struct drm_clip_rect *cur; + int i; + + cur = dPriv->pClipRects; + + for (i = 0; i < dPriv->numClipRects; ++i) { + if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { + if (pipe->surface_copy) { + pipe->surface_copy(pipe, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } else { + util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } + } + } +} + +static void +dri1_present_texture_locked(__DRIdrawable * dPriv, + struct pipe_texture *ptex, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; + struct drm_clip_rect bbox; + boolean visible = TRUE; + + *fence = NULL; + + bbox.x1 = 0; + bbox.x2 = ptex->width0; + bbox.y1 = 0; + bbox.y2 = ptex->height0; + + if (sub_box) + visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); + if (!visible) + return; + + pipe = dri1_get_pipe_context(screen); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + + if (__dri1_api_hooks->present_locked) { + __dri1_api_hooks->present_locked(pipe, psurf, + dPriv->pClipRects, dPriv->numClipRects, + dPriv->x, dPriv->y, &bbox, fence); + } else if (__dri1_api_hooks->front_srf_locked) { + struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); + + if (front) + dri1_swap_copy(pipe, front, psurf, dPriv, &bbox); + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, fence); + } +} + +static void +dri1_copy_to_front(struct dri_context *ctx, + struct pipe_texture *ptex, + __DRIdrawable * dPriv, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + boolean save_lost_lock; + + dri1_lock(ctx); + save_lost_lock = ctx->stLostLock; + dri1_update_drawables_locked(ctx, dPriv, dPriv); + + dri1_present_texture_locked(dPriv, ptex, sub_box, fence); + + ctx->stLostLock = save_lost_lock; + + /** + * FIXME: Revisit this: Update drawables on copy_sub_buffer ? + */ + + if (!sub_box) + dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); + + dri1_unlock(ctx); + dri1_propagate_drawable_change(ctx); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +void +dri1_flush_frontbuffer(struct dri_drawable *draw, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(draw->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct pipe_fence_handle *dummy_fence; + struct pipe_texture *ptex; + + if (!ctx) + return; /* For now */ + + ptex = draw->textures[statt]; + if (ptex) { + dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + } + + /** + * FIXME: Do we need swap throttling here? + */ +} + +void +dri1_swap_buffers(__DRIdrawable * dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *draw = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(draw->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct pipe_fence_handle *fence; + struct pipe_texture *ptex; + + assert(__dri1_api_hooks != NULL); + + if (!ctx) + return; /* For now */ + + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + fence = dri1_swap_fences_pop_front(draw); + if (fence) { + (void)pipe_screen->fence_finish(pipe_screen, fence, 0); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); + } + dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); + dri1_swap_fences_push_back(draw, fence); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); + } +} + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(dPriv->driScreenPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct drm_clip_rect sub_bbox; + struct dri_drawable *draw = dri_drawable(dPriv); + struct pipe_fence_handle *dummy_fence; + struct pipe_texture *ptex; + + assert(__dri1_api_hooks != NULL); + + if (!ctx) + return; + + sub_bbox.x1 = x; + sub_bbox.x2 = x + w; + sub_bbox.y1 = y; + sub_bbox.y2 = y + h; + + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + dri1_copy_to_front(ctx, ptex, dPriv, &sub_bbox, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + } +} + +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + */ +void +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + unsigned width, height; + boolean resized; + int i; + + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + + /* remove outdated textures */ + if (resized) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; +} + +static void +st_dri_lock(struct pipe_context *pipe) +{ + dri1_lock((struct dri_context *)pipe->priv); +} + +static void +st_dri_unlock(struct pipe_context *pipe) +{ + dri1_unlock((struct dri_context *)pipe->priv); +} + +static boolean +st_dri_is_locked(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->isLocked; +} + +static boolean +st_dri_lost_lock(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->wsLostLock; +} + +static void +st_dri_clear_lost_lock(struct pipe_context *pipe) +{ + ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; +} + +static struct dri1_api_lock_funcs dri1_lf = { + .lock = st_dri_lock, + .unlock = st_dri_unlock, + .is_locked = st_dri_is_locked, + .is_lock_lost = st_dri_lost_lock, + .clear_lost_lock = st_dri_clear_lost_lock +}; + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *dri1_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + NULL +}; + +struct dri1_api *__dri1_api_hooks = NULL; + +static INLINE void +dri1_copy_version(struct dri1_api_version *dst, + const struct __DRIversionRec *src) +{ + dst->major = src->major; + dst->minor = src->minor; + dst->patch_level = src->patch; +} + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + const __DRIconfig **configs; + struct dri1_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; + + sPriv->private = (void *)screen; + sPriv->extensions = dri1_screen_extensions; + + arg.base.mode = DRM_CREATE_DRI1; + arg.lf = &dri1_lf; + arg.ddx_info = sPriv->pDevPriv; + arg.ddx_info_size = sPriv->devPrivSize; + arg.sarea = sPriv->pSAREA; + dri1_copy_version(&arg.ddx_version, &sPriv->ddx_version); + dri1_copy_version(&arg.dri_version, &sPriv->dri_version); + dri1_copy_version(&arg.drm_version, &sPriv->drm_version); + arg.api = NULL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); + + if (!screen->pipe_screen || !arg.api) { + debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); + goto out_no_screen; + } + + __dri1_api_hooks = arg.api; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + /** + * FIXME: If the driver supports format conversion swapbuffer blits, we might + * want to support other color bit depths than the server is currently + * using. + */ + + configs = dri_fill_in_modes(screen, sPriv->fbBPP); + if (!configs) + goto out_no_configs; + + return configs; + out_no_configs: + screen->pipe_screen->destroy(screen->pipe_screen); + out_no_screen: + FREE(screen); + return NULL; +} diff --git a/src/gallium/state_trackers/dri/drm/dri1.h b/src/gallium/state_trackers/dri/drm/dri1.h new file mode 100644 index 00000000000..f7441f98abc --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1.h @@ -0,0 +1,59 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI1_H +#define DRI1_H + +#include "dri_context.h" +#include "dri_drawable.h" + +#include "state_tracker/st_api.h" +#include "dri_wrapper.h" + +extern struct dri1_api *__dri1_api_hooks; + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv); + +void +dri1_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned mask); + +void dri1_swap_buffers(__DRIdrawable * dPriv); + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); + +#endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/drm/dri1_helper.c b/src/gallium/state_trackers/dri/drm/dri1_helper.c new file mode 120000 index 00000000000..7006a8d882f --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1_helper.c @@ -0,0 +1 @@ +../dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c new file mode 100644 index 00000000000..108b18e9d3c --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -0,0 +1,413 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * 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 + * BRIAN PAUL 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: + * Keith Whitwell + * Jakob Bornecrantz + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri2.h" + +/** + * DRI2 flush extension. + */ +static void +dri2_flush_drawable(__DRIdrawable *draw) +{ +} + +static void +dri2_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_context *ctx = dri_context(dPriv->driContextPriv); + + dri2InvalidateDrawable(dPriv); + drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; + + if (ctx) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + +static const __DRI2flushExtension dri2FlushExtension = { + { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, + dri2_flush_drawable, + dri2_invalidate_drawable, +}; + +/** + * These are used for GLX_EXT_texture_from_pixmap + */ +static void +dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, + GLint format, __DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_context(pDRICtx); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *pt; + + dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); + + pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; + + if (pt) { + ctx->st->teximage(ctx->st, + (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, + 0, drawable->stvis.color_format, pt, FALSE); + } +} + +static void +dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, + __DRIdrawable *dPriv) +{ + dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); +} + +static const __DRItexBufferExtension dri2TexBufferExtension = { + { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, + dri2_set_tex_buffer, + dri2_set_tex_buffer2, +}; + +/** + * Get the format of an attachment. + */ +static INLINE enum pipe_format +dri2_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum pipe_format format; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + return format; +} + +/** + * Retrieve __DRIbuffer from the DRI loader. + */ +static __DRIbuffer * +dri2_drawable_get_buffers(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned *count) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + boolean with_format; + __DRIbuffer *buffers; + int num_buffers; + unsigned attachments[10]; + unsigned num_attachments, i; + + assert(loader); + with_format = dri_with_format(drawable->sPriv); + + num_attachments = 0; + + /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ + if (!with_format) + attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; + + for (i = 0; i < *count; i++) { + enum pipe_format format; + int att, bpp; + + format = dri2_drawable_get_format(drawable, statts[i]); + if (format == PIPE_FORMAT_NONE) + continue; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + /* already added */ + if (!with_format) + continue; + att = __DRI_BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + att = __DRI_BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + att = __DRI_BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + att = __DRI_BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + att = __DRI_BUFFER_DEPTH_STENCIL; + break; + default: + att = -1; + break; + } + + bpp = util_format_get_blocksizebits(format); + + if (att >= 0) { + attachments[num_attachments++] = att; + if (with_format) { + attachments[num_attachments++] = bpp; + } + } + } + + if (with_format) { + num_attachments /= 2; + buffers = loader->getBuffersWithFormat(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + else { + buffers = loader->getBuffers(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + + if (buffers) { + /* set one cliprect to cover the whole dri_drawable */ + dri_drawable->x = 0; + dri_drawable->y = 0; + dri_drawable->backX = 0; + dri_drawable->backY = 0; + dri_drawable->numClipRects = 1; + dri_drawable->pClipRects[0].x1 = 0; + dri_drawable->pClipRects[0].y1 = 0; + dri_drawable->pClipRects[0].x2 = dri_drawable->w; + dri_drawable->pClipRects[0].y2 = dri_drawable->h; + dri_drawable->numBackClipRects = 1; + dri_drawable->pBackClipRects[0].x1 = 0; + dri_drawable->pBackClipRects[0].y1 = 0; + dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; + dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; + + *count = num_buffers; + } + + return buffers; +} + +/** + * Process __DRIbuffer and convert them into pipe_textures. + */ +static void +dri2_drawable_process_buffers(struct dri_drawable *drawable, + __DRIbuffer *buffers, unsigned count) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + __DRIdrawable *dri_drawable = drawable->dPriv; + struct pipe_texture templ; + struct winsys_handle whandle; + boolean have_depth = FALSE; + unsigned i; + + if (drawable->old_num == count && + drawable->old_w == dri_drawable->w && + drawable->old_h == dri_drawable->h && + memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) + return; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + memset(&templ, 0, sizeof(templ)); + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri_drawable->w; + templ.height0 = dri_drawable->h; + templ.depth0 = 1; + + memset(&whandle, 0, sizeof(whandle)); + + for (i = 0; i < count; i++) { + __DRIbuffer *buf = &buffers[i]; + enum st_attachment_type statt; + enum pipe_format format; + + switch (buf->attachment) { + case __DRI_BUFFER_FRONT_LEFT: + if (!screen->auto_fake_front) { + statt = ST_ATTACHMENT_INVALID; + break; + } + /* fallthrough */ + case __DRI_BUFFER_FAKE_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case __DRI_BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case __DRI_BUFFER_DEPTH: + case __DRI_BUFFER_DEPTH_STENCIL: + case __DRI_BUFFER_STENCIL: + /* use only the first depth/stencil buffer */ + if (!have_depth) { + have_depth = TRUE; + statt = ST_ATTACHMENT_DEPTH_STENCIL; + } + else { + statt = ST_ATTACHMENT_INVALID; + } + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + format = dri2_drawable_get_format(drawable, statt); + if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + whandle.handle = buf->name; + whandle.stride = buf->pitch; + + drawable->textures[statt] = + screen->pipe_screen->texture_from_handle(screen->pipe_screen, + &templ, &whandle); + } + + drawable->old_num = count; + drawable->old_w = dri_drawable->w; + drawable->old_h = dri_drawable->h; + memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); +} + +/* + * Backend functions for st_framebuffer interface. + */ + +void +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) +{ + __DRIbuffer *buffers; + unsigned num_buffers = count; + + buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); + dri2_drawable_process_buffers(drawable, buffers, num_buffers); +} + +void +dri2_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + + if (loader->flushFrontBuffer == NULL) + return; + + if (statt == ST_ATTACHMENT_FRONT_LEFT) { + loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); + } +} + +/* + * Backend function init_screen. + */ + +static const __DRIextension *dri_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + &dri2TexBufferExtension.base, + &dri2FlushExtension.base, + NULL +}; + +/** + * This is the driver specific part of the createNewScreen entry point. + * + * Returns the __GLcontextModes supported by this driver. + */ +const __DRIconfig ** +dri2_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + sPriv->private = (void *)screen; + sPriv->extensions = dri_screen_extensions; + arg.mode = DRM_CREATE_NORMAL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + screen->auto_fake_front = dri_with_format(sPriv); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drm/dri2.h b/src/gallium/state_trackers/dri/drm/dri2.h new file mode 100644 index 00000000000..379963431fb --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri2.h @@ -0,0 +1,46 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRI2_H +#define DRI2_H + +#include "dri_drawable.h" +#include "dri_wrapper.h" + +const __DRIconfig ** +dri2_init_screen(__DRIscreen * sPriv); + +void +dri2_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count); + +#endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/drm/dri_context.c b/src/gallium/state_trackers/dri/drm/dri_context.c new file mode 120000 index 00000000000..989ef4438a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_context.c @@ -0,0 +1 @@ +../dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_drawable.c b/src/gallium/state_trackers/dri/drm/dri_drawable.c new file mode 120000 index 00000000000..422c4c1d740 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_drawable.c @@ -0,0 +1 @@ +../dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_extensions.c b/src/gallium/state_trackers/dri/drm/dri_extensions.c new file mode 120000 index 00000000000..b793f06747d --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_extensions.c @@ -0,0 +1 @@ +../dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_screen.c b/src/gallium/state_trackers/dri/drm/dri_screen.c new file mode 120000 index 00000000000..938f4c3bdc7 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_screen.c @@ -0,0 +1 @@ +../dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_st_api.c b/src/gallium/state_trackers/dri/drm/dri_st_api.c new file mode 120000 index 00000000000..9ae88230ddc --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_st_api.c @@ -0,0 +1 @@ +../dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/Makefile b/src/gallium/state_trackers/dri/sw/Makefile new file mode 100644 index 00000000000..35e31e6466a --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = drisw + +LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H + +LIBRARY_INCLUDES = \ + -I../dri \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + -D__NOT_HAVE_DRM_H + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + drisw.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/dri/sw/dri1_helper.c b/src/gallium/state_trackers/dri/sw/dri1_helper.c new file mode 120000 index 00000000000..7006a8d882f --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri1_helper.c @@ -0,0 +1 @@ +../dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_context.c b/src/gallium/state_trackers/dri/sw/dri_context.c new file mode 120000 index 00000000000..989ef4438a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_context.c @@ -0,0 +1 @@ +../dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c b/src/gallium/state_trackers/dri/sw/dri_drawable.c new file mode 120000 index 00000000000..422c4c1d740 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c @@ -0,0 +1 @@ +../dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_extensions.c b/src/gallium/state_trackers/dri/sw/dri_extensions.c new file mode 120000 index 00000000000..b793f06747d --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_extensions.c @@ -0,0 +1 @@ +../dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_screen.c b/src/gallium/state_trackers/dri/sw/dri_screen.c new file mode 120000 index 00000000000..938f4c3bdc7 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_screen.c @@ -0,0 +1 @@ +../dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_st_api.c b/src/gallium/state_trackers/dri/sw/dri_st_api.c new file mode 120000 index 00000000000..9ae88230ddc --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_st_api.c @@ -0,0 +1 @@ +../dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c new file mode 100644 index 00000000000..73bc45d9060 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -0,0 +1,318 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* TODO: + * + * stride: + * + * The driver and the loaders (libGL, xserver/glx) compute the stride from the + * width independently. winsys has a workaround that works for softpipe but may + * explode for other drivers or platforms, rendering- or performance-wise. + * Solving this issue properly requires extending the DRISW loader extension, + * in order to make the stride available to the putImage callback. + * + * drisw_api: + * + * Define drisw_api similarly to dri_api and use it to call the loader. This is + * predicated on support for calling the loader from the winsys, which has to + * grow for DRI2 as well. + * + * xshm: + * + * Allow the loaders to use the XSHM extension. It probably requires callbacks + * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth + * it, given the scope of DRISW, unless it falls naturally from properly + * solving the above two issues. + * + * swrast_create_screen: + * + * Allow for any software renderer to be used. Factor out the code from + * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and + * use it in all software targets. + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#include "drisw.h" + + +static INLINE void +get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + int x, y; + + loader->getDrawableInfo(dPriv, + &x, &y, w, h, + dPriv->loaderPrivate); +} + +static INLINE void +put_image(__DRIdrawable *dPriv, void *data) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + + loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, + 0, 0, dPriv->w, dPriv->h, + data, dPriv->loaderPrivate); +} + +void +drisw_update_drawable_info(__DRIdrawable *dPriv) +{ + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); +} + +static INLINE void +drisw_present_texture(__DRIdrawable *dPriv, + struct pipe_texture *ptex) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; + struct pipe_transfer *ptrans; + void *pmap; + + pipe = dri1_get_pipe_context(screen); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + + ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, dPriv->w, dPriv->h); + + pmap = pipe->transfer_map(pipe, ptrans); + + assert(pmap); + + put_image(dPriv, pmap); + + pipe->transfer_unmap(pipe, ptrans); + + pipe->tex_transfer_destroy(pipe, ptrans); +} + +static INLINE void +drisw_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + 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->stfb); +} + +static INLINE void +drisw_copy_to_front(__DRIdrawable * dPriv, + struct pipe_texture *ptex) +{ + drisw_present_texture(dPriv, ptex); + + drisw_invalidate_drawable(dPriv); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[statt]; + + if (ptex) { + drisw_copy_to_front(ctx->dPriv, ptex); + } +} + +void +drisw_swap_buffers(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; + + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + drisw_copy_to_front(dPriv, ptex); + } +} + +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + * + * It should be possible for DRI1 and DRISW to share this function, but it + * seems a better seperation and safer for each DRI version to provide its own + * function. + */ +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + unsigned width, height; + boolean resized; + int i; + + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + + /* remove outdated textures */ + if (resized) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; +} + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *drisw_screen_extensions[] = { + NULL +}; + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = -1; + sPriv->private = (void *)screen; + sPriv->extensions = drisw_screen_extensions; + arg.mode = DRM_CREATE_DRISW; + + screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/sw/drisw.h b/src/gallium/state_trackers/dri/sw/drisw.h new file mode 100644 index 00000000000..2c0d5610fac --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/drisw.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRISW_H +#define DRISW_H + +#include "dri_context.h" +#include "dri_drawable.h" + +#include "state_tracker/st_api.h" +#include "dri_wrapper.h" + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv); + +void +drisw_update_drawable_info(__DRIdrawable *dPriv); + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask); + +void drisw_swap_buffers(__DRIdrawable * dPriv); + +#endif /* DRISW_H */ diff --git a/src/gallium/state_trackers/drisw/Makefile b/src/gallium/state_trackers/drisw/Makefile deleted file mode 100644 index dec9a39edec..00000000000 --- a/src/gallium/state_trackers/drisw/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = drisw - -LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H - -LIBRARY_INCLUDES = \ - -I../dri \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -I$(TOP)/src/mesa/main \ - -D__NOT_HAVE_DRM_H - - -C_SOURCES = \ - dri_context.c \ - dri_screen.c \ - dri_drawable.c \ - dri_extensions.c \ - dri_st_api.c \ - dri1_helper.c \ - drisw.c - -include ../../Makefile.template diff --git a/src/gallium/state_trackers/drisw/dri1_helper.c b/src/gallium/state_trackers/drisw/dri1_helper.c deleted file mode 120000 index e704e382e05..00000000000 --- a/src/gallium/state_trackers/drisw/dri1_helper.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_context.c b/src/gallium/state_trackers/drisw/dri_context.c deleted file mode 120000 index e4e879dc867..00000000000 --- a/src/gallium/state_trackers/drisw/dri_context.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_drawable.c b/src/gallium/state_trackers/drisw/dri_drawable.c deleted file mode 120000 index d7f65c85d20..00000000000 --- a/src/gallium/state_trackers/drisw/dri_drawable.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_extensions.c b/src/gallium/state_trackers/drisw/dri_extensions.c deleted file mode 120000 index 60ecde9547d..00000000000 --- a/src/gallium/state_trackers/drisw/dri_extensions.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_screen.c b/src/gallium/state_trackers/drisw/dri_screen.c deleted file mode 120000 index f22c562c84f..00000000000 --- a/src/gallium/state_trackers/drisw/dri_screen.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_st_api.c b/src/gallium/state_trackers/drisw/dri_st_api.c deleted file mode 120000 index eac8ec66905..00000000000 --- a/src/gallium/state_trackers/drisw/dri_st_api.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/drisw.c b/src/gallium/state_trackers/drisw/drisw.c deleted file mode 120000 index 258a79021ef..00000000000 --- a/src/gallium/state_trackers/drisw/drisw.c +++ /dev/null @@ -1 +0,0 @@ -../dri/drisw.c \ No newline at end of file diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile index facbcb1803a..822d4b57bbb 100644 --- a/src/gallium/targets/dri-i915/Makefile +++ b/src/gallium/targets/dri-i915/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = i915_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile index c622bbcaf65..e267ba3a023 100644 --- a/src/gallium/targets/dri-i965/Makefile +++ b/src/gallium/targets/dri-i965/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = i965_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/winsys/sw/drm/libswdrm.a \ diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile index 9ba5e18ba70..74d352c6a70 100644 --- a/src/gallium/targets/dri-nouveau/Makefile +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = nouveau_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile index ce25559e946..66dd392b68b 100644 --- a/src/gallium/targets/dri-radeong/Makefile +++ b/src/gallium/targets/dri-radeong/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = radeong_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile index 57a9e02a4bb..3780da27550 100644 --- a/src/gallium/targets/dri-swrast/Makefile +++ b/src/gallium/targets/dri-swrast/Makefile @@ -6,7 +6,7 @@ LIBNAME = swrastg_dri.so DRIVER_DEFINES = -D__NOT_HAVE_DRM_H PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/drisw/libdrisw.a \ + $(TOP)/src/gallium/state_trackers/dri/sw/libdrisw.a \ $(TOP)/src/gallium/winsys/sw/dri/libswdri.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile index 32edc46a3d9..4b002e828fa 100644 --- a/src/gallium/targets/dri-vmwgfx/Makefile +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = vmwgfx_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a -- cgit v1.2.3 From ff0987a15da31a56c77f9a80c170e009f6056f33 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Fri, 26 Mar 2010 11:02:03 +0100 Subject: svga: Fix typo in configure script Introduced in a82e37b9e9e34175b7542d0c9b4e462833eab202 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index caa2cf65766..f2e87f4d4c2 100644 --- a/configure.ac +++ b/configure.ac @@ -1344,7 +1344,7 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga="$enableval"], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga/drm" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" gallium_check_st "svga/drm" "dri-vmwgfx" "egl-vmwgfx" "xorg-vmwgfx" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" -- cgit v1.2.3 From c727ef01083c873abfaf3c79b28d7cbcd6361bf3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 1 Apr 2010 11:17:43 +0800 Subject: progs/egl: Move demos a level deeper. Move the demos to "opengl" subdirectory. --- configs/linux-dri | 2 +- configs/linux-egl | 2 +- configure.ac | 2 +- progs/egl/.gitignore | 12 - progs/egl/Makefile | 70 --- progs/egl/demo1.c | 147 ------- progs/egl/demo2.c | 216 ---------- progs/egl/demo3.c | 647 ---------------------------- progs/egl/eglgears.c | 482 --------------------- progs/egl/eglinfo.c | 223 ---------- progs/egl/eglscreen.c | 120 ------ progs/egl/egltri.c | 264 ------------ progs/egl/opengl/.gitignore | 12 + progs/egl/opengl/Makefile | 70 +++ progs/egl/opengl/demo1.c | 147 +++++++ progs/egl/opengl/demo2.c | 216 ++++++++++ progs/egl/opengl/demo3.c | 647 ++++++++++++++++++++++++++++ progs/egl/opengl/eglgears.c | 482 +++++++++++++++++++++ progs/egl/opengl/eglinfo.c | 223 ++++++++++ progs/egl/opengl/eglscreen.c | 120 ++++++ progs/egl/opengl/egltri.c | 264 ++++++++++++ progs/egl/opengl/peglgears.c | 451 +++++++++++++++++++ progs/egl/opengl/xegl_tri.c | 361 ++++++++++++++++ progs/egl/opengl/xeglgears.c | 954 +++++++++++++++++++++++++++++++++++++++++ progs/egl/opengl/xeglthreads.c | 775 +++++++++++++++++++++++++++++++++ progs/egl/peglgears.c | 451 ------------------- progs/egl/xegl_tri.c | 361 ---------------- progs/egl/xeglgears.c | 954 ----------------------------------------- progs/egl/xeglthreads.c | 775 --------------------------------- 29 files changed, 4725 insertions(+), 4725 deletions(-) delete mode 100644 progs/egl/.gitignore delete mode 100644 progs/egl/Makefile delete mode 100644 progs/egl/demo1.c delete mode 100644 progs/egl/demo2.c delete mode 100644 progs/egl/demo3.c delete mode 100644 progs/egl/eglgears.c delete mode 100644 progs/egl/eglinfo.c delete mode 100644 progs/egl/eglscreen.c delete mode 100644 progs/egl/egltri.c create mode 100644 progs/egl/opengl/.gitignore create mode 100644 progs/egl/opengl/Makefile create mode 100644 progs/egl/opengl/demo1.c create mode 100644 progs/egl/opengl/demo2.c create mode 100644 progs/egl/opengl/demo3.c create mode 100644 progs/egl/opengl/eglgears.c create mode 100644 progs/egl/opengl/eglinfo.c create mode 100644 progs/egl/opengl/eglscreen.c create mode 100644 progs/egl/opengl/egltri.c create mode 100644 progs/egl/opengl/peglgears.c create mode 100644 progs/egl/opengl/xegl_tri.c create mode 100644 progs/egl/opengl/xeglgears.c create mode 100644 progs/egl/opengl/xeglthreads.c delete mode 100644 progs/egl/peglgears.c delete mode 100644 progs/egl/xegl_tri.c delete mode 100644 progs/egl/xeglgears.c delete mode 100644 progs/egl/xeglthreads.c (limited to 'configure.ac') diff --git a/configs/linux-dri b/configs/linux-dri index e21a3e95943..9017becdafe 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -52,7 +52,7 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ # Directories SRC_DIRS := glx egl $(SRC_DIRS) -PROGRAM_DIRS := egl $(PROGRAM_DIRS) +PROGRAM_DIRS := egl/opengl $(PROGRAM_DIRS) # EGL directories EGL_DRIVERS_DIRS = glx diff --git a/configs/linux-egl b/configs/linux-egl index 28165ed5b5a..cd664b4171f 100644 --- a/configs/linux-egl +++ b/configs/linux-egl @@ -48,7 +48,7 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ # Directories SRC_DIRS = gallium mesa gallium/winsys gallium/targets glu egl -PROGRAM_DIRS = egl +PROGRAM_DIRS = egl/opengl DRIVER_DIRS = dri GALLIUM_WINSYS_DIRS = egl_drm diff --git a/configure.ac b/configure.ac index f2e87f4d4c2..5647442ea17 100644 --- a/configure.ac +++ b/configure.ac @@ -954,7 +954,7 @@ if test "x$enable_egl" = xyes; then fi if test "$with_demos" = yes; then - PROGRAM_DIRS="$PROGRAM_DIRS egl" + PROGRAM_DIRS="$PROGRAM_DIRS egl/opengl" fi fi AC_SUBST([EGL_LIB_DEPS]) diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore deleted file mode 100644 index 7a13d4686a0..00000000000 --- a/progs/egl/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -demo1 -demo2 -demo3 -eglgears -eglinfo -eglscreen -egltri -peglgears -xeglbindtex -xeglgears -xeglthreads -xegl_tri diff --git a/progs/egl/Makefile b/progs/egl/Makefile deleted file mode 100644 index 890240f9a38..00000000000 --- a/progs/egl/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# progs/egl/Makefile - -TOP = ../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = -I$(TOP)/include - -HEADERS = $(TOP)/include/GLES/egl.h -LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so - -LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL - -PROGRAMS = \ - demo1 \ - demo2 \ - demo3 \ - egltri \ - eglinfo \ - eglgears \ - eglscreen \ - peglgears \ - xeglgears \ - xeglthreads \ - xegl_tri - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) - -demo1: demo1.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo2: demo2.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo3: demo3.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -egltri: egltri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) - -eglgears: eglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm - -eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -peglgears: peglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm - -xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) - -xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) - -xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) - -clean: - -rm -f *.o *~ - -rm -f $(PROGRAMS) diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c deleted file mode 100644 index d892734ee55..00000000000 --- a/progs/egl/demo1.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include - - -/** - * Test EGL_MESA_screen_surface functions - */ -static void -TestScreens(EGLDisplay dpy) -{ -#define MAX 8 - EGLScreenMESA screens[MAX]; - EGLint numScreens; - EGLint i; - - eglGetScreensMESA(dpy, screens, MAX, &numScreens); - printf("Found %d screens\n", numScreens); - for (i = 0; i < numScreens; i++) { - printf(" Screen %d handle: %d\n", i, (int) screens[i]); - } -} - -/** - * Print table of all available configurations. - */ -static void -PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs) -{ - EGLint i; - - printf("Configurations:\n"); - printf(" bf lv d st colorbuffer dp st supported \n"); - printf(" id sz l b ro r g b a th cl surfaces \n"); - printf("----------------------------------------------\n"); - for (i = 0; i < numConfigs; i++) { - EGLint id, size, level; - EGLint red, green, blue, alpha; - EGLint depth, stencil; - EGLint surfaces; - EGLint doubleBuf = 1, stereo = 0; - char surfString[100] = ""; - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); - eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); - - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); - eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); - eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); - eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); - - if (surfaces & EGL_WINDOW_BIT) - strcat(surfString, "win,"); - if (surfaces & EGL_PBUFFER_BIT) - strcat(surfString, "pb,"); - if (surfaces & EGL_PIXMAP_BIT) - strcat(surfString, "pix,"); - if (strlen(surfString) > 0) - surfString[strlen(surfString) - 1] = 0; - - printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n", - id, size, level, - doubleBuf ? 'y' : '.', - stereo ? 'y' : '.', - red, green, blue, alpha, - depth, stencil, surfString); - } -} - - - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface pbuffer; - EGLConfig *configs; - EGLint numConfigs; - EGLBoolean b; - const EGLint pbufAttribs[] = { - EGL_WIDTH, 500, - EGL_HEIGHT, 500, - EGL_NONE - }; - - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("demo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL version = %d.%d\n", maj, min); - printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - eglGetConfigs(d, NULL, 0, &numConfigs); - configs = malloc(sizeof(*configs) *numConfigs); - eglGetConfigs(d, configs, numConfigs, &numConfigs); - - PrintConfigs(d, configs, numConfigs); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("failed to create context\n"); - return 0; - } - - pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); - if (pbuffer == EGL_NO_SURFACE) { - printf("failed to create pbuffer\n"); - return 0; - } - - free(configs); - - b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - TestScreens(d); - - eglDestroySurface(d, pbuffer); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c deleted file mode 100644 index b9e92f62ac2..00000000000 --- a/progs/egl/demo2.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include - -#include -#include -#include - -/*#define FRONTBUFFER*/ - -static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, - GLfloat r, GLfloat g, GLfloat b) -{ - GLfloat v[4][2], c[4][4]; - int i; - - v[0][0] = x1; v[0][1] = y1; - v[1][0] = x2; v[1][1] = y1; - v[2][0] = x2; v[2][1] = y2; - v[3][0] = x1; v[3][1] = y2; - - for (i = 0; i < 4; i++) { - c[i][0] = r; - c[i][1] = g; - c[i][2] = b; - c[i][3] = 1.0; - } - - glVertexPointer(2, GL_FLOAT, 0, v); - glColorPointer(4, GL_FLOAT, 0, v); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); -} - - -static void redraw(EGLDisplay dpy, EGLSurface surf, int rot) -{ - GLfloat r, g, b; - - printf("Redraw event\n"); - - glClearColor( rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX, - 1); - - glClear( GL_COLOR_BUFFER_BIT ); - - r = rand()/(float)RAND_MAX; - g = rand()/(float)RAND_MAX; - b = rand()/(float)RAND_MAX; - - glPushMatrix(); - glRotatef(rot, 0, 0, 1); - glScalef(.5, .5, .5); - _subset_Rectf( -1, -1, 1, 1, r, g, b ); - glPopMatrix(); - -#ifdef FRONTBUFFER - glFlush(); -#else - eglSwapBuffers( dpy, surf ); -#endif - glFinish(); -} - - -/** - * Test EGL_MESA_screen_surface functions - */ -static void -TestScreens(EGLDisplay dpy) -{ -#define MAX 8 - EGLScreenMESA screens[MAX]; - EGLint numScreens; - EGLint i; - - eglGetScreensMESA(dpy, screens, MAX, &numScreens); - printf("Found %d screens\n", numScreens); - for (i = 0; i < numScreens; i++) { - printf(" Screen %d handle: %d\n", i, (int) screens[i]); - } -} - - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface pbuffer, screen_surf; - EGLConfig configs[10]; - EGLint numConfigs, i; - EGLBoolean b; - const EGLint pbufAttribs[] = { - EGL_WIDTH, 500, - EGL_HEIGHT, 500, - EGL_NONE - }; - EGLint screenAttribs[32]; - EGLModeMESA mode; - EGLScreenMESA screen; - EGLint count; - - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("demo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL version = %d.%d\n", maj, min); - printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - if (!strstr(eglQueryString(d, EGL_EXTENSIONS), - "EGL_MESA_screen_surface")) { - printf("EGL_MESA_screen_surface is not supported\n"); - exit(1); - } - - eglGetConfigs(d, configs, 10, &numConfigs); - printf("Got %d EGL configs:\n", numConfigs); - for (i = 0; i < numConfigs; i++) { - EGLint id, red, depth; - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); - printf("%2d: Red Size = %d Depth Size = %d\n", id, red, depth); - } - - eglGetScreensMESA(d, &screen, 1, &count); - eglGetModesMESA(d, screen, &mode, 1, &count); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("failed to create context\n"); - return 0; - } - - pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); - if (pbuffer == EGL_NO_SURFACE) { - printf("failed to create pbuffer\n"); - return 0; - } - - b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - i = 0; - screenAttribs[i++] = EGL_WIDTH; - eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]); - screenAttribs[i++] = EGL_HEIGHT; - eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]); - screenAttribs[i] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("failed to create screen surface\n"); - return 0; - } - - eglShowScreenSurfaceMESA(d, screen, screen_surf, mode); - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - glViewport(0, 0, 1024, 768); - - glClearColor( 0, - 1.0, - 0, - 1); - - glClear( GL_COLOR_BUFFER_BIT ); - - - TestScreens(d); - - glShadeModel( GL_FLAT ); - - for (i = 0; i < 6; i++) { - redraw(d, screen_surf, i*10 ); - - printf("sleep(1)\n"); - sleep(1); - } - - eglDestroySurface(d, pbuffer); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c deleted file mode 100644 index 64b9ee652cd..00000000000 --- a/progs/egl/demo3.c +++ /dev/null @@ -1,647 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include -#include -#include - - - -#define PIXEL_CENTER(x) ((long)(x) + 0.5) - -#define GAP 10 -#define ROWS 3 -#define COLS 4 - -#define OPENGL_WIDTH 48 -#define OPENGL_HEIGHT 13 - - -GLenum rgb, doubleBuffer, windType; -GLint windW, windH; - -GLenum mode1, mode2; -GLint boxW, boxH; -GLubyte OpenGL_bits[] = { - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, - 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01, - 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00, - 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00, - 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00, - 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00, - 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a, - 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e, - 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e, - 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00, -}; - - -static void Init(void) -{ - - mode1 = GL_TRUE; - mode2 = GL_TRUE; -} - -static void Reshape(int width, int height) -{ - - windW = (GLint)width; - windH = (GLint)height; -} - -#if 0 -static void RotateColorMask(void) -{ - static GLint rotation = 0; - - rotation = (rotation + 1) & 0x3; - switch (rotation) { - case 0: - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glIndexMask( 0xff ); - break; - case 1: - glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); - glIndexMask(0xFE); - break; - case 2: - glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); - glIndexMask(0xFD); - break; - case 3: - glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); - glIndexMask(0xFB); - break; - } -} -#endif - -static void Viewport(GLint row, GLint column) -{ - GLint x, y; - - boxW = (windW - (COLS + 1) * GAP) / COLS; - boxH = (windH - (ROWS + 1) * GAP) / ROWS; - - x = GAP + column * (boxW + GAP); - y = GAP + row * (boxH + GAP); - - glViewport(x, y, boxW, boxH); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0); - glMatrixMode(GL_MODELVIEW); - - glEnable(GL_SCISSOR_TEST); - glScissor(x, y, boxW, boxH); -} - -enum { - COLOR_BLACK = 0, - COLOR_RED, - COLOR_GREEN, - COLOR_YELLOW, - COLOR_BLUE, - COLOR_MAGENTA, - COLOR_CYAN, - COLOR_WHITE -}; - -static float RGBMap[9][3] = { - {0, 0, 0}, - {1, 0, 0}, - {0, 1, 0}, - {1, 1, 0}, - {0, 0, 1}, - {1, 0, 1}, - {0, 1, 1}, - {1, 1, 1}, - {0.5, 0.5, 0.5} -}; - -static void SetColor(int c) -{ - glColor3fv(RGBMap[c]); -} - -static void Point(void) -{ - GLint i; - - glBegin(GL_POINTS); - SetColor(COLOR_WHITE); - glVertex2i(0, 0); - for (i = 1; i < 8; i++) { - GLint j = i * 2; - SetColor(COLOR_BLACK+i); - glVertex2i(-j, -j); - glVertex2i(-j, 0); - glVertex2i(-j, j); - glVertex2i(0, j); - glVertex2i(j, j); - glVertex2i(j, 0); - glVertex2i(j, -j); - glVertex2i(0, -j); - } - glEnd(); -} - -static void Lines(void) -{ - GLint i; - - glPushMatrix(); - - glTranslatef(-12, 0, 0); - for (i = 1; i < 8; i++) { - SetColor(COLOR_BLACK+i); - glBegin(GL_LINES); - glVertex2i(-boxW/4, -boxH/4); - glVertex2i(boxW/4, boxH/4); - glEnd(); - glTranslatef(4, 0, 0); - } - - glPopMatrix(); - - glBegin(GL_LINES); - glVertex2i(0, 0); - glEnd(); -} - -static void LineStrip(void) -{ - - glBegin(GL_LINE_STRIP); - SetColor(COLOR_RED); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); - SetColor(COLOR_GREEN); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_BLUE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_WHITE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); - glEnd(); - - glBegin(GL_LINE_STRIP); - glVertex2i(0, 0); - glEnd(); -} - -static void LineLoop(void) -{ - - glBegin(GL_LINE_LOOP); - SetColor(COLOR_RED); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); - SetColor(COLOR_GREEN); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_BLUE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_WHITE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); - glEnd(); - - glEnable(GL_LOGIC_OP); - glLogicOp(GL_XOR); - - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - - SetColor(COLOR_MAGENTA); - glBegin(GL_LINE_LOOP); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8)); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8)); - glEnd(); - glBegin(GL_LINE_LOOP); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5)); - glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5)); - glEnd(); - glDisable(GL_LOGIC_OP); - glDisable(GL_BLEND); - - SetColor(COLOR_GREEN); - glBegin(GL_POINTS); - glVertex2i(0, 0); - glEnd(); - - glBegin(GL_LINE_LOOP); - glVertex2i(0, 0); - glEnd(); -} - -static void Bitmap(void) -{ - - glBegin(GL_LINES); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/2, 0); - glVertex2i(boxW/2, 0); - glVertex2i(0, -boxH/2); - glVertex2i(0, boxH/2); - SetColor(COLOR_RED); - glVertex2i(0, -3); - glVertex2i(0, -3+OPENGL_HEIGHT); - SetColor(COLOR_BLUE); - glVertex2i(0, -3); - glVertex2i(OPENGL_WIDTH, -3); - glEnd(); - - SetColor(COLOR_GREEN); - - glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - glRasterPos2i(0, 0); - glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits); -} - -static void Triangles(void) -{ - - glBegin(GL_TRIANGLES); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, -boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, -boxH/16); - - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, boxH/16); - glEnd(); - - glBegin(GL_TRIANGLES); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void TriangleStrip(void) -{ - - glBegin(GL_TRIANGLE_STRIP); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_BLUE); - glVertex2i(0, -boxH/4); - SetColor(COLOR_WHITE); - glVertex2i(0, boxH/4); - SetColor(COLOR_CYAN); - glVertex2i(boxW/4, -boxH/4); - SetColor(COLOR_YELLOW); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_TRIANGLE_STRIP); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void TriangleFan(void) -{ - GLint vx[8][2]; - GLint x0, y0, x1, y1, x2, y2, x3, y3; - GLint i; - - y0 = -boxH/4; - y1 = y0 + boxH/2/3; - y2 = y1 + boxH/2/3; - y3 = boxH/4; - x0 = -boxW/4; - x1 = x0 + boxW/2/3; - x2 = x1 + boxW/2/3; - x3 = boxW/4; - - vx[0][0] = x0; vx[0][1] = y1; - vx[1][0] = x0; vx[1][1] = y2; - vx[2][0] = x1; vx[2][1] = y3; - vx[3][0] = x2; vx[3][1] = y3; - vx[4][0] = x3; vx[4][1] = y2; - vx[5][0] = x3; vx[5][1] = y1; - vx[6][0] = x2; vx[6][1] = y0; - vx[7][0] = x1; vx[7][1] = y0; - - glBegin(GL_TRIANGLE_FAN); - SetColor(COLOR_WHITE); - glVertex2i(0, 0); - for (i = 0; i < 8; i++) { - SetColor(COLOR_WHITE-i); - glVertex2iv(vx[i]); - } - glEnd(); - - glBegin(GL_TRIANGLE_FAN); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void Rect(void) -{ - - SetColor(COLOR_GREEN); - glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4); -} - -static void PolygonFunc(void) -{ - GLint vx[8][2]; - GLint x0, y0, x1, y1, x2, y2, x3, y3; - GLint i; - - y0 = -boxH/4; - y1 = y0 + boxH/2/3; - y2 = y1 + boxH/2/3; - y3 = boxH/4; - x0 = -boxW/4; - x1 = x0 + boxW/2/3; - x2 = x1 + boxW/2/3; - x3 = boxW/4; - - vx[0][0] = x0; vx[0][1] = y1; - vx[1][0] = x0; vx[1][1] = y2; - vx[2][0] = x1; vx[2][1] = y3; - vx[3][0] = x2; vx[3][1] = y3; - vx[4][0] = x3; vx[4][1] = y2; - vx[5][0] = x3; vx[5][1] = y1; - vx[6][0] = x2; vx[6][1] = y0; - vx[7][0] = x1; vx[7][1] = y0; - - glBegin(GL_POLYGON); - for (i = 0; i < 8; i++) { - SetColor(COLOR_WHITE-i); - glVertex2iv(vx[i]); - } - glEnd(); - - glBegin(GL_POLYGON); - glVertex2i(0, 0); - glVertex2i(100, 100); - glEnd(); -} - -static void Quads(void) -{ - - glBegin(GL_QUADS); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, -boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, -boxH/16); - SetColor(COLOR_WHITE); - glVertex2i(boxW/4, -boxH/4); - - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, boxH/16); - SetColor(COLOR_WHITE); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_QUADS); - glVertex2i(0, 0); - glVertex2i(100, 100); - glVertex2i(-100, 100); - glEnd(); -} - -static void QuadStrip(void) -{ - - glBegin(GL_QUAD_STRIP); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_BLUE); - glVertex2i(0, -boxH/4); - SetColor(COLOR_WHITE); - glVertex2i(0, boxH/4); - SetColor(COLOR_CYAN); - glVertex2i(boxW/4, -boxH/4); - SetColor(COLOR_YELLOW); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_QUAD_STRIP); - glVertex2i(0, 0); - glVertex2i(100, 100); - glVertex2i(-100, 100); - glEnd(); -} - -static void Draw(EGLDisplay dpy, EGLSurface surf) -{ - - glViewport(0, 0, windW, windH); - glDisable(GL_SCISSOR_TEST); - - glPushAttrib(GL_COLOR_BUFFER_BIT); - - glColorMask(1, 1, 1, 1); - glIndexMask(~0); - - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - glPopAttrib(); - - if (mode1) { - glShadeModel(GL_SMOOTH); - } else { - glShadeModel(GL_FLAT); - } - - if (mode2) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } else { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - } - - Viewport(0, 0); Point(); - Viewport(0, 1); Lines(); - Viewport(0, 2); LineStrip(); - Viewport(0, 3); LineLoop(); - - Viewport(1, 0); Bitmap(); - - Viewport(1, 1); TriangleFan(); - Viewport(1, 2); Triangles(); - Viewport(1, 3); TriangleStrip(); - - Viewport(2, 0); Rect(); - Viewport(2, 1); PolygonFunc(); - Viewport(2, 2); Quads(); - Viewport(2, 3); QuadStrip(); - - glFlush(); - - if (doubleBuffer) { - eglSwapBuffers(dpy, surf); - } -} - -static void -write_ppm(const char *filename, const GLubyte *buffer, int width, int height) -{ - const int binary = 0; - FILE *f = fopen( filename, "w" ); - if (f) { - int i, x, y; - const GLubyte *ptr = buffer; - if (binary) { - fprintf(f,"P6\n"); - fprintf(f,"# ppm-file created by osdemo.c\n"); - fprintf(f,"%i %i\n", width,height); - fprintf(f,"255\n"); - fclose(f); - f = fopen( filename, "ab" ); /* reopen in binary append mode */ - for (y=height-1; y>=0; y--) { - for (x=0; x=0; y--) { - for (x=0; x -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include -#include - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static GLint gear1, gear2, gear3; -static GLfloat angle = 0.0; - -#if 0 -static GLfloat eyesep = 5.0; /* Eye separation. */ -static GLfloat fix_point = 40.0; /* Fixation point distance. */ -static GLfloat left, right, asp; /* Stereo frustum params. */ -#endif - - -/* - * - * Draw a gear wheel. You'll probably want to call this function when - * building a display list since we do a lot of trig here. - * - * Input: inner_radius - radius of hole at center - * outer_radius - radius at center of teeth - * width - width of gear - * teeth - number of teeth - * tooth_depth - depth of tooth - */ -static void -gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, - GLint teeth, GLfloat tooth_depth) -{ - GLint i; - GLfloat r0, r1, r2; - GLfloat angle, da; - GLfloat u, v, len; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0; - r2 = outer_radius + tooth_depth / 2.0; - - da = 2.0 * M_PI / teeth / 4.0; - - glShadeModel(GL_FLAT); - - glNormal3f(0.0, 0.0, 1.0); - - /* draw front face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - if (i < teeth) { - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - } - glEnd(); - - /* draw front sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - glEnd(); - - glNormal3f(0.0, 0.0, -1.0); - - /* draw back face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - if (i < teeth) { - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - } - } - glEnd(); - - /* draw back sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - } - glEnd(); - - /* draw outward faces of teeth */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - u = r2 * cos(angle + da) - r1 * cos(angle); - v = r2 * sin(angle + da) - r1 * sin(angle); - len = sqrt(u * u + v * v); - u /= len; - v /= len; - glNormal3f(v, -u, 0.0); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); - v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); - glNormal3f(v, -u, 0.0); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - } - - glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); - glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); - - glEnd(); - - glShadeModel(GL_SMOOTH); - - /* draw inside radius cylinder */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glNormal3f(-cos(angle), -sin(angle), 0.0); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - } - glEnd(); -} - - -static void -draw(void) -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1.0, 0.0, 0.0); - glRotatef(view_roty, 0.0, 1.0, 0.0); - glRotatef(view_rotz, 0.0, 0.0, 1.0); - - glPushMatrix(); - glTranslatef(-3.0, -2.0, 0.0); - glRotatef(angle, 0.0, 0.0, 1.0); - glCallList(gear1); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(3.1, -2.0, 0.0); - glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); - glCallList(gear2); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(-3.1, 4.2, 0.0); - glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); - glCallList(gear3); - glPopMatrix(); - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat h = (GLfloat) height / (GLfloat) width; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); -} - - - -static void -init(void) -{ - static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; - static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; - static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; - static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; - - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - - /* make the gears */ - gear1 = glGenLists(1); - glNewList(gear1, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); - gear(1.0, 4.0, 1.0, 20, 0.7); - glEndList(); - - gear2 = glGenLists(1); - glNewList(gear2, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); - gear(0.5, 2.0, 2.0, 10, 0.7); - glEndList(); - - gear3 = glGenLists(1); - glNewList(gear3, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); - gear(1.3, 2.0, 0.5, 10, 0.7); - glEndList(); - - glEnable(GL_NORMALIZE); -} - - - - -static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) -{ - double st = current_time(); - double ct = st; - int frames = 0; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - double tt = current_time(); - double dt = tt - ct; - ct = tt; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - draw(); - - eglSwapBuffers(dpy, surf); - - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); - -} - - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface screen_surf; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - EGLModeMESA mode[MAX_MODES]; - EGLScreenMESA screen; - EGLint count; - EGLint chosenMode = 0; - GLboolean printInfo = GL_FALSE; - EGLint width = 0, height = 0; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-info") == 0) - { - printInfo = GL_TRUE; - } - else - printf("Warning: unknown parameter: %s\n", argv[i]); - } - - /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("eglgears: eglInitialize failed\n"); - exit(1); - } - - printf("eglgears: EGL version = %d.%d\n", maj, min); - printf("eglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - /* XXX use ChooseConfig */ - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - - if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { - printf("eglgears: eglGetModesMESA failed!\n"); - return 0; - } - - /* Print list of modes, and find the one to use */ - printf("eglgears: Found %d modes:\n", count); - for (i = 0; i < count; i++) { - EGLint w, h; - eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - chosenMode = i; - } - } - printf("eglgears: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("eglgears: failed to create context\n"); - return 0; - } - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("eglgears: failed to create screen surface\n"); - return 0; - } - - b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); - if (!b) { - printf("eglgears: show surface failed\n"); - return 0; - } - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("eglgears: make current failed\n"); - return 0; - } - - if (printInfo) - { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - reshape(width, height); - - glDrawBuffer( GL_BACK ); - - run_gears(d, screen_surf, 5.0); - - eglDestroySurface(d, screen_surf); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c deleted file mode 100644 index 961fd9ccc76..00000000000 --- a/progs/egl/eglinfo.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * eglinfo - like glxinfo but for EGL - * - * Brian Paul - * 11 March 2005 - * - * Copyright (C) 2005 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include - -#define MAX_CONFIGS 1000 -#define MAX_MODES 1000 -#define MAX_SCREENS 10 - -/* These are X visual types, so if you're running eglinfo under - * something not X, they probably don't make sense. */ -static const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" }; - -/** - * Print table of all available configurations. - */ -static void -PrintConfigs(EGLDisplay d) -{ - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - - printf("Configurations:\n"); - printf(" bf lv colorbuffer dp st ms vis cav bi renderable supported\n"); - printf(" id sz l r g b a th cl ns b id eat nd gl es es2 vg surfaces \n"); - printf("---------------------------------------------------------------------\n"); - for (i = 0; i < numConfigs; i++) { - EGLint id, size, level; - EGLint red, green, blue, alpha; - EGLint depth, stencil; - EGLint renderable, surfaces; - EGLint vid, vtype, caveat, bindRgb, bindRgba; - EGLint samples, sampleBuffers; - char surfString[100] = ""; - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); - eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); - - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); - eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); - eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); - eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid); - eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype); - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat); - eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb); - eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba); - eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable); - eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); - - eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples); - eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers); - - if (surfaces & EGL_WINDOW_BIT) - strcat(surfString, "win,"); - if (surfaces & EGL_PBUFFER_BIT) - strcat(surfString, "pb,"); - if (surfaces & EGL_PIXMAP_BIT) - strcat(surfString, "pix,"); -#ifdef EGL_MESA_screen_surface - if (surfaces & EGL_SCREEN_BIT_MESA) - strcat(surfString, "scrn,"); -#endif - if (strlen(surfString) > 0) - surfString[strlen(surfString) - 1] = 0; - - printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ", - id, size, level, - red, green, blue, alpha, - depth, stencil, - samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--"); - printf(" %c %c %c %c %c %c %s\n", - (caveat != EGL_NONE) ? 'y' : ' ', - (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ', - (renderable & EGL_OPENGL_BIT) ? 'y' : ' ', - (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ', - (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ', - (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', - surfString); - } -} - - -/** - * Print table of all available configurations. - */ -static void -PrintModes(EGLDisplay d) -{ -#ifdef EGL_MESA_screen_surface - const char *extensions = eglQueryString(d, EGL_EXTENSIONS); - if (strstr(extensions, "EGL_MESA_screen_surface")) { - EGLScreenMESA screens[MAX_SCREENS]; - EGLint numScreens = 1, scrn; - EGLModeMESA modes[MAX_MODES]; - - eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens); - printf("Number of Screens: %d\n\n", numScreens); - - for (scrn = 0; scrn < numScreens; scrn++) { - EGLint numModes, i; - - eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes); - - printf("Screen %d Modes:\n", scrn); - printf(" id width height refresh name\n"); - printf("-----------------------------------------\n"); - for (i = 0; i < numModes; i++) { - EGLint id, w, h, r; - const char *str; - eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id); - eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h); - eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r); - str = eglQueryModeStringMESA(d, modes[i]); - printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str); - } - } - } -#endif -} - -static void -PrintExtensions(EGLDisplay d) -{ - const char *extensions, *p, *end, *next; - int column; - - printf("EGL extensions string:\n"); - - extensions = eglQueryString(d, EGL_EXTENSIONS); - - column = 0; - end = extensions + strlen(extensions); - - for (p = extensions; p < end; p = next + 1) { - next = strchr(p, ' '); - if (next == NULL) - next = end; - - if (column > 0 && column + next - p + 1 > 70) { - printf("\n"); - column = 0; - } - if (column == 0) - printf(" "); - else - printf(" "); - column += next - p + 1; - - printf("%.*s", (int) (next - p), p); - - p = next + 1; - } - - if (column > 0) - printf("\n"); -} - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - - if (!eglInitialize(d, &maj, &min)) { - printf("eglinfo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL API version: %d.%d\n", maj, min); - printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR)); - printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION)); -#ifdef EGL_VERSION_1_2 - printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS)); -#endif - - PrintExtensions(d); - - PrintConfigs(d); - - PrintModes(d); - - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/eglscreen.c b/progs/egl/eglscreen.c deleted file mode 100644 index 520f76ea036..00000000000 --- a/progs/egl/eglscreen.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -/* - * Stolen from eglgears - * - * Creates a surface and show that on the first screen - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLSurface screen_surf; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - EGLModeMESA mode[MAX_MODES]; - EGLScreenMESA screen; - EGLint count; - EGLint chosenMode = 0; - EGLint width = 0, height = 0; - - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("eglscreen: eglInitialize failed\n"); - exit(1); - } - - printf("eglscreen: EGL version = %d.%d\n", maj, min); - printf("eglscreen: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - /* XXX use ChooseConfig */ - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - - if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { - printf("eglscreen: eglGetModesMESA failed!\n"); - return 0; - } - - /* Print list of modes, and find the one to use */ - printf("eglscreen: Found %d modes:\n", count); - for (i = 0; i < count; i++) { - EGLint w, h; - eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - chosenMode = i; - } - } - printf("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("eglscreen: Failed to create screen surface\n"); - return 0; - } - - b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); - if (!b) { - printf("eglscreen: Show surface failed\n"); - return 0; - } - - usleep(5000000); - - eglDestroySurface(d, screen_surf); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c deleted file mode 100644 index 006e06eb03e..00000000000 --- a/progs/egl/egltri.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -/* - * This program is based on eglgears and xegl_tri. - * Remixed by Jakob Bornecrantz - * - * No command line options. - * Program runs for 5 seconds then exits, outputing framerate to console - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - - -/* XXX this probably isn't very portable */ - -#include -#include - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - -static void draw() -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(3, GL_FLOAT, 0, colors); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - glPopMatrix(); -} - -static void init() -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} - -/* new window size or exposure */ -static void reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - -static void run(EGLDisplay dpy, EGLSurface surf, int ttr) -{ - double st = current_time(); - double ct = st; - int frames = 0; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - ct = current_time(); - - draw(); - - eglSwapBuffers(dpy, surf); - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); -} - -int main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface screen_surf; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - EGLModeMESA mode[MAX_MODES]; - EGLScreenMESA screen; - EGLint count, chosenMode = 0; - GLboolean printInfo = GL_FALSE; - EGLint width = 0, height = 0; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-info") == 0) - { - printInfo = GL_TRUE; - } - else - printf("Warning: unknown parameter: %s\n", argv[i]); - } - - /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("egltri: eglInitialize failed\n"); - exit(1); - } - - printf("egltri: EGL version = %d.%d\n", maj, min); - printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - /* XXX use ChooseConfig */ - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - - if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { - printf("egltri: eglGetModesMESA failed!\n"); - return 0; - } - - /* Print list of modes, and find the one to use */ - printf("egltri: Found %d modes:\n", count); - for (i = 0; i < count; i++) { - EGLint w, h; - eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - chosenMode = i; - } - } - printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("egltri: failed to create context\n"); - return 0; - } - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("egltri: failed to create screen surface\n"); - return 0; - } - - b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); - if (!b) { - printf("egltri: show surface failed\n"); - return 0; - } - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("egltri: make current failed\n"); - return 0; - } - - if (printInfo) - { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - reshape(width, height); - - glDrawBuffer( GL_BACK ); - - run(d, screen_surf, 5.0); - - eglDestroySurface(d, screen_surf); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/.gitignore b/progs/egl/opengl/.gitignore new file mode 100644 index 00000000000..7a13d4686a0 --- /dev/null +++ b/progs/egl/opengl/.gitignore @@ -0,0 +1,12 @@ +demo1 +demo2 +demo3 +eglgears +eglinfo +eglscreen +egltri +peglgears +xeglbindtex +xeglgears +xeglthreads +xegl_tri diff --git a/progs/egl/opengl/Makefile b/progs/egl/opengl/Makefile new file mode 100644 index 00000000000..50a60c701d0 --- /dev/null +++ b/progs/egl/opengl/Makefile @@ -0,0 +1,70 @@ +# progs/egl/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +INCLUDE_DIRS = -I$(TOP)/include + +HEADERS = $(TOP)/include/GLES/egl.h +LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so + +LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL + +PROGRAMS = \ + demo1 \ + demo2 \ + demo3 \ + egltri \ + eglinfo \ + eglgears \ + eglscreen \ + peglgears \ + xeglgears \ + xeglthreads \ + xegl_tri + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) + +demo1: demo1.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +demo2: demo2.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +demo3: demo3.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +egltri: egltri.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) + +eglgears: eglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm + +eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +peglgears: peglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm + +xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) + +xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) + +xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) + +clean: + -rm -f *.o *~ + -rm -f $(PROGRAMS) diff --git a/progs/egl/opengl/demo1.c b/progs/egl/opengl/demo1.c new file mode 100644 index 00000000000..d892734ee55 --- /dev/null +++ b/progs/egl/opengl/demo1.c @@ -0,0 +1,147 @@ +/* + * Exercise EGL API functions + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include + + +/** + * Test EGL_MESA_screen_surface functions + */ +static void +TestScreens(EGLDisplay dpy) +{ +#define MAX 8 + EGLScreenMESA screens[MAX]; + EGLint numScreens; + EGLint i; + + eglGetScreensMESA(dpy, screens, MAX, &numScreens); + printf("Found %d screens\n", numScreens); + for (i = 0; i < numScreens; i++) { + printf(" Screen %d handle: %d\n", i, (int) screens[i]); + } +} + +/** + * Print table of all available configurations. + */ +static void +PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs) +{ + EGLint i; + + printf("Configurations:\n"); + printf(" bf lv d st colorbuffer dp st supported \n"); + printf(" id sz l b ro r g b a th cl surfaces \n"); + printf("----------------------------------------------\n"); + for (i = 0; i < numConfigs; i++) { + EGLint id, size, level; + EGLint red, green, blue, alpha; + EGLint depth, stencil; + EGLint surfaces; + EGLint doubleBuf = 1, stereo = 0; + char surfString[100] = ""; + + eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); + eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); + eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); + + eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); + eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); + eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); + eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); + eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); + eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); + eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); + + if (surfaces & EGL_WINDOW_BIT) + strcat(surfString, "win,"); + if (surfaces & EGL_PBUFFER_BIT) + strcat(surfString, "pb,"); + if (surfaces & EGL_PIXMAP_BIT) + strcat(surfString, "pix,"); + if (strlen(surfString) > 0) + surfString[strlen(surfString) - 1] = 0; + + printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n", + id, size, level, + doubleBuf ? 'y' : '.', + stereo ? 'y' : '.', + red, green, blue, alpha, + depth, stencil, surfString); + } +} + + + +int +main(int argc, char *argv[]) +{ + int maj, min; + EGLContext ctx; + EGLSurface pbuffer; + EGLConfig *configs; + EGLint numConfigs; + EGLBoolean b; + const EGLint pbufAttribs[] = { + EGL_WIDTH, 500, + EGL_HEIGHT, 500, + EGL_NONE + }; + + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("demo: eglInitialize failed\n"); + exit(1); + } + + printf("EGL version = %d.%d\n", maj, min); + printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + eglGetConfigs(d, NULL, 0, &numConfigs); + configs = malloc(sizeof(*configs) *numConfigs); + eglGetConfigs(d, configs, numConfigs, &numConfigs); + + PrintConfigs(d, configs, numConfigs); + + eglBindAPI(EGL_OPENGL_API); + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("failed to create context\n"); + return 0; + } + + pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); + if (pbuffer == EGL_NO_SURFACE) { + printf("failed to create pbuffer\n"); + return 0; + } + + free(configs); + + b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); + if (!b) { + printf("make current failed\n"); + return 0; + } + + b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + TestScreens(d); + + eglDestroySurface(d, pbuffer); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/demo2.c b/progs/egl/opengl/demo2.c new file mode 100644 index 00000000000..b9e92f62ac2 --- /dev/null +++ b/progs/egl/opengl/demo2.c @@ -0,0 +1,216 @@ +/* + * Exercise EGL API functions + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include + +#include +#include +#include + +/*#define FRONTBUFFER*/ + +static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, + GLfloat r, GLfloat g, GLfloat b) +{ + GLfloat v[4][2], c[4][4]; + int i; + + v[0][0] = x1; v[0][1] = y1; + v[1][0] = x2; v[1][1] = y1; + v[2][0] = x2; v[2][1] = y2; + v[3][0] = x1; v[3][1] = y2; + + for (i = 0; i < 4; i++) { + c[i][0] = r; + c[i][1] = g; + c[i][2] = b; + c[i][3] = 1.0; + } + + glVertexPointer(2, GL_FLOAT, 0, v); + glColorPointer(4, GL_FLOAT, 0, v); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); +} + + +static void redraw(EGLDisplay dpy, EGLSurface surf, int rot) +{ + GLfloat r, g, b; + + printf("Redraw event\n"); + + glClearColor( rand()/(float)RAND_MAX, + rand()/(float)RAND_MAX, + rand()/(float)RAND_MAX, + 1); + + glClear( GL_COLOR_BUFFER_BIT ); + + r = rand()/(float)RAND_MAX; + g = rand()/(float)RAND_MAX; + b = rand()/(float)RAND_MAX; + + glPushMatrix(); + glRotatef(rot, 0, 0, 1); + glScalef(.5, .5, .5); + _subset_Rectf( -1, -1, 1, 1, r, g, b ); + glPopMatrix(); + +#ifdef FRONTBUFFER + glFlush(); +#else + eglSwapBuffers( dpy, surf ); +#endif + glFinish(); +} + + +/** + * Test EGL_MESA_screen_surface functions + */ +static void +TestScreens(EGLDisplay dpy) +{ +#define MAX 8 + EGLScreenMESA screens[MAX]; + EGLint numScreens; + EGLint i; + + eglGetScreensMESA(dpy, screens, MAX, &numScreens); + printf("Found %d screens\n", numScreens); + for (i = 0; i < numScreens; i++) { + printf(" Screen %d handle: %d\n", i, (int) screens[i]); + } +} + + +int +main(int argc, char *argv[]) +{ + int maj, min; + EGLContext ctx; + EGLSurface pbuffer, screen_surf; + EGLConfig configs[10]; + EGLint numConfigs, i; + EGLBoolean b; + const EGLint pbufAttribs[] = { + EGL_WIDTH, 500, + EGL_HEIGHT, 500, + EGL_NONE + }; + EGLint screenAttribs[32]; + EGLModeMESA mode; + EGLScreenMESA screen; + EGLint count; + + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("demo: eglInitialize failed\n"); + exit(1); + } + + printf("EGL version = %d.%d\n", maj, min); + printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + if (!strstr(eglQueryString(d, EGL_EXTENSIONS), + "EGL_MESA_screen_surface")) { + printf("EGL_MESA_screen_surface is not supported\n"); + exit(1); + } + + eglGetConfigs(d, configs, 10, &numConfigs); + printf("Got %d EGL configs:\n", numConfigs); + for (i = 0; i < numConfigs; i++) { + EGLint id, red, depth; + eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); + eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); + eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); + printf("%2d: Red Size = %d Depth Size = %d\n", id, red, depth); + } + + eglGetScreensMESA(d, &screen, 1, &count); + eglGetModesMESA(d, screen, &mode, 1, &count); + + eglBindAPI(EGL_OPENGL_API); + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("failed to create context\n"); + return 0; + } + + pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); + if (pbuffer == EGL_NO_SURFACE) { + printf("failed to create pbuffer\n"); + return 0; + } + + b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); + if (!b) { + printf("make current failed\n"); + return 0; + } + + b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + i = 0; + screenAttribs[i++] = EGL_WIDTH; + eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]); + screenAttribs[i++] = EGL_HEIGHT; + eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]); + screenAttribs[i] = EGL_NONE; + + screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); + if (screen_surf == EGL_NO_SURFACE) { + printf("failed to create screen surface\n"); + return 0; + } + + eglShowScreenSurfaceMESA(d, screen, screen_surf, mode); + + b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); + if (!b) { + printf("make current failed\n"); + return 0; + } + + glViewport(0, 0, 1024, 768); + + glClearColor( 0, + 1.0, + 0, + 1); + + glClear( GL_COLOR_BUFFER_BIT ); + + + TestScreens(d); + + glShadeModel( GL_FLAT ); + + for (i = 0; i < 6; i++) { + redraw(d, screen_surf, i*10 ); + + printf("sleep(1)\n"); + sleep(1); + } + + eglDestroySurface(d, pbuffer); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/demo3.c b/progs/egl/opengl/demo3.c new file mode 100644 index 00000000000..64b9ee652cd --- /dev/null +++ b/progs/egl/opengl/demo3.c @@ -0,0 +1,647 @@ +/* + * Exercise EGL API functions + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include + + + +#define PIXEL_CENTER(x) ((long)(x) + 0.5) + +#define GAP 10 +#define ROWS 3 +#define COLS 4 + +#define OPENGL_WIDTH 48 +#define OPENGL_HEIGHT 13 + + +GLenum rgb, doubleBuffer, windType; +GLint windW, windH; + +GLenum mode1, mode2; +GLint boxW, boxH; +GLubyte OpenGL_bits[] = { + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01, + 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00, + 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e, + 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e, + 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00, +}; + + +static void Init(void) +{ + + mode1 = GL_TRUE; + mode2 = GL_TRUE; +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; +} + +#if 0 +static void RotateColorMask(void) +{ + static GLint rotation = 0; + + rotation = (rotation + 1) & 0x3; + switch (rotation) { + case 0: + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask( 0xff ); + break; + case 1: + glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask(0xFE); + break; + case 2: + glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); + glIndexMask(0xFD); + break; + case 3: + glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); + glIndexMask(0xFB); + break; + } +} +#endif + +static void Viewport(GLint row, GLint column) +{ + GLint x, y; + + boxW = (windW - (COLS + 1) * GAP) / COLS; + boxH = (windH - (ROWS + 1) * GAP) / ROWS; + + x = GAP + column * (boxW + GAP); + y = GAP + row * (boxH + GAP); + + glViewport(x, y, boxW, boxH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glEnable(GL_SCISSOR_TEST); + glScissor(x, y, boxW, boxH); +} + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +static float RGBMap[9][3] = { + {0, 0, 0}, + {1, 0, 0}, + {0, 1, 0}, + {1, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {0, 1, 1}, + {1, 1, 1}, + {0.5, 0.5, 0.5} +}; + +static void SetColor(int c) +{ + glColor3fv(RGBMap[c]); +} + +static void Point(void) +{ + GLint i; + + glBegin(GL_POINTS); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 1; i < 8; i++) { + GLint j = i * 2; + SetColor(COLOR_BLACK+i); + glVertex2i(-j, -j); + glVertex2i(-j, 0); + glVertex2i(-j, j); + glVertex2i(0, j); + glVertex2i(j, j); + glVertex2i(j, 0); + glVertex2i(j, -j); + glVertex2i(0, -j); + } + glEnd(); +} + +static void Lines(void) +{ + GLint i; + + glPushMatrix(); + + glTranslatef(-12, 0, 0); + for (i = 1; i < 8; i++) { + SetColor(COLOR_BLACK+i); + glBegin(GL_LINES); + glVertex2i(-boxW/4, -boxH/4); + glVertex2i(boxW/4, boxH/4); + glEnd(); + glTranslatef(4, 0, 0); + } + + glPopMatrix(); + + glBegin(GL_LINES); + glVertex2i(0, 0); + glEnd(); +} + +static void LineStrip(void) +{ + + glBegin(GL_LINE_STRIP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2i(0, 0); + glEnd(); +} + +static void LineLoop(void) +{ + + glBegin(GL_LINE_LOOP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glEnable(GL_LOGIC_OP); + glLogicOp(GL_XOR); + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + + SetColor(COLOR_MAGENTA); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8)); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8)); + glEnd(); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5)); + glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5)); + glEnd(); + glDisable(GL_LOGIC_OP); + glDisable(GL_BLEND); + + SetColor(COLOR_GREEN); + glBegin(GL_POINTS); + glVertex2i(0, 0); + glEnd(); + + glBegin(GL_LINE_LOOP); + glVertex2i(0, 0); + glEnd(); +} + +static void Bitmap(void) +{ + + glBegin(GL_LINES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/2, 0); + glVertex2i(boxW/2, 0); + glVertex2i(0, -boxH/2); + glVertex2i(0, boxH/2); + SetColor(COLOR_RED); + glVertex2i(0, -3); + glVertex2i(0, -3+OPENGL_HEIGHT); + SetColor(COLOR_BLUE); + glVertex2i(0, -3); + glVertex2i(OPENGL_WIDTH, -3); + glEnd(); + + SetColor(COLOR_GREEN); + + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glRasterPos2i(0, 0); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits); +} + +static void Triangles(void) +{ + + glBegin(GL_TRIANGLES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + glEnd(); + + glBegin(GL_TRIANGLES); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleStrip(void) +{ + + glBegin(GL_TRIANGLE_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleFan(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_TRIANGLE_FAN); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_TRIANGLE_FAN); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void Rect(void) +{ + + SetColor(COLOR_GREEN); + glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4); +} + +static void PolygonFunc(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_POLYGON); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_POLYGON); + glVertex2i(0, 0); + glVertex2i(100, 100); + glEnd(); +} + +static void Quads(void) +{ + + glBegin(GL_QUADS); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, -boxH/4); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUADS); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void QuadStrip(void) +{ + + glBegin(GL_QUAD_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUAD_STRIP); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void Draw(EGLDisplay dpy, EGLSurface surf) +{ + + glViewport(0, 0, windW, windH); + glDisable(GL_SCISSOR_TEST); + + glPushAttrib(GL_COLOR_BUFFER_BIT); + + glColorMask(1, 1, 1, 1); + glIndexMask(~0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glPopAttrib(); + + if (mode1) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + + if (mode2) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + + Viewport(0, 0); Point(); + Viewport(0, 1); Lines(); + Viewport(0, 2); LineStrip(); + Viewport(0, 3); LineLoop(); + + Viewport(1, 0); Bitmap(); + + Viewport(1, 1); TriangleFan(); + Viewport(1, 2); Triangles(); + Viewport(1, 3); TriangleStrip(); + + Viewport(2, 0); Rect(); + Viewport(2, 1); PolygonFunc(); + Viewport(2, 2); Quads(); + Viewport(2, 3); QuadStrip(); + + glFlush(); + + if (doubleBuffer) { + eglSwapBuffers(dpy, surf); + } +} + +static void +write_ppm(const char *filename, const GLubyte *buffer, int width, int height) +{ + const int binary = 0; + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLubyte *ptr = buffer; + if (binary) { + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x=0; y--) { + for (x=0; x +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include +#include + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static double +current_time(void) +{ + /* update this function for other platforms! */ + static double t = 0.0; + static int warn = 1; + if (warn) { + fprintf(stderr, "Warning: current_time() not implemented!!\n"); + warn = 0; + } + return t += 1.0; +} + +#endif /*BENCHMARK*/ + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +#if 0 +static GLfloat eyesep = 5.0; /* Eye separation. */ +static GLfloat fix_point = 40.0; /* Fixation point distance. */ +static GLfloat left, right, asp; /* Stereo frustum params. */ +#endif + + +/* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +static void +init(void) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); +} + + + + +static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) +{ + double st = current_time(); + double ct = st; + int frames = 0; + GLfloat seconds, fps; + + while (ct - st < ttr) + { + double tt = current_time(); + double dt = tt - ct; + ct = tt; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + draw(); + + eglSwapBuffers(dpy, surf); + + + frames++; + } + + seconds = ct - st; + fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); + +} + + +int +main(int argc, char *argv[]) +{ + int maj, min; + EGLContext ctx; + EGLSurface screen_surf; + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + EGLBoolean b; + EGLDisplay d; + EGLint screenAttribs[10]; + EGLModeMESA mode[MAX_MODES]; + EGLScreenMESA screen; + EGLint count; + EGLint chosenMode = 0; + GLboolean printInfo = GL_FALSE; + EGLint width = 0, height = 0; + + /* parse cmd line args */ + for (i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-info") == 0) + { + printInfo = GL_TRUE; + } + else + printf("Warning: unknown parameter: %s\n", argv[i]); + } + + /* DBR : Create EGL context/surface etc */ + d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("eglgears: eglInitialize failed\n"); + exit(1); + } + + printf("eglgears: EGL version = %d.%d\n", maj, min); + printf("eglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + /* XXX use ChooseConfig */ + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + eglGetScreensMESA(d, &screen, 1, &count); + + if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { + printf("eglgears: eglGetModesMESA failed!\n"); + return 0; + } + + /* Print list of modes, and find the one to use */ + printf("eglgears: Found %d modes:\n", count); + for (i = 0; i < count; i++) { + EGLint w, h; + eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); + eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); + printf("%3d: %d x %d\n", i, w, h); + if (w > width && h > height) { + width = w; + height = h; + chosenMode = i; + } + } + printf("eglgears: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); + + eglBindAPI(EGL_OPENGL_API); + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("eglgears: failed to create context\n"); + return 0; + } + + /* build up screenAttribs array */ + i = 0; + screenAttribs[i++] = EGL_WIDTH; + screenAttribs[i++] = width; + screenAttribs[i++] = EGL_HEIGHT; + screenAttribs[i++] = height; + screenAttribs[i++] = EGL_NONE; + + screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); + if (screen_surf == EGL_NO_SURFACE) { + printf("eglgears: failed to create screen surface\n"); + return 0; + } + + b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); + if (!b) { + printf("eglgears: show surface failed\n"); + return 0; + } + + b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); + if (!b) { + printf("eglgears: make current failed\n"); + return 0; + } + + if (printInfo) + { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + reshape(width, height); + + glDrawBuffer( GL_BACK ); + + run_gears(d, screen_surf, 5.0); + + eglDestroySurface(d, screen_surf); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/eglinfo.c b/progs/egl/opengl/eglinfo.c new file mode 100644 index 00000000000..961fd9ccc76 --- /dev/null +++ b/progs/egl/opengl/eglinfo.c @@ -0,0 +1,223 @@ +/* + * eglinfo - like glxinfo but for EGL + * + * Brian Paul + * 11 March 2005 + * + * Copyright (C) 2005 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 1000 +#define MAX_MODES 1000 +#define MAX_SCREENS 10 + +/* These are X visual types, so if you're running eglinfo under + * something not X, they probably don't make sense. */ +static const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" }; + +/** + * Print table of all available configurations. + */ +static void +PrintConfigs(EGLDisplay d) +{ + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + + printf("Configurations:\n"); + printf(" bf lv colorbuffer dp st ms vis cav bi renderable supported\n"); + printf(" id sz l r g b a th cl ns b id eat nd gl es es2 vg surfaces \n"); + printf("---------------------------------------------------------------------\n"); + for (i = 0; i < numConfigs; i++) { + EGLint id, size, level; + EGLint red, green, blue, alpha; + EGLint depth, stencil; + EGLint renderable, surfaces; + EGLint vid, vtype, caveat, bindRgb, bindRgba; + EGLint samples, sampleBuffers; + char surfString[100] = ""; + + eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); + eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); + eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); + + eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); + eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); + eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); + eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); + eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); + eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); + eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid); + eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype); + + eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat); + eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb); + eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba); + eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable); + eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); + + eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples); + eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers); + + if (surfaces & EGL_WINDOW_BIT) + strcat(surfString, "win,"); + if (surfaces & EGL_PBUFFER_BIT) + strcat(surfString, "pb,"); + if (surfaces & EGL_PIXMAP_BIT) + strcat(surfString, "pix,"); +#ifdef EGL_MESA_screen_surface + if (surfaces & EGL_SCREEN_BIT_MESA) + strcat(surfString, "scrn,"); +#endif + if (strlen(surfString) > 0) + surfString[strlen(surfString) - 1] = 0; + + printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ", + id, size, level, + red, green, blue, alpha, + depth, stencil, + samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--"); + printf(" %c %c %c %c %c %c %s\n", + (caveat != EGL_NONE) ? 'y' : ' ', + (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ', + (renderable & EGL_OPENGL_BIT) ? 'y' : ' ', + (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ', + (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ', + (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', + surfString); + } +} + + +/** + * Print table of all available configurations. + */ +static void +PrintModes(EGLDisplay d) +{ +#ifdef EGL_MESA_screen_surface + const char *extensions = eglQueryString(d, EGL_EXTENSIONS); + if (strstr(extensions, "EGL_MESA_screen_surface")) { + EGLScreenMESA screens[MAX_SCREENS]; + EGLint numScreens = 1, scrn; + EGLModeMESA modes[MAX_MODES]; + + eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens); + printf("Number of Screens: %d\n\n", numScreens); + + for (scrn = 0; scrn < numScreens; scrn++) { + EGLint numModes, i; + + eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes); + + printf("Screen %d Modes:\n", scrn); + printf(" id width height refresh name\n"); + printf("-----------------------------------------\n"); + for (i = 0; i < numModes; i++) { + EGLint id, w, h, r; + const char *str; + eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id); + eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w); + eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h); + eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r); + str = eglQueryModeStringMESA(d, modes[i]); + printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str); + } + } + } +#endif +} + +static void +PrintExtensions(EGLDisplay d) +{ + const char *extensions, *p, *end, *next; + int column; + + printf("EGL extensions string:\n"); + + extensions = eglQueryString(d, EGL_EXTENSIONS); + + column = 0; + end = extensions + strlen(extensions); + + for (p = extensions; p < end; p = next + 1) { + next = strchr(p, ' '); + if (next == NULL) + next = end; + + if (column > 0 && column + next - p + 1 > 70) { + printf("\n"); + column = 0; + } + if (column == 0) + printf(" "); + else + printf(" "); + column += next - p + 1; + + printf("%.*s", (int) (next - p), p); + + p = next + 1; + } + + if (column > 0) + printf("\n"); +} + +int +main(int argc, char *argv[]) +{ + int maj, min; + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + + if (!eglInitialize(d, &maj, &min)) { + printf("eglinfo: eglInitialize failed\n"); + exit(1); + } + + printf("EGL API version: %d.%d\n", maj, min); + printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR)); + printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION)); +#ifdef EGL_VERSION_1_2 + printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS)); +#endif + + PrintExtensions(d); + + PrintConfigs(d); + + PrintModes(d); + + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/eglscreen.c b/progs/egl/opengl/eglscreen.c new file mode 100644 index 00000000000..520f76ea036 --- /dev/null +++ b/progs/egl/opengl/eglscreen.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +/* + * Stolen from eglgears + * + * Creates a surface and show that on the first screen + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + +int +main(int argc, char *argv[]) +{ + int maj, min; + EGLSurface screen_surf; + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + EGLBoolean b; + EGLDisplay d; + EGLint screenAttribs[10]; + EGLModeMESA mode[MAX_MODES]; + EGLScreenMESA screen; + EGLint count; + EGLint chosenMode = 0; + EGLint width = 0, height = 0; + + d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("eglscreen: eglInitialize failed\n"); + exit(1); + } + + printf("eglscreen: EGL version = %d.%d\n", maj, min); + printf("eglscreen: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + /* XXX use ChooseConfig */ + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + eglGetScreensMESA(d, &screen, 1, &count); + + if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { + printf("eglscreen: eglGetModesMESA failed!\n"); + return 0; + } + + /* Print list of modes, and find the one to use */ + printf("eglscreen: Found %d modes:\n", count); + for (i = 0; i < count; i++) { + EGLint w, h; + eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); + eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); + printf("%3d: %d x %d\n", i, w, h); + if (w > width && h > height) { + width = w; + height = h; + chosenMode = i; + } + } + printf("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); + + /* build up screenAttribs array */ + i = 0; + screenAttribs[i++] = EGL_WIDTH; + screenAttribs[i++] = width; + screenAttribs[i++] = EGL_HEIGHT; + screenAttribs[i++] = height; + screenAttribs[i++] = EGL_NONE; + + screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); + if (screen_surf == EGL_NO_SURFACE) { + printf("eglscreen: Failed to create screen surface\n"); + return 0; + } + + b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); + if (!b) { + printf("eglscreen: Show surface failed\n"); + return 0; + } + + usleep(5000000); + + eglDestroySurface(d, screen_surf); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/egltri.c b/progs/egl/opengl/egltri.c new file mode 100644 index 00000000000..006e06eb03e --- /dev/null +++ b/progs/egl/opengl/egltri.c @@ -0,0 +1,264 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * Copyright (C) 2008 Brian Paul All Rights Reserved. + * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +/* + * This program is based on eglgears and xegl_tri. + * Remixed by Jakob Bornecrantz + * + * No command line options. + * Program runs for 5 seconds then exits, outputing framerate to console + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + + +/* XXX this probably isn't very portable */ + +#include +#include + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + + +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; + +static void draw() +{ + static const GLfloat verts[3][2] = { + { -1, -1 }, + { 1, -1 }, + { 0, 1 } + }; + static const GLfloat colors[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1, 0, 0); + glRotatef(view_roty, 0, 1, 0); + glRotatef(view_rotz, 0, 0, 1); + + { + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(3, GL_FLOAT, 0, colors); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + } + + glPopMatrix(); +} + +static void init() +{ + glClearColor(0.4, 0.4, 0.4, 0.0); +} + +/* new window size or exposure */ +static void reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + +static void run(EGLDisplay dpy, EGLSurface surf, int ttr) +{ + double st = current_time(); + double ct = st; + int frames = 0; + GLfloat seconds, fps; + + while (ct - st < ttr) + { + ct = current_time(); + + draw(); + + eglSwapBuffers(dpy, surf); + + frames++; + } + + seconds = ct - st; + fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); +} + +int main(int argc, char *argv[]) +{ + int maj, min; + EGLContext ctx; + EGLSurface screen_surf; + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + EGLBoolean b; + EGLDisplay d; + EGLint screenAttribs[10]; + EGLModeMESA mode[MAX_MODES]; + EGLScreenMESA screen; + EGLint count, chosenMode = 0; + GLboolean printInfo = GL_FALSE; + EGLint width = 0, height = 0; + + /* parse cmd line args */ + for (i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-info") == 0) + { + printInfo = GL_TRUE; + } + else + printf("Warning: unknown parameter: %s\n", argv[i]); + } + + /* DBR : Create EGL context/surface etc */ + d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("egltri: eglInitialize failed\n"); + exit(1); + } + + printf("egltri: EGL version = %d.%d\n", maj, min); + printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + /* XXX use ChooseConfig */ + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + eglGetScreensMESA(d, &screen, 1, &count); + + if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { + printf("egltri: eglGetModesMESA failed!\n"); + return 0; + } + + /* Print list of modes, and find the one to use */ + printf("egltri: Found %d modes:\n", count); + for (i = 0; i < count; i++) { + EGLint w, h; + eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); + eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); + printf("%3d: %d x %d\n", i, w, h); + if (w > width && h > height) { + width = w; + height = h; + chosenMode = i; + } + } + printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); + + eglBindAPI(EGL_OPENGL_API); + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("egltri: failed to create context\n"); + return 0; + } + + /* build up screenAttribs array */ + i = 0; + screenAttribs[i++] = EGL_WIDTH; + screenAttribs[i++] = width; + screenAttribs[i++] = EGL_HEIGHT; + screenAttribs[i++] = height; + screenAttribs[i++] = EGL_NONE; + + screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); + if (screen_surf == EGL_NO_SURFACE) { + printf("egltri: failed to create screen surface\n"); + return 0; + } + + b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); + if (!b) { + printf("egltri: show surface failed\n"); + return 0; + } + + b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); + if (!b) { + printf("egltri: make current failed\n"); + return 0; + } + + if (printInfo) + { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + reshape(width, height); + + glDrawBuffer( GL_BACK ); + + run(d, screen_surf, 5.0); + + eglDestroySurface(d, screen_surf); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/peglgears.c b/progs/egl/opengl/peglgears.c new file mode 100644 index 00000000000..212d1acf692 --- /dev/null +++ b/progs/egl/opengl/peglgears.c @@ -0,0 +1,451 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +/* + * This is a port of the infamous "glxgears" demo to straight EGL + * Port by Dane Rushton 10 July 2005 + * + * No command line options. + * Program runs for 5 seconds then exits, outputing framerate to console + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include +#include + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static double +current_time(void) +{ + /* update this function for other platforms! */ + static double t = 0.0; + static int warn = 1; + if (warn) { + fprintf(stderr, "Warning: current_time() not implemented!!\n"); + warn = 0; + } + return t += 1.0; +} + +#endif /*BENCHMARK*/ + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +#if 0 +static GLfloat eyesep = 5.0; /* Eye separation. */ +static GLfloat fix_point = 40.0; /* Fixation point distance. */ +static GLfloat left, right, asp; /* Stereo frustum params. */ +#endif + + +/* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +static void +init(void) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); +} + + + + +static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) +{ + double st = current_time(); + double ct = st; + int frames = 0; + GLfloat seconds, fps; + + while (ct - st < ttr) + { + double tt = current_time(); + double dt = tt - ct; + ct = tt; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + draw(); + + eglSwapBuffers(dpy, surf); + + + frames++; + } + + seconds = ct - st; + fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); + +} + + +int +main(int argc, char *argv[]) +{ + int major, minor; + EGLContext ctx; + EGLSurface surface; + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + EGLBoolean b; + EGLDisplay d; + EGLint screenAttribs[10]; + GLboolean printInfo = GL_FALSE; + EGLint width = 300, height = 300; + + /* parse cmd line args */ + for (i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-info") == 0) + { + printInfo = GL_TRUE; + } + else + printf("Warning: unknown parameter: %s\n", argv[i]); + } + + /* DBR : Create EGL context/surface etc */ + d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(d); + + if (!eglInitialize(d, &major, &minor)) { + printf("peglgears: eglInitialize failed\n"); + return 0; + } + + printf("peglgears: EGL version = %d.%d\n", major, minor); + printf("peglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("peglgears: failed to create context\n"); + return 0; + } + + /* build up screenAttribs array */ + i = 0; + screenAttribs[i++] = EGL_WIDTH; + screenAttribs[i++] = width; + screenAttribs[i++] = EGL_HEIGHT; + screenAttribs[i++] = height; + screenAttribs[i++] = EGL_NONE; + + surface = eglCreatePbufferSurface(d, configs[0], screenAttribs); + if (surface == EGL_NO_SURFACE) { + printf("peglgears: failed to create pbuffer surface\n"); + return 0; + } + + b = eglMakeCurrent(d, surface, surface, ctx); + if (!b) { + printf("peglgears: make current failed\n"); + return 0; + } + + if (printInfo) + { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + reshape(width, height); + + glDrawBuffer( GL_BACK ); + + run_gears(d, surface, 5.0); + + eglDestroySurface(d, surface); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} diff --git a/progs/egl/opengl/xegl_tri.c b/progs/egl/opengl/xegl_tri.c new file mode 100644 index 00000000000..1f1a005a210 --- /dev/null +++ b/progs/egl/opengl/xegl_tri.c @@ -0,0 +1,361 @@ +/* + * Copyright (C) 2008 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +/* + * Draw a triangle with X/EGL. + * Brian Paul + * 3 June 2008 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* using full OpenGL for now */ +#include + + +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; + + +static void +draw(void) +{ + static const GLfloat verts[3][2] = { + { -1, -1 }, + { 1, -1 }, + { 0, 1 } + }; + static const GLfloat colors[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1, 0, 0); + glRotatef(view_roty, 0, 1, 0); + glRotatef(view_rotz, 0, 0, 1); + + { + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(3, GL_FLOAT, 0, colors); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + } + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + + +static void +init(void) +{ + glClearColor(0.4, 0.4, 0.4, 0.0); +} + + +/* + * Create an RGB, double-buffered X window. + * Return the window and context handles. + */ +static void +make_x_window(Display *x_dpy, EGLDisplay egl_dpy, + const char *name, + int x, int y, int width, int height, + Window *winRet, + EGLContext *ctxRet, + EGLSurface *surfRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLContext ctx; + EGLConfig config; + EGLint num_configs; + EGLint vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) || + !num_configs) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( x_dpy, root, 0, 0, width, height, + 0, visInfo->depth, InputOutput, + visInfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); + + if (!*surfRet) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); + } + + XFree(visInfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win, + EGLDisplay egl_dpy, EGLSurface egl_surf) +{ + while (1) { + int redraw = 0; + XEvent event; + + XNextEvent(dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + + if (redraw) { + draw(); + eglSwapBuffers(egl_dpy, egl_surf); + } + } +} + + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display set the display to run on\n"); + printf(" -info display OpenGL renderer info\n"); +} + + +int +main(int argc, char *argv[]) +{ + const int winWidth = 300, winHeight = 300; + Display *x_dpy; + Window win; + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + EGLint egl_major, egl_minor; + int i; + const char *s; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else { + usage(); + return -1; + } + } + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + egl_dpy = eglGetDisplay(x_dpy); + if (!egl_dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(egl_dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_x_window(x_dpy, egl_dpy, + "xegl_tri", 0, 0, winWidth, winHeight, + &win, &egl_ctx, &egl_surf); + + XMapWindow(x_dpy, win); + if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + return -1; + } + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + } + + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + reshape(winWidth, winHeight); + + event_loop(x_dpy, win, egl_dpy, egl_surf); + + eglDestroyContext(egl_dpy, egl_ctx); + eglDestroySurface(egl_dpy, egl_surf); + eglTerminate(egl_dpy); + + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} diff --git a/progs/egl/opengl/xeglgears.c b/progs/egl/opengl/xeglgears.c new file mode 100644 index 00000000000..a6a977d9fff --- /dev/null +++ b/progs/egl/opengl/xeglgears.c @@ -0,0 +1,954 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + */ + +/* + * Ported to X/EGL/GLES. XXX Actually, uses full OpenGL ATM. + * Brian Paul + * 30 May 2008 + */ + +/* + * Command line options: + * -info print GL implementation information + * + */ + + +#define GL_GLEXT_PROTOTYPES +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include +#include + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static double +current_time(void) +{ + /* update this function for other platforms! */ + static double t = 0.0; + static int warn = 1; + if (warn) { + fprintf(stderr, "Warning: current_time() not implemented!!\n"); + warn = 0; + } + return t += 1.0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +/* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(void) +{ + glClearColor(0.2, 0.2, 0.2, 0.2); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +static void +init(void) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); +} + + +struct egl_manager { + EGLNativeDisplayType xdpy; + EGLNativeWindowType xwin; + EGLNativePixmapType xpix; + + EGLDisplay dpy; + EGLConfig conf; + EGLContext ctx; + + EGLSurface win; + EGLSurface pix; + EGLSurface pbuf; + EGLImageKHR image; + + EGLBoolean verbose; + EGLint major, minor; + + GC gc; + GLuint fbo; +}; + +static struct egl_manager * +egl_manager_new(EGLNativeDisplayType xdpy, const EGLint *attrib_list, + EGLBoolean verbose) +{ + struct egl_manager *eman; + const char *ver; + EGLint num_conf; + + eman = calloc(1, sizeof(*eman)); + if (!eman) + return NULL; + + eman->verbose = verbose; + eman->xdpy = xdpy; + + eman->dpy = eglGetDisplay(eman->xdpy); + if (eman->dpy == EGL_NO_DISPLAY) { + printf("eglGetDisplay() failed\n"); + free(eman); + return NULL; + } + + if (!eglInitialize(eman->dpy, &eman->major, &eman->minor)) { + printf("eglInitialize() failed\n"); + free(eman); + return NULL; + } + + ver = eglQueryString(eman->dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", ver); + + if (!eglChooseConfig(eman->dpy, attrib_list, &eman->conf, 1, &num_conf) || + !num_conf) { + printf("eglChooseConfig() failed\n"); + eglTerminate(eman->dpy); + free(eman); + return NULL; + } + + eman->ctx = eglCreateContext(eman->dpy, eman->conf, EGL_NO_CONTEXT, NULL); + if (eman->ctx == EGL_NO_CONTEXT) { + printf("eglCreateContext() failed\n"); + eglTerminate(eman->dpy); + free(eman); + return NULL; + } + + return eman; +} + +static EGLBoolean +egl_manager_create_window(struct egl_manager *eman, const char *name, + EGLint w, EGLint h, EGLBoolean need_surface, + EGLBoolean fullscreen, const EGLint *attrib_list) +{ + XVisualInfo vinfo_template, *vinfo = NULL; + EGLint val, num_vinfo; + Window root; + XSetWindowAttributes attrs; + unsigned long mask; + EGLint x = 0, y = 0; + + if (!eglGetConfigAttrib(eman->dpy, eman->conf, + EGL_NATIVE_VISUAL_ID, &val)) { + printf("eglGetConfigAttrib() failed\n"); + return EGL_FALSE; + } + if (val) { + vinfo_template.visualid = (VisualID) val; + vinfo = XGetVisualInfo(eman->xdpy, VisualIDMask, &vinfo_template, &num_vinfo); + } + /* try harder if window surface is not needed */ + if (!vinfo && !need_surface && + eglGetConfigAttrib(eman->dpy, eman->conf, EGL_BUFFER_SIZE, &val)) { + if (val == 32) + val = 24; + vinfo_template.depth = val; + vinfo = XGetVisualInfo(eman->xdpy, VisualDepthMask, &vinfo_template, &num_vinfo); + } + + if (!vinfo) { + printf("XGetVisualInfo() failed\n"); + return EGL_FALSE; + } + + root = DefaultRootWindow(eman->xdpy); + if (fullscreen) { + x = y = 0; + w = DisplayWidth(eman->xdpy, DefaultScreen(eman->xdpy)); + h = DisplayHeight(eman->xdpy, DefaultScreen(eman->xdpy)); + } + + /* window attributes */ + attrs.background_pixel = 0; + attrs.border_pixel = 0; + attrs.colormap = XCreateColormap(eman->xdpy, root, vinfo->visual, AllocNone); + attrs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + attrs.override_redirect = fullscreen; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + eman->xwin = XCreateWindow(eman->xdpy, root, x, y, w, h, + 0, vinfo->depth, InputOutput, + vinfo->visual, mask, &attrs); + XFree(vinfo); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = w; + sizehints.height = h; + sizehints.flags = USSize | USPosition; + XSetNormalHints(eman->xdpy, eman->xwin, &sizehints); + XSetStandardProperties(eman->xdpy, eman->xwin, name, name, + None, (char **)NULL, 0, &sizehints); + } + + if (need_surface) { + eman->win = eglCreateWindowSurface(eman->dpy, eman->conf, + eman->xwin, attrib_list); + if (eman->win == EGL_NO_SURFACE) { + printf("eglCreateWindowSurface() failed\n"); + XDestroyWindow(eman->xdpy, eman->xwin); + eman->xwin = None; + return EGL_FALSE; + } + } + + eman->gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL); + + XMapWindow(eman->xdpy, eman->xwin); + + return EGL_TRUE; +} + +static EGLBoolean +egl_manager_create_pixmap(struct egl_manager *eman, EGLNativeWindowType xwin, + EGLBoolean need_surface, const EGLint *attrib_list) +{ + XWindowAttributes attrs; + + if (!XGetWindowAttributes(eman->xdpy, xwin, &attrs)) { + printf("XGetWindowAttributes() failed\n"); + return EGL_FALSE; + } + + eman->xpix = XCreatePixmap(eman->xdpy, xwin, + attrs.width, attrs.height, attrs.depth); + + if (need_surface) { + eman->pix = eglCreatePixmapSurface(eman->dpy, eman->conf, + eman->xpix, attrib_list); + if (eman->pix == EGL_NO_SURFACE) { + printf("eglCreatePixmapSurface() failed\n"); + XFreePixmap(eman->xdpy, eman->xpix); + eman->xpix = None; + return EGL_FALSE; + } + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_manager_create_pbuffer(struct egl_manager *eman, const EGLint *attrib_list) +{ + eman->pbuf = eglCreatePbufferSurface(eman->dpy, eman->conf, attrib_list); + if (eman->pbuf == EGL_NO_SURFACE) { + printf("eglCreatePbufferSurface() failed\n"); + return EGL_FALSE; + } + + return EGL_TRUE; +} + +static void +egl_manager_destroy(struct egl_manager *eman) +{ + eglMakeCurrent(eman->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglTerminate(eman->dpy); + + if (eman->xwin != None) + XDestroyWindow(eman->xdpy, eman->xwin); + if (eman->xpix != None) + XFreePixmap(eman->xdpy, eman->xpix); + + XFreeGC(eman->xdpy, eman->gc); + + free(eman); +} + +enum { + GEARS_WINDOW, + GEARS_PIXMAP, + GEARS_PIXMAP_TEXTURE, + GEARS_PBUFFER, + GEARS_PBUFFER_TEXTURE, + GEARS_RENDERBUFFER +}; + +static void +texture_gears(struct egl_manager *eman, int surface_type) +{ + static const GLint verts[12] = + { -5, -6, -10, 5, -6, -10, -5, 4, 10, 5, 4, 10 }; + static const GLint tex_coords[8] = { 0, 0, 1, 0, 0, 1, 1, 1 }; + + eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); + + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(3, GL_INT, 0, verts); + glTexCoordPointer(2, GL_INT, 0, tex_coords); + + if (surface_type == GEARS_PBUFFER_TEXTURE) + eglBindTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisable(GL_TEXTURE_2D); + + if (surface_type == GEARS_PBUFFER_TEXTURE) + eglReleaseTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); + + eglSwapBuffers(eman->dpy, eman->win); +} + +static void +copy_gears(struct egl_manager *eman, + EGLint tile_w, EGLint tile_h, EGLint w, EGLint h) +{ + int x, y; + + eglWaitClient(); + + for (x = 0; x < w; x += tile_w) { + for (y = 0; y < h; y += tile_h) { + + XCopyArea(eman->xdpy, eman->xpix, eman->xwin, eman->gc, + 0, 0, tile_w, tile_h, x, y); + } + } +} + +static void +event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h) +{ + int window_w = w, window_h = h; + + if (surface_type == EGL_PBUFFER_BIT) + printf("there will be no screen update if " + "eglCopyBuffers() is not implemented\n"); + + while (1) { + while (XPending(eman->xdpy) > 0) { + XEvent event; + XNextEvent(eman->xdpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + window_w = event.xconfigure.width; + window_h = event.xconfigure.height; + if (surface_type == EGL_WINDOW_BIT) + reshape(window_w, window_h); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + { + static int frames = 0; + static double tRot0 = -1.0, tRate0 = -1.0; + double dt, t = current_time(); + if (tRot0 < 0.0) + tRot0 = t; + dt = t - tRot0; + tRot0 = t; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + switch (surface_type) { + case GEARS_WINDOW: + draw(); + eglSwapBuffers(eman->dpy, eman->win); + break; + + case GEARS_PBUFFER: + draw(); + if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix)) + break; + copy_gears(eman, w, h, window_w, window_h); + break; + + case GEARS_PBUFFER_TEXTURE: + eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); + draw(); + texture_gears(eman, surface_type); + break; + + case GEARS_PIXMAP: + draw(); + copy_gears(eman, w, h, window_w, window_h); + break; + + case GEARS_PIXMAP_TEXTURE: + eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); + draw(); + texture_gears(eman, surface_type); + break; + + case GEARS_RENDERBUFFER: + glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); + draw(); + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + texture_gears(eman, surface_type); + break; + } + + frames++; + + if (tRate0 < 0.0) + tRate0 = t; + if (t - tRate0 >= 5.0) { + GLfloat seconds = t - tRate0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + tRate0 = t; + frames = 0; + } + } + } +} + + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display set the display to run on\n"); + printf(" -fullscreen run in fullscreen mode\n"); + printf(" -info display OpenGL renderer info\n"); + printf(" -pixmap use pixmap surface\n"); + printf(" -pixmap-texture use pixmap surface and texture using EGLImage\n"); + printf(" -pbuffer use pbuffer surface and eglCopyBuffers\n"); + printf(" -pbuffer-texture use pbuffer surface and eglBindTexImage\n"); + printf(" -renderbuffer renderbuffer as EGLImage and bind as texture from\n"); +} + +static const char *names[] = { + "window", + "pixmap", + "pixmap_texture", + "pbuffer", + "pbuffer_texture", + "renderbuffer" +}; + +int +main(int argc, char *argv[]) +{ + const int winWidth = 300, winHeight = 300; + Display *x_dpy; + char *dpyName = NULL; + struct egl_manager *eman; + EGLint attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, /* may be changed later */ + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE + }; + char win_title[] = "xeglgears (window/pixmap/pbuffer)"; + EGLint surface_type = GEARS_WINDOW; + GLboolean printInfo = GL_FALSE; + GLboolean fullscreen = GL_FALSE; + EGLBoolean ret; + GLuint texture, color_rb, depth_rb; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else if (strcmp(argv[i], "-fullscreen") == 0) { + fullscreen = GL_TRUE; + } + else if (strcmp(argv[i], "-pixmap") == 0) { + surface_type = GEARS_PIXMAP; + attribs[1] = EGL_PIXMAP_BIT; + } + else if (strcmp(argv[i], "-pixmap-texture") == 0) { + surface_type = GEARS_PIXMAP_TEXTURE; + attribs[1] = EGL_PIXMAP_BIT; + } + else if (strcmp(argv[i], "-pbuffer") == 0) { + surface_type = GEARS_PBUFFER; + attribs[1] = EGL_PBUFFER_BIT; + } + else if (strcmp(argv[i], "-pbuffer-texture") == 0) { + surface_type = GEARS_PBUFFER_TEXTURE; + attribs[1] = EGL_PBUFFER_BIT; + } + else if (strcmp(argv[i], "-renderbuffer") == 0) { + surface_type = GEARS_RENDERBUFFER; + } + else { + usage(); + return -1; + } + } + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + eglBindAPI(EGL_OPENGL_API); + + eman = egl_manager_new(x_dpy, attribs, printInfo); + if (!eman) { + XCloseDisplay(x_dpy); + return -1; + } + + snprintf(win_title, sizeof(win_title), + "xeglgears (%s)", names[surface_type]); + + ret = egl_manager_create_window(eman, win_title, winWidth, winHeight, + EGL_TRUE, fullscreen, NULL); + if (!ret) + return -1; + + /* create surface(s) */ + switch (surface_type) { + case GEARS_WINDOW: + if (ret) + ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); + break; + case GEARS_PIXMAP: + case GEARS_PIXMAP_TEXTURE: + ret = egl_manager_create_pixmap(eman, eman->xwin, EGL_TRUE, NULL); + if (surface_type == GEARS_PIXMAP_TEXTURE) + eman->image = eglCreateImageKHR (eman->dpy, eman->ctx, + EGL_NATIVE_PIXMAP_KHR, + (EGLClientBuffer) eman->xpix, NULL); + if (ret) + ret = eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); + break; + case GEARS_PBUFFER: + case GEARS_PBUFFER_TEXTURE: + { + EGLint pbuf_attribs[] = { + EGL_WIDTH, winWidth, + EGL_HEIGHT, winHeight, + EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, + EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, + EGL_NONE + }; + ret = (egl_manager_create_pixmap(eman, eman->xwin, + EGL_TRUE, NULL) && + egl_manager_create_pbuffer(eman, pbuf_attribs)); + if (ret) + ret = eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); + } + break; + + + case GEARS_RENDERBUFFER: + ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); + if (ret == EGL_FALSE) + printf("failed to make context current\n"); + + glGenFramebuffers(1, &eman->fbo); + glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); + + glGenRenderbuffers(1, &color_rb); + glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_rb); + glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_RGBA, winWidth, winHeight); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, + color_rb); + + eman->image = eglCreateImageKHR(eman->dpy, eman->ctx, + EGL_GL_RENDERBUFFER_KHR, + (EGLClientBuffer) color_rb, NULL); + + glGenRenderbuffers(1, &depth_rb); + glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_rb); + glRenderbufferStorage(GL_RENDERBUFFER_EXT, + GL_DEPTH_COMPONENT, winWidth, winHeight); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, + depth_rb); + + if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE) { + printf("framebuffer not complete\n"); + exit(1); + } + + break; + + default: + ret = EGL_FALSE; + break; + } + + switch (surface_type) { + case GEARS_PIXMAP_TEXTURE: + case GEARS_RENDERBUFFER: + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eman->image); + break; + case GEARS_PBUFFER_TEXTURE: + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + break; + } + + if (!ret) { + egl_manager_destroy(eman); + XCloseDisplay(x_dpy); + return -1; + } + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + } + + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + reshape(winWidth, winHeight); + + event_loop(eman, surface_type, winWidth, winHeight); + + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + + egl_manager_destroy(eman); + XCloseDisplay(x_dpy); + + return 0; +} diff --git a/progs/egl/opengl/xeglthreads.c b/progs/egl/opengl/xeglthreads.c new file mode 100644 index 00000000000..5787faecb90 --- /dev/null +++ b/progs/egl/opengl/xeglthreads.c @@ -0,0 +1,775 @@ +/* + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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 + * BRIAN PAUL 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. + * + * Ported to EGL by Chia-I Wu + */ + + +/* + * This program tests EGL thread safety. + * Command line options: + * -p Open a display connection for each thread + * -l Enable application-side locking + * -n Number of threads to create (default is 2) + * -display Specify X display (default is $DISPLAY) + * -t Use texture mapping + * + * Brian Paul 20 July 2000 + */ + + +/* + * Notes: + * - Each thread gets its own EGL context. + * + * - The EGL contexts share texture objects. + * + * - When 't' is pressed to update the texture image, the window/thread which + * has input focus is signalled to change the texture. The other threads + * should see the updated texture the next time they call glBindTexture. + */ + + +#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + * Each window/thread/context: + */ +struct winthread { + Display *Dpy; + int Index; + pthread_t Thread; + Window Win; + EGLDisplay Display; + EGLContext Context; + EGLSurface Surface; + float Angle; + int WinWidth, WinHeight; + GLboolean NewSize; + GLboolean Initialized; + GLboolean MakeNewTexture; +}; + + +#define MAX_WINTHREADS 100 +static struct winthread WinThreads[MAX_WINTHREADS]; +static int NumWinThreads = 0; +static volatile GLboolean ExitFlag = GL_FALSE; + +static GLboolean MultiDisplays = 0; +static GLboolean Locking = 0; +static GLboolean Texture = GL_FALSE; +static GLuint TexObj = 12; +static GLboolean Animate = GL_TRUE; + +static pthread_mutex_t Mutex; +static pthread_cond_t CondVar; +static pthread_mutex_t CondMutex; + + +static void +Error(const char *msg) +{ + fprintf(stderr, "Error: %s\n", msg); + exit(1); +} + + +static void +signal_redraw(void) +{ + pthread_mutex_lock(&CondMutex); + pthread_cond_broadcast(&CondVar); + pthread_mutex_unlock(&CondMutex); +} + + +static void +MakeNewTexture(struct winthread *wt) +{ +#define TEX_SIZE 128 + static float step = 0.0; + GLfloat image[TEX_SIZE][TEX_SIZE][4]; + GLint width; + int i, j; + + for (j = 0; j < TEX_SIZE; j++) { + for (i = 0; i < TEX_SIZE; i++) { + float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; + float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; + float r = dt * dt + ds * ds + step; + image[j][i][0] = + image[j][i][1] = + image[j][i][2] = 0.75 + 0.25 * cos(r); + image[j][i][3] = 1.0; + } + } + + step += 0.5; + + glBindTexture(GL_TEXTURE_2D, TexObj); + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + if (width) { + assert(width == TEX_SIZE); + /* sub-tex replace */ + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, + GL_RGBA, GL_FLOAT, image); + } + else { + /* create new */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, + GL_RGBA, GL_FLOAT, image); + } +} + + + +/* draw a colored cube */ +static void +draw_object(void) +{ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + + if (Texture) { + glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(GL_TEXTURE_2D); + } + else { + glDisable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + + /* -X */ + glColor3f(0, 1, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +X */ + glColor3f(1, 0, 0); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + + /* -Y */ + glColor3f(1, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +Y */ + glColor3f(0, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + /* -Z */ + glColor3f(1, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + + /* +Y */ + glColor3f(0, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + glEnd(); + + glPopMatrix(); +} + + +/* signal resize of given window */ +static void +resize(struct winthread *wt, int w, int h) +{ + wt->NewSize = GL_TRUE; + wt->WinWidth = w; + wt->WinHeight = h; + if (!Animate) + signal_redraw(); +} + + +/* + * We have an instance of this for each thread. + */ +static void +draw_loop(struct winthread *wt) +{ + while (!ExitFlag) { + + if (Locking) + pthread_mutex_lock(&Mutex); + + if (!wt->Initialized) { + eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context); + printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index, + (char *) glGetString(GL_RENDERER)); + if (Texture /*&& wt->Index == 0*/) { + MakeNewTexture(wt); + } + wt->Initialized = GL_TRUE; + } + + if (Locking) + pthread_mutex_unlock(&Mutex); + + eglBindAPI(EGL_OPENGL_API); + if (eglGetCurrentContext() != wt->Context) { + printf("xeglthreads: current context %p != %p\n", + eglGetCurrentContext(), wt->Context); + } + + glEnable(GL_DEPTH_TEST); + + if (wt->NewSize) { + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; + glViewport(0, 0, wt->WinWidth, wt->WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-w, w, -1.0, 1.0, 1.5, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2.5); + wt->NewSize = GL_FALSE; + } + + if (wt->MakeNewTexture) { + MakeNewTexture(wt); + wt->MakeNewTexture = GL_FALSE; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(wt->Angle, 0, 1, 0); + glRotatef(wt->Angle, 1, 0, 0); + glScalef(0.7, 0.7, 0.7); + draw_object(); + glPopMatrix(); + + if (Locking) + pthread_mutex_lock(&Mutex); + + eglSwapBuffers(wt->Display, wt->Surface); + + if (Locking) + pthread_mutex_unlock(&Mutex); + + if (Animate) { + usleep(5000); + } + else { + /* wait for signal to draw */ + pthread_mutex_lock(&CondMutex); + pthread_cond_wait(&CondVar, &CondMutex); + pthread_mutex_unlock(&CondMutex); + } + wt->Angle += 1.0; + } + eglMakeCurrent(wt->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + + +static void +keypress(XEvent *event, struct winthread *wt) +{ + char buf[100]; + KeySym keySym; + XComposeStatus stat; + + XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); + + switch (keySym) { + case XK_Escape: + /* tell all threads to exit */ + if (!Animate) { + signal_redraw(); + } + ExitFlag = GL_TRUE; + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + case XK_t: + case XK_T: + if (Texture) { + wt->MakeNewTexture = GL_TRUE; + if (!Animate) + signal_redraw(); + } + break; + case XK_a: + case XK_A: + Animate = !Animate; + if (Animate) /* yes, prev Animate state! */ + signal_redraw(); + break; + case XK_s: + case XK_S: + if (!Animate) + signal_redraw(); + break; + default: + ; /* nop */ + } +} + + +/* + * The main process thread runs this loop. + * Single display connection for all threads. + */ +static void +event_loop(Display *dpy) +{ + XEvent event; + int i; + + assert(!MultiDisplays); + + while (!ExitFlag) { + + if (Locking) { + while (1) { + int k; + pthread_mutex_lock(&Mutex); + k = XPending(dpy); + if (k) { + XNextEvent(dpy, &event); + pthread_mutex_unlock(&Mutex); + break; + } + pthread_mutex_unlock(&Mutex); + usleep(5000); + } + } + else { + XNextEvent(dpy, &event); + } + + switch (event.type) { + case ConfigureNotify: + /* Find winthread for this event's window */ + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xconfigure.window == wt->Win) { + resize(wt, event.xconfigure.width, + event.xconfigure.height); + break; + } + } + break; + case KeyPress: + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xkey.window == wt->Win) { + keypress(&event, wt); + break; + } + } + break; + default: + /*no-op*/ ; + } + } +} + + +/* + * Separate display connection for each thread. + */ +static void +event_loop_multi(void) +{ + XEvent event; + int w = 0; + + assert(MultiDisplays); + + while (!ExitFlag) { + struct winthread *wt = &WinThreads[w]; + if (XPending(wt->Dpy)) { + XNextEvent(wt->Dpy, &event); + switch (event.type) { + case ConfigureNotify: + resize(wt, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + keypress(&event, wt); + break; + default: + ; /* nop */ + } + } + w = (w + 1) % NumWinThreads; + usleep(5000); + } +} + + + +/* + * we'll call this once for each thread, before the threads are created. + */ +static void +create_window(struct winthread *wt, EGLContext shareCtx) +{ + Window win; + EGLContext ctx; + EGLSurface surf; + EGLint attribs[] = { EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE }; + EGLConfig config; + EGLint num_configs; + EGLint vid; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo, visTemplate; + int num_visuals; + int width = 160, height = 160; + int xpos = (wt->Index % 8) * (width + 10); + int ypos = (wt->Index / 8) * (width + 20); + + scrnum = DefaultScreen(wt->Dpy); + root = RootWindow(wt->Dpy, scrnum); + + if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs) || + !num_configs) { + Error("Unable to choose an EGL config"); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(wt->Display, config, EGL_NATIVE_VISUAL_ID, &vid)) { + Error("Unable to get visual id of EGL config\n"); + } + + visTemplate.visualid = vid; + visinfo = XGetVisualInfo(wt->Dpy, VisualIDMask, + &visTemplate, &num_visuals); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error("Couldn't create window"); + } + + XFree(visinfo); + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(wt->Dpy, win, &sizehints); + XSetStandardProperties(wt->Dpy, win, "xeglthreads", "xeglthreads", + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(wt->Display, config, shareCtx, NULL); + if (!ctx) { + Error("Couldn't create EGL context"); + } + surf = eglCreateWindowSurface(wt->Display, config, win, NULL); + if (!surf) { + Error("Couldn't create EGL surface"); + } + + XMapWindow(wt->Dpy, win); + XSync(wt->Dpy, 0); + + /* save the info for this window/context */ + wt->Win = win; + wt->Context = ctx; + wt->Surface = surf; + wt->Angle = 0.0; + wt->WinWidth = width; + wt->WinHeight = height; + wt->NewSize = GL_TRUE; +} + + +/* + * Called by pthread_create() + */ +static void * +thread_function(void *p) +{ + struct winthread *wt = (struct winthread *) p; + draw_loop(wt); + return NULL; +} + + +/* + * called before exit to wait for all threads to finish + */ +static void +clean_up(void) +{ + int i; + + /* wait for threads to finish */ + for (i = 0; i < NumWinThreads; i++) { + pthread_join(WinThreads[i].Thread, NULL); + } + + for (i = 0; i < NumWinThreads; i++) { + eglDestroyContext(WinThreads[i].Display, WinThreads[i].Context); + XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); + } +} + + +static void +usage(void) +{ + printf("xeglthreads: test of EGL/GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" xeglthreads [options]\n"); + printf("Options:\n"); + printf(" -display DISPLAYNAME Specify display string\n"); + printf(" -n NUMTHREADS Number of threads to create\n"); + printf(" -p Use a separate display connection for each thread\n"); + printf(" -l Use application-side locking\n"); + printf(" -t Enable texturing\n"); + printf("Keyboard:\n"); + printf(" Esc Exit\n"); + printf(" t Change texture image (requires -t option)\n"); + printf(" a Toggle animation\n"); + printf(" s Step rotation (when not animating)\n"); +} + + +int +main(int argc, char *argv[]) +{ + char *displayName = NULL; + int numThreads = 2; + Display *dpy = NULL; + EGLDisplay *egl_dpy = NULL; + int i; + Status threadStat; + + if (argc == 1) { + usage(); + } + else { + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + displayName = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "-p") == 0) { + MultiDisplays = 1; + } + else if (strcmp(argv[i], "-l") == 0) { + Locking = 1; + } + else if (strcmp(argv[i], "-t") == 0) { + Texture = 1; + } + else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { + numThreads = atoi(argv[i + 1]); + if (numThreads < 1) + numThreads = 1; + else if (numThreads > MAX_WINTHREADS) + numThreads = MAX_WINTHREADS; + i++; + } + else { + usage(); + exit(1); + } + } + } + + if (Locking) + printf("xeglthreads: Using explicit locks around Xlib calls.\n"); + else + printf("xeglthreads: No explict locking.\n"); + + if (MultiDisplays) + printf("xeglthreads: Per-thread display connections.\n"); + else + printf("xeglthreads: Single display connection.\n"); + + /* + * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. + */ + if (!MultiDisplays) { + if (!Locking) { + threadStat = XInitThreads(); + if (threadStat) { + printf("XInitThreads() returned %d (success)\n", + (int) threadStat); + } + else { + printf("XInitThreads() returned 0 " + "(failure- this program may fail)\n"); + } + } + + dpy = XOpenDisplay(displayName); + if (!dpy) { + fprintf(stderr, "Unable to open display %s\n", + XDisplayName(displayName)); + return -1; + } + egl_dpy = eglGetDisplay(dpy); + if (!egl_dpy) { + fprintf(stderr, "Unable to get EGL display\n"); + XCloseDisplay(dpy); + return -1; + } + if (!eglInitialize(egl_dpy, NULL, NULL)) { + fprintf(stderr, "Unable to initialize EGL display\n"); + return -1; + } + } + + pthread_mutex_init(&Mutex, NULL); + pthread_mutex_init(&CondMutex, NULL); + pthread_cond_init(&CondVar, NULL); + + printf("xeglthreads: creating windows\n"); + + NumWinThreads = numThreads; + + /* Create the EGL windows and contexts */ + for (i = 0; i < numThreads; i++) { + EGLContext share; + + if (MultiDisplays) { + WinThreads[i].Dpy = XOpenDisplay(displayName); + assert(WinThreads[i].Dpy); + WinThreads[i].Display = eglGetDisplay(WinThreads[i].Dpy); + assert(eglInitialize(WinThreads[i].Display, NULL, NULL)); + } + else { + WinThreads[i].Dpy = dpy; + WinThreads[i].Display = egl_dpy; + } + WinThreads[i].Index = i; + WinThreads[i].Initialized = GL_FALSE; + + share = (Texture && i > 0) ? WinThreads[0].Context : 0; + + create_window(&WinThreads[i], share); + } + + printf("xeglthreads: creating threads\n"); + + /* Create the threads */ + for (i = 0; i < numThreads; i++) { + pthread_create(&WinThreads[i].Thread, NULL, thread_function, + (void*) &WinThreads[i]); + printf("xeglthreads: Created thread %p\n", + (void *) WinThreads[i].Thread); + } + + if (MultiDisplays) + event_loop_multi(); + else + event_loop(dpy); + + clean_up(); + + if (MultiDisplays) { + for (i = 0; i < numThreads; i++) { + eglTerminate(WinThreads[i].Display); + XCloseDisplay(WinThreads[i].Dpy); + } + } + else { + eglTerminate(egl_dpy); + XCloseDisplay(dpy); + } + + return 0; +} + + +#else /* PTHREADS */ + + +#include + +int +main(int argc, char *argv[]) +{ + printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); + return 0; +} + + +#endif /* PTHREADS */ diff --git a/progs/egl/peglgears.c b/progs/egl/peglgears.c deleted file mode 100644 index 212d1acf692..00000000000 --- a/progs/egl/peglgears.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -/* - * This is a port of the infamous "glxgears" demo to straight EGL - * Port by Dane Rushton 10 July 2005 - * - * No command line options. - * Program runs for 5 seconds then exits, outputing framerate to console - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include -#include - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static GLint gear1, gear2, gear3; -static GLfloat angle = 0.0; - -#if 0 -static GLfloat eyesep = 5.0; /* Eye separation. */ -static GLfloat fix_point = 40.0; /* Fixation point distance. */ -static GLfloat left, right, asp; /* Stereo frustum params. */ -#endif - - -/* - * - * Draw a gear wheel. You'll probably want to call this function when - * building a display list since we do a lot of trig here. - * - * Input: inner_radius - radius of hole at center - * outer_radius - radius at center of teeth - * width - width of gear - * teeth - number of teeth - * tooth_depth - depth of tooth - */ -static void -gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, - GLint teeth, GLfloat tooth_depth) -{ - GLint i; - GLfloat r0, r1, r2; - GLfloat angle, da; - GLfloat u, v, len; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0; - r2 = outer_radius + tooth_depth / 2.0; - - da = 2.0 * M_PI / teeth / 4.0; - - glShadeModel(GL_FLAT); - - glNormal3f(0.0, 0.0, 1.0); - - /* draw front face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - if (i < teeth) { - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - } - glEnd(); - - /* draw front sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - glEnd(); - - glNormal3f(0.0, 0.0, -1.0); - - /* draw back face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - if (i < teeth) { - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - } - } - glEnd(); - - /* draw back sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - } - glEnd(); - - /* draw outward faces of teeth */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - u = r2 * cos(angle + da) - r1 * cos(angle); - v = r2 * sin(angle + da) - r1 * sin(angle); - len = sqrt(u * u + v * v); - u /= len; - v /= len; - glNormal3f(v, -u, 0.0); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); - v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); - glNormal3f(v, -u, 0.0); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - } - - glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); - glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); - - glEnd(); - - glShadeModel(GL_SMOOTH); - - /* draw inside radius cylinder */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glNormal3f(-cos(angle), -sin(angle), 0.0); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - } - glEnd(); -} - - -static void -draw(void) -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1.0, 0.0, 0.0); - glRotatef(view_roty, 0.0, 1.0, 0.0); - glRotatef(view_rotz, 0.0, 0.0, 1.0); - - glPushMatrix(); - glTranslatef(-3.0, -2.0, 0.0); - glRotatef(angle, 0.0, 0.0, 1.0); - glCallList(gear1); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(3.1, -2.0, 0.0); - glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); - glCallList(gear2); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(-3.1, 4.2, 0.0); - glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); - glCallList(gear3); - glPopMatrix(); - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat h = (GLfloat) height / (GLfloat) width; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); -} - - - -static void -init(void) -{ - static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; - static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; - static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; - static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; - - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - - /* make the gears */ - gear1 = glGenLists(1); - glNewList(gear1, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); - gear(1.0, 4.0, 1.0, 20, 0.7); - glEndList(); - - gear2 = glGenLists(1); - glNewList(gear2, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); - gear(0.5, 2.0, 2.0, 10, 0.7); - glEndList(); - - gear3 = glGenLists(1); - glNewList(gear3, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); - gear(1.3, 2.0, 0.5, 10, 0.7); - glEndList(); - - glEnable(GL_NORMALIZE); -} - - - - -static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) -{ - double st = current_time(); - double ct = st; - int frames = 0; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - double tt = current_time(); - double dt = tt - ct; - ct = tt; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - draw(); - - eglSwapBuffers(dpy, surf); - - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); - -} - - -int -main(int argc, char *argv[]) -{ - int major, minor; - EGLContext ctx; - EGLSurface surface; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - GLboolean printInfo = GL_FALSE; - EGLint width = 300, height = 300; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-info") == 0) - { - printInfo = GL_TRUE; - } - else - printf("Warning: unknown parameter: %s\n", argv[i]); - } - - /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &major, &minor)) { - printf("peglgears: eglInitialize failed\n"); - return 0; - } - - printf("peglgears: EGL version = %d.%d\n", major, minor); - printf("peglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - - eglBindAPI(EGL_OPENGL_API); - - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("peglgears: failed to create context\n"); - return 0; - } - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - surface = eglCreatePbufferSurface(d, configs[0], screenAttribs); - if (surface == EGL_NO_SURFACE) { - printf("peglgears: failed to create pbuffer surface\n"); - return 0; - } - - b = eglMakeCurrent(d, surface, surface, ctx); - if (!b) { - printf("peglgears: make current failed\n"); - return 0; - } - - if (printInfo) - { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - reshape(width, height); - - glDrawBuffer( GL_BACK ); - - run_gears(d, surface, 5.0); - - eglDestroySurface(d, surface); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/xegl_tri.c b/progs/egl/xegl_tri.c deleted file mode 100644 index 1f1a005a210..00000000000 --- a/progs/egl/xegl_tri.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -/* - * Draw a triangle with X/EGL. - * Brian Paul - * 3 June 2008 - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include /* using full OpenGL for now */ -#include - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -draw(void) -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(3, GL_FLOAT, 0, colors); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - - -static void -init(void) -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} - - -/* - * Create an RGB, double-buffered X window. - * Return the window and context handles. - */ -static void -make_x_window(Display *x_dpy, EGLDisplay egl_dpy, - const char *name, - int x, int y, int width, int height, - Window *winRet, - EGLContext *ctxRet, - EGLSurface *surfRet) -{ - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_NONE - }; - - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - Window win; - XVisualInfo *visInfo, visTemplate; - int num_visuals; - EGLContext ctx; - EGLConfig config; - EGLint num_configs; - EGLint vid; - - scrnum = DefaultScreen( x_dpy ); - root = RootWindow( x_dpy, scrnum ); - - if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) || - !num_configs) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_API); - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: glXCreateContext failed\n"); - exit(1); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf) -{ - while (1) { - int redraw = 0; - XEvent event; - - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - - if (redraw) { - draw(); - eglSwapBuffers(egl_dpy, egl_surf); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - const int winWidth = 300, winHeight = 300; - Display *x_dpy; - Window win; - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "xegl_tri", 0, 0, winWidth, winHeight, - &win, &egl_ctx, &egl_surf); - - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - } - - init(); - - /* Set initial projection/viewing transformation. - * We can't be sure we'll get a ConfigureNotify event when the window - * first appears. - */ - reshape(winWidth, winHeight); - - event_loop(x_dpy, win, egl_dpy, egl_surf); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c deleted file mode 100644 index a6a977d9fff..00000000000 --- a/progs/egl/xeglgears.c +++ /dev/null @@ -1,954 +0,0 @@ -/* - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - */ - -/* - * Ported to X/EGL/GLES. XXX Actually, uses full OpenGL ATM. - * Brian Paul - * 30 May 2008 - */ - -/* - * Command line options: - * -info print GL implementation information - * - */ - - -#define GL_GLEXT_PROTOTYPES -#define EGL_EGLEXT_PROTOTYPES - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include -#include - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static GLint gear1, gear2, gear3; -static GLfloat angle = 0.0; - -/* - * - * Draw a gear wheel. You'll probably want to call this function when - * building a display list since we do a lot of trig here. - * - * Input: inner_radius - radius of hole at center - * outer_radius - radius at center of teeth - * width - width of gear - * teeth - number of teeth - * tooth_depth - depth of tooth - */ -static void -gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, - GLint teeth, GLfloat tooth_depth) -{ - GLint i; - GLfloat r0, r1, r2; - GLfloat angle, da; - GLfloat u, v, len; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0; - r2 = outer_radius + tooth_depth / 2.0; - - da = 2.0 * M_PI / teeth / 4.0; - - glShadeModel(GL_FLAT); - - glNormal3f(0.0, 0.0, 1.0); - - /* draw front face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - if (i < teeth) { - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - } - glEnd(); - - /* draw front sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - glEnd(); - - glNormal3f(0.0, 0.0, -1.0); - - /* draw back face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - if (i < teeth) { - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - } - } - glEnd(); - - /* draw back sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - } - glEnd(); - - /* draw outward faces of teeth */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - u = r2 * cos(angle + da) - r1 * cos(angle); - v = r2 * sin(angle + da) - r1 * sin(angle); - len = sqrt(u * u + v * v); - u /= len; - v /= len; - glNormal3f(v, -u, 0.0); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); - v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); - glNormal3f(v, -u, 0.0); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - } - - glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); - glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); - - glEnd(); - - glShadeModel(GL_SMOOTH); - - /* draw inside radius cylinder */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glNormal3f(-cos(angle), -sin(angle), 0.0); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - } - glEnd(); -} - - -static void -draw(void) -{ - glClearColor(0.2, 0.2, 0.2, 0.2); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1.0, 0.0, 0.0); - glRotatef(view_roty, 0.0, 1.0, 0.0); - glRotatef(view_rotz, 0.0, 0.0, 1.0); - - glPushMatrix(); - glTranslatef(-3.0, -2.0, 0.0); - glRotatef(angle, 0.0, 0.0, 1.0); - glCallList(gear1); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(3.1, -2.0, 0.0); - glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); - glCallList(gear2); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(-3.1, 4.2, 0.0); - glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); - glCallList(gear3); - glPopMatrix(); - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); -} - - - -static void -init(void) -{ - static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; - static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; - static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; - static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; - - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - - /* make the gears */ - gear1 = glGenLists(1); - glNewList(gear1, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); - gear(1.0, 4.0, 1.0, 20, 0.7); - glEndList(); - - gear2 = glGenLists(1); - glNewList(gear2, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); - gear(0.5, 2.0, 2.0, 10, 0.7); - glEndList(); - - gear3 = glGenLists(1); - glNewList(gear3, GL_COMPILE); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); - gear(1.3, 2.0, 0.5, 10, 0.7); - glEndList(); - - glEnable(GL_NORMALIZE); -} - - -struct egl_manager { - EGLNativeDisplayType xdpy; - EGLNativeWindowType xwin; - EGLNativePixmapType xpix; - - EGLDisplay dpy; - EGLConfig conf; - EGLContext ctx; - - EGLSurface win; - EGLSurface pix; - EGLSurface pbuf; - EGLImageKHR image; - - EGLBoolean verbose; - EGLint major, minor; - - GC gc; - GLuint fbo; -}; - -static struct egl_manager * -egl_manager_new(EGLNativeDisplayType xdpy, const EGLint *attrib_list, - EGLBoolean verbose) -{ - struct egl_manager *eman; - const char *ver; - EGLint num_conf; - - eman = calloc(1, sizeof(*eman)); - if (!eman) - return NULL; - - eman->verbose = verbose; - eman->xdpy = xdpy; - - eman->dpy = eglGetDisplay(eman->xdpy); - if (eman->dpy == EGL_NO_DISPLAY) { - printf("eglGetDisplay() failed\n"); - free(eman); - return NULL; - } - - if (!eglInitialize(eman->dpy, &eman->major, &eman->minor)) { - printf("eglInitialize() failed\n"); - free(eman); - return NULL; - } - - ver = eglQueryString(eman->dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", ver); - - if (!eglChooseConfig(eman->dpy, attrib_list, &eman->conf, 1, &num_conf) || - !num_conf) { - printf("eglChooseConfig() failed\n"); - eglTerminate(eman->dpy); - free(eman); - return NULL; - } - - eman->ctx = eglCreateContext(eman->dpy, eman->conf, EGL_NO_CONTEXT, NULL); - if (eman->ctx == EGL_NO_CONTEXT) { - printf("eglCreateContext() failed\n"); - eglTerminate(eman->dpy); - free(eman); - return NULL; - } - - return eman; -} - -static EGLBoolean -egl_manager_create_window(struct egl_manager *eman, const char *name, - EGLint w, EGLint h, EGLBoolean need_surface, - EGLBoolean fullscreen, const EGLint *attrib_list) -{ - XVisualInfo vinfo_template, *vinfo = NULL; - EGLint val, num_vinfo; - Window root; - XSetWindowAttributes attrs; - unsigned long mask; - EGLint x = 0, y = 0; - - if (!eglGetConfigAttrib(eman->dpy, eman->conf, - EGL_NATIVE_VISUAL_ID, &val)) { - printf("eglGetConfigAttrib() failed\n"); - return EGL_FALSE; - } - if (val) { - vinfo_template.visualid = (VisualID) val; - vinfo = XGetVisualInfo(eman->xdpy, VisualIDMask, &vinfo_template, &num_vinfo); - } - /* try harder if window surface is not needed */ - if (!vinfo && !need_surface && - eglGetConfigAttrib(eman->dpy, eman->conf, EGL_BUFFER_SIZE, &val)) { - if (val == 32) - val = 24; - vinfo_template.depth = val; - vinfo = XGetVisualInfo(eman->xdpy, VisualDepthMask, &vinfo_template, &num_vinfo); - } - - if (!vinfo) { - printf("XGetVisualInfo() failed\n"); - return EGL_FALSE; - } - - root = DefaultRootWindow(eman->xdpy); - if (fullscreen) { - x = y = 0; - w = DisplayWidth(eman->xdpy, DefaultScreen(eman->xdpy)); - h = DisplayHeight(eman->xdpy, DefaultScreen(eman->xdpy)); - } - - /* window attributes */ - attrs.background_pixel = 0; - attrs.border_pixel = 0; - attrs.colormap = XCreateColormap(eman->xdpy, root, vinfo->visual, AllocNone); - attrs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - attrs.override_redirect = fullscreen; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; - - eman->xwin = XCreateWindow(eman->xdpy, root, x, y, w, h, - 0, vinfo->depth, InputOutput, - vinfo->visual, mask, &attrs); - XFree(vinfo); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = w; - sizehints.height = h; - sizehints.flags = USSize | USPosition; - XSetNormalHints(eman->xdpy, eman->xwin, &sizehints); - XSetStandardProperties(eman->xdpy, eman->xwin, name, name, - None, (char **)NULL, 0, &sizehints); - } - - if (need_surface) { - eman->win = eglCreateWindowSurface(eman->dpy, eman->conf, - eman->xwin, attrib_list); - if (eman->win == EGL_NO_SURFACE) { - printf("eglCreateWindowSurface() failed\n"); - XDestroyWindow(eman->xdpy, eman->xwin); - eman->xwin = None; - return EGL_FALSE; - } - } - - eman->gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL); - - XMapWindow(eman->xdpy, eman->xwin); - - return EGL_TRUE; -} - -static EGLBoolean -egl_manager_create_pixmap(struct egl_manager *eman, EGLNativeWindowType xwin, - EGLBoolean need_surface, const EGLint *attrib_list) -{ - XWindowAttributes attrs; - - if (!XGetWindowAttributes(eman->xdpy, xwin, &attrs)) { - printf("XGetWindowAttributes() failed\n"); - return EGL_FALSE; - } - - eman->xpix = XCreatePixmap(eman->xdpy, xwin, - attrs.width, attrs.height, attrs.depth); - - if (need_surface) { - eman->pix = eglCreatePixmapSurface(eman->dpy, eman->conf, - eman->xpix, attrib_list); - if (eman->pix == EGL_NO_SURFACE) { - printf("eglCreatePixmapSurface() failed\n"); - XFreePixmap(eman->xdpy, eman->xpix); - eman->xpix = None; - return EGL_FALSE; - } - } - - return EGL_TRUE; -} - -static EGLBoolean -egl_manager_create_pbuffer(struct egl_manager *eman, const EGLint *attrib_list) -{ - eman->pbuf = eglCreatePbufferSurface(eman->dpy, eman->conf, attrib_list); - if (eman->pbuf == EGL_NO_SURFACE) { - printf("eglCreatePbufferSurface() failed\n"); - return EGL_FALSE; - } - - return EGL_TRUE; -} - -static void -egl_manager_destroy(struct egl_manager *eman) -{ - eglMakeCurrent(eman->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglTerminate(eman->dpy); - - if (eman->xwin != None) - XDestroyWindow(eman->xdpy, eman->xwin); - if (eman->xpix != None) - XFreePixmap(eman->xdpy, eman->xpix); - - XFreeGC(eman->xdpy, eman->gc); - - free(eman); -} - -enum { - GEARS_WINDOW, - GEARS_PIXMAP, - GEARS_PIXMAP_TEXTURE, - GEARS_PBUFFER, - GEARS_PBUFFER_TEXTURE, - GEARS_RENDERBUFFER -}; - -static void -texture_gears(struct egl_manager *eman, int surface_type) -{ - static const GLint verts[12] = - { -5, -6, -10, 5, -6, -10, -5, 4, 10, 5, 4, 10 }; - static const GLint tex_coords[8] = { 0, 0, 1, 0, 0, 1, 1, 1 }; - - eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(3, GL_INT, 0, verts); - glTexCoordPointer(2, GL_INT, 0, tex_coords); - - if (surface_type == GEARS_PBUFFER_TEXTURE) - eglBindTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisable(GL_TEXTURE_2D); - - if (surface_type == GEARS_PBUFFER_TEXTURE) - eglReleaseTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); - - eglSwapBuffers(eman->dpy, eman->win); -} - -static void -copy_gears(struct egl_manager *eman, - EGLint tile_w, EGLint tile_h, EGLint w, EGLint h) -{ - int x, y; - - eglWaitClient(); - - for (x = 0; x < w; x += tile_w) { - for (y = 0; y < h; y += tile_h) { - - XCopyArea(eman->xdpy, eman->xpix, eman->xwin, eman->gc, - 0, 0, tile_w, tile_h, x, y); - } - } -} - -static void -event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h) -{ - int window_w = w, window_h = h; - - if (surface_type == EGL_PBUFFER_BIT) - printf("there will be no screen update if " - "eglCopyBuffers() is not implemented\n"); - - while (1) { - while (XPending(eman->xdpy) > 0) { - XEvent event; - XNextEvent(eman->xdpy, &event); - switch (event.type) { - case Expose: - /* we'll redraw below */ - break; - case ConfigureNotify: - window_w = event.xconfigure.width; - window_h = event.xconfigure.height; - if (surface_type == EGL_WINDOW_BIT) - reshape(window_w, window_h); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - } - } - - { - static int frames = 0; - static double tRot0 = -1.0, tRate0 = -1.0; - double dt, t = current_time(); - if (tRot0 < 0.0) - tRot0 = t; - dt = t - tRot0; - tRot0 = t; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - switch (surface_type) { - case GEARS_WINDOW: - draw(); - eglSwapBuffers(eman->dpy, eman->win); - break; - - case GEARS_PBUFFER: - draw(); - if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix)) - break; - copy_gears(eman, w, h, window_w, window_h); - break; - - case GEARS_PBUFFER_TEXTURE: - eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); - draw(); - texture_gears(eman, surface_type); - break; - - case GEARS_PIXMAP: - draw(); - copy_gears(eman, w, h, window_w, window_h); - break; - - case GEARS_PIXMAP_TEXTURE: - eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); - draw(); - texture_gears(eman, surface_type); - break; - - case GEARS_RENDERBUFFER: - glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); - draw(); - glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); - texture_gears(eman, surface_type); - break; - } - - frames++; - - if (tRate0 < 0.0) - tRate0 = t; - if (t - tRate0 >= 5.0) { - GLfloat seconds = t - tRate0; - GLfloat fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, - fps); - tRate0 = t; - frames = 0; - } - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display set the display to run on\n"); - printf(" -fullscreen run in fullscreen mode\n"); - printf(" -info display OpenGL renderer info\n"); - printf(" -pixmap use pixmap surface\n"); - printf(" -pixmap-texture use pixmap surface and texture using EGLImage\n"); - printf(" -pbuffer use pbuffer surface and eglCopyBuffers\n"); - printf(" -pbuffer-texture use pbuffer surface and eglBindTexImage\n"); - printf(" -renderbuffer renderbuffer as EGLImage and bind as texture from\n"); -} - -static const char *names[] = { - "window", - "pixmap", - "pixmap_texture", - "pbuffer", - "pbuffer_texture", - "renderbuffer" -}; - -int -main(int argc, char *argv[]) -{ - const int winWidth = 300, winHeight = 300; - Display *x_dpy; - char *dpyName = NULL; - struct egl_manager *eman; - EGLint attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, /* may be changed later */ - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_NONE - }; - char win_title[] = "xeglgears (window/pixmap/pbuffer)"; - EGLint surface_type = GEARS_WINDOW; - GLboolean printInfo = GL_FALSE; - GLboolean fullscreen = GL_FALSE; - EGLBoolean ret; - GLuint texture, color_rb, depth_rb; - int i; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else if (strcmp(argv[i], "-fullscreen") == 0) { - fullscreen = GL_TRUE; - } - else if (strcmp(argv[i], "-pixmap") == 0) { - surface_type = GEARS_PIXMAP; - attribs[1] = EGL_PIXMAP_BIT; - } - else if (strcmp(argv[i], "-pixmap-texture") == 0) { - surface_type = GEARS_PIXMAP_TEXTURE; - attribs[1] = EGL_PIXMAP_BIT; - } - else if (strcmp(argv[i], "-pbuffer") == 0) { - surface_type = GEARS_PBUFFER; - attribs[1] = EGL_PBUFFER_BIT; - } - else if (strcmp(argv[i], "-pbuffer-texture") == 0) { - surface_type = GEARS_PBUFFER_TEXTURE; - attribs[1] = EGL_PBUFFER_BIT; - } - else if (strcmp(argv[i], "-renderbuffer") == 0) { - surface_type = GEARS_RENDERBUFFER; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - eglBindAPI(EGL_OPENGL_API); - - eman = egl_manager_new(x_dpy, attribs, printInfo); - if (!eman) { - XCloseDisplay(x_dpy); - return -1; - } - - snprintf(win_title, sizeof(win_title), - "xeglgears (%s)", names[surface_type]); - - ret = egl_manager_create_window(eman, win_title, winWidth, winHeight, - EGL_TRUE, fullscreen, NULL); - if (!ret) - return -1; - - /* create surface(s) */ - switch (surface_type) { - case GEARS_WINDOW: - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - break; - case GEARS_PIXMAP: - case GEARS_PIXMAP_TEXTURE: - ret = egl_manager_create_pixmap(eman, eman->xwin, EGL_TRUE, NULL); - if (surface_type == GEARS_PIXMAP_TEXTURE) - eman->image = eglCreateImageKHR (eman->dpy, eman->ctx, - EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer) eman->xpix, NULL); - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); - break; - case GEARS_PBUFFER: - case GEARS_PBUFFER_TEXTURE: - { - EGLint pbuf_attribs[] = { - EGL_WIDTH, winWidth, - EGL_HEIGHT, winHeight, - EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, - EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, - EGL_NONE - }; - ret = (egl_manager_create_pixmap(eman, eman->xwin, - EGL_TRUE, NULL) && - egl_manager_create_pbuffer(eman, pbuf_attribs)); - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); - } - break; - - - case GEARS_RENDERBUFFER: - ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - if (ret == EGL_FALSE) - printf("failed to make context current\n"); - - glGenFramebuffers(1, &eman->fbo); - glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); - - glGenRenderbuffers(1, &color_rb); - glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_rb); - glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_RGBA, winWidth, winHeight); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - GL_RENDERBUFFER_EXT, - color_rb); - - eman->image = eglCreateImageKHR(eman->dpy, eman->ctx, - EGL_GL_RENDERBUFFER_KHR, - (EGLClientBuffer) color_rb, NULL); - - glGenRenderbuffers(1, &depth_rb); - glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_rb); - glRenderbufferStorage(GL_RENDERBUFFER_EXT, - GL_DEPTH_COMPONENT, winWidth, winHeight); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - depth_rb); - - if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE) { - printf("framebuffer not complete\n"); - exit(1); - } - - break; - - default: - ret = EGL_FALSE; - break; - } - - switch (surface_type) { - case GEARS_PIXMAP_TEXTURE: - case GEARS_RENDERBUFFER: - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eman->image); - break; - case GEARS_PBUFFER_TEXTURE: - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - break; - } - - if (!ret) { - egl_manager_destroy(eman); - XCloseDisplay(x_dpy); - return -1; - } - - if (printInfo) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - } - - init(); - - /* Set initial projection/viewing transformation. - * We can't be sure we'll get a ConfigureNotify event when the window - * first appears. - */ - reshape(winWidth, winHeight); - - event_loop(eman, surface_type, winWidth, winHeight); - - glDeleteLists(gear1, 1); - glDeleteLists(gear2, 1); - glDeleteLists(gear3, 1); - - egl_manager_destroy(eman); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/xeglthreads.c b/progs/egl/xeglthreads.c deleted file mode 100644 index 5787faecb90..00000000000 --- a/progs/egl/xeglthreads.c +++ /dev/null @@ -1,775 +0,0 @@ -/* - * Copyright (C) 2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice 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 - * BRIAN PAUL 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. - * - * Ported to EGL by Chia-I Wu - */ - - -/* - * This program tests EGL thread safety. - * Command line options: - * -p Open a display connection for each thread - * -l Enable application-side locking - * -n Number of threads to create (default is 2) - * -display Specify X display (default is $DISPLAY) - * -t Use texture mapping - * - * Brian Paul 20 July 2000 - */ - - -/* - * Notes: - * - Each thread gets its own EGL context. - * - * - The EGL contexts share texture objects. - * - * - When 't' is pressed to update the texture image, the window/thread which - * has input focus is signalled to change the texture. The other threads - * should see the updated texture the next time they call glBindTexture. - */ - - -#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* - * Each window/thread/context: - */ -struct winthread { - Display *Dpy; - int Index; - pthread_t Thread; - Window Win; - EGLDisplay Display; - EGLContext Context; - EGLSurface Surface; - float Angle; - int WinWidth, WinHeight; - GLboolean NewSize; - GLboolean Initialized; - GLboolean MakeNewTexture; -}; - - -#define MAX_WINTHREADS 100 -static struct winthread WinThreads[MAX_WINTHREADS]; -static int NumWinThreads = 0; -static volatile GLboolean ExitFlag = GL_FALSE; - -static GLboolean MultiDisplays = 0; -static GLboolean Locking = 0; -static GLboolean Texture = GL_FALSE; -static GLuint TexObj = 12; -static GLboolean Animate = GL_TRUE; - -static pthread_mutex_t Mutex; -static pthread_cond_t CondVar; -static pthread_mutex_t CondMutex; - - -static void -Error(const char *msg) -{ - fprintf(stderr, "Error: %s\n", msg); - exit(1); -} - - -static void -signal_redraw(void) -{ - pthread_mutex_lock(&CondMutex); - pthread_cond_broadcast(&CondVar); - pthread_mutex_unlock(&CondMutex); -} - - -static void -MakeNewTexture(struct winthread *wt) -{ -#define TEX_SIZE 128 - static float step = 0.0; - GLfloat image[TEX_SIZE][TEX_SIZE][4]; - GLint width; - int i, j; - - for (j = 0; j < TEX_SIZE; j++) { - for (i = 0; i < TEX_SIZE; i++) { - float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; - float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; - float r = dt * dt + ds * ds + step; - image[j][i][0] = - image[j][i][1] = - image[j][i][2] = 0.75 + 0.25 * cos(r); - image[j][i][3] = 1.0; - } - } - - step += 0.5; - - glBindTexture(GL_TEXTURE_2D, TexObj); - - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); - if (width) { - assert(width == TEX_SIZE); - /* sub-tex replace */ - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, - GL_RGBA, GL_FLOAT, image); - } - else { - /* create new */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, - GL_RGBA, GL_FLOAT, image); - } -} - - - -/* draw a colored cube */ -static void -draw_object(void) -{ - glPushMatrix(); - glScalef(0.75, 0.75, 0.75); - - glColor3f(1, 0, 0); - - if (Texture) { - glBindTexture(GL_TEXTURE_2D, TexObj); - glEnable(GL_TEXTURE_2D); - } - else { - glDisable(GL_TEXTURE_2D); - } - - glBegin(GL_QUADS); - - /* -X */ - glColor3f(0, 1, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); - glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - - /* +X */ - glColor3f(1, 0, 0); - glTexCoord2f(0, 0); glVertex3f(1, -1, -1); - glTexCoord2f(1, 0); glVertex3f(1, 1, -1); - glTexCoord2f(1, 1); glVertex3f(1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(1, -1, 1); - - /* -Y */ - glColor3f(1, 0, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - - /* +Y */ - glColor3f(0, 1, 0); - glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); - - /* -Z */ - glColor3f(1, 1, 0); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); - - /* +Y */ - glColor3f(0, 0, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); - - glEnd(); - - glPopMatrix(); -} - - -/* signal resize of given window */ -static void -resize(struct winthread *wt, int w, int h) -{ - wt->NewSize = GL_TRUE; - wt->WinWidth = w; - wt->WinHeight = h; - if (!Animate) - signal_redraw(); -} - - -/* - * We have an instance of this for each thread. - */ -static void -draw_loop(struct winthread *wt) -{ - while (!ExitFlag) { - - if (Locking) - pthread_mutex_lock(&Mutex); - - if (!wt->Initialized) { - eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context); - printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index, - (char *) glGetString(GL_RENDERER)); - if (Texture /*&& wt->Index == 0*/) { - MakeNewTexture(wt); - } - wt->Initialized = GL_TRUE; - } - - if (Locking) - pthread_mutex_unlock(&Mutex); - - eglBindAPI(EGL_OPENGL_API); - if (eglGetCurrentContext() != wt->Context) { - printf("xeglthreads: current context %p != %p\n", - eglGetCurrentContext(), wt->Context); - } - - glEnable(GL_DEPTH_TEST); - - if (wt->NewSize) { - GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; - glViewport(0, 0, wt->WinWidth, wt->WinHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-w, w, -1.0, 1.0, 1.5, 10); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, -2.5); - wt->NewSize = GL_FALSE; - } - - if (wt->MakeNewTexture) { - MakeNewTexture(wt); - wt->MakeNewTexture = GL_FALSE; - } - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(wt->Angle, 0, 1, 0); - glRotatef(wt->Angle, 1, 0, 0); - glScalef(0.7, 0.7, 0.7); - draw_object(); - glPopMatrix(); - - if (Locking) - pthread_mutex_lock(&Mutex); - - eglSwapBuffers(wt->Display, wt->Surface); - - if (Locking) - pthread_mutex_unlock(&Mutex); - - if (Animate) { - usleep(5000); - } - else { - /* wait for signal to draw */ - pthread_mutex_lock(&CondMutex); - pthread_cond_wait(&CondVar, &CondMutex); - pthread_mutex_unlock(&CondMutex); - } - wt->Angle += 1.0; - } - eglMakeCurrent(wt->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); -} - - -static void -keypress(XEvent *event, struct winthread *wt) -{ - char buf[100]; - KeySym keySym; - XComposeStatus stat; - - XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); - - switch (keySym) { - case XK_Escape: - /* tell all threads to exit */ - if (!Animate) { - signal_redraw(); - } - ExitFlag = GL_TRUE; - /*printf("exit draw_loop %d\n", wt->Index);*/ - return; - case XK_t: - case XK_T: - if (Texture) { - wt->MakeNewTexture = GL_TRUE; - if (!Animate) - signal_redraw(); - } - break; - case XK_a: - case XK_A: - Animate = !Animate; - if (Animate) /* yes, prev Animate state! */ - signal_redraw(); - break; - case XK_s: - case XK_S: - if (!Animate) - signal_redraw(); - break; - default: - ; /* nop */ - } -} - - -/* - * The main process thread runs this loop. - * Single display connection for all threads. - */ -static void -event_loop(Display *dpy) -{ - XEvent event; - int i; - - assert(!MultiDisplays); - - while (!ExitFlag) { - - if (Locking) { - while (1) { - int k; - pthread_mutex_lock(&Mutex); - k = XPending(dpy); - if (k) { - XNextEvent(dpy, &event); - pthread_mutex_unlock(&Mutex); - break; - } - pthread_mutex_unlock(&Mutex); - usleep(5000); - } - } - else { - XNextEvent(dpy, &event); - } - - switch (event.type) { - case ConfigureNotify: - /* Find winthread for this event's window */ - for (i = 0; i < NumWinThreads; i++) { - struct winthread *wt = &WinThreads[i]; - if (event.xconfigure.window == wt->Win) { - resize(wt, event.xconfigure.width, - event.xconfigure.height); - break; - } - } - break; - case KeyPress: - for (i = 0; i < NumWinThreads; i++) { - struct winthread *wt = &WinThreads[i]; - if (event.xkey.window == wt->Win) { - keypress(&event, wt); - break; - } - } - break; - default: - /*no-op*/ ; - } - } -} - - -/* - * Separate display connection for each thread. - */ -static void -event_loop_multi(void) -{ - XEvent event; - int w = 0; - - assert(MultiDisplays); - - while (!ExitFlag) { - struct winthread *wt = &WinThreads[w]; - if (XPending(wt->Dpy)) { - XNextEvent(wt->Dpy, &event); - switch (event.type) { - case ConfigureNotify: - resize(wt, event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - keypress(&event, wt); - break; - default: - ; /* nop */ - } - } - w = (w + 1) % NumWinThreads; - usleep(5000); - } -} - - - -/* - * we'll call this once for each thread, before the threads are created. - */ -static void -create_window(struct winthread *wt, EGLContext shareCtx) -{ - Window win; - EGLContext ctx; - EGLSurface surf; - EGLint attribs[] = { EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_NONE }; - EGLConfig config; - EGLint num_configs; - EGLint vid; - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - XVisualInfo *visinfo, visTemplate; - int num_visuals; - int width = 160, height = 160; - int xpos = (wt->Index % 8) * (width + 10); - int ypos = (wt->Index / 8) * (width + 20); - - scrnum = DefaultScreen(wt->Dpy); - root = RootWindow(wt->Dpy, scrnum); - - if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs) || - !num_configs) { - Error("Unable to choose an EGL config"); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(wt->Display, config, EGL_NATIVE_VISUAL_ID, &vid)) { - Error("Unable to get visual id of EGL config\n"); - } - - visTemplate.visualid = vid; - visinfo = XGetVisualInfo(wt->Dpy, VisualIDMask, - &visTemplate, &num_visuals); - if (!visinfo) { - Error("Unable to find RGB, Z, double-buffered visual"); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, - 0, visinfo->depth, InputOutput, - visinfo->visual, mask, &attr); - if (!win) { - Error("Couldn't create window"); - } - - XFree(visinfo); - - { - XSizeHints sizehints; - sizehints.x = xpos; - sizehints.y = ypos; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(wt->Dpy, win, &sizehints); - XSetStandardProperties(wt->Dpy, win, "xeglthreads", "xeglthreads", - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_API); - - ctx = eglCreateContext(wt->Display, config, shareCtx, NULL); - if (!ctx) { - Error("Couldn't create EGL context"); - } - surf = eglCreateWindowSurface(wt->Display, config, win, NULL); - if (!surf) { - Error("Couldn't create EGL surface"); - } - - XMapWindow(wt->Dpy, win); - XSync(wt->Dpy, 0); - - /* save the info for this window/context */ - wt->Win = win; - wt->Context = ctx; - wt->Surface = surf; - wt->Angle = 0.0; - wt->WinWidth = width; - wt->WinHeight = height; - wt->NewSize = GL_TRUE; -} - - -/* - * Called by pthread_create() - */ -static void * -thread_function(void *p) -{ - struct winthread *wt = (struct winthread *) p; - draw_loop(wt); - return NULL; -} - - -/* - * called before exit to wait for all threads to finish - */ -static void -clean_up(void) -{ - int i; - - /* wait for threads to finish */ - for (i = 0; i < NumWinThreads; i++) { - pthread_join(WinThreads[i].Thread, NULL); - } - - for (i = 0; i < NumWinThreads; i++) { - eglDestroyContext(WinThreads[i].Display, WinThreads[i].Context); - XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); - } -} - - -static void -usage(void) -{ - printf("xeglthreads: test of EGL/GL thread safety (any key = exit)\n"); - printf("Usage:\n"); - printf(" xeglthreads [options]\n"); - printf("Options:\n"); - printf(" -display DISPLAYNAME Specify display string\n"); - printf(" -n NUMTHREADS Number of threads to create\n"); - printf(" -p Use a separate display connection for each thread\n"); - printf(" -l Use application-side locking\n"); - printf(" -t Enable texturing\n"); - printf("Keyboard:\n"); - printf(" Esc Exit\n"); - printf(" t Change texture image (requires -t option)\n"); - printf(" a Toggle animation\n"); - printf(" s Step rotation (when not animating)\n"); -} - - -int -main(int argc, char *argv[]) -{ - char *displayName = NULL; - int numThreads = 2; - Display *dpy = NULL; - EGLDisplay *egl_dpy = NULL; - int i; - Status threadStat; - - if (argc == 1) { - usage(); - } - else { - int i; - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { - displayName = argv[i + 1]; - i++; - } - else if (strcmp(argv[i], "-p") == 0) { - MultiDisplays = 1; - } - else if (strcmp(argv[i], "-l") == 0) { - Locking = 1; - } - else if (strcmp(argv[i], "-t") == 0) { - Texture = 1; - } - else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { - numThreads = atoi(argv[i + 1]); - if (numThreads < 1) - numThreads = 1; - else if (numThreads > MAX_WINTHREADS) - numThreads = MAX_WINTHREADS; - i++; - } - else { - usage(); - exit(1); - } - } - } - - if (Locking) - printf("xeglthreads: Using explicit locks around Xlib calls.\n"); - else - printf("xeglthreads: No explict locking.\n"); - - if (MultiDisplays) - printf("xeglthreads: Per-thread display connections.\n"); - else - printf("xeglthreads: Single display connection.\n"); - - /* - * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. - */ - if (!MultiDisplays) { - if (!Locking) { - threadStat = XInitThreads(); - if (threadStat) { - printf("XInitThreads() returned %d (success)\n", - (int) threadStat); - } - else { - printf("XInitThreads() returned 0 " - "(failure- this program may fail)\n"); - } - } - - dpy = XOpenDisplay(displayName); - if (!dpy) { - fprintf(stderr, "Unable to open display %s\n", - XDisplayName(displayName)); - return -1; - } - egl_dpy = eglGetDisplay(dpy); - if (!egl_dpy) { - fprintf(stderr, "Unable to get EGL display\n"); - XCloseDisplay(dpy); - return -1; - } - if (!eglInitialize(egl_dpy, NULL, NULL)) { - fprintf(stderr, "Unable to initialize EGL display\n"); - return -1; - } - } - - pthread_mutex_init(&Mutex, NULL); - pthread_mutex_init(&CondMutex, NULL); - pthread_cond_init(&CondVar, NULL); - - printf("xeglthreads: creating windows\n"); - - NumWinThreads = numThreads; - - /* Create the EGL windows and contexts */ - for (i = 0; i < numThreads; i++) { - EGLContext share; - - if (MultiDisplays) { - WinThreads[i].Dpy = XOpenDisplay(displayName); - assert(WinThreads[i].Dpy); - WinThreads[i].Display = eglGetDisplay(WinThreads[i].Dpy); - assert(eglInitialize(WinThreads[i].Display, NULL, NULL)); - } - else { - WinThreads[i].Dpy = dpy; - WinThreads[i].Display = egl_dpy; - } - WinThreads[i].Index = i; - WinThreads[i].Initialized = GL_FALSE; - - share = (Texture && i > 0) ? WinThreads[0].Context : 0; - - create_window(&WinThreads[i], share); - } - - printf("xeglthreads: creating threads\n"); - - /* Create the threads */ - for (i = 0; i < numThreads; i++) { - pthread_create(&WinThreads[i].Thread, NULL, thread_function, - (void*) &WinThreads[i]); - printf("xeglthreads: Created thread %p\n", - (void *) WinThreads[i].Thread); - } - - if (MultiDisplays) - event_loop_multi(); - else - event_loop(dpy); - - clean_up(); - - if (MultiDisplays) { - for (i = 0; i < numThreads; i++) { - eglTerminate(WinThreads[i].Display); - XCloseDisplay(WinThreads[i].Dpy); - } - } - else { - eglTerminate(egl_dpy); - XCloseDisplay(dpy); - } - - return 0; -} - - -#else /* PTHREADS */ - - -#include - -int -main(int argc, char *argv[]) -{ - printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); - return 0; -} - - -#endif /* PTHREADS */ -- cgit v1.2.3 From 44bafca1a0b1e9bf06e05a3ec982e0feab5ada47 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 17 Apr 2010 15:17:33 +0100 Subject: i915g: Add a software only debuging winsys --- configure.ac | 2 + src/gallium/winsys/i915/sw/Makefile | 12 ++ src/gallium/winsys/i915/sw/SConscript | 17 +++ src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c | 157 +++++++++++++++++++++++ src/gallium/winsys/i915/sw/i915_sw_buffer.c | 116 +++++++++++++++++ src/gallium/winsys/i915/sw/i915_sw_fence.c | 58 +++++++++ src/gallium/winsys/i915/sw/i915_sw_winsys.c | 59 +++++++++ src/gallium/winsys/i915/sw/i915_sw_winsys.h | 59 +++++++++ 8 files changed, 480 insertions(+) create mode 100644 src/gallium/winsys/i915/sw/Makefile create mode 100644 src/gallium/winsys/i915/sw/SConscript create mode 100644 src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c create mode 100644 src/gallium/winsys/i915/sw/i915_sw_buffer.c create mode 100644 src/gallium/winsys/i915/sw/i915_sw_fence.c create mode 100644 src/gallium/winsys/i915/sw/i915_sw_winsys.c create mode 100644 src/gallium/winsys/i915/sw/i915_sw_winsys.h (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 5647442ea17..0e777074339 100644 --- a/configure.ac +++ b/configure.ac @@ -1359,9 +1359,11 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel="$enableval"], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965" elif test "x$enable_gallium_intel" = xauto; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" fi diff --git a/src/gallium/winsys/i915/sw/Makefile b/src/gallium/winsys/i915/sw/Makefile new file mode 100644 index 00000000000..6aab6d29614 --- /dev/null +++ b/src/gallium/winsys/i915/sw/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = i915sw + +C_SOURCES = \ + i915_sw_batchbuffer.c \ + i915_sw_buffer.c \ + i915_sw_fence.c \ + i915_sw_winsys.c + +include ../../../Makefile.template diff --git a/src/gallium/winsys/i915/sw/SConscript b/src/gallium/winsys/i915/sw/SConscript new file mode 100644 index 00000000000..84f427a128a --- /dev/null +++ b/src/gallium/winsys/i915/sw/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = env.Clone() + +i915_sw_sources = [ + 'i915_sw_batchbuffer.c', + 'i915_sw_buffer.c', + 'i915_sw_winsys.c', + 'i915_sw_fence.c', +] + +i915sw = env.ConvenienceLibrary( + target ='i915sw', + source = i915_sw_sources, +) + +Export('i915sw') diff --git a/src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c b/src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c new file mode 100644 index 00000000000..a480cfed57b --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c @@ -0,0 +1,157 @@ + +#include "i915_sw_winsys.h" +#include "i915/i915_batchbuffer.h" +#include "util/u_memory.h" + +#define BATCH_RESERVED 16 + +#define INTEL_DEFAULT_RELOCS 100 +#define INTEL_MAX_RELOCS 400 + +#define INTEL_BATCH_NO_CLIPRECTS 0x1 +#define INTEL_BATCH_CLIPRECTS 0x2 + +#define INTEL_ALWAYS_FLUSH + +struct i915_sw_batchbuffer +{ + struct i915_winsys_batchbuffer base; + + size_t actual_size; +}; + +static INLINE struct i915_sw_batchbuffer * +i915_sw_batchbuffer(struct i915_winsys_batchbuffer *batch) +{ + return (struct i915_sw_batchbuffer *)batch; +} + +static void +i915_sw_batchbuffer_reset(struct i915_sw_batchbuffer *batch) +{ + memset(batch->base.map, 0, batch->actual_size); + batch->base.ptr = batch->base.map; + batch->base.size = batch->actual_size - BATCH_RESERVED; + batch->base.relocs = 0; +} + +static struct i915_winsys_batchbuffer * +i915_sw_batchbuffer_create(struct i915_winsys *iws) +{ + struct i915_sw_winsys *isws = i915_sw_winsys(iws); + struct i915_sw_batchbuffer *batch = CALLOC_STRUCT(i915_sw_batchbuffer); + + batch->actual_size = isws->max_batch_size; + + batch->base.map = MALLOC(batch->actual_size); + batch->base.ptr = NULL; + batch->base.size = 0; + + batch->base.relocs = 0; + batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ + + batch->base.iws = iws; + + i915_sw_batchbuffer_reset(batch); + + return &batch->base; +} + +static int +i915_sw_batchbuffer_reloc(struct i915_winsys_batchbuffer *ibatch, + struct i915_winsys_buffer *buffer, + enum i915_winsys_buffer_usage usage, + unsigned pre_add) +{ + struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch); + int ret = 0; + + assert(batch->base.relocs < batch->base.max_relocs); + + if (usage == I915_USAGE_SAMPLER) { + + } else if (usage == I915_USAGE_RENDER) { + + } else if (usage == I915_USAGE_2D_TARGET) { + + } else if (usage == I915_USAGE_2D_SOURCE) { + + } else if (usage == I915_USAGE_VERTEX) { + + } else { + assert(0); + return -1; + } + + ((uint32_t*)batch->base.ptr)[0] = 0; + batch->base.ptr += 4; + + if (!ret) + batch->base.relocs++; + + return ret; +} + +static void +i915_sw_batchbuffer_flush(struct i915_winsys_batchbuffer *ibatch, + struct pipe_fence_handle **fence) +{ + struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch); + unsigned used = 0; + int i; + + assert(i915_winsys_batchbuffer_space(ibatch) >= 0); + + used = batch->base.ptr - batch->base.map; + assert((used & 3) == 0); + +#ifdef INTEL_ALWAYS_FLUSH + /* MI_FLUSH | FLUSH_MAP_CACHE */ + i915_winsys_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); + used += 4; +#endif + + if ((used & 4) == 0) { + /* MI_NOOP */ + i915_winsys_batchbuffer_dword(ibatch, 0); + } + /* MI_BATCH_BUFFER_END */ + i915_winsys_batchbuffer_dword(ibatch, (0xA<<23)); + + used = batch->base.ptr - batch->base.map; + assert((used & 4) == 0); + + if (i915_sw_winsys(ibatch->iws)->dump_cmd) { + unsigned *ptr = (unsigned *)batch->base.map; + + debug_printf("%s:\n", __func__); + for (i = 0; i < used / 4; i++, ptr++) { + debug_printf("\t%08x: %08x\n", i*4, *ptr); + } + } + + if (fence) { + ibatch->iws->fence_reference(ibatch->iws, fence, NULL); + + (*fence) = i915_sw_fence_create(); + } + + i915_sw_batchbuffer_reset(batch); +} + +static void +i915_sw_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch) +{ + struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch); + + FREE(batch->base.map); + FREE(batch); +} + +void i915_sw_winsys_init_batchbuffer_functions(struct i915_sw_winsys *isws) +{ + isws->base.batchbuffer_create = i915_sw_batchbuffer_create; + isws->base.batchbuffer_reloc = i915_sw_batchbuffer_reloc; + isws->base.batchbuffer_flush = i915_sw_batchbuffer_flush; + isws->base.batchbuffer_destroy = i915_sw_batchbuffer_destroy; +} diff --git a/src/gallium/winsys/i915/sw/i915_sw_buffer.c b/src/gallium/winsys/i915/sw/i915_sw_buffer.c new file mode 100644 index 00000000000..9a27da5e1a2 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_buffer.c @@ -0,0 +1,116 @@ + +#include "i915_sw_winsys.h" +#include "util/u_memory.h" + +static struct i915_winsys_buffer * +i915_sw_buffer_create(struct i915_winsys *iws, + unsigned size, unsigned alignment, + enum i915_winsys_buffer_type type) +{ + struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer); + char *name; + + if (!buf) + return NULL; + + if (type == I915_NEW_TEXTURE) { + name = "gallium3d_texture"; + } else if (type == I915_NEW_VERTEX) { + name = "gallium3d_vertex"; + } else if (type == I915_NEW_SCANOUT) { + name = "gallium3d_scanout"; + } else { + assert(0); + name = "gallium3d_unknown"; + } + + buf->magic = 0xDEAD1337; + buf->name = name; + buf->type = type; + buf->ptr = calloc(size, 1); + + if (!buf->ptr) + goto err; + + return (struct i915_winsys_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static int +i915_sw_buffer_set_fence_reg(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + unsigned stride, + enum i915_winsys_buffer_tile tile) +{ + struct i915_sw_buffer *buf = i915_sw_buffer(buffer); + + if (tile != I915_TILE_NONE) { + assert(buf->map_count == 0); + } + + buf->tile = tile; + + return 0; +} + +static void * +i915_sw_buffer_map(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + boolean write) +{ + struct i915_sw_buffer *buf = i915_sw_buffer(buffer); + + buf->map_count += 1; + return buf->ptr; +} + +static void +i915_sw_buffer_unmap(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + struct i915_sw_buffer *buf = i915_sw_buffer(buffer); + + buf->map_count -= 1; +} + +static int +i915_sw_buffer_write(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + size_t offset, + size_t size, + const void *data) +{ + struct i915_sw_buffer *buf = i915_sw_buffer(buffer); + + memcpy(buf->ptr + offset, data, size); + return 0; +} + +static void +i915_sw_buffer_destroy(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + struct i915_sw_buffer *buf = i915_sw_buffer(buffer); + +#ifdef DEBUG + buf->magic = 0; +#endif + + FREE(buf->ptr); + FREE(buf); +} + +void +i915_sw_winsys_init_buffer_functions(struct i915_sw_winsys *isws) +{ + isws->base.buffer_create = i915_sw_buffer_create; + isws->base.buffer_set_fence_reg = i915_sw_buffer_set_fence_reg; + isws->base.buffer_map = i915_sw_buffer_map; + isws->base.buffer_unmap = i915_sw_buffer_unmap; + isws->base.buffer_write = i915_sw_buffer_write; + isws->base.buffer_destroy = i915_sw_buffer_destroy; +} diff --git a/src/gallium/winsys/i915/sw/i915_sw_fence.c b/src/gallium/winsys/i915/sw/i915_sw_fence.c new file mode 100644 index 00000000000..4b61b2a5e30 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_fence.c @@ -0,0 +1,58 @@ + +#include "i915_sw_winsys.h" +#include "util/u_memory.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +struct i915_sw_fence +{ + struct pipe_reference reference; +}; + +struct pipe_fence_handle * +i915_sw_fence_create() +{ + struct i915_sw_fence *fence = CALLOC_STRUCT(i915_sw_fence); + + pipe_reference_init(&fence->reference, 1); + + return (struct pipe_fence_handle *)fence; +} + +static void +i915_sw_fence_reference(struct i915_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct i915_sw_fence *old = (struct i915_sw_fence *)*ptr; + struct i915_sw_fence *f = (struct i915_sw_fence *)fence; + + if (pipe_reference(&((struct i915_sw_fence *)(*ptr))->reference, &f->reference)) { + FREE(old); + } + *ptr = fence; +} + +static int +i915_sw_fence_signalled(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + assert(0); + + return 0; +} + +static int +i915_sw_fence_finish(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + return 0; +} + +void +i915_sw_winsys_init_fence_functions(struct i915_sw_winsys *isws) +{ + isws->base.fence_reference = i915_sw_fence_reference; + isws->base.fence_signalled = i915_sw_fence_signalled; + isws->base.fence_finish = i915_sw_fence_finish; +} diff --git a/src/gallium/winsys/i915/sw/i915_sw_winsys.c b/src/gallium/winsys/i915/sw/i915_sw_winsys.c new file mode 100644 index 00000000000..a95f2009dd4 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_winsys.c @@ -0,0 +1,59 @@ + +#include "i915_sw_winsys.h" +#include "util/u_memory.h" + +#include "i915/i915_context.h" +#include "i915/i915_screen.h" + + +/* + * Helper functions + */ + + +static void +i915_sw_get_device_id(unsigned int *device_id) +{ + /* just pick a i945 hw id */ + *device_id = 0x27A2; +} + +static void +i915_sw_destroy(struct i915_winsys *iws) +{ + struct i915_sw_winsys *isws = i915_sw_winsys(iws); + FREE(isws); +} + + +/* + * Exported functions + */ + + +struct pipe_screen * +i915_sw_create_screen() +{ + struct i915_sw_winsys *isws; + unsigned int deviceID; + + isws = CALLOC_STRUCT(i915_sw_winsys); + if (!isws) + return NULL; + + i915_sw_get_device_id(&deviceID); + + i915_sw_winsys_init_batchbuffer_functions(isws); + i915_sw_winsys_init_buffer_functions(isws); + i915_sw_winsys_init_fence_functions(isws); + + isws->base.destroy = i915_sw_destroy; + + isws->id = deviceID; + isws->max_batch_size = 16 * 4096; + + isws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); + + /* XXX so this will leak winsys:es */ + return i915_create_screen(&isws->base, deviceID); +} diff --git a/src/gallium/winsys/i915/sw/i915_sw_winsys.h b/src/gallium/winsys/i915/sw/i915_sw_winsys.h new file mode 100644 index 00000000000..92e7c36fd8c --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_winsys.h @@ -0,0 +1,59 @@ + +#ifndef I915_SW_WINSYS_H +#define I915_SW_WINSYS_H + +#include "i915/i915_winsys.h" + + +/* + * Winsys + */ + + +struct i915_sw_winsys +{ + struct i915_winsys base; + + boolean dump_cmd; + + unsigned id; + + size_t max_batch_size; +}; + +static INLINE struct i915_sw_winsys * +i915_sw_winsys(struct i915_winsys *iws) +{ + return (struct i915_sw_winsys *)iws; +} + +struct pipe_screen* i915_sw_create_screen(void); +struct pipe_fence_handle * i915_sw_fence_create(void); + +void i915_sw_winsys_init_batchbuffer_functions(struct i915_sw_winsys *idws); +void i915_sw_winsys_init_buffer_functions(struct i915_sw_winsys *idws); +void i915_sw_winsys_init_fence_functions(struct i915_sw_winsys *idws); + + +/* + * Buffer + */ + + +struct i915_sw_buffer { + unsigned magic; + + void *ptr; + unsigned map_count; + enum i915_winsys_buffer_type type; + enum i915_winsys_buffer_tile tile; + const char *name; +}; + +static INLINE struct i915_sw_buffer * +i915_sw_buffer(struct i915_winsys_buffer *buffer) +{ + return (struct i915_sw_buffer *)buffer; +} + +#endif -- cgit v1.2.3 From 81fe19843ac2afdc4fa1e1c87bc979b295af240e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 22 Apr 2010 14:59:29 +1000 Subject: llvmpipe: add initial autoconf support. allows the swrastg_dri.so to be built with llvmpipe, also links llvm to all dri drivers use --enable-gallium-llvm to use it. Signed-off-by: Dave Airlie --- configs/autoconf.in | 12 ++++++++++ configure.ac | 42 +++++++++++++++++++++++++++++++++++ src/gallium/Makefile.template | 2 +- src/gallium/drivers/llvmpipe/Makefile | 5 +++-- src/gallium/targets/Makefile.dri | 15 ++++++++++++- 5 files changed, 72 insertions(+), 4 deletions(-) (limited to 'configure.ac') diff --git a/configs/autoconf.in b/configs/autoconf.in index b6cc9b3b73e..3ef385a8a66 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -26,6 +26,10 @@ INTEL_LIBS = @INTEL_LIBS@ INTEL_CFLAGS = @INTEL_CFLAGS@ X11_LIBS = @X11_LIBS@ X11_CFLAGS = @X11_CFLAGS@ +LLVM_CFLAGS = @LLVM_CFLAGS@ +LLVM_LDFLAGS = @LLVM_LDFLAGS@ +LLVM_LIBS = @LLVM_LIBS@ + # Assembler MESA_ASM_SOURCES = @MESA_ASM_SOURCES@ @@ -157,3 +161,11 @@ OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@ EGL_DRI2_CFLAGS = @EGL_DRI2_CFLAGS@ EGL_DRI2_LIBS = @EGL_DRI2_LIBS@ + +MESA_LLVM = @MESA_LLVM@ + +LLVM_VERSION = @LLVM_VERSION@ +ifneq ($(LLVM_VERSION),) + HAVE_LLVM := 0x0$(subst .,0,$(LLVM_VERSION:svn=)) + DEFINES += -DHAVE_LLVM=$(HAVE_LLVM) +endif diff --git a/configure.ac b/configure.ac index 0e777074339..bcf4104515e 100644 --- a/configure.ac +++ b/configure.ac @@ -488,6 +488,7 @@ AC_SUBST([GALLIUM_TARGET_DIRS]) AC_SUBST([GALLIUM_WINSYS_DIRS]) AC_SUBST([GALLIUM_DRIVERS_DIRS]) AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS]) +AC_SUBST([MESA_LLVM]) dnl dnl User supplied program configuration @@ -1181,8 +1182,26 @@ AC_ARG_ENABLE([gallium], [enable_gallium=yes]) if test "x$enable_gallium" = xyes; then SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets" + AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"], + [HAS_UDIS86="no"]) + AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no]) + if test "x$LLVM_CONFIG" != xno; then + LLVM_VERSION=`$LLVM_CONFIG --version` + LLVM_CFLAGS=`$LLVM_CONFIG --cflags` + LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++" + + if test "x$HAS_UDIS86" != xno; then + LLVM_LIBS="$LLVM_LIBS -ludis86" + fi + LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` + fi fi +AC_SUBST([LLVM_CFLAGS]) +AC_SUBST([LLVM_LIBS]) +AC_SUBST([LLVM_LDFLAGS]) +AC_SUBST([LLVM_VERSION]) + dnl dnl Gallium state trackers configuration dnl @@ -1316,6 +1335,29 @@ AC_ARG_WITH([max-height], [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])] ) +dnl +dnl Gallium LLVM +dnl +AC_ARG_ENABLE([gallium-llvm], + [AS_HELP_STRING([--enable-gallium-llvm], + [build gallium LLVM support @<:@default=disabled@:>@])], + [enable_gallium_llvm="$enableval"], + [enable_gallium_llvm=auto]) +if test "x$enable_gallium_llvm" = xyes; then + if test "x$LLVM_CONFIG" != xno; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + DEFINES="$DEFINES -DMESA_LLVM -D__STDC_CONSTANT_MACROS" + if test "x$HAS_UDIS86" != xno; then + DEFINES="$DEFINES -DHAVE_UDIS86" + fi + MESA_LLVM=1 + else + MESA_LLVM=0 + fi +else + MESA_LLVM=0 +fi + dnl dnl Gallium helper functions dnl diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template index b5a9938c740..1ba0724949a 100644 --- a/src/gallium/Makefile.template +++ b/src/gallium/Makefile.template @@ -37,7 +37,7 @@ depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURC $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null $(PROGS): % : %.o - $(LD) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group + $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group # Emacs tags tags: diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 4a3fc036c49..7bf5b097628 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -58,8 +58,9 @@ include ../../Makefile.template lp_tile_soa.c: lp_tile_soa.py ../../auxiliary/util/u_format_parse.py ../../auxiliary/util/u_format_pack.py ../../auxiliary/util/u_format.csv python lp_tile_soa.py ../../auxiliary/util/u_format.csv > $@ - -LIBS += $(GL_LIB_DEPS) -L../../auxiliary/ -lgallium libllvmpipe.a +LDFLAGS += $(LLVM_LDFLAGS) +LIBS += $(GL_LIB_DEPS) -L../../auxiliary/ -lgallium libllvmpipe.a $(LLVM_LIBS) +LD=g++ $(PROGS): lp_test_main.o libllvmpipe.a diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri index 8efbf4e828c..3cbaf615e2f 100644 --- a/src/gallium/targets/Makefile.dri +++ b/src/gallium/targets/Makefile.dri @@ -1,5 +1,14 @@ # -*-makefile-*- +ifeq ($(MESA_LLVM),1) +DRIVER_DEFINES += -DGALLIUM_LLVMPIPE +PIPE_DRIVERS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a +LDFLAGS += $(LLVM_LDFLAGS) +LD = g++ +DRIVER_EXTRAS = $(LLVM_LIBS) +USE_CXX=1 +endif + MESA_MODULES = \ $(TOP)/src/mesa/libmesagallium.a \ $(GALLIUM_AUXILIARIES) @@ -69,7 +78,11 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ $(OBJECTS) $(PIPE_DRIVERS) \ -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) - $(CC) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) + if [ "x${USE_CXX}" == "x" ]; then \ + $(CC) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS); \ + else \ + $(CXX) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS); \ + fi @rm -f $@.test mv -f $@.tmp $@ -- cgit v1.2.3 From 22e8ddc74843b82606c1f0934ec1d4fad2ffc853 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 25 Apr 2010 07:48:48 +1000 Subject: llvm: fix configure.ac harder --- configure.ac | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index bcf4104515e..a4d9d94ff98 100644 --- a/configure.ac +++ b/configure.ac @@ -1185,16 +1185,6 @@ if test "x$enable_gallium" = xyes; then AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"], [HAS_UDIS86="no"]) AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no]) - if test "x$LLVM_CONFIG" != xno; then - LLVM_VERSION=`$LLVM_CONFIG --version` - LLVM_CFLAGS=`$LLVM_CONFIG --cflags` - LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++" - - if test "x$HAS_UDIS86" != xno; then - LLVM_LIBS="$LLVM_LIBS -ludis86" - fi - LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` - fi fi AC_SUBST([LLVM_CFLAGS]) @@ -1344,18 +1334,24 @@ AC_ARG_ENABLE([gallium-llvm], [enable_gallium_llvm="$enableval"], [enable_gallium_llvm=auto]) if test "x$enable_gallium_llvm" = xyes; then - if test "x$LLVM_CONFIG" != xno; then - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" - DEFINES="$DEFINES -DMESA_LLVM -D__STDC_CONSTANT_MACROS" - if test "x$HAS_UDIS86" != xno; then - DEFINES="$DEFINES -DHAVE_UDIS86" - fi - MESA_LLVM=1 - else - MESA_LLVM=0 + if test "x$LLVM_CONFIG" != xno; then + LLVM_VERSION=`$LLVM_CONFIG --version` + LLVM_CFLAGS=`$LLVM_CONFIG --cflags` + LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++" + + if test "x$HAS_UDIS86" != xno; then + LLVM_LIBS="$LLVM_LIBS -ludis86" + DEFINES="$DEFINES -DHAVE_UDIS86" fi -else + LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + DEFINES="$DEFINES -DMESA_LLVM -D__STDC_CONSTANT_MACROS" + MESA_LLVM=1 + else MESA_LLVM=0 + fi +else + MESA_LLVM=0 fi dnl -- cgit v1.2.3 From fbfecda6ae9cf3ccaa1cef3ea60dfec12ca6e503 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 27 Apr 2010 14:13:13 +0800 Subject: progs/egl: Add egl/eglut to PROGRAM_DIRS. Make sure eglut is built before the demos. This should work more reliably with make -j. --- configs/linux-dri | 2 +- configs/linux-egl | 2 +- configs/linux-opengl-es | 2 +- configure.ac | 2 +- progs/egl/eglut/Makefile | 5 ++++- progs/egl/opengl/Makefile | 4 ---- progs/egl/opengles1/Makefile | 4 ---- progs/egl/openvg/Makefile | 4 ---- 8 files changed, 8 insertions(+), 17 deletions(-) (limited to 'configure.ac') diff --git a/configs/linux-dri b/configs/linux-dri index 9017becdafe..49e35790463 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -52,7 +52,7 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ # Directories SRC_DIRS := glx egl $(SRC_DIRS) -PROGRAM_DIRS := egl/opengl $(PROGRAM_DIRS) +PROGRAM_DIRS := egl/eglut egl/opengl $(PROGRAM_DIRS) # EGL directories EGL_DRIVERS_DIRS = glx diff --git a/configs/linux-egl b/configs/linux-egl index cd664b4171f..566c7b941c6 100644 --- a/configs/linux-egl +++ b/configs/linux-egl @@ -48,7 +48,7 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ # Directories SRC_DIRS = gallium mesa gallium/winsys gallium/targets glu egl -PROGRAM_DIRS = egl/opengl +PROGRAM_DIRS = egl/eglut egl/opengl DRIVER_DIRS = dri GALLIUM_WINSYS_DIRS = egl_drm diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es index ead47136f4a..6984aa9b2cd 100644 --- a/configs/linux-opengl-es +++ b/configs/linux-opengl-es @@ -7,7 +7,7 @@ CONFIG_NAME = linux-opengl-es # Directories to build LIB_DIR = lib SRC_DIRS = egl glsl mesa/es gallium gallium/winsys gallium/targets -PROGRAM_DIRS = egl/opengles1 egl/opengles2 +PROGRAM_DIRS = egl/eglut egl/opengles1 egl/opengles2 # egl st needs this DEFINES += -DGLX_DIRECT_RENDERING diff --git a/configure.ac b/configure.ac index a4d9d94ff98..53425631521 100644 --- a/configure.ac +++ b/configure.ac @@ -955,7 +955,7 @@ if test "x$enable_egl" = xyes; then fi if test "$with_demos" = yes; then - PROGRAM_DIRS="$PROGRAM_DIRS egl/opengl" + PROGRAM_DIRS="$PROGRAM_DIRS egl/eglut egl/opengl" fi fi AC_SUBST([EGL_LIB_DEPS]) diff --git a/progs/egl/eglut/Makefile b/progs/egl/eglut/Makefile index dec89117bb9..364f5b0be3d 100644 --- a/progs/egl/eglut/Makefile +++ b/progs/egl/eglut/Makefile @@ -7,7 +7,10 @@ INCLUDES = \ -I$(TOP)/include \ $(X11_CFLAGS) -SOURCES = $(wildcard *.c) +SOURCES = \ + eglut.c \ + eglut_screen.c \ + eglut_x11.c EGLUT_X11_OBJECTS = eglut.o eglut_x11.o EGLUT_SCREEN_OBJECTS = eglut.o eglut_screen.o diff --git a/progs/egl/opengl/Makefile b/progs/egl/opengl/Makefile index 20158b1f0bc..79cd5fc6533 100644 --- a/progs/egl/opengl/Makefile +++ b/progs/egl/opengl/Makefile @@ -62,9 +62,6 @@ xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) -$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: - @$(MAKE) -C $(EGLUT_DIR) - # define the rules for EGLUT demos define eglut-demo-rule $(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(LIB_DEP) @@ -80,4 +77,3 @@ $(EGLUT_SCREEN_DEMOS): clean: -rm -f *.o *~ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) - @$(MAKE) -C $(EGLUT_DIR) clean diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile index ba9d1b84d5f..593145d4bf2 100644 --- a/progs/egl/opengles1/Makefile +++ b/progs/egl/opengles1/Makefile @@ -81,9 +81,6 @@ two_win: two_win.o $(ES1_LIB_DEPS) $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@ -$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: - @$(MAKE) -C $(EGLUT_DIR) - # define the rules for EGLUT demos define eglut-demo-rule $(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS) @@ -100,4 +97,3 @@ $(EGLUT_SCREEN_DEMOS): clean: -rm -f *.o *~ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) - @$(MAKE) -C $(EGLUT_DIR) clean diff --git a/progs/egl/openvg/Makefile b/progs/egl/openvg/Makefile index 431341c8a3f..3b11933db26 100644 --- a/progs/egl/openvg/Makefile +++ b/progs/egl/openvg/Makefile @@ -34,9 +34,6 @@ lion_screen: lion.o lion-render.o $(EGLUT_DIR)/libeglut-screen.a -L$(EGLUT_DIR) -leglut-screen $(VG_LIBS) -$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: - @$(MAKE) -C $(EGLUT_DIR) - # define the rules for EGLUT demos define eglut-demo-rule $(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a @@ -52,4 +49,3 @@ $(EGLUT_SCREEN_DEMOS): clean: rm -f *.o *~ rm -f $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) - @$(MAKE) -C $(EGLUT_DIR) clean -- cgit v1.2.3 From fe0fe67aafbb2283895dfebd76c9e99db955e73c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 28 Apr 2010 13:38:58 +0100 Subject: configure.ac: Print some llvm info --- configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 53425631521..01ed1b3cd31 100644 --- a/configure.ac +++ b/configure.ac @@ -1499,6 +1499,15 @@ fi fi echo " Use XCB: $enable_xcb" +echo "" +if test "x$MESA_LLVM" == x1; then + echo " llvm: yes" + echo " llvm-config: $LLVM_CONFIG" + echo " llvm-version: $LLVM_VERSION" +else + echo " llvm: no" +fi + echo "" if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then echo " Gallium: yes" -- cgit v1.2.3